-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix The tag and category lists lack consistent alphabetical order #45236
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
Changes from 5 commits
fa5f408
9b7a14b
8027861
b16268e
932b6b8
83085ce
fa58232
2a57a74
deb54bc
28fc5de
4d06761
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -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 & { | ||
|
@@ -59,6 +61,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { | |
const backTo = route.params?.backTo; | ||
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyId}`); | ||
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); | ||
const sortedPolicyCategories = lodashSortBy(Object.values(policyCategories ?? {}), 'name', localeCompare) as PolicyCategory[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason to sort this outside useMemo @dominictb ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gentle bump @dominictb There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do it for easier readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can put this as it is, inside usememo, just so it is memoized we dont sort on every render There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ishpaul777 I updated |
||
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; | ||
const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); | ||
|
||
|
@@ -83,21 +86,19 @@ 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')} />, | ||
}; | ||
}), | ||
[policyCategories, selectedCategories, translate], | ||
sortedPolicyCategories.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')} />, | ||
}; | ||
}), | ||
[sortedPolicyCategories, selectedCategories, translate], | ||
); | ||
|
||
const toggleCategory = (category: PolicyOption) => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.