Skip to content
Merged
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ const CONST = {
RETRACT_NEWDOT: 'retractNewDot',
PRIVATE_DOMAIN_ONBOARDING: 'privateDomainOnboarding',
IS_TRAVEL_VERIFIED: 'isTravelVerified',
MULTI_LEVEL_TAGS: 'multiLevelTags',
NEWDOT_MULTI_FILES_DRAG_AND_DROP: 'newDotMultiFilesDragAndDrop',
PLAID_COMPANY_CARDS: 'plaidCompanyCards',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type ExportMultiLevelTagsSpreadSheetParams = {
/** ID of the policy */
policyID: string;
};

export default ExportMultiLevelTagsSpreadSheetParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,5 @@ export type {default as GetGuideCallAvailabilityScheduleParams} from './GetGuide
export type {default as GetEmphemeralTokenParams} from './GetEmphemeralTokenParams';
export type {default as CompleteConciergeCallParams} from './CompleteConciergeCallParams';
export type {default as FinishCorpayBankAccountOnboardingParams} from './FinishCorpayBankAccountOnboardingParams';
export type {default as ExportMultiLevelTagsSpreadSheetParams} from './ExportMultiLevelTagsSpreadSheetParams';
export type {default as ReopenReportParams} from './ReopenReportParams';
4 changes: 3 additions & 1 deletion src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ const WRITE_COMMANDS = {
IMPORT_PER_DIEM_RATES: 'ImportPerDiemRates',
EXPORT_CATEGORIES_CSV: 'ExportCategoriesCSV',
EXPORT_MEMBERS_CSV: 'ExportMembersCSV',
EXPORT_TAGS_CSV: 'ExportTagsCSV',
EXPORT_TAGS_CSV: 'ExportSingleLevelTags',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to rename the label as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it was mentioned in the design doc, the backend for that is not yet updated, asked for details https://expensify.enterprise.slack.com/archives/C07HPDRELLD/p1747381834260859?thread_ts=1747095451.933699&channel=C07HPDRELLD&message_ts=1747381834.260859

lets see what we hear

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so i am holding to rename the label for now, else i am going to revert that change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The backend is updated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

    } elseif ($command === 'ExportTagsCSV' || $command === 'ExportSingleLevelTagsCSV') {
        PolicyAPI::exportTagsCSV($authToken, $policyID);

EXPORT_MULTI_LEVEL_TAGS_CSV: 'ExportMultiLevelTagsCSV',
EXPORT_PER_DIEM_CSV: 'ExportPerDiemCSV',
EXPORT_REPORT_TO_CSV: 'ExportReportToCSV',
MOVE_IOU_REPORT_TO_EXISTING_POLICY: 'MoveIOUReportToExistingPolicy',
Expand Down Expand Up @@ -621,6 +622,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.EXPORT_CATEGORIES_CSV]: Parameters.ExportCategoriesSpreadsheetParams;
[WRITE_COMMANDS.EXPORT_MEMBERS_CSV]: Parameters.ExportMembersSpreadsheetParams;
[WRITE_COMMANDS.EXPORT_TAGS_CSV]: Parameters.ExportTagsSpreadsheetParams;
[WRITE_COMMANDS.EXPORT_MULTI_LEVEL_TAGS_CSV]: Parameters.ExportMultiLevelTagsSpreadSheetParams;
[WRITE_COMMANDS.EXPORT_PER_DIEM_CSV]: Parameters.ExportPerDiemCSVParams;
[WRITE_COMMANDS.EXPORT_REPORT_TO_PDF]: Parameters.ExportReportPDFParams;
[WRITE_COMMANDS.RENAME_WORKSPACE_CATEGORY]: Parameters.RenameWorkspaceCategoriesParams;
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function canUseNetSuiteUSATax(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.NETSUITE_USA_TAX) || canUseAllBetas(betas);
}

function canUseMultiLevelTags(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.MULTI_LEVEL_TAGS) || canUseAllBetas(betas);
}

/**
* Link previews are temporarily disabled.
*/
Expand Down Expand Up @@ -104,6 +108,7 @@ export default {
canUsePrivateDomainOnboarding,
canUseRetractNewDot,
canUseCallScheduling,
canUseMultiLevelTags,
canUseMultiFilesDragAndDrop,
canUsePlaidCompanyCards,
};
8 changes: 8 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,13 @@ function hasDependentTags(policy: OnyxEntry<Policy>, policyTagList: OnyxEntry<Po
return Object.values(policyTagList ?? {}).some((tagList) => Object.values(tagList.tags).some((tag) => !!tag.rules?.parentTagsFilter || !!tag.parentTagsFilter));
}

function hasIndependentTags(policy: OnyxEntry<Policy>, policyTagList: OnyxEntry<PolicyTagLists>) {
if (!policy?.hasMultipleTagLists) {
return false;
}
return Object.values(policyTagList ?? {}).every((tagList) => Object.values(tagList.tags).every((tag) => !tag.rules?.parentTagsFilter && !tag.parentTagsFilter));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@allgandalf I am getting this error on all my existing sessions. Once I am logout and login again it goes away. Best to add tagList.tags ?? {}

desktop-error-tags mweb-chrome-error-tags

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@allgandalf Were you able to follow-up on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[].every(callback) always returns true, which caused this bug.
More details: #82573 (comment)

}

