Commit 471ad1ac authored by pburdette's avatar pburdette

Implement apollo mutations

Setup the mutations in the
header component.
parent f3099eae
<script> <script>
import { GlAlert, GlButton, GlLoadingIcon, GlModal, GlModalDirective } from '@gitlab/ui'; import { GlAlert, GlButton, GlLoadingIcon, GlModal, GlModalDirective } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import axios from '~/lib/utils/axios_utils';
import ciHeader from '~/vue_shared/components/header_ci_component.vue'; import ciHeader from '~/vue_shared/components/header_ci_component.vue';
import { setUrlFragment, redirectTo } from '~/lib/utils/url_utility'; import { setUrlFragment, redirectTo } from '~/lib/utils/url_utility';
import getPipelineQuery from '../graphql/queries/get_pipeline_header_data.query.graphql'; import getPipelineQuery from '../graphql/queries/get_pipeline_header_data.query.graphql';
...@@ -32,7 +31,7 @@ export default { ...@@ -32,7 +31,7 @@ export default {
[DEFAULT]: __('An unknown error occurred.'), [DEFAULT]: __('An unknown error occurred.'),
}, },
inject: { inject: {
// Receive `cancel`, `delete`, `fullProject` and `retry` // Receive `fullProject` and `pipelinesPath`
paths: { paths: {
default: {}, default: {},
}, },
...@@ -126,37 +125,47 @@ export default { ...@@ -126,37 +125,47 @@ export default {
reportFailure(errorType) { reportFailure(errorType) {
this.failureType = errorType; this.failureType = errorType;
}, },
async postAction(path) { async cancelPipeline() {
this.isCanceling = true;
try { try {
await axios.post(path); await this.$apollo.mutate({
mutation: cancelPipelineMutation,
variables: { id: this.pipeline.id },
});
this.$apollo.queries.pipeline.refetch(); this.$apollo.queries.pipeline.refetch();
} catch { } catch {
this.reportFailure(POST_FAILURE); this.reportFailure(POST_FAILURE);
} }
}, },
async cancelPipeline() {
this.isCanceling = true;
this.postAction(this.paths.cancel);
},
async retryPipeline() { async retryPipeline() {
this.isRetrying = true; this.isRetrying = true;
this.postAction(this.paths.retry);
try {
await this.$apollo.mutate({
mutation: retryPipelineMutation,
variables: { id: this.pipeline.id },
});
this.$apollo.queries.pipeline.refetch();
} catch {
this.reportFailure(POST_FAILURE);
}
}, },
async deletePipeline() { async deletePipeline() {
this.isDeleting = true; this.isDeleting = true;
this.$apollo.queries.pipeline.stopPolling(); this.$apollo.queries.pipeline.stopPolling();
try { try {
const { request } = await axios.delete(this.paths.delete); await this.$apollo.mutate({
mutation: deletePipelineMutation,
// const data = await this.$apollo.mutate({ variables: {
// mutation: deletePipelineMutation, id: this.pipeline.id,
// variables: { },
// id: this.pipelineId, });
// },
// });
redirectTo(setUrlFragment(request.responseURL, 'delete_success')); redirectTo(setUrlFragment(this.paths.pipelinesPath, 'delete_success'));
} catch { } catch {
this.$apollo.queries.pipeline.startPolling(POLL_INTERVAL); this.$apollo.queries.pipeline.startPolling(POLL_INTERVAL);
this.reportFailure(DELETE_FAILURE); this.reportFailure(DELETE_FAILURE);
......
...@@ -2,4 +2,4 @@ mutation cancelPipeline($id: CiPipelineID!) { ...@@ -2,4 +2,4 @@ mutation cancelPipeline($id: CiPipelineID!) {
pipelineCancel(input: { id: $id }) { pipelineCancel(input: { id: $id }) {
errors errors
} }
} }
\ No newline at end of file
...@@ -2,4 +2,4 @@ mutation deletePipeline($id: CiPipelineID!) { ...@@ -2,4 +2,4 @@ mutation deletePipeline($id: CiPipelineID!) {
pipelineDestroy(input: { id: $id }) { pipelineDestroy(input: { id: $id }) {
errors errors
} }
} }
\ No newline at end of file
...@@ -2,4 +2,4 @@ mutation retryPipeline($id: CiPipelineID!) { ...@@ -2,4 +2,4 @@ mutation retryPipeline($id: CiPipelineID!) {
pipelineRetry(input: { id: $id }) { pipelineRetry(input: { id: $id }) {
errors errors
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ export const createPipelineHeaderApp = elSelector => { ...@@ -16,7 +16,7 @@ export const createPipelineHeaderApp = elSelector => {
return; return;
} }
const { cancelPath, deletePath, fullPath, pipelineId, pipelineIid, retryPath } = el?.dataset; const { fullPath, pipelineId, pipelineIid, pipelinesPath } = el?.dataset;
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el, el,
...@@ -26,10 +26,8 @@ export const createPipelineHeaderApp = elSelector => { ...@@ -26,10 +26,8 @@ export const createPipelineHeaderApp = elSelector => {
apolloProvider, apolloProvider,
provide: { provide: {
paths: { paths: {
cancel: cancelPath,
delete: deletePath,
fullProject: fullPath, fullProject: fullPath,
retry: retryPath, pipelinesPath,
}, },
pipelineId, pipelineId,
pipelineIid, pipelineIid,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
- add_page_specific_style 'page_bundles/ci_status' - add_page_specific_style 'page_bundles/ci_status'
.js-pipeline-container{ data: { controller_action: "#{controller.action_name}" } } .js-pipeline-container{ data: { controller_action: "#{controller.action_name}" } }
#js-pipeline-header-vue.pipeline-header-container{ data: {full_path: @project.full_path, retry_path: retry_project_pipeline_path(@pipeline.project, @pipeline), cancel_path: cancel_project_pipeline_path(@pipeline.project, @pipeline), delete_path: project_pipeline_path(@pipeline.project, @pipeline), pipeline_iid: @pipeline.iid, pipeline_id: @pipeline.id} } #js-pipeline-header-vue.pipeline-header-container{ data: { full_path: @project.full_path, pipeline_iid: @pipeline.iid, pipeline_id: @pipeline.id, pipelines_path: project_pipelines_path(@project) } }
- if @pipeline.commit.present? - if @pipeline.commit.present?
= render "projects/pipelines/info", commit: @pipeline.commit = render "projects/pipelines/info", commit: @pipeline.commit
......
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