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

70 lines
1.7 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-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-03-08 18:12:59 +05:30
commitSha,
2021-04-17 20:07:23 +05:30
initialBranchName,
2021-03-11 19:13:27 +05:30
// Add to provide/inject API for static values
ciConfigPath,
2021-03-08 18:12:59 +05:30
defaultBranch,
2021-04-17 20:07:23 +05:30
emptyStateIllustrationPath,
2021-03-08 18:12:59 +05:30
lintHelpPagePath,
2021-03-11 19:13:27 +05:30
newMergeRequestPath,
2021-03-08 18:12:59 +05:30
projectFullPath,
projectPath,
projectNamespace,
ymlHelpPagePath,
} = el?.dataset;
2021-01-29 00:20:46 +05:30
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(resolvers, { typeDefs }),
});
2021-03-11 19:13:27 +05:30
apolloProvider.clients.defaultClient.cache.writeData({
data: {
2021-04-17 20:07:23 +05:30
currentBranch: initialBranchName || defaultBranch,
2021-03-11 19:13:27 +05:30
commitSha,
},
});
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,
defaultBranch,
2021-04-17 20:07:23 +05:30
emptyStateIllustrationPath,
2021-03-08 18:12:59 +05:30
lintHelpPagePath,
2021-03-11 19:13:27 +05:30
newMergeRequestPath,
2021-03-08 18:12:59 +05:30
projectFullPath,
projectPath,
projectNamespace,
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
},
});
};