Skip to content

Commit

Permalink
Merge pull request #45236 from dominictb/fix/44922
Browse files Browse the repository at this point in the history
fix The tag and category lists lack consistent alphabetical order
  • Loading branch information
chiragsalian authored Jul 22, 2024
2 parents 2c99d8b + 4d06761 commit 757a6ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
28 changes: 14 additions & 14 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import lodashSortBy from 'lodash/sortBy';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -37,6 +38,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {PolicyCategory} from '@src/types/onyx';
import type DeepValueOf from '@src/types/utils/DeepValueOf';

type PolicyOption = ListItem & {
Expand Down Expand Up @@ -83,20 +85,18 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {

const categoryList = useMemo<PolicyOption[]>(
() =>
Object.values(policyCategories ?? {})
.sort((a, b) => localeCompare(a.name, b.name))
.map((value) => {
const isDisabled = value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
return {
text: value.name,
keyForList: value.name,
isSelected: !!selectedCategories[value.name],
isDisabled,
pendingAction: value.pendingAction,
errors: value.errors ?? undefined,
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
};
}),
(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],
isDisabled,
pendingAction: value.pendingAction,
errors: value.errors ?? undefined,
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
};
}),
[policyCategories, selectedCategories, translate],
);

Expand Down
26 changes: 13 additions & 13 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import type {StackScreenProps} from '@react-navigation/stack';
import lodashSortBy from 'lodash/sortBy';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -101,19 +102,18 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
),
}));
}
return Object.values(policyTagLists[0]?.tags ?? {})
.sort((tagA, tagB) => localeCompare(tagA.name, tagB.name))
.map((tag) => ({
value: tag.name,
text: PolicyUtils.getCleanedTagName(tag.name),
keyForList: tag.name,
isSelected: selectedTags[tag.name],
pendingAction: tag.pendingAction,
errors: tag.errors ?? undefined,
enabled: tag.enabled,
isDisabled: tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
rightElement: <ListItemRightCaretWithLabel labelText={tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
}));
const sortedTags = lodashSortBy(Object.values(policyTagLists[0]?.tags ?? {}), 'name', localeCompare) as PolicyTag[];
return sortedTags.map((tag) => ({
value: tag.name,
text: PolicyUtils.getCleanedTagName(tag.name),
keyForList: tag.name,
isSelected: selectedTags[tag.name],
pendingAction: tag.pendingAction,
errors: tag.errors ?? undefined,
enabled: tag.enabled,
isDisabled: tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
rightElement: <ListItemRightCaretWithLabel labelText={tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
}));
}, [isMultiLevelTags, policyTagLists, selectedTags, translate]);

const tagListKeyedByName = useMemo(
Expand Down

0 comments on commit 757a6ac

Please sign in to comment.