diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 18462cc24c7b265ca984381b98fddeae2b76d5b7..a259118003901146072ae6e088605d41325e5777 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -483,6 +483,16 @@ export const historyPushState = newUrl => { window.history.pushState({}, document.title, newUrl); }; +/** + * Based on the current location and the string parameters provided + * overwrites the current entry in the history without reloading the page. + * + * @param {String} param + */ +export const historyReplaceState = newUrl => { + window.history.replaceState({}, document.title, newUrl); +}; + /** * Returns true for a String value of "true" and false otherwise. * This is the opposite of Boolean(...).toString(). diff --git a/app/assets/javascripts/pages/projects/pipelines/index/index.js b/app/assets/javascripts/pages/projects/pipelines/index/index.js index fd72d2ddbe06296cfed33eed34740a833e778e63..4b4a274794dc46b6f691b1c1ed3a515f043daa6f 100644 --- a/app/assets/javascripts/pages/projects/pipelines/index/index.js +++ b/app/assets/javascripts/pages/projects/pipelines/index/index.js @@ -1,10 +1,18 @@ import Vue from 'vue'; +import { GlToast } from '@gitlab/ui'; +import { doesHashExistInUrl } from '~/lib/utils/url_utility'; +import { + parseBoolean, + historyReplaceState, + buildUrlWithCurrentLocation, +} from '~/lib/utils/common_utils'; +import { __ } from '~/locale'; import PipelinesStore from '../../../../pipelines/stores/pipelines_store'; import pipelinesComponent from '../../../../pipelines/components/pipelines.vue'; import Translate from '../../../../vue_shared/translate'; -import { parseBoolean } from '../../../../lib/utils/common_utils'; Vue.use(Translate); +Vue.use(GlToast); document.addEventListener( 'DOMContentLoaded', @@ -21,6 +29,11 @@ document.addEventListener( }, created() { this.dataset = document.querySelector(this.$options.el).dataset; + + if (doesHashExistInUrl('delete_success')) { + this.$toast.show(__('The pipeline has been deleted')); + historyReplaceState(buildUrlWithCurrentLocation()); + } }, render(createElement) { return createElement('pipelines-component', { diff --git a/app/assets/javascripts/pipelines/components/header_component.vue b/app/assets/javascripts/pipelines/components/header_component.vue index 39afa87afc37cf1ee24823972d93fff2f9813e75..726bba7f9f471ae7675022f41dafb136c09b43b2 100644 --- a/app/assets/javascripts/pipelines/components/header_component.vue +++ b/app/assets/javascripts/pipelines/components/header_component.vue @@ -1,14 +1,17 @@ diff --git a/app/assets/javascripts/pipelines/pipeline_details_bundle.js b/app/assets/javascripts/pipelines/pipeline_details_bundle.js index d8dbc3c2454d6ef7f8322d299f58132832fbd6bf..c874c4c6fdd1060f51ece92cc32a59a12f7522a1 100644 --- a/app/assets/javascripts/pipelines/pipeline_details_bundle.js +++ b/app/assets/javascripts/pipelines/pipeline_details_bundle.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import Flash from '~/flash'; import Translate from '~/vue_shared/translate'; import { __ } from '~/locale'; +import { setUrlFragment, redirectTo } from '~/lib/utils/url_utility'; import pipelineGraph from './components/graph/graph_component.vue'; import GraphBundleMixin from './mixins/graph_pipeline_bundle_mixin'; import PipelinesMediator from './pipeline_details_mediator'; @@ -62,9 +63,11 @@ export default () => { }, created() { eventHub.$on('headerPostAction', this.postAction); + eventHub.$on('headerDeleteAction', this.deleteAction); }, beforeDestroy() { eventHub.$off('headerPostAction', this.postAction); + eventHub.$off('headerDeleteAction', this.deleteAction); }, methods: { postAction(action) { @@ -73,6 +76,13 @@ export default () => { .then(() => this.mediator.refreshPipeline()) .catch(() => Flash(__('An error occurred while making the request.'))); }, + deleteAction(action) { + this.mediator.stopPipelinePoll(); + this.mediator.service + .deleteAction(action.path) + .then(({ request }) => redirectTo(setUrlFragment(request.responseURL, 'delete_success'))) + .catch(() => Flash(__('An error occurred while deleting the pipeline.'))); + }, }, render(createElement) { return createElement('pipeline-header', { diff --git a/app/assets/javascripts/pipelines/pipeline_details_mediator.js b/app/assets/javascripts/pipelines/pipeline_details_mediator.js index bf021a0b447e70bf5ca558aa8a6fdb2573b5a85a..f3387f00fc1fff8392e627321d28d3d385ffd854 100644 --- a/app/assets/javascripts/pipelines/pipeline_details_mediator.js +++ b/app/assets/javascripts/pipelines/pipeline_details_mediator.js @@ -35,7 +35,7 @@ export default class pipelinesMediator { if (!Visibility.hidden()) { this.poll.restart(); } else { - this.poll.stop(); + this.stopPipelinePoll(); } }); } @@ -51,7 +51,7 @@ export default class pipelinesMediator { } refreshPipeline() { - this.poll.stop(); + this.stopPipelinePoll(); return this.service .getPipeline() @@ -64,6 +64,10 @@ export default class pipelinesMediator { ); } + stopPipelinePoll() { + this.poll.stop(); + } + /** * Backend expects paramets in the following format: `expanded[]=id&expanded[]=id` */ diff --git a/app/assets/javascripts/pipelines/services/pipeline_service.js b/app/assets/javascripts/pipelines/services/pipeline_service.js index e44eb9cdfd11201a8b99b6fdf412c67488af2c9d..ba2830ec59614748bc48c9d22678a67a1f520eaf 100644 --- a/app/assets/javascripts/pipelines/services/pipeline_service.js +++ b/app/assets/javascripts/pipelines/services/pipeline_service.js @@ -9,6 +9,11 @@ export default class PipelineService { return axios.get(this.pipeline, { params }); } + // eslint-disable-next-line class-methods-use-this + deleteAction(endpoint) { + return axios.delete(`${endpoint}.json`); + } + // eslint-disable-next-line class-methods-use-this postAction(endpoint) { return axios.post(`${endpoint}.json`); diff --git a/app/assets/javascripts/vue_shared/components/header_ci_component.vue b/app/assets/javascripts/vue_shared/components/header_ci_component.vue index c652a684d7ce8dff7b210913ef902e6b6d371349..dba4a9231a1704b5fa4e6c7aa1055939f53668a6 100644 --- a/app/assets/javascripts/vue_shared/components/header_ci_component.vue +++ b/app/assets/javascripts/vue_shared/components/header_ci_component.vue @@ -117,28 +117,7 @@ export default {