2020-10-30 12:08:44 +00:00
|
|
|
import Vue from 'vue';
|
2020-10-30 21:08:52 +00:00
|
|
|
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2021-02-16 15:09:50 +00:00
|
|
|
import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
|
2021-10-27 18:13:16 +00:00
|
|
|
import { EDITOR_APP_STATUS_LOADING } from './constants';
|
2021-04-08 18:09:32 +00:00
|
|
|
import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants';
|
2021-12-14 21:13:08 +00:00
|
|
|
import getCurrentBranch from './graphql/queries/client/current_branch.query.graphql';
|
|
|
|
import getAppStatus from './graphql/queries/client/app_status.query.graphql';
|
2021-12-16 12:15:41 +00:00
|
|
|
import getLastCommitBranch from './graphql/queries/client/last_commit_branch.query.graphql';
|
2021-12-14 21:13:08 +00:00
|
|
|
import getPipelineEtag from './graphql/queries/client/pipeline_etag.query.graphql';
|
2020-10-30 21:08:52 +00:00
|
|
|
import { resolvers } from './graphql/resolvers';
|
2021-02-14 18:09:20 +00:00
|
|
|
import typeDefs from './graphql/typedefs.graphql';
|
2020-10-30 12:08:44 +00:00
|
|
|
import PipelineEditorApp from './pipeline_editor_app.vue';
|
|
|
|
|
|
|
|
export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
|
2021-02-16 15:09:50 +00:00
|
|
|
// 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();
|
|
|
|
|
2020-10-30 12:08:44 +00:00
|
|
|
const el = document.querySelector(selector);
|
|
|
|
|
2020-11-20 21:09:12 +00:00
|
|
|
if (!el) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-12-22 15:09:51 +00:00
|
|
|
const {
|
2021-02-03 21:09:17 +00:00
|
|
|
// Add to apollo cache as it can be updated by future queries
|
2021-03-09 15:08:59 +00:00
|
|
|
initialBranchName,
|
2021-04-28 00:10:21 +00:00
|
|
|
pipelineEtag,
|
2021-02-03 21:09:17 +00:00
|
|
|
// Add to provide/inject API for static values
|
|
|
|
ciConfigPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
ciExamplesHelpPagePath,
|
|
|
|
ciHelpPagePath,
|
2020-12-22 15:09:51 +00:00
|
|
|
defaultBranch,
|
2021-03-01 21:11:09 +00:00
|
|
|
emptyStateIllustrationPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
helpPaths,
|
2020-12-22 15:09:51 +00:00
|
|
|
lintHelpPagePath,
|
2021-12-20 18:13:27 +00:00
|
|
|
lintUnavailableHelpPagePath,
|
2021-05-11 15:10:20 +00:00
|
|
|
needsHelpPagePath,
|
2021-02-03 21:09:17 +00:00
|
|
|
newMergeRequestPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
pipelinePagePath,
|
2021-01-09 00:10:30 +00:00
|
|
|
projectFullPath,
|
2020-12-22 15:09:51 +00:00
|
|
|
projectPath,
|
2021-01-09 00:10:30 +00:00
|
|
|
projectNamespace,
|
2021-05-11 15:10:20 +00:00
|
|
|
runnerHelpPagePath,
|
2021-05-13 18:10:32 +00:00
|
|
|
totalBranches,
|
2021-01-06 21:10:18 +00:00
|
|
|
ymlHelpPagePath,
|
2020-12-22 15:09:51 +00:00
|
|
|
} = el?.dataset;
|
2020-10-30 21:08:52 +00:00
|
|
|
|
2021-04-08 18:09:32 +00:00
|
|
|
const configurationPaths = Object.fromEntries(
|
|
|
|
Object.entries(CODE_SNIPPET_SOURCE_SETTINGS).map(([source, { datasetKey }]) => [
|
|
|
|
source,
|
|
|
|
el.dataset[datasetKey],
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
2020-10-30 21:08:52 +00:00
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
2021-08-23 15:10:43 +00:00
|
|
|
defaultClient: createDefaultClient(resolvers, {
|
|
|
|
typeDefs,
|
|
|
|
useGet: true,
|
|
|
|
}),
|
2020-10-30 21:08:52 +00:00
|
|
|
});
|
2021-03-24 12:09:32 +00:00
|
|
|
const { cache } = apolloProvider.clients.defaultClient;
|
2020-10-30 21:08:52 +00:00
|
|
|
|
2021-10-27 18:13:16 +00:00
|
|
|
cache.writeQuery({
|
|
|
|
query: getAppStatus,
|
|
|
|
data: {
|
2021-12-16 12:15:41 +00:00
|
|
|
app: {
|
|
|
|
__typename: 'PipelineEditorApp',
|
|
|
|
status: EDITOR_APP_STATUS_LOADING,
|
|
|
|
},
|
2021-10-27 18:13:16 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-24 12:09:32 +00:00
|
|
|
cache.writeQuery({
|
|
|
|
query: getCurrentBranch,
|
2021-02-03 21:09:17 +00:00
|
|
|
data: {
|
2021-12-16 12:15:41 +00:00
|
|
|
workBranches: {
|
|
|
|
__typename: 'BranchList',
|
|
|
|
current: {
|
|
|
|
__typename: 'WorkBranch',
|
|
|
|
name: initialBranchName || defaultBranch,
|
|
|
|
},
|
|
|
|
},
|
2021-03-24 12:09:32 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-04-28 00:10:21 +00:00
|
|
|
cache.writeQuery({
|
2021-12-16 12:15:41 +00:00
|
|
|
query: getLastCommitBranch,
|
2021-04-28 00:10:21 +00:00
|
|
|
data: {
|
2021-12-16 12:15:41 +00:00
|
|
|
workBranches: {
|
|
|
|
__typename: 'BranchList',
|
|
|
|
lastCommit: {
|
|
|
|
__typename: 'WorkBranch',
|
|
|
|
name: '',
|
|
|
|
},
|
|
|
|
},
|
2021-04-28 00:10:21 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-15 18:09:57 +00:00
|
|
|
cache.writeQuery({
|
2021-12-16 12:15:41 +00:00
|
|
|
query: getPipelineEtag,
|
2021-06-15 18:09:57 +00:00
|
|
|
data: {
|
2021-12-16 12:15:41 +00:00
|
|
|
etags: {
|
|
|
|
__typename: 'EtagValues',
|
|
|
|
pipeline: pipelineEtag,
|
|
|
|
},
|
2021-06-15 18:09:57 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-10-30 12:08:44 +00:00
|
|
|
return new Vue({
|
|
|
|
el,
|
2020-10-30 21:08:52 +00:00
|
|
|
apolloProvider,
|
2020-12-22 15:09:51 +00:00
|
|
|
provide: {
|
2021-02-03 21:09:17 +00:00
|
|
|
ciConfigPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
ciExamplesHelpPagePath,
|
|
|
|
ciHelpPagePath,
|
|
|
|
configurationPaths,
|
2021-10-25 21:12:12 +00:00
|
|
|
dataMethod: 'graphql',
|
2021-02-03 21:09:17 +00:00
|
|
|
defaultBranch,
|
2021-03-01 21:11:09 +00:00
|
|
|
emptyStateIllustrationPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
helpPaths,
|
2020-12-22 15:09:51 +00:00
|
|
|
lintHelpPagePath,
|
2021-12-20 18:13:27 +00:00
|
|
|
lintUnavailableHelpPagePath,
|
2021-05-11 15:10:20 +00:00
|
|
|
needsHelpPagePath,
|
2021-02-03 21:09:17 +00:00
|
|
|
newMergeRequestPath,
|
2021-05-11 15:10:20 +00:00
|
|
|
pipelinePagePath,
|
2021-01-09 00:10:30 +00:00
|
|
|
projectFullPath,
|
|
|
|
projectPath,
|
|
|
|
projectNamespace,
|
2021-05-11 15:10:20 +00:00
|
|
|
runnerHelpPagePath,
|
2021-05-13 18:10:32 +00:00
|
|
|
totalBranches: parseInt(totalBranches, 10),
|
2021-01-06 21:10:18 +00:00
|
|
|
ymlHelpPagePath,
|
2020-12-22 15:09:51 +00:00
|
|
|
},
|
2020-10-30 12:08:44 +00:00
|
|
|
render(h) {
|
2021-02-03 21:09:17 +00:00
|
|
|
return h(PipelineEditorApp);
|
2020-10-30 12:08:44 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|