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

144 lines
3.6 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-12-11 22:18:48 +05:30
import { EDITOR_APP_STATUS_LOADING } from './constants';
2021-04-29 21:17:54 +05:30
import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants';
2022-01-26 12:08:38 +05:30
import getCurrentBranch from './graphql/queries/client/current_branch.query.graphql';
import getAppStatus from './graphql/queries/client/app_status.query.graphql';
import getLastCommitBranch from './graphql/queries/client/last_commit_branch.query.graphql';
import getPipelineEtag from './graphql/queries/client/pipeline_etag.query.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,
2022-03-02 08:16:31 +05:30
lintUnavailableHelpPagePath,
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,
}),
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-12-11 22:18:48 +05:30
cache.writeQuery({
query: getAppStatus,
data: {
2022-01-26 12:08:38 +05:30
app: {
__typename: 'PipelineEditorApp',
status: EDITOR_APP_STATUS_LOADING,
},
2021-12-11 22:18:48 +05:30
},
});
2021-04-29 21:17:54 +05:30
cache.writeQuery({
query: getCurrentBranch,
2021-03-11 19:13:27 +05:30
data: {
2022-01-26 12:08:38 +05:30
workBranches: {
__typename: 'BranchList',
current: {
__typename: 'WorkBranch',
name: initialBranchName || defaultBranch,
},
},
2021-04-29 21:17:54 +05:30
},
});
2021-06-08 01:23:25 +05:30
cache.writeQuery({
2022-01-26 12:08:38 +05:30
query: getLastCommitBranch,
2021-06-08 01:23:25 +05:30
data: {
2022-01-26 12:08:38 +05:30
workBranches: {
__typename: 'BranchList',
lastCommit: {
__typename: 'WorkBranch',
name: '',
},
},
2021-06-08 01:23:25 +05:30
},
});
2021-09-04 01:27:46 +05:30
cache.writeQuery({
2022-01-26 12:08:38 +05:30
query: getPipelineEtag,
2021-09-04 01:27:46 +05:30
data: {
2022-01-26 12:08:38 +05:30
etags: {
__typename: 'EtagValues',
pipeline: pipelineEtag,
},
2021-09-04 01:27:46 +05:30
},
});
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-12-11 22:18:48 +05:30
dataMethod: 'graphql',
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,
2022-03-02 08:16:31 +05:30
lintUnavailableHelpPagePath,
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
},
});
};