Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Taxes - App allows deleted tax rate to be selected as currency default in offline mode. #42620

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function RadioListItem<TItem extends ListItem>({
keyForList={item.keyForList}
onFocus={onFocus}
shouldSyncFocus={shouldSyncFocus}
pendingAction={item.pendingAction}
>
<>
<View style={[styles.flex1, styles.alignItemsStart]}>
Expand Down
2 changes: 2 additions & 0 deletions src/components/TagPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import type * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTag, PolicyTagList, PolicyTags, RecentlyUsedTags} from '@src/types/onyx';
import type {PendingAction} from '@src/types/onyx/OnyxCommon';

type SelectedTagOption = {
name: string;
enabled: boolean;
isSelected?: boolean;
accountID: number | undefined;
pendingAction?: PendingAction;
};

type TagPickerOnyxProps = {
Expand Down
30 changes: 21 additions & 9 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type OptionTree = {
tooltipText: string;
isDisabled: boolean;
isSelected: boolean;
pendingAction?: OnyxCommon.PendingAction;
} & Option;

type PayeePersonalDetails = {
Expand Down Expand Up @@ -106,6 +107,7 @@ type TaxRatesOption = {
isDisabled?: boolean;
keyForList?: string;
isSelected?: boolean;
pendingAction?: OnyxCommon.PendingAction;
};

type TaxSection = {
Expand All @@ -123,6 +125,7 @@ type Category = {
name: string;
enabled: boolean;
isSelected?: boolean;
pendingAction?: OnyxCommon.PendingAction;
};

type Tax = {
Expand Down Expand Up @@ -952,6 +955,7 @@ function sortCategories(categories: Record<string, Category>): Category[] {
lodashSet(hierarchy, path, {
...existedValue,
name: category.name,
pendingAction: category.pendingAction,
});
});

Expand All @@ -962,10 +966,11 @@ function sortCategories(categories: Record<string, Category>): Category[] {
*/
const flatHierarchy = (initialHierarchy: Hierarchy) =>
Object.values(initialHierarchy).reduce((acc: Category[], category) => {
const {name, ...subcategories} = category;
const {name, pendingAction, ...subcategories} = category;
if (name) {
const categoryObject: Category = {
name,
pendingAction,
enabled: categories[name]?.enabled ?? false,
};

Expand Down Expand Up @@ -1015,8 +1020,9 @@ function getCategoryOptionTree(options: Record<string, Category> | Category[], i
keyForList: option.name,
searchText: option.name,
tooltipText: option.name,
isDisabled: !option.enabled,
isDisabled: !option.enabled || option.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
isSelected: !!option.isSelected,
pendingAction: option.pendingAction,
});

return;
Expand All @@ -1036,8 +1042,9 @@ function getCategoryOptionTree(options: Record<string, Category> | Category[], i
keyForList: searchText,
searchText,
tooltipText: optionName,
isDisabled: isChild ? !option.enabled : true,
isDisabled: isChild ? !option.enabled || option.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE : true,
isSelected: isChild ? !!option.isSelected : selectedOptionsName.includes(searchText),
pendingAction: option.pendingAction,
});
});
});
Expand Down Expand Up @@ -1137,7 +1144,10 @@ function getCategoryListSections(
}

const filteredRecentlyUsedCategories = recentlyUsedCategories
.filter((categoryName) => !selectedOptionNames.includes(categoryName) && categories[categoryName]?.enabled)
.filter(
(categoryName) =>
!selectedOptionNames.includes(categoryName) && categories[categoryName]?.enabled && categories[categoryName]?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
)
.map((categoryName) => ({
name: categoryName,
enabled: categories[categoryName].enabled ?? false,
Expand Down Expand Up @@ -1173,7 +1183,7 @@ function getCategoryListSections(
*
* @param tags - an initial tag array
*/
function getTagsOptions(tags: Array<Pick<PolicyTag, 'name' | 'enabled'>>, selectedOptions?: SelectedTagOption[]): Option[] {
function getTagsOptions(tags: Array<Pick<PolicyTag, 'name' | 'enabled' | 'pendingAction'>>, selectedOptions?: SelectedTagOption[]): Option[] {
return tags.map((tag) => {
// This is to remove unnecessary escaping backslash in tag name sent from backend.
const cleanedName = PolicyUtils.getCleanedTagName(tag.name);
Expand All @@ -1182,8 +1192,9 @@ function getTagsOptions(tags: Array<Pick<PolicyTag, 'name' | 'enabled'>>, select
keyForList: tag.name,
searchText: tag.name,
tooltipText: cleanedName,
isDisabled: !tag.enabled,
isDisabled: !tag.enabled || tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
isSelected: selectedOptions?.some((selectedTag) => selectedTag.name === tag.name),
pendingAction: tag.pendingAction,
};
});
}
Expand Down Expand Up @@ -1256,7 +1267,7 @@ function getTagListSections(
const filteredRecentlyUsedTags = recentlyUsedTags
.filter((recentlyUsedTag) => {
const tagObject = tags.find((tag) => tag.name === recentlyUsedTag);
return !!tagObject?.enabled && !selectedOptionNames.includes(recentlyUsedTag);
return !!tagObject?.enabled && !selectedOptionNames.includes(recentlyUsedTag) && tagObject?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
})
.map((tag) => ({name: tag, enabled: true}));

Expand Down Expand Up @@ -1386,14 +1397,15 @@ function sortTaxRates(taxRates: TaxRates): TaxRate[] {
* Builds the options for taxRates
*/
function getTaxRatesOptions(taxRates: Array<Partial<TaxRate>>): TaxRatesOption[] {
return taxRates.map(({code, modifiedName, isDisabled, isSelected}) => ({
return taxRates.map(({code, modifiedName, isDisabled, isSelected, pendingAction}) => ({
code,
text: modifiedName,
keyForList: modifiedName,
searchText: modifiedName,
tooltipText: modifiedName,
isDisabled,
isDisabled: !!isDisabled || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
isSelected,
pendingAction,
}));
}

Expand Down
Loading
Loading