Skip to content

Commit

Permalink
Preserve previous tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Esteban Beltran committed Dec 2, 2021
1 parent 2d63d79 commit a24a200
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,30 @@ import { EffectedPolicySelection } from './effected_policy_select';

export const GLOBAL_POLICY_TAG = 'policy:all';

/**
* Given a list of artifact tags, returns the tags that are not policy tags
* policy tags follow the format: `policy:id`
*/
export function getArtifactTagsWithoutPolicies(tags?: string[]): string[] {
return tags?.filter((tag) => !tag.startsWith('policy:')) || [];
}

/**
* Return a list of artifact policy tags based on a current
* selection by the EffectedPolicySelection component.
*/
export function getArtifactTagsByEffectedPolicySelection(
selection: EffectedPolicySelection
selection: EffectedPolicySelection,
otherTags: string[] = []
): string[] {
if (selection.isGlobal) {
return [GLOBAL_POLICY_TAG];
return [GLOBAL_POLICY_TAG, ...otherTags];
}
return selection.selected.map((policy) => {
const newTags = selection.selected.map((policy) => {
return `policy:${policy.id}`;
});

return newTags.concat(otherTags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '../../../../components/effected_policy_select';
import {
getArtifactTagsByEffectedPolicySelection,
getArtifactTagsWithoutPolicies,
getEffectedPolicySelectionByTags,
isGlobalPolicyEffected,
} from '../../../../components/effected_policy_select/utils';
Expand Down Expand Up @@ -126,10 +127,13 @@ export const HostIsolationExceptionsForm: React.FC<{
setSelectedPolicies(() => selection);
}
onChange({
tags: getArtifactTagsByEffectedPolicySelection(selection),
tags: getArtifactTagsByEffectedPolicySelection(
selection,
getArtifactTagsWithoutPolicies(exception.tags)
),
});
},
[onChange]
[exception.tags, onChange]
);

const handleOnDescriptionChange = useCallback(
Expand Down

0 comments on commit a24a200

Please sign in to comment.