Commit 4ccc158d authored by Alexander Turinske's avatar Alexander Turinske

Clean up policy_editor code

- remove unnecessary props to buttons
- make expression more readable
- update `idx` to `index`
parent a7ae8b4d
...@@ -149,18 +149,21 @@ export default { ...@@ -149,18 +149,21 @@ export default {
handleAlertUpdate(includeAlert) { handleAlertUpdate(includeAlert) {
this.policy.annotations = includeAlert ? { 'app.gitlab.com/alert': 'true' } : ''; this.policy.annotations = includeAlert ? { 'app.gitlab.com/alert': 'true' } : '';
}, },
isNotFirstRule(index) {
return index > 0;
},
updateEndpointMatchMode(mode) { updateEndpointMatchMode(mode) {
this.policy.endpointMatchMode = mode; this.policy.endpointMatchMode = mode;
}, },
updateEndpointLabels(labels) { updateEndpointLabels(labels) {
this.policy.endpointLabels = labels; this.policy.endpointLabels = labels;
}, },
updateRuleType(ruleIdx, ruleType) { updateRuleType(ruleIndex, ruleType) {
const rule = this.policy.rules[ruleIdx]; const rule = this.policy.rules[ruleIndex];
this.policy.rules.splice(ruleIdx, 1, buildRule(ruleType, rule)); this.policy.rules.splice(ruleIndex, 1, buildRule(ruleType, rule));
}, },
removeRule(ruleIdx) { removeRule(ruleIndex) {
this.policy.rules.splice(ruleIdx, 1); this.policy.rules.splice(ruleIndex, 1);
}, },
loadYaml(manifest) { loadYaml(manifest) {
this.yamlEditorValue = manifest; this.yamlEditorValue = manifest;
...@@ -288,29 +291,25 @@ export default { ...@@ -288,29 +291,25 @@ export default {
</template> </template>
<policy-rule-builder <policy-rule-builder
v-for="(rule, idx) in policy.rules" v-for="(rule, index) in policy.rules"
:key="idx" :key="index"
class="gl-mb-4" class="gl-mb-4"
:rule="rule" :rule="rule"
:endpoint-match-mode="policy.endpointMatchMode" :endpoint-match-mode="policy.endpointMatchMode"
:endpoint-labels="policy.endpointLabels" :endpoint-labels="policy.endpointLabels"
:endpoint-selector-disabled="idx > 0" :endpoint-selector-disabled="isNotFirstRule(index)"
@rule-type-change="updateRuleType(idx, $event)" @rule-type-change="updateRuleType(index, $event)"
@endpoint-match-mode-change="updateEndpointMatchMode" @endpoint-match-mode-change="updateEndpointMatchMode"
@endpoint-labels-change="updateEndpointLabels" @endpoint-labels-change="updateEndpointLabels"
@remove="removeRule(idx)" @remove="removeRule(index)"
/> />
<div <div
class="gl-p-3 gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-mb-5" class="gl-p-3 gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-mb-5"
> >
<gl-button <gl-button variant="link" data-testid="add-rule" @click="addRule">{{
variant="link" s__('Network Policy|New rule')
category="primary" }}</gl-button>
data-testid="add-rule"
@click="addRule"
>{{ s__('Network Policy|New rule') }}</gl-button
>
</div> </div>
</dim-disable-container> </dim-disable-container>
...@@ -366,7 +365,6 @@ export default { ...@@ -366,7 +365,6 @@ export default {
<div> <div>
<gl-button <gl-button
type="submit" type="submit"
category="primary"
variant="success" variant="success"
data-testid="save-policy" data-testid="save-policy"
:loading="isUpdatingPolicy" :loading="isUpdatingPolicy"
...@@ -382,9 +380,7 @@ export default { ...@@ -382,9 +380,7 @@ export default {
:loading="isRemovingPolicy" :loading="isRemovingPolicy"
>{{ s__('NetworkPolicies|Delete policy') }}</gl-button >{{ s__('NetworkPolicies|Delete policy') }}</gl-button
> >
<gl-button category="secondary" variant="default" :href="threatMonitoringPath">{{ <gl-button category="secondary" :href="threatMonitoringPath">{{ __('Cancel') }}</gl-button>
__('Cancel')
}}</gl-button>
</div> </div>
<gl-modal <gl-modal
modal-id="delete-modal" modal-id="delete-modal"
......
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