debian-mirror-gitlab/app/assets/javascripts/pipeline_editor/index.js

115 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-01-29 00:20:46 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
2021-03-11 19:13:27 +05:30
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
2021-04-29 21:17:54 +05:30
import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants';
import getCurrentBranch from './graphql/queries/client/current_branch.graphql';
2021-09-04 01:27:46 +05:30
import getLastCommitBranchQuery from './graphql/queries/client/last_commit_branch.query.graphql';
2021-06-08 01:23:25 +05:30
import getPipelineEtag from './graphql/queries/client/pipeline_etag.graphql';
2021-01-29 00:20:46 +05:30
import { resolvers } from './graphql/resolvers';
2021-03-11 19:13:27 +05:30
import typeDefs from './graphql/typedefs.graphql';
2021-01-29 00:20:46 +05:30
import PipelineEditorApp from './pipeline_editor_app.vue';
export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
2021-03-11 19:13:27 +05:30
// Prevent issues loading syntax validation workers
// Fixes https://gitlab.com/gitlab-org/gitlab/-/issues/297252
// TODO Remove when https://gitlab.com/gitlab-org/gitlab/-/issues/321656 is resolved
resetServiceWorkersPublicPath();
2021-01-29 00:20:46 +05:30
const el = document.querySelector(selector);
2021-02-22 17:27:13 +05:30
if (!el) {
return null;
}
2021-03-08 18:12:59 +05:30
const {
2021-03-11 19:13:27 +05:30
// Add to apollo cache as it can be updated by future queries
2021-04-17 20:07:23 +05:30
initialBranchName,
2021-06-08 01:23:25 +05:30
pipelineEtag,
2021-03-11 19:13:27 +05:30
// Add to provide/inject API for static values
ciConfigPath,
2021-06-08 01:23:25 +05:30
ciExamplesHelpPagePath,
ciHelpPagePath,
2021-03-08 18:12:59 +05:30
defaultBranch,
2021-04-17 20:07:23 +05:30
emptyStateIllustrationPath,
2021-06-08 01:23:25 +05:30
helpPaths,
2021-03-08 18:12:59 +05:30
lintHelpPagePath,
2021-06-08 01:23:25 +05:30
needsHelpPagePath,
2021-03-11 19:13:27 +05:30
newMergeRequestPath,
2021-06-08 01:23:25 +05:30
pipelinePagePath,
2021-03-08 18:12:59 +05:30
projectFullPath,
projectPath,
projectNamespace,
2021-06-08 01:23:25 +05:30
runnerHelpPagePath,
totalBranches,
2021-03-08 18:12:59 +05:30
ymlHelpPagePath,
} = el?.dataset;
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
const configurationPaths = Object.fromEntries(
Object.entries(CODE_SNIPPET_SOURCE_SETTINGS).map(([source, { datasetKey }]) => [
source,
el.dataset[datasetKey],
]),
);
2021-01-29 00:20:46 +05:30
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
2021-11-11 11:23:49 +05:30
defaultClient: createDefaultClient(resolvers, {
typeDefs,
useGet: true,
assumeImmutableResults: true,
}),
2021-01-29 00:20:46 +05:30
});
2021-04-29 21:17:54 +05:30
const { cache } = apolloProvider.clients.defaultClient;
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
cache.writeQuery({
query: getCurrentBranch,
2021-03-11 19:13:27 +05:30
data: {
2021-04-17 20:07:23 +05:30
currentBranch: initialBranchName || defaultBranch,
2021-04-29 21:17:54 +05:30
},
});
2021-06-08 01:23:25 +05:30
cache.writeQuery({
query: getPipelineEtag,
data: {
pipelineEtag,
},
});
2021-09-04 01:27:46 +05:30
cache.writeQuery({
query: getLastCommitBranchQuery,
data: {
lastCommitBranch: '',
},
});
2021-01-29 00:20:46 +05:30
return new Vue({
el,
apolloProvider,
2021-03-08 18:12:59 +05:30
provide: {
2021-03-11 19:13:27 +05:30
ciConfigPath,
2021-06-08 01:23:25 +05:30
ciExamplesHelpPagePath,
ciHelpPagePath,
configurationPaths,
2021-03-11 19:13:27 +05:30
defaultBranch,
2021-04-17 20:07:23 +05:30
emptyStateIllustrationPath,
2021-06-08 01:23:25 +05:30
helpPaths,
2021-03-08 18:12:59 +05:30
lintHelpPagePath,
2021-06-08 01:23:25 +05:30
needsHelpPagePath,
2021-03-11 19:13:27 +05:30
newMergeRequestPath,
2021-06-08 01:23:25 +05:30
pipelinePagePath,
2021-03-08 18:12:59 +05:30
projectFullPath,
projectPath,
projectNamespace,
2021-06-08 01:23:25 +05:30
runnerHelpPagePath,
totalBranches: parseInt(totalBranches, 10),
2021-03-08 18:12:59 +05:30
ymlHelpPagePath,
},
2021-01-29 00:20:46 +05:30
render(h) {
2021-03-11 19:13:27 +05:30
return h(PipelineEditorApp);
2021-01-29 00:20:46 +05:30
},
});
};