From 37b438ca41be518a71de604cc9d67096f0251709 Mon Sep 17 00:00:00 2001 From: Prince Mendiratta Date: Thu, 16 Nov 2023 17:47:39 +0530 Subject: [PATCH] fix: dependency cycle Signed-off-by: Prince Mendiratta --- src/libs/ReportUtils.js | 22 ++++++++++++++++++++-- src/libs/actions/IOU.js | 5 ----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6a34611838c2..99d8e19fd884 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -11,7 +11,6 @@ import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvata import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import * as IOU from './actions/IOU'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; @@ -81,6 +80,25 @@ Onyx.connect({ callback: (val) => (loginList = val), }); +let allPolicyTags = {}; + +Onyx.connect({ + key: ONYXKEYS.COLLECTION.POLICY_TAGS, + waitForCollectionCallback: true, + callback: (value) => { + if (!value) { + allPolicyTags = {}; + return; + } + + allPolicyTags = value; + }, +}); + +function getPolicyTags(policyID) { + return lodashGet(allPolicyTags, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {}); +} + function getChatType(report) { return report ? report.chatType : ''; } @@ -1921,7 +1939,7 @@ function getModifiedExpenseMessage(reportAction) { } const reportID = lodashGet(reportAction, 'reportID', ''); const policyID = lodashGet(getReport(reportID), 'policyID', ''); - const policyTags = IOU.getPolicyTags(policyID); + const policyTags = getPolicyTags(policyID); const policyTag = PolicyUtils.getTag(policyTags); const policyTagListName = lodashGet(policyTag, 'name', Localize.translateLocal('common.tag')); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 158c1960895a..aa07f0e7ca34 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2951,10 +2951,6 @@ function getIOUReportID(iou, route) { return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', ''); } -function getPolicyTags(policyID) { - return lodashGet(allPolicyTags, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {}); -} - export { createDistanceRequest, editMoneyRequest, @@ -2991,5 +2987,4 @@ export { replaceReceipt, detachReceipt, getIOUReportID, - getPolicyTags, };