Skip to content
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

[CP Staging] Use isMultiLevelTags instead of isSingleLevelTags #42106

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading