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

Enable / Disable multi level tags #42315

Merged
merged 10 commits into from
May 23, 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
5 changes: 5 additions & 0 deletions src/libs/API/parameters/SetPolicyTagsEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ type SetPolicyTagsEnabled = {
* Array<{name: string; enabled: boolean}>
*/
tags: string;
/**
* When the tags are imported as multi level tags, the index of the top
* most tag list item
*/
tagListIndex: number;
};

export default SetPolicyTagsEnabled;
8 changes: 5 additions & 3 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import type {
UpdateWorkspaceGeneralSettingsParams,
UpdateWorkspaceMembersRoleParams,
} from '@libs/API/parameters';
import type SetPolicyTagsEnabled from '@libs/API/parameters/SetPolicyTagsEnabled';
import type UpdatePolicyAddressParams from '@libs/API/parameters/UpdatePolicyAddressParams';
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
Expand Down Expand Up @@ -3466,8 +3467,8 @@ function createPolicyTag(policyID: string, tagName: string) {
API.write(WRITE_COMMANDS.CREATE_POLICY_TAG, parameters, onyxData);
}

function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record<string, {name: string; enabled: boolean}>) {
const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[0] ?? {};
function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record<string, {name: string; enabled: boolean}>, tagListIndex: number) {
const policyTag = PolicyUtils.getTagLists(allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {})?.[tagListIndex] ?? {};

const onyxData: OnyxData = {
optimisticData: [
Expand Down Expand Up @@ -3547,9 +3548,10 @@ function setWorkspaceTagEnabled(policyID: string, tagsToUpdate: Record<string, {
],
};

const parameters = {
const parameters: SetPolicyTagsEnabled = {
policyID,
tags: JSON.stringify(Object.keys(tagsToUpdate).map((key) => tagsToUpdate[key])),
tagListIndex,
};

API.write(WRITE_COMMANDS.SET_POLICY_TAGS_ENABLED, parameters, onyxData);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/TagSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function TagSettingsPage({route, policyTags, navigation}: TagSettingsPageProps)
};

const updateWorkspaceTagEnabled = (value: boolean) => {
setWorkspaceTagEnabled(route.params.policyID, {[currentPolicyTag.name]: {name: currentPolicyTag.name, enabled: value}});
setWorkspaceTagEnabled(route.params.policyID, {[currentPolicyTag.name]: {name: currentPolicyTag.name, enabled: value}}, policyTag.orderWeight);
};

const navigateToEditTag = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
value: CONST.POLICY.TAGS_BULK_ACTION_TYPES.DISABLE,
onSelected: () => {
setSelectedTags({});
Policy.setWorkspaceTagEnabled(policyID, tagsToDisable);
Policy.setWorkspaceTagEnabled(policyID, tagsToDisable, 0);
},
});
}
Expand All @@ -250,7 +250,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
value: CONST.POLICY.TAGS_BULK_ACTION_TYPES.ENABLE,
onSelected: () => {
setSelectedTags({});
Policy.setWorkspaceTagEnabled(policyID, tagsToEnable);
Policy.setWorkspaceTagEnabled(policyID, tagsToEnable, 0);
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/tags/WorkspaceViewTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
value: CONST.POLICY.TAGS_BULK_ACTION_TYPES.DISABLE,
onSelected: () => {
setSelectedTags({});
Policy.setWorkspaceTagEnabled(policyID, tagsToDisable);
Policy.setWorkspaceTagEnabled(policyID, tagsToDisable, route.params.orderWeight);
},
});
}
Expand All @@ -186,7 +186,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) {
value: CONST.POLICY.TAGS_BULK_ACTION_TYPES.ENABLE,
onSelected: () => {
setSelectedTags({});
Policy.setWorkspaceTagEnabled(policyID, tagsToEnable);
Policy.setWorkspaceTagEnabled(policyID, tagsToEnable, route.params.orderWeight);
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/actions/PolicyTagTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe('actions/Policy', () => {
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
})
.then(() => {
Policy.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate);
Policy.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
return waitForBatchedUpdates();
})
.then(
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('actions/Policy', () => {
.then(() => {
mockFetch?.fail?.();

Policy.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate);
Policy.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
return waitForBatchedUpdates();
})
.then(mockFetch?.resume)
Expand Down
Loading