diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-31 00:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-31 00:08:52 +0300 |
commit | 07c452dfa09f8215053d42e010efebb0c4b69ae6 (patch) | |
tree | 31504bddd7cf705ac8fadc94d7a412831aac857c /app/assets/javascripts/pipeline_editor | |
parent | 98d7cc758fb73239fb957c297446c811ab4150d9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/pipeline_editor')
6 files changed, 144 insertions, 15 deletions
diff --git a/app/assets/javascripts/pipeline_editor/components/text_editor.vue b/app/assets/javascripts/pipeline_editor/components/text_editor.vue new file mode 100644 index 00000000000..6ea25af45b3 --- /dev/null +++ b/app/assets/javascripts/pipeline_editor/components/text_editor.vue @@ -0,0 +1,21 @@ +<script> +import EditorLite from '~/vue_shared/components/editor_lite.vue'; + +export default { + components: { + EditorLite, + }, + props: { + value: { + type: String, + required: false, + default: '', + }, + }, +}; +</script> +<template> + <div class="gl-border-solid gl-border-gray-100 gl-border-1"> + <editor-lite v-model="value" file-name="*.yml" :editor-options="{ readOnly: true }" /> + </div> +</template> diff --git a/app/assets/javascripts/pipeline_editor/graphql/queries/blob_content.graphql b/app/assets/javascripts/pipeline_editor/graphql/queries/blob_content.graphql new file mode 100644 index 00000000000..9f1b5b13088 --- /dev/null +++ b/app/assets/javascripts/pipeline_editor/graphql/queries/blob_content.graphql @@ -0,0 +1,5 @@ +query getBlobContent($projectPath: ID!, $path: String, $ref: String!) { + blobContent(projectPath: $projectPath, path: $path, ref: $ref) @client { + rawData + } +} diff --git a/app/assets/javascripts/pipeline_editor/graphql/resolvers.js b/app/assets/javascripts/pipeline_editor/graphql/resolvers.js new file mode 100644 index 00000000000..7b8c70ac93e --- /dev/null +++ b/app/assets/javascripts/pipeline_editor/graphql/resolvers.js @@ -0,0 +1,16 @@ +import Api from '~/api'; + +export const resolvers = { + Query: { + blobContent(_, { projectPath, path, ref }) { + return { + __typename: 'BlobContent', + rawData: Api.getRawFile(projectPath, path, { ref }).then(({ data }) => { + return data; + }), + }; + }, + }, +}; + +export default resolvers; diff --git a/app/assets/javascripts/pipeline_editor/graphql/typedefs.graphql b/app/assets/javascripts/pipeline_editor/graphql/typedefs.graphql new file mode 100644 index 00000000000..f4f65262158 --- /dev/null +++ b/app/assets/javascripts/pipeline_editor/graphql/typedefs.graphql @@ -0,0 +1,7 @@ +type BlobContent { + rawData: String! +} + +extend type Query { + blobContent: BlobContent +} diff --git a/app/assets/javascripts/pipeline_editor/index.js b/app/assets/javascripts/pipeline_editor/index.js index 7d3d5159d58..ccd7b74064f 100644 --- a/app/assets/javascripts/pipeline_editor/index.js +++ b/app/assets/javascripts/pipeline_editor/index.js @@ -1,13 +1,34 @@ import Vue from 'vue'; + +import VueApollo from 'vue-apollo'; +import createDefaultClient from '~/lib/graphql'; +import typeDefs from './graphql/typedefs.graphql'; +import { resolvers } from './graphql/resolvers'; + import PipelineEditorApp from './pipeline_editor_app.vue'; export const initPipelineEditor = (selector = '#js-pipeline-editor') => { const el = document.querySelector(selector); + const { projectPath, defaultBranch, ciConfigPath } = el?.dataset; + + Vue.use(VueApollo); + + const apolloProvider = new VueApollo({ + defaultClient: createDefaultClient(resolvers, { typeDefs }), + }); + return new Vue({ el, + apolloProvider, render(h) { - return h(PipelineEditorApp); + return h(PipelineEditorApp, { + props: { + projectPath, + defaultBranch, + ciConfigPath, + }, + }); }, }); }; diff --git a/app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue b/app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue index add8cfb2a3e..efc241937c4 100644 --- a/app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue +++ b/app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue @@ -1,26 +1,85 @@ <script> -import { GlEmptyState } from '@gitlab/ui'; -import { __, s__ } from '~/locale'; +import { GlLoadingIcon, GlAlert } from '@gitlab/ui'; +import { __, s__, sprintf } from '~/locale'; + +import TextEditor from './components/text_editor.vue'; + +import getBlobContent from './graphql/queries/blob_content.graphql'; export default { components: { - GlEmptyState, + GlLoadingIcon, + GlAlert, + TextEditor, + }, + props: { + projectPath: { + type: String, + required: true, + }, + defaultBranch: { + type: String, + required: false, + default: null, + }, + ciConfigPath: { + type: String, + required: true, + }, + }, + data() { + return { + error: null, + content: '', + }; + }, + apollo: { + content: { + query: getBlobContent, + variables() { + return { + projectPath: this.projectPath, + path: this.ciConfigPath, + ref: this.defaultBranch, + }; + }, + update(data) { + return data?.blobContent?.rawData; + }, + error(error) { + this.error = error; + }, + }, + }, + computed: { + loading() { + return this.$apollo.queries.content.loading; + }, + errorMessage() { + const { message: generalReason, networkError } = this.error ?? {}; + + const { data } = networkError?.response ?? {}; + // 404 for missing file uses `message` + // 400 for a missing ref uses `error` + const networkReason = data?.message ?? data?.error; + + const reason = networkReason ?? generalReason ?? this.$options.i18n.unknownError; + return sprintf(this.$options.i18n.errorMessageWithReason, { reason }); + }, }, i18n: { - title: s__('Pipelines|Pipeline Editor'), - description: s__( - 'Pipelines|We are beginning our work around building the foundation for our dedicated pipeline editor.', - ), - primaryButtonText: __('Learn more'), + unknownError: __('Unknown Error'), + errorMessageWithReason: s__('Pipelines|CI file could not be loaded: %{reason}'), }, }; </script> <template> - <gl-empty-state - :title="$options.i18n.title" - :description="$options.i18n.description" - :primary-button-text="$options.i18n.primaryButtonText" - primary-button-link="https://about.gitlab.com/direction/verify/pipeline_authoring/" - /> + <div class="gl-mt-4"> + <gl-alert v-if="error" :dismissible="false" variant="danger">{{ errorMessage }}</gl-alert> + <div class="gl-mt-4"> + <gl-loading-icon v-if="loading" size="lg" /> + <text-editor v-else v-model="content" /> + </div> + </div> </template> |