Skip to content

Commit

Permalink
Merge pull request #42106 from s77rt/tags-use-isMultiLevelTags
Browse files Browse the repository at this point in the history
[CP Staging] Use isMultiLevelTags instead of isSingleLevelTags

(cherry picked from commit f8a30a1)
  • Loading branch information
marcaaron authored and OSBotify committed May 14, 2024
1 parent 6fb6e76 commit bfcb355
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
const {environmentURL} = useEnvironment();
const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0;
const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);
const doesPolicyContainOnlyOneTagList = policyTagLists.length === 1;
const canSelectMultiple = doesPolicyContainOnlyOneTagList;
const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]);
const canSelectMultiple = !isMultiLevelTags;

const fetchTags = useCallback(() => {
Policy.openPolicyTagsPage(policyID);
Expand All @@ -72,7 +71,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
}, [isFocused]);

const tagList = useMemo<TagListItem[]>(() => {
if (!doesPolicyContainOnlyOneTagList) {
if (isMultiLevelTags) {
return policyTagLists.map((policyTagList) => ({
value: policyTagList.name,
orderWeight: policyTagList.orderWeight,
Expand All @@ -89,7 +88,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
),
}));
}
return Object.values(policyTagLists[0].tags)
return Object.values(policyTagLists[0]?.tags ?? {})
.sort((tagA, tagB) => localeCompare(tagA.name, tagB.name))
.map((tag) => ({
value: tag.name,
Expand All @@ -102,7 +101,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
isDisabled: tag.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
rightElement: <ListItemRightCaretWithLabel labelText={tag.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
}));
}, [doesPolicyContainOnlyOneTagList, policyTagLists, selectedTags, translate]);
}, [isMultiLevelTags, policyTagLists, selectedTags, translate]);

const tagListKeyedByName = useMemo(
() =>
Expand Down Expand Up @@ -166,12 +165,11 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {

const getHeaderButtons = () => {
const isThereAnyAccountingConnection = Object.keys(policy?.connections ?? {}).length !== 0;
const isMultiLevelTags = PolicyUtils.isMultiLevelTags(policyTags);

if (selectedTagsArray.length === 0) {
return (
<View style={[styles.w100, styles.flexRow, isSmallScreenWidth && styles.mb3]}>
{doesPolicyContainOnlyOneTagList && !isThereAnyAccountingConnection && (
{!isThereAnyAccountingConnection && !isMultiLevelTags && (
<Button
medium
success
Expand Down
5 changes: 2 additions & 3 deletions src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ type WorkspaceTagsSettingsPageProps = WorkspaceTagsSettingsPageOnyxProps & Stack
function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);
const doesPolicyContainOnlyOneTagList = policyTagLists.length === 1;
const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]);

const updateWorkspaceRequiresTag = useCallback(
(value: boolean) => {
Expand Down Expand Up @@ -71,7 +70,7 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag
</View>
</View>
</OfflineWithFeedback>
{doesPolicyContainOnlyOneTagList && (
{!isMultiLevelTags && (
<OfflineWithFeedback
errors={policyTags?.[policyTagLists[0].name]?.errors}
pendingAction={policyTags?.[policyTagLists[0].name]?.pendingAction}
Expand Down

0 comments on commit bfcb355

Please sign in to comment.