Commit a17be4ee authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '339796-fix-policy-preview-for-non-parseable-policies' into 'master'

Fix policy preview for non-parseable policies

See merge request gitlab-org/gitlab!70104
parents 3fb23ada c41ba9bd
...@@ -48,7 +48,6 @@ export default { ...@@ -48,7 +48,6 @@ export default {
noEnvironmentButton: __('Learn more'), noEnvironmentButton: __('Learn more'),
policyPreview: s__('SecurityOrchestration|Policy preview'), policyPreview: s__('SecurityOrchestration|Policy preview'),
rules: s__('SecurityOrchestration|Rules'), rules: s__('SecurityOrchestration|Rules'),
unparseable: s__('SecurityOrchestration|Unable to parse policy'),
}, },
components: { components: {
GlEmptyState, GlEmptyState,
...@@ -102,6 +101,9 @@ export default { ...@@ -102,6 +101,9 @@ export default {
humanizedPolicy() { humanizedPolicy() {
return this.policy.error ? null : humanizeNetworkPolicy(this.policy); return this.policy.error ? null : humanizeNetworkPolicy(this.policy);
}, },
initialTab() {
return this.hasParsingError ? 1 : 0;
},
policyAlert() { policyAlert() {
return Boolean(this.policy.annotations); return Boolean(this.policy.annotations);
}, },
...@@ -282,7 +284,7 @@ export default { ...@@ -282,7 +284,7 @@ export default {
</template> </template>
<template #disabled> <template #disabled>
<policy-preview :policy-yaml="$options.i18n.unparsable" /> <policy-preview :initial-tab="initialTab" :policy-yaml="yamlEditorValue" />
</template> </template>
<policy-preview :policy-yaml="policyYaml" :policy-description="humanizedPolicy" /> <policy-preview :policy-yaml="policyYaml" :policy-description="humanizedPolicy" />
......
import { GlEmptyState, GlLoadingIcon, GlToggle } from '@gitlab/ui'; import { GlEmptyState, GlLoadingIcon, GlToggle } from '@gitlab/ui';
import { EDITOR_MODE_YAML } from 'ee/threat_monitoring/components/policy_editor/constants'; import { EDITOR_MODE_YAML } from 'ee/threat_monitoring/components/policy_editor/constants';
import DimDisableContainer from 'ee/threat_monitoring/components/policy_editor/dim_disable_container.vue';
import { import {
RuleDirectionInbound, RuleDirectionInbound,
PortMatchModeAny, PortMatchModeAny,
...@@ -56,7 +57,7 @@ describe('NetworkPolicyEditor component', () => { ...@@ -56,7 +57,7 @@ describe('NetworkPolicyEditor component', () => {
...provide, ...provide,
}, },
store, store,
stubs: { PolicyYamlEditor: true }, stubs: { DimDisableContainer, PolicyYamlEditor: true },
}); });
}; };
...@@ -212,8 +213,12 @@ describe('NetworkPolicyEditor component', () => { ...@@ -212,8 +213,12 @@ describe('NetworkPolicyEditor component', () => {
expect(wrapper.findByTestId('policy-action-container').props().disabled).toBe(true); expect(wrapper.findByTestId('policy-action-container').props().disabled).toBe(true);
}); });
it('disables policy preview', () => { it('disables policy preview and sets initial tab to yaml', () => {
expect(wrapper.findByTestId('policy-preview-container').props().disabled).toBe(true); expect(wrapper.findByTestId('policy-preview-container').props().disabled).toBe(true);
expect(findPreview().props()).toMatchObject({
initialTab: 1,
policyYaml: mockExistingL7Policy.manifest,
});
}); });
it('does not update yaml editor value on switch to yaml editor', async () => { it('does not update yaml editor value on switch to yaml editor', async () => {
......
...@@ -29908,9 +29908,6 @@ msgstr "" ...@@ -29908,9 +29908,6 @@ msgstr ""
msgid "SecurityOrchestration|To widen your search, change filters above or select a different security policy project." msgid "SecurityOrchestration|To widen your search, change filters above or select a different security policy project."
msgstr "" msgstr ""
msgid "SecurityOrchestration|Unable to parse policy"
msgstr ""
msgid "SecurityOrchestration|Update scan execution policies" msgid "SecurityOrchestration|Update scan execution policies"
msgstr "" msgstr ""
......
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