Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type MoneyReportHeaderSecondaryActionsProps = {
primaryAction: ValueOf<typeof CONST.REPORT.PRIMARY_ACTIONS> | '';
isReportInSearch?: boolean;
backTo?: Route;
dropdownMenuRef?: React.RefObject<ButtonWithDropdownMenuRef>;
dropdownMenuRef?: React.RefObject<ButtonWithDropdownMenuRef | null>;
/** Disables the "More" dropdown, e.g. while expenses are selected */
isDisabled?: boolean;
};
Expand Down
7 changes: 2 additions & 5 deletions src/components/MoneyReportHeaderActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ import MoneyReportHeaderSelectionDropdown from './MoneyReportHeaderSelectionDrop
* TRANSACTION_PRIMARY_ACTIONS values (e.g. "keepThisOne") are irrelevant here.
*/
function narrowPrimaryAction(primaryAction: MoneyReportHeaderActionsProps['primaryAction']): ValueOf<typeof CONST.REPORT.PRIMARY_ACTIONS> | '' {
if ((Object.values(CONST.REPORT.PRIMARY_ACTIONS) as string[]).includes(primaryAction)) {
return primaryAction as ValueOf<typeof CONST.REPORT.PRIMARY_ACTIONS>;
}
return '';
return Object.values(CONST.REPORT.PRIMARY_ACTIONS).find((action) => action === primaryAction) ?? '';
}