/** Get the Xero organizations connected to the policy */
function getXeroTenants(policy: Policy | undefined): Tenant[] {
// Due to the way optional chain is being handled in this useMemo we are forced to use this approach to properly handle undefined values
Expand Down Expand Up @@ -1537,6 +1544,7 @@ export {
getActiveEmployeeWorkspaces,
isUserInvitedToWorkspace,
getPolicyRole,
hasIndependentTags,
};

export type {MemberEmailsToAccountIDs};
15 changes: 15 additions & 0 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,20 @@ function downloadTagsCSV(policyID: string, onDownloadFailed: () => void) {
fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_TAGS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

function downloadMultiLevelIndependentTagsCSV(policyID: string, onDownloadFailed: () => void) {
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_MULTI_LEVEL_TAGS_CSV, {
policyID,
});
const fileName = 'MultiLevelTags.csv';

const formData = new FormData();
Object.entries(finalParameters).forEach(([key, value]) => {
formData.append(key, String(value));
});

fileDownload(ApiUtils.getCommandURL({command: WRITE_COMMANDS.EXPORT_MULTI_LEVEL_TAGS_CSV}), fileName, '', false, formData, CONST.NETWORK.METHOD.POST, onDownloadFailed);
}

function getPolicyTagsData(policyID: string | undefined) {
return allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}
Expand All @@ -1058,4 +1072,5 @@ export {
importPolicyTags,
downloadTagsCSV,
getPolicyTagsData,
downloadMultiLevelIndependentTagsCSV,
};
35 changes: 28 additions & 7 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import useFilteredSelection from '@hooks/useFilteredSelection';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSearchBackPress from '@hooks/useSearchBackPress';
Expand All @@ -38,7 +39,15 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useThreeDotsAnchorPosition from '@hooks/useThreeDotsAnchorPosition';
import {isConnectionInProgress, isConnectionUnverified} from '@libs/actions/connections';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {clearPolicyTagErrors, deletePolicyTags, downloadTagsCSV, openPolicyTagsPage, setPolicyTagsRequired, setWorkspaceTagEnabled} from '@libs/actions/Policy/Tag';
import {
clearPolicyTagErrors,
deletePolicyTags,
downloadMultiLevelIndependentTagsCSV,
downloadTagsCSV,
openPolicyTagsPage,
setPolicyTagsRequired,
setWorkspaceTagEnabled,
} from '@libs/actions/Policy/Tag';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import localeCompare from '@libs/LocaleCompare';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -50,6 +59,8 @@ import {
getCurrentConnectionName,
getTagLists,
hasAccountingConnections as hasAccountingConnectionsPolicyUtils,
hasDependentTags as hasDependentTagsPolicyUtils,
hasIndependentTags as hasIndependentTagsPolicyUtils,
isMultiLevelTags as isMultiLevelTagsPolicyUtils,
shouldShowSyncError,
} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -89,12 +100,16 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const connectedIntegration = getConnectedIntegration(policy) ?? connectionSyncProgress?.connectionName;
const isConnectionVerified = connectedIntegration && !isConnectionUnverified(policy, connectedIntegration);
const currentConnectionName = getCurrentConnectionName(policy);
const [policyTagLists, isMultiLevelTags] = useMemo(() => [getTagLists(policyTags), isMultiLevelTagsPolicyUtils(policyTags)], [policyTags]);
const [policyTagLists, isMultiLevelTags, hasDependentTags, hasIndependentTags] = useMemo(
() => [getTagLists(policyTags), isMultiLevelTagsPolicyUtils(policyTags), hasDependentTagsPolicyUtils(policy, policyTags), hasIndependentTagsPolicyUtils(policy, policyTags)],
[policy, policyTags],
);
const canSelectMultiple = !isMultiLevelTags && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true);
const fetchTags = useCallback(() => {
openPolicyTagsPage(policyID);
}, [policyID]);
const isQuickSettingsFlow = !!backTo;
const {canUseMultiLevelTags} = usePermissions();

const tagsList = useMemo(() => {
if (isMultiLevelTags) {
Expand Down Expand Up @@ -403,16 +418,22 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
return;
}
close(() => {
downloadTagsCSV(policyID, () => {
setIsDownloadFailureModalVisible(true);
});
if (hasIndependentTags && canUseMultiLevelTags) {
downloadMultiLevelIndependentTagsCSV(policyID, () => {
setIsDownloadFailureModalVisible(true);
});
} else {
downloadTagsCSV(policyID, () => {
setIsDownloadFailureModalVisible(true);
});
}
});
},
});
}

return menuItems;
}, [policy, hasVisibleTags, translate, isOffline, isQuickSettingsFlow, policyID, backTo]);
}, [policy, hasVisibleTags, translate, isOffline, isQuickSettingsFlow, policyID, backTo, canUseMultiLevelTags, hasIndependentTags]);

const selectionModeHeader = selectionMode?.isEnabled && shouldUseNarrowLayout;

Expand Down Expand Up @@ -449,7 +470,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {

Navigation.popToSidebar();
}}
shouldShowThreeDotsButton={!policy?.hasMultipleTagLists}
shouldShowThreeDotsButton={canUseMultiLevelTags ? !hasDependentTags : !policy?.hasMultipleTagLists}
threeDotsMenuItems={threeDotsMenuItems}
threeDotsAnchorPosition={threeDotsAnchorPosition}
>
Expand Down
Loading