Skip to content

Commit a79233c

Browse files
authored
Merge pull request #97094 from neerajbachani/96390-show-tag-gl-codes-in-picker
Add tag GL code display in tag picker
2 parents a459a09 + 0ba936d commit a79233c

31 files changed

Lines changed: 369 additions & 24 deletions

src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemWide.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function TransactionListItemWide<TItem extends ListItem>({
4545
exportedReportActions,
4646
policyCategories,
4747
policyTagLists,
48+
rowPolicy,
4849
nonPersonalAndWorkspaceCards,
4950
isAttendeesEnabledForMovingPolicy,
5051
currentSearchHash,
@@ -180,7 +181,7 @@ function TransactionListItemWide<TItem extends ListItem>({
180181
transactionItem={transactionItem}
181182
report={transactionItem.report}
182183
chatReport={chatReport}
183-
policy={transactionItem.policy}
184+
policy={rowPolicy ?? transactionItem.policy}
184185
policyCategories={policyCategories}
185186
policyTagLists={policyTagLists}
186187
shouldShowTooltip={showTooltip}

src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function TransactionListItemInner<TItem extends ListItem>({
171171
// Use snapshotReport/snapshotPolicy as fallbacks to fix offline issues where
172172
// newly created reports aren't in the search snapshot yet
173173
const policyForViolations = parentPolicy ?? snapshotPolicy;
174+
const rowPolicy = parentPolicy || snapshotPolicy.id || transactionItem.policy ? {...transactionItem.policy, ...snapshotPolicy, ...parentPolicy} : undefined;
174175
const reportForViolations = parentReport ?? snapshotReport;
175176

176177
const onyxViolations = (transactionViolationsForRow ?? []).filter(
@@ -265,6 +266,7 @@ function TransactionListItemInner<TItem extends ListItem>({
265266
exportedReportActions,
266267
policyCategories,
267268
policyTagLists,
269+
rowPolicy,
268270
nonPersonalAndWorkspaceCards,
269271
isAttendeesEnabledForMovingPolicy,
270272
chatReport,

src/components/Search/SearchList/ListItem/TransactionListItem/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {ListItem} from '@components/SelectionList/types';
55
import type {TransactionPreviewData} from '@libs/actions/Search';
66
import type {ModifiedMouseEvent} from '@libs/Navigation/helpers/openInternalRouteInNewTab';
77

8-
import type {CardList, PolicyCategories, PolicyTagLists, Report, ReportAction, TransactionViolation} from '@src/types/onyx';
8+
import type {CardList, Policy, PolicyCategories, PolicyTagLists, Report, ReportAction, TransactionViolation} from '@src/types/onyx';
99

1010
type TransactionListItemSharedProps<TItem extends ListItem> = {
1111
item: TItem;
@@ -30,6 +30,7 @@ type TransactionListItemSharedProps<TItem extends ListItem> = {
3030
exportedReportActions: ReportAction[];
3131
policyCategories?: PolicyCategories;
3232
policyTagLists?: PolicyTagLists;
33+
rowPolicy?: Policy;
3334
nonPersonalAndWorkspaceCards?: CardList;
3435
isAttendeesEnabledForMovingPolicy?: boolean;
3536
chatReport?: Report;

src/components/TagPicker/TagPickerModal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ type TagPickerModalProps = {
4242
/** Whether the policy has dependent tags */
4343
hasDependentTags?: boolean;
4444

45+
/** Optional override for whether to show GL codes under each tag */
46+
shouldShowGLCode?: boolean;
47+
4548
/** Called when the user confirms a tag selection */
4649
onSelected?: (tag: string) => void;
4750
} & Omit<PopoverWithMeasuredContentProps, 'anchorRef' | 'children' | 'onClose'>;
@@ -54,6 +57,7 @@ function TagPickerModal({
5457
selectedTag = '',
5558
transactionTag,
5659
hasDependentTags,
60+
shouldShowGLCode,
5761
onSelected,
5862
anchorAlignment = DEFAULT_ANCHOR_ALIGNMENT,
5963
shouldMeasureAnchorPositionFromTop = false,
@@ -100,6 +104,7 @@ function TagPickerModal({
100104
selectedTag={selectedTag}
101105
transactionTag={transactionTag}
102106
hasDependentTags={hasDependentTags}
107+
shouldShowGLCode={shouldShowGLCode}
103108
onSubmit={handleTagSelected}
104109
/>
105110
</View>

src/components/TagPicker/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ type TagPickerProps = {
5454
* split-edit where the active workspace no longer carries the original tag value.
5555
*/
5656
additionalTagsToInclude?: string[];
57+
58+
/**
59+
* Optional override for whether to show GL codes. When omitted, TagPicker reads
60+
* `showTagGLCodes && glCodes` from the policy in Onyx.
61+
*/
62+
shouldShowGLCode?: boolean;
5763
};
5864

5965
const getSelectedOptions = (selectedTag: string): SelectedTagOption[] => {
@@ -80,8 +86,13 @@ function TagPicker({
8086
shouldOrderListByTagName = false,
8187
onSubmit,
8288
additionalTagsToInclude,
89+
shouldShowGLCode: shouldShowGLCodeProp,
8390
}: TagPickerProps) {
8491
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
92+
const [shouldShowGLCodeFromPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
93+
selector: (policy) => !!policy?.showTagGLCodes && !!policy?.glCodes,
94+
});
95+
const shouldShowGLCode = shouldShowGLCodeProp ?? shouldShowGLCodeFromPolicy;
8596
const [policyRecentlyUsedTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${policyID}`);
8697
const styles = useThemeStyles();
8798
const {inputCallbackRef} = useAutoFocusInput();
@@ -146,6 +157,7 @@ function TagPicker({
146157
recentlyUsedTags: policyRecentlyUsedTagsList,
147158
localeCompare,
148159
translate,
160+
shouldShowGLCode,
149161
});
150162
const sections = shouldOrderListByTagName
151163
? tagSections.map((option) => ({

src/components/TransactionItemRow/DataCells/TagCell.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {getDecodedTagName} from '@libs/TagUtils';
1313
import {getTagForDisplay} from '@libs/TransactionUtils';
1414

1515
import ONYXKEYS from '@src/ONYXKEYS';
16+
import type {Policy} from '@src/types/onyx';
1617

1718
import React from 'react';
1819

@@ -21,16 +22,19 @@ import type TransactionDataCellProps from './TransactionDataCellProps';
2122
type TagCellProps = TransactionDataCellProps &
2223
EditableProps<string> & {
2324
policyID?: string;
25+
policy?: Policy;
2426
};
2527

26-
function TagCell({canEdit, onSave, shouldUseNarrowLayout, shouldShowTooltip, transactionItem, policyID}: TagCellProps) {
28+
function TagCell({canEdit, onSave, shouldUseNarrowLayout, shouldShowTooltip, transactionItem, policyID, policy: policyProp}: TagCellProps) {
2729
const icons = useMemoizedLazyExpensifyIcons(['Tag']);
2830
const styles = useThemeStyles();
2931

30-
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
32+
const [livePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
3133
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
34+
const policy = livePolicy ? {...policyProp, ...livePolicy} : policyProp;
3235

3336
const policyHasDependentTags = hasDependentTags(policy, policyTags);
37+
const shouldShowGLCode = !!policy?.showTagGLCodes && !!policy?.glCodes;
3438

3539
const {isEditing, anchorRef, isPopoverVisible, popoverPosition, isInverted, startEditing, cancelEditing, handleSave} = usePopoverEditState({
3640
canEdit,
@@ -69,6 +73,7 @@ function TagCell({canEdit, onSave, shouldUseNarrowLayout, shouldShowTooltip, tra
6973
selectedTag={transactionItem?.tag ?? ''}
7074
transactionTag={transactionItem?.tag}
7175
hasDependentTags={policyHasDependentTags}
76+
shouldShowGLCode={shouldShowGLCode}
7277
isVisible={isPopoverVisible}
7378
onClose={cancelEditing}
7479
anchorPosition={popoverPosition}

src/components/TransactionItemRow/TransactionItemRowWide.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function TransactionItemRowWide({
204204
canEdit={canEditTag}
205205
onSave={onEditTag}
206206
policyID={effectivePolicyID}
207+
policy={policy}
207208
/>
208209
</View>
209210
);

src/languages/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6495,6 +6495,7 @@ _Für ausführlichere Anweisungen [besuchen Sie unsere Hilfeseite](${CONST.NETSU
64956495
one: '1 Tag',
64966496
other: (count: number) => `${count} Tags`,
64976497
}),
6498+
showTagGLCodes: 'Kontenplan-Codes beim Auswählen eines Tags anzeigen',
64986499
},
64996500
taxes: {
65006501
subtitle: 'Steuernamen und -sätze hinzufügen und Standardwerte festlegen.',

src/languages/el.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6637,6 +6637,7 @@ _Για πιο αναλυτικές οδηγίες, [επισκεφθείτε τ
66376637
one: '1 ετικέτα',
66386638
other: (count: number) => `${count} ετικέτες`,
66396639
}),
6640+
showTagGLCodes: 'Εμφάνιση κωδικών Γ.Λ. κατά την επιλογή ετικέτας',
66406641
},
66416642
taxes: {
66426643
subtitle: 'Προσθέστε ονόματα φόρων, συντελεστές και ορίστε προεπιλογές.',

src/languages/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6509,6 +6509,7 @@ const translations = {
65096509
tags: {
65106510
tagName: 'Tag name',
65116511
requiresTag: 'Members must tag all expenses',
6512+
showTagGLCodes: 'Show GL codes when selecting a tag',
65126513
trackBillable: 'Track billable expenses',
65136514
customTagName: 'Custom tag name',
65146515
enableTag: 'Enable tag',

0 commit comments

Comments
 (0)