function MoneyReportHeaderActions({reportID, primaryAction, isReportInSearch, backTo}: MoneyReportHeaderActionsProps) {
const styles = useThemeStyles();
const {pageGutter} = useLayoutSpacing();
const dropdownMenuRef = useRef<ButtonWithDropdownMenuRef>(null) as React.RefObject<ButtonWithDropdownMenuRef>;
const dropdownMenuRef = useRef<ButtonWithDropdownMenuRef>(null);

const {shouldUseNarrowLayout, isMediumScreenWidth, isInLandscapeMode} = useResponsiveLayout();
const shouldDisplayNarrowVersion = shouldUseNarrowLayout || isMediumScreenWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ const displayAddress = (street: string, city: string, state: string, zipCode: st
return country === CONST.COUNTRY.US || country === CONST.COUNTRY.CA ? `${street}, ${city}, ${state}, ${zipCode}, ${country}` : `${street}, ${city}, ${zipCode}, ${country}`;
};

// The saved form values are plain strings, so read the code maps through string-keyed views.
const countryNames: Partial<Record<string, string>> = CONST.ALL_COUNTRIES;
const stateNames: Partial<Record<string, {stateName: string}>> = COMMON_CONST.STATES;
const provinceNames: Partial<Record<string, {provinceName: string}>> = COMMON_CONST.PROVINCES;

const displayIncorporationLocation = (country: string, state: string) => {
const countryFullName = CONST.ALL_COUNTRIES[country as keyof typeof CONST.COUNTRY];
const stateFullName = COMMON_CONST.STATES[state as keyof typeof COMMON_CONST.STATES]?.stateName ?? COMMON_CONST.PROVINCES[state as keyof typeof COMMON_CONST.PROVINCES]?.provinceName;
const countryFullName = countryNames[country];
const stateFullName = stateNames[state]?.stateName ?? provinceNames[state]?.provinceName;

return country === CONST.COUNTRY.US || country === CONST.COUNTRY.CA ? `${stateFullName}, ${countryFullName}` : `${countryFullName}`;
};
Expand Down
19 changes: 15 additions & 4 deletions src/pages/inbox/cleanStaleReportActionBackToParam.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import navigationRef from '@libs/Navigation/navigationRef';

import type {NavigationState} from '@react-navigation/native';
import type {Route} from '@react-navigation/native';

import {CommonActions} from '@react-navigation/native';

/** The parts of a navigation state that the walk reads. Nested states can be partial, so their keys are optional. */
type RouteView = {
key?: string;
params?: Route<string>['params'];
state?: {
key?: string;
routes: readonly RouteView[];
};
};

/**
* Cleans stale reportActionID from `backTo` params on sibling routes.
*
Expand All @@ -24,9 +34,10 @@ function cleanStaleReportActionBackToParam(reportID: string, reportActionID: str
const cleanSegment = `r/${reportID}`;
const stalePattern = new RegExp(`${staleSegment}(?=[?/]|$)`);

function walk(routes: NavigationState['routes'], navigatorKey?: string) {
function walk(routes: readonly RouteView[], navigatorKey?: string) {
for (const route of routes) {
const backTo = (route.params as Record<string, unknown> | undefined)?.backTo;
// Each screen has its own params, so check for `backTo` itself.
const backTo = route.params && 'backTo' in route.params ? route.params.backTo : undefined;
if (typeof backTo === 'string' && stalePattern.test(backTo)) {
navigationRef.current?.dispatch({
...CommonActions.setParams({backTo: backTo.replace(stalePattern, cleanSegment)}),
Expand All @@ -35,7 +46,7 @@ function cleanStaleReportActionBackToParam(reportID: string, reportActionID: str
});
}
if (route.state?.routes) {
walk(route.state.routes as NavigationState['routes'], (route.state as NavigationState).key);
walk(route.state.routes, route.state.key);
}
}
}
Expand Down
53 changes: 13 additions & 40 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ function getPendingAction(policyTagList: PolicyTagList): PendingAction | undefin
if (!policyTagList) {
return undefined;
}
return ((policyTagList.pendingAction as PendingAction) ?? Object.values(policyTagList.tags).some((tag: PolicyTag) => tag.pendingAction))
? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE
: undefined;
return (policyTagList.pendingAction ?? Object.values(policyTagList.tags).some((tag: PolicyTag) => tag.pendingAction)) ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : undefined;
}

/** Tag list names can repeat, so add the unique orderWeight to make each multi-level row key unique. */
Expand Down Expand Up @@ -181,12 +179,8 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const canSelectMultiple = isSelectionEnabled && (shouldUseNarrowLayout ? isMobileSelectionModeEnabled : true);
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_ROOT;

const tagsList = isMultiLevelTags
? policyTagLists.reduce<Record<string, PolicyTagList>>((acc, policyTagList) => {
acc[getTagListRowKey(policyTagList)] = policyTagList;
return acc;
}, {})
: policyTagLists?.at(0)?.tags;
// Only single-level tags can be selected (see `isSelectionEnabled`), so only their tags are needed to update the selection.
const singleLevelTags = policyTagLists.at(0)?.tags;

const updateWorkspaceRequiresTag = (value: boolean, orderWeight: number) => {
if (!canWriteTags) {
Expand All @@ -206,45 +200,24 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const newSelectedTags = [];

for (const tagName of prevSelectedTags) {
if (isMultiLevelTags) {
const tagListExists = tagsList?.[tagName];
if (!tagListExists) {
const renamedTagList = Object.entries(tagsList ?? {}).find(([, tagList]) => {
const typedTagList = tagList as {previousTagName?: string};
return typedTagList.previousTagName === tagName;
});
if (renamedTagList) {
newSelectedTags.push(renamedTagList[0]);
continue;
}
}

if (tagListExists && tagListExists.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
newSelectedTags.push(tagName);
}
} else {
const tagExists = tagsList?.[tagName];
if (!tagExists) {
const renamedTag = Object.entries(tagsList ?? {}).find(([, tag]) => {
const typedTag = tag as {previousTagName?: string};
return typedTag.previousTagName === tagName;
});
if (renamedTag) {
newSelectedTags.push(renamedTag[0]);
continue;
}
const tagExists = singleLevelTags?.[tagName];
if (!tagExists) {
const renamedTag = Object.entries(singleLevelTags ?? {}).find(([, tag]) => tag.previousTagName === tagName);
if (renamedTag) {
newSelectedTags.push(renamedTag[0]);
continue;
}
}

if (tagExists && tagExists.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
newSelectedTags.push(tagName);
}
if (tagExists && tagExists.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
newSelectedTags.push(tagName);
}
}

return newSelectedTags;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tagsList]);
}, [singleLevelTags]);

useEffect(() => {
if (!canWriteTags || !isMultiLevelTags || hasDependentTags) {
Expand Down
Loading