Skip to content

Commit

Permalink
fixed duplicate search result of the selected parent:child tag
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Dec 1, 2023
1 parent dad6391 commit e0d34b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ function getTagsOptions(tags) {
/**
* Build the section list for tags
*
* @param {Object[]} rawTags
* @param {Object[]} tags
* @param {String} tags[].name
* @param {Boolean} tags[].enabled
* @param {String[]} recentlyUsedTags
Expand All @@ -934,14 +934,8 @@ function getTagsOptions(tags) {
* @param {Number} maxRecentReportsToShow
* @returns {Array<Object>}
*/
function getTagListSections(rawTags, recentlyUsedTags, selectedOptions, searchInputValue, maxRecentReportsToShow) {
function getTagListSections(tags, recentlyUsedTags, selectedOptions, searchInputValue, maxRecentReportsToShow) {
const tagSections = [];
const tags = _.map(rawTags, (tag) => {
// This is to remove unnecessary escaping backslash in tag name sent from backend.
const tagName = tag.name && tag.name.replace(/\\{1,2}:/g, ':');

return {...tag, name: tagName};
});
const sortedTags = sortTags(tags);
const enabledTags = _.filter(sortedTags, (tag) => tag.enabled);
const numberOfTags = _.size(enabledTags);
Expand Down
18 changes: 14 additions & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Str from 'expensify-common/lib/str';
import {cloneDeep} from 'lodash';
import {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {PersonalDetails, Policy, PolicyMembers, PolicyTag, PolicyTags} from '@src/types/onyx';
import {PersonalDetails, Policy, PolicyMembers, PolicyTags} from '@src/types/onyx';
import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';

type MemberEmailsToAccountIDs = Record<string, number>;
Expand Down Expand Up @@ -158,7 +159,7 @@ function getIneligibleInvitees(policyMembers: OnyxEntry<PolicyMembers>, personal
/**
* Gets the tag from policy tags, defaults to the first if no key is provided.
*/
function getTag(policyTags: OnyxEntry<PolicyTags>, tagKey?: keyof typeof policyTags): PolicyTag | undefined | EmptyObject {
function getTag(policyTags: OnyxCollection<PolicyTags>, tagKey?: keyof typeof policyTags): PolicyTags | undefined | EmptyObject {
if (isEmptyObject(policyTags)) {
return {};
}
Expand All @@ -171,7 +172,7 @@ function getTag(policyTags: OnyxEntry<PolicyTags>, tagKey?: keyof typeof policyT
/**
* Gets the first tag name from policy tags.
*/
function getTagListName(policyTags: OnyxEntry<PolicyTags>) {
function getTagListName(policyTags: OnyxCollection<PolicyTags>) {
if (Object.keys(policyTags ?? {})?.length === 0) {
return '';
}
Expand All @@ -190,8 +191,17 @@ function getTagList(policyTags: OnyxCollection<PolicyTags>, tagKey: string) {
}

const policyTagKey = tagKey ?? Object.keys(policyTags ?? {})[0];
const tags = cloneDeep(policyTags?.[policyTagKey]?.tags ?? {});

return policyTags?.[policyTagKey]?.tags ?? {};
// This is to remove unnecessary escaping backslash in tag name sent from backend for "Parent: Child" type of tags.
Object.keys(tags).forEach((key) => {
const cleanedTagName = tags[key]?.name?.replace(/\\{1,2}:/g, ':');
if (cleanedTagName) {
tags[key].name = cleanedTagName;
}
});

return tags;
}

function isPendingDeletePolicy(policy: OnyxEntry<Policy>): boolean {
Expand Down
6 changes: 5 additions & 1 deletion src/types/onyx/PolicyTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ type PolicyTag = {
'GL Code': string;
};

type PolicyTags = Record<string, PolicyTag>;
type PolicyTags = {
name: string;
required: boolean;
tags: Record<string, PolicyTag>;
};

export default PolicyTag;
export type {PolicyTags};

0 comments on commit e0d34b8

Please sign in to comment.