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

Filter deleted workspace categories #54613

Merged
Merged
Changes from 2 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
30 changes: 16 additions & 14 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
const [deleteCategoriesConfirmModalVisible, setDeleteCategoriesConfirmModalVisible] = useState(false);
const isFocused = useIsFocused();
const {environmentURL} = useEnvironment();
const policyId = route.params.policyID ?? '-1';
const policyId = route.params.policyID;
const backTo = route.params?.backTo;
const policy = usePolicy(policyId);
const {selectionMode} = useMobileSelectionMode();
Expand Down Expand Up @@ -107,19 +107,21 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {

const categoryList = useMemo<PolicyOption[]>(
() =>
(lodashSortBy(Object.values(policyCategories ?? {}), 'name', localeCompare) as PolicyCategory[]).map((value) => {
const isDisabled = value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
return {
text: value.name,
keyForList: value.name,
isSelected: !!selectedCategories[value.name] && canSelectMultiple,
isDisabled,
pendingAction: value.pendingAction,
errors: value.errors ?? undefined,
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
};
}),
[policyCategories, selectedCategories, canSelectMultiple, translate],
(lodashSortBy(Object.values(policyCategories ?? {}), 'name', localeCompare) as PolicyCategory[])
.filter((value) => (isOffline ? value : value.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE))
.map((value) => {
const isDisabled = value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
return {
text: value.name,
keyForList: value.name,
isSelected: !!selectedCategories[value.name] && canSelectMultiple,
isDisabled,
pendingAction: value.pendingAction,
errors: value.errors ?? undefined,
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
};
}),
[policyCategories, isOffline, selectedCategories, canSelectMultiple, translate],
Copy link
Contributor

@ZhenjaHorbach ZhenjaHorbach Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment
but maybe we should use reduce instead filter+map to decrease the number of operations and increase performance a bit?

    const categoryList = useMemo<PolicyOption[]>(
        () =>
            (lodashSortBy(Object.values(policyCategories ?? {}), 'name', localeCompare) as PolicyCategory[]).reduce((acc, value) => {
                const isDeleted = value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

                if (!isOffline && isDeleted) {
                    return acc;
                }

                acc.push({
                    text: value.name,
                    keyForList: value.name,
                    isSelected: !!selectedCategories[value.name] && canSelectMultiple,
                    isDisabled: isDeleted,
                    pendingAction: value.pendingAction,
                    errors: value.errors ?? undefined,
                    rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
                });

                return acc;
            }, [] as PolicyOption[]),
        [policyCategories, isOffline, selectedCategories, canSelectMultiple, translate],
    );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZhenjaHorbach I've addressed both of your comments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice
Thanks !

);

useAutoTurnSelectionModeOffWhenHasNoActiveOption(categoryList);
Expand Down
Loading