Skip to content

Commit 0e378f9

Browse files
committed
Fix - Tapping on sub projects tag directs to hmm not here
1 parent 755b505 commit 0e378f9

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/libs/PolicyUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,23 @@ function getTagList(policyTagList: OnyxEntry<PolicyTagLists>, tagIndex: number):
412412
);
413413
}
414414

415+
/**
416+
* Gets a tag list of a policy by a tag's orderWeight.
417+
*/
418+
function getTagListByOrderWeight(policyTagList: OnyxEntry<PolicyTagLists>, orderWeight: number): ValueOf<PolicyTagLists> {
419+
const tagListEmpty = {
420+
name: '',
421+
required: false,
422+
tags: {},
423+
orderWeight: 0,
424+
};
425+
if (isEmptyObject(policyTagList)) {
426+
return tagListEmpty;
427+
}
428+
429+
return Object.values(policyTagList).find((tag) => tag.orderWeight === orderWeight) ?? tagListEmpty;
430+
}
431+
415432
function getTagNamesFromTagsLists(policyTagLists: PolicyTagLists): string[] {
416433
const uniqueTagNames = new Set<string>();
417434

@@ -1463,6 +1480,7 @@ export {
14631480
getPolicyEmployeeListByIdWithoutCurrentUser,
14641481
getSortedTagKeys,
14651482
getTagList,
1483+
getTagListByOrderWeight,
14661484
getTagListName,
14671485
getTagLists,
14681486
getTaxByID,

src/pages/workspace/tags/EditTagPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import useOnyx from '@hooks/useOnyx';
1212
import useThemeStyles from '@hooks/useThemeStyles';
1313
import Navigation from '@libs/Navigation/Navigation';
1414
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
15-
import {escapeTagName, getCleanedTagName, getTagList} from '@libs/PolicyUtils';
15+
import {escapeTagName, getCleanedTagName, getTagListByOrderWeight} from '@libs/PolicyUtils';
1616
import {isRequiredFulfilled} from '@libs/ValidationUtils';
1717
import type {SettingsNavigatorParamList} from '@navigation/types';
1818
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
@@ -42,7 +42,7 @@ function EditTagPage({route}: EditTagPageProps) {
4242
const errors: FormInputErrors<typeof ONYXKEYS.FORMS.WORKSPACE_TAG_FORM> = {};
4343
const tagName = values.tagName.trim();
4444
const escapedTagName = escapeTagName(values.tagName.trim());
45-
const {tags} = getTagList(policyTags, route.params.orderWeight);
45+
const {tags} = getTagListByOrderWeight(policyTags, route.params.orderWeight);
4646
if (!isRequiredFulfilled(tagName)) {
4747
errors.tagName = translate('workspace.tags.tagRequiredError');
4848
} else if (escapedTagName === '0') {

src/pages/workspace/tags/TagGLCodePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import usePolicy from '@hooks/usePolicy';
1212
import useThemeStyles from '@hooks/useThemeStyles';
1313
import Navigation from '@libs/Navigation/Navigation';
1414
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
15-
import {getTagList, hasAccountingConnections} from '@libs/PolicyUtils';
15+
import {getTagListByOrderWeight, hasAccountingConnections} from '@libs/PolicyUtils';
1616
import type {SettingsNavigatorParamList} from '@navigation/types';
1717
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
1818
import {setPolicyTagGLCode} from '@userActions/Policy/Tag';
@@ -37,7 +37,7 @@ function TagGLCodePage({route}: EditTagGLCodePageProps) {
3737

3838
const tagName = route.params.tagName;
3939
const orderWeight = route.params.orderWeight;
40-
const {tags} = getTagList(policyTags, orderWeight);
40+
const {tags} = getTagListByOrderWeight(policyTags, orderWeight);
4141
const glCode = tags?.[route.params.tagName]?.['GL Code'];
4242
const isQuickSettingsFlow = route.name === SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE;
4343

src/pages/workspace/tags/TagSettingsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
2222
import {
2323
getCleanedTagName,
2424
getTagApproverRule,
25-
getTagList,
25+
getTagListByOrderWeight,
2626
getWorkflowApprovalsUnavailable,
2727
hasAccountingConnections as hasAccountingConnectionsPolicyUtils,
2828
hasDependentTags as hasDependentTagsPolicyUtils,
@@ -47,7 +47,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) {
4747
const {orderWeight, policyID, tagName, backTo, parentTagsFilter} = route.params;
4848
const styles = useThemeStyles();
4949
const {translate} = useLocalize();
50-
const policyTag = useMemo(() => getTagList(policyTags, orderWeight), [policyTags, orderWeight]);
50+
const policyTag = useMemo(() => getTagListByOrderWeight(policyTags, orderWeight), [policyTags, orderWeight]);
5151
const policy = usePolicy(policyID);
5252
const hasAccountingConnections = hasAccountingConnectionsPolicyUtils(policy);
5353
const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false);

0 commit comments

Comments
 (0)