Commit 22cf4a79 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'mw-fix-deploy-rollback-modal-regression' into 'master'

Deployment rollback modal: Change form submit to POST

See merge request gitlab-org/gitlab!67763
parents 2bdafdb3 4e2db193
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
import { GlModal } from '@gitlab/ui'; import { GlModal } from '@gitlab/ui';
import { escape } from 'lodash'; import { escape } from 'lodash';
import { s__, sprintf } from '~/locale'; import csrf from '~/lib/utils/csrf';
import { __, s__, sprintf } from '~/locale';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
...@@ -35,6 +36,11 @@ export default { ...@@ -35,6 +36,11 @@ export default {
required: false, required: false,
default: true, default: true,
}, },
retryUrl: {
type: String,
required: false,
default: null,
},
}, },
computed: { computed: {
...@@ -66,6 +72,12 @@ export default { ...@@ -66,6 +72,12 @@ export default {
return this.environment.commitUrl; return this.environment.commitUrl;
}, },
modalActionText() {
return this.environment.isLastDeployment
? s__('Environments|Re-deploy')
: s__('Environments|Rollback');
},
modalText() { modalText() {
const linkStart = `<a class="commit-sha mr-0" href="${escape(this.commitUrl)}">`; const linkStart = `<a class="commit-sha mr-0" href="${escape(this.commitUrl)}">`;
const commitId = escape(this.commitShortSha); const commitId = escape(this.commitShortSha);
...@@ -90,10 +102,17 @@ export default { ...@@ -90,10 +102,17 @@ export default {
); );
}, },
modalActionText() { primaryProps() {
return this.environment.isLastDeployment let attributes = [{ variant: 'danger' }];
? s__('Environments|Re-deploy')
: s__('Environments|Rollback'); if (this.retryUrl) {
attributes = [...attributes, { 'data-method': 'post' }, { href: this.retryUrl }];
}
return {
text: this.modalActionText,
attributes,
};
}, },
}, },
...@@ -114,15 +133,20 @@ export default { ...@@ -114,15 +133,20 @@ export default {
return ''; return '';
}, },
}, },
csrf,
cancelProps: {
text: __('Cancel'),
attributes: [{ variant: 'danger' }],
},
}; };
</script> </script>
<template> <template>
<gl-modal <gl-modal
:title="modalTitle" :title="modalTitle"
:visible="visible" :visible="visible"
:action-cancel="$options.cancelProps"
:action-primary="primaryProps"
modal-id="confirm-rollback-modal" modal-id="confirm-rollback-modal"
:ok-title="modalActionText"
ok-variant="danger"
@ok="onOk" @ok="onOk"
@change="handleChange" @change="handleChange"
> >
......
<script> <script>
import { parseBoolean } from '~/lib/utils/common_utils'; import { parseBoolean } from '~/lib/utils/common_utils';
import { redirectTo } from '~/lib/utils/url_utility';
import eventHub from '../event_hub';
import ConfirmRollbackModal from './confirm_rollback_modal.vue'; import ConfirmRollbackModal from './confirm_rollback_modal.vue';
export default { export default {
...@@ -22,10 +20,6 @@ export default { ...@@ -22,10 +20,6 @@ export default {
}; };
}, },
mounted() { mounted() {
eventHub.$on('rollbackEnvironment', () => {
redirectTo(this.retryPath);
});
document.querySelectorAll(this.selector).forEach((button) => { document.querySelectorAll(this.selector).forEach((button) => {
button.addEventListener('click', (e) => { button.addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
...@@ -57,6 +51,7 @@ export default { ...@@ -57,6 +51,7 @@ export default {
v-model="visible" v-model="visible"
:environment="environment" :environment="environment"
:has-multiple-commits="false" :has-multiple-commits="false"
:retry-url="retryPath"
/> />
<div v-else></div> <div v-else></div>
</template> </template>
...@@ -23,11 +23,15 @@ describe('Confirm Rollback Modal Component', () => { ...@@ -23,11 +23,15 @@ describe('Confirm Rollback Modal Component', () => {
commitUrl: 'test/-/commit/abc0123', commitUrl: 'test/-/commit/abc0123',
}; };
const retryPath = 'test/-/jobs/123/retry';
describe.each` describe.each`
hasMultipleCommits | environmentData hasMultipleCommits | environmentData | retryUrl | primaryPropsAttrs
${true} | ${envWithLastDeployment} ${true} | ${envWithLastDeployment} | ${null} | ${[{ variant: 'danger' }]}
${false} | ${envWithoutLastDeployment} ${false} | ${envWithoutLastDeployment} | ${retryPath} | ${[{ variant: 'danger' }, { 'data-method': 'post' }, { href: retryPath }]}
`('when hasMultipleCommits=$hasMultipleCommits', ({ hasMultipleCommits, environmentData }) => { `(
'when hasMultipleCommits=$hasMultipleCommits',
({ hasMultipleCommits, environmentData, retryUrl, primaryPropsAttrs }) => {
beforeEach(() => { beforeEach(() => {
environment = environmentData; environment = environmentData;
}); });
...@@ -40,13 +44,15 @@ describe('Confirm Rollback Modal Component', () => { ...@@ -40,13 +44,15 @@ describe('Confirm Rollback Modal Component', () => {
isLastDeployment: false, isLastDeployment: false,
}, },
hasMultipleCommits, hasMultipleCommits,
retryUrl,
}, },
}); });
const modal = component.find(GlModal); const modal = component.find(GlModal);
expect(modal.attributes('title')).toContain('Rollback'); expect(modal.attributes('title')).toContain('Rollback');
expect(modal.attributes('title')).toContain('test'); expect(modal.attributes('title')).toContain('test');
expect(modal.attributes('ok-title')).toBe('Rollback'); expect(modal.props('actionPrimary').text).toBe('Rollback');
expect(modal.props('actionPrimary').attributes).toEqual(primaryPropsAttrs);
expect(modal.text()).toContain('commit abc0123'); expect(modal.text()).toContain('commit abc0123');
expect(modal.text()).toContain('Are you sure you want to continue?'); expect(modal.text()).toContain('Are you sure you want to continue?');
}); });
...@@ -65,7 +71,7 @@ describe('Confirm Rollback Modal Component', () => { ...@@ -65,7 +71,7 @@ describe('Confirm Rollback Modal Component', () => {
expect(modal.attributes('title')).toContain('Re-deploy'); expect(modal.attributes('title')).toContain('Re-deploy');
expect(modal.attributes('title')).toContain('test'); expect(modal.attributes('title')).toContain('test');
expect(modal.attributes('ok-title')).toBe('Re-deploy'); expect(modal.props('actionPrimary').text).toBe('Re-deploy');
expect(modal.text()).toContain('commit abc0123'); expect(modal.text()).toContain('commit abc0123');
expect(modal.text()).toContain('Are you sure you want to continue?'); expect(modal.text()).toContain('Are you sure you want to continue?');
}); });
...@@ -84,5 +90,6 @@ describe('Confirm Rollback Modal Component', () => { ...@@ -84,5 +90,6 @@ describe('Confirm Rollback Modal Component', () => {
expect(eventHubSpy).toHaveBeenCalledWith('rollbackEnvironment', env); expect(eventHubSpy).toHaveBeenCalledWith('rollbackEnvironment', env);
}); });
}); },
);
}); });
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