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

fixed duplicate search result of the selected parent:child tag #32365

Merged
merged 17 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
{shouldShowTags && (
<MenuItemWithTopDescription
shouldShowRightIcon={!isReadOnly}
title={iouTag}
title={PolicyUtils.unescapeColon(iouTag)}
description={policyTagListName}
numberOfLinesTitle={2}
onPress={() =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
<OfflineWithFeedback pendingAction={lodashGet(transaction, 'pendingFields.tag') || lodashGet(transaction, 'pendingAction')}>
<MenuItemWithTopDescription
description={lodashGet(policyTag, 'name', translate('common.tag'))}
title={transactionTag}
title={PolicyUtils.unescapeColon(transactionTag)}
interactive={canEdit}
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
Expand Down
31 changes: 15 additions & 16 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Navigation from './Navigation/Navigation';
import Permissions from './Permissions';
import * as PersonalDetailsUtils from './PersonalDetailsUtils';
import * as PhoneNumber from './PhoneNumber';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import * as TaskUtils from './TaskUtils';
Expand Down Expand Up @@ -945,19 +946,23 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
* @returns {Array<Object>}
*/
function getTagsOptions(tags) {
return _.map(tags, (tag) => ({
text: tag.name,
keyForList: tag.name,
searchText: tag.name,
tooltipText: tag.name,
isDisabled: !tag.enabled,
}));
return _.map(tags, (tag) => {
// This is to remove unnecessary escaping backslash in tag name sent from backend.
const cleanedName = PolicyUtils.unescapeColon(tag.name);
return {
text: cleanedName,
keyForList: tag.name,
searchText: tag.name,
tooltipText: cleanedName,
isDisabled: !tag.enabled,
};
});
}

/**
* 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 @@ -967,14 +972,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 All @@ -999,7 +998,7 @@ function getTagListSections(rawTags, recentlyUsedTags, selectedOptions, searchIn
}

if (!_.isEmpty(searchInputValue)) {
const searchTags = _.filter(enabledTags, (tag) => tag.name.toLowerCase().includes(searchInputValue.toLowerCase()));
const searchTags = _.filter(enabledTags, (tag) => PolicyUtils.unescapeColon(tag.name.toLowerCase()).includes(searchInputValue.toLowerCase()));

tagSections.push({
// "Search" section
Expand Down
10 changes: 7 additions & 3 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Str from 'expensify-common/lib/str';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTag, PolicyTags} from '@src/types/onyx';
import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTags} from '@src/types/onyx';
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand Down Expand Up @@ -158,7 +158,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 {
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
if (isEmptyObject(policyTags)) {
return {};
}
Expand All @@ -171,7 +171,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 @@ -194,6 +194,9 @@ function getTagList(policyTags: OnyxCollection<PolicyTags>, tagKey: string) {
return policyTags?.[policyTagKey]?.tags ?? {};
}

// This is to remove unnecessary escaping backslash in tag name sent from backend for "Parent: Child" type of tags.
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved
const unescapeColon = (tag: string) => tag?.replace(/\\{1,2}:/g, ':');
FitseTLT marked this conversation as resolved.
Show resolved Hide resolved

function isPendingDeletePolicy(policy: OnyxEntry<Policy>): boolean {
return policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}
Expand All @@ -220,6 +223,7 @@ export {
getTag,
getTagListName,
getTagList,
unescapeColon,
isPendingDeletePolicy,
isPolicyMember,
isPaidGroupPolicy,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Onyx from 'react-native-onyx';
import type {Phrase, PhraseParameters} from '@libs/Localize';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyCategories, PolicyTags, Transaction, TransactionViolation} from '@src/types/onyx';
import type {PolicyCategories, PolicyTag, Transaction, TransactionViolation} from '@src/types/onyx';

const ViolationsUtils = {
/**
Expand All @@ -14,7 +14,7 @@ const ViolationsUtils = {
transaction: Transaction,
transactionViolations: TransactionViolation[],
policyRequiresTags: boolean,
policyTags: PolicyTags,
policyTags: Record<string, PolicyTag>,
policyRequiresCategories: boolean,
policyCategories: PolicyCategories,
): {
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,6 +10,10 @@ type PolicyTag = {
'GL Code': string;
};

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

export type {PolicyTag, PolicyTags};
Loading