Skip to content

fix: tag name in RHP is not correct #38988

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

Merged
merged 12 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,16 @@ const ROUTES = {
getUrlWithBackToParam(`${action}/${iouType}/scan/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAG: {
route: ':action/:iouType/tag/:tagIndex/:transactionID/:reportID/:reportActionID?',
route: ':action/:iouType/tag/:orderWeight/:transactionID/:reportID/:reportActionID?',
getRoute: (
action: ValueOf<typeof CONST.IOU.ACTION>,
iouType: ValueOf<typeof CONST.IOU.TYPE>,
tagIndex: number,
orderWeight: number,
transactionID: string,
reportID: string,
backTo = '',
reportActionID?: string,
) => getUrlWithBackToParam(`${action}/${iouType}/tag/${tagIndex}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
) => getUrlWithBackToParam(`${action}/${iouType}/tag/${orderWeight}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
},
MONEY_REQUEST_STEP_WAYPOINT: {
route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex',
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function MoneyRequestView({
</OfflineWithFeedback>
)}
{shouldShowTag &&
policyTagLists.map(({name}, index) => (
policyTagLists.map(({name, orderWeight}, index) => (
<OfflineWithFeedback
key={name}
pendingAction={getPendingFieldAction('tag')}
Expand All @@ -404,7 +404,7 @@ function MoneyRequestView({
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, index, transaction?.transactionID ?? '', report.reportID),
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, orderWeight, transaction?.transactionID ?? '', report.reportID),
)
}
brickRoadIndicator={getErrorForField('tag', {tagListIndex: index, tagListName: name}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
Expand Down
7 changes: 3 additions & 4 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,18 @@ function getSortedTagKeys(policyTagList: OnyxEntry<PolicyTagList>): Array<keyof
}

/**
* Gets a tag name of policy tags based on a tag index.
* Gets a tag name of policy tags based on a tag's orderWeight.
*/
function getTagListName(policyTagList: OnyxEntry<PolicyTagList>, tagIndex: number): string {
function getTagListName(policyTagList: OnyxEntry<PolicyTagList>, orderWeight: number): string {
if (isEmptyObject(policyTagList)) {
return '';
}

const policyTagKeys = getSortedTagKeys(policyTagList ?? {});
const policyTagKey = policyTagKeys[tagIndex] ?? '';
const policyTagKey = policyTagKeys[orderWeight] ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    return Object.values(policyTagList).find((policy) => policy.orderWeight === orderWeight)?.name ?? '';

@tienifr, I think your previous code would be more semantically and functionally appropriate.
In addition, we can also comment, currently, the orderWeight and tagIndex values are the same, and we want to migrate from tagIndex to orderWeight, and finally attach the discussion link. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntdiary, I believe adding a comment is unnecessary as the function is straightforward enough to understand on its own.


return policyTagList?.[policyTagKey]?.name ?? '';
}

/**
* Gets all tag lists of a policy
*/
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function IOURequestStepTag({
policyTags,
report,
route: {
params: {action, tagIndex: rawTagIndex, transactionID, backTo, iouType, reportActionID},
params: {action, orderWeight: rawTagIndex, transactionID, backTo, iouType, reportActionID},
},
transaction,
splitDraftTransaction,
Expand Down