Refactor computed props

parent e17c24ed
...@@ -26,16 +26,14 @@ export const POLICY_KINDS = { ...@@ -26,16 +26,14 @@ export const POLICY_KINDS = {
scanExecution: 'scanner_profile', scanExecution: 'scanner_profile',
}; };
export const POLICY_TYPE_NETWORK = s__('SecurityPolicies|Network');
export const POLICY_TYPE_SCAN_EXECUTION = s__('SecurityPolicies|Scan execution');
export const POLICY_TYPE_OPTIONS = { export const POLICY_TYPE_OPTIONS = {
POLICY_TYPE_NETWORK: { POLICY_TYPE_NETWORK: {
value: 'POLICY_TYPE_NETWORK', value: 'POLICY_TYPE_NETWORK',
text: POLICY_TYPE_NETWORK, text: s__('SecurityPolicies|Network'),
}, },
POLICY_TYPE_SCAN_EXECUTION: { POLICY_TYPE_SCAN_EXECUTION: {
value: 'POLICY_TYPE_SCAN_EXECUTION', value: 'POLICY_TYPE_SCAN_EXECUTION',
text: POLICY_TYPE_SCAN_EXECUTION, text: s__('SecurityPolicies|Scan execution'),
}, },
ALL: { ALL: {
value: '', value: '',
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
GlIcon, GlIcon,
GlTooltipDirective, GlTooltipDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { flatten } from 'lodash';
import { mapState, mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import { PREDEFINED_NETWORK_POLICIES } from 'ee/threat_monitoring/constants'; import { PREDEFINED_NETWORK_POLICIES } from 'ee/threat_monitoring/constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -17,7 +18,7 @@ import { setUrlFragment, mergeUrlParams } from '~/lib/utils/url_utility'; ...@@ -17,7 +18,7 @@ import { setUrlFragment, mergeUrlParams } from '~/lib/utils/url_utility';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import networkPoliciesQuery from '../graphql/queries/network_policies.query.graphql'; import networkPoliciesQuery from '../graphql/queries/network_policies.query.graphql';
import scanExecutionPoliciesQuery from '../graphql/queries/scan_execution_policies.query.graphql'; import scanExecutionPoliciesQuery from '../graphql/queries/scan_execution_policies.query.graphql';
import { POLICY_TYPE_NETWORK, POLICY_TYPE_SCAN_EXECUTION, POLICY_TYPE_OPTIONS } from './constants'; import { POLICY_TYPE_OPTIONS } from './constants';
import EnvironmentPicker from './environment_picker.vue'; import EnvironmentPicker from './environment_picker.vue';
import PolicyDrawer from './policy_drawer/policy_drawer.vue'; import PolicyDrawer from './policy_drawer/policy_drawer.vue';
import PolicyTypeFilter from './policy_type_filter.vue'; import PolicyTypeFilter from './policy_type_filter.vue';
...@@ -114,6 +115,12 @@ export default { ...@@ -114,6 +115,12 @@ export default {
'isLoadingEnvironments', 'isLoadingEnvironments',
]), ]),
...mapGetters('threatMonitoring', ['currentEnvironmentGid']), ...mapGetters('threatMonitoring', ['currentEnvironmentGid']),
allPolicyTypes() {
return {
[POLICY_TYPE_OPTIONS.POLICY_TYPE_NETWORK.value]: this.networkPolicies,
[POLICY_TYPE_OPTIONS.POLICY_TYPE_SCAN_EXECUTION.value]: this.scanExecutionPolicies,
};
},
documentationFullPath() { documentationFullPath() {
return setUrlFragment(this.documentationPath, 'container-network-policy'); return setUrlFragment(this.documentationPath, 'container-network-policy');
}, },
...@@ -123,21 +130,16 @@ export default { ...@@ -123,21 +130,16 @@ export default {
POLICY_TYPE_OPTIONS.POLICY_TYPE_NETWORK.value, POLICY_TYPE_OPTIONS.POLICY_TYPE_NETWORK.value,
].includes(this.selectedPolicyType); ].includes(this.selectedPolicyType);
}, },
shouldShowScanExecutionPolicies() {
return [
POLICY_TYPE_OPTIONS.ALL.value,
POLICY_TYPE_OPTIONS.POLICY_TYPE_SCAN_EXECUTION.value,
].includes(this.selectedPolicyType);
},
policies() { policies() {
return [ const policyTypes =
...(this.shouldShowNetworkPolicies this.selectedPolicyType === POLICY_TYPE_OPTIONS.ALL.value
? getPoliciesWithType(this.networkPolicies, POLICY_TYPE_NETWORK) ? Object.keys(this.allPolicyTypes)
: []), : [this.selectedPolicyType];
...(this.shouldShowScanExecutionPolicies const policies = policyTypes.map((type) =>
? getPoliciesWithType(this.scanExecutionPolicies, POLICY_TYPE_SCAN_EXECUTION) getPoliciesWithType(this.allPolicyTypes[type], POLICY_TYPE_OPTIONS[type].text),
: []), );
];
return flatten(policies);
}, },
isLoadingPolicies() { isLoadingPolicies() {
return ( return (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment