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