Skip to content

Commit

Permalink
Merge pull request #42620 from Krishna2323/krishna2323/issue/41066
Browse files Browse the repository at this point in the history
fix: Taxes - App allows deleted tax rate to be selected as currency default in offline mode.
  • Loading branch information
Beamanator authored May 29, 2024
2 parents e177a69 + 26a0c3d commit 53f9e57
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 16 deletions.
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 @@ -78,6 +78,7 @@ type OptionTree = {
tooltipText: string;
isDisabled: boolean;
isSelected: boolean;
pendingAction?: OnyxCommon.PendingAction;
} & Option;

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

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

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

Expand All @@ -958,10 +962,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 @@ -1011,8 +1016,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 @@ -1032,8 +1038,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 @@ -1133,7 +1140,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 @@ -1169,7 +1179,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 @@ -1178,8 +1188,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 @@ -1252,7 +1263,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 @@ -1382,14 +1393,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

0 comments on commit 53f9e57

Please sign in to comment.