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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

147 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';
2022-11-25 23:54:43 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
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') => {
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,
2022-08-13 15:12:31 +05:30
ciLintPath,
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,
2022-07-16 23:28:13 +05:30
includesHelpPagePath,
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,
2022-08-13 15:12:31 +05:30
simulatePipelineHelpPagePath,
2021-06-08 01:23:25 +05:30
totalBranches,
2022-11-25 23:54:43 +05:30
usesExternalConfig,
2022-07-23 23:45:48 +05:30
validateTabIllustrationPath,
2021-03-08 18:12:59 +05:30
ymlHelpPagePath,
2022-07-16 23:28:13 +05:30
} = 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,
2022-08-13 15:12:31 +05:30
ciLintPath,
2021-06-08 01:23:25 +05:30
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,
2022-07-16 23:28:13 +05:30
includesHelpPagePath,
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,
2022-08-13 15:12:31 +05:30
simulatePipelineHelpPagePath,
2021-06-08 01:23:25 +05:30
totalBranches: parseInt(totalBranches, 10),
2022-11-25 23:54:43 +05:30
usesExternalConfig: parseBoolean(usesExternalConfig),
2022-07-23 23:45:48 +05:30
validateTabIllustrationPath,
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
},
});
};