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 getCommitSha from './graphql/queries/client/commit_sha.graphql';
|
|
|
|
import getCurrentBranch from './graphql/queries/client/current_branch.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-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
|
|
|
|
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({
|
|
|
|
defaultClient: createDefaultClient(resolvers, { typeDefs }),
|
|
|
|
});
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
cache.writeQuery({
|
|
|
|
query: getCommitSha,
|
|
|
|
data: {
|
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-04-29 21:17:54 +05:30
|
|
|
configurationPaths,
|
2021-03-08 18:12:59 +05:30
|
|
|
},
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|