diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-15 09:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-15 09:08:40 +0300 |
commit | 1e9d859394883d104191c51fa18c2353f7bcc1fd (patch) | |
tree | 802d89d8ae8004805a656dfc764fde2775248b9d /app/assets/javascripts/static_site_editor | |
parent | 31169f0b93010da91b59cada40e17c67295038df (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/static_site_editor')
8 files changed, 113 insertions, 14 deletions
diff --git a/app/assets/javascripts/static_site_editor/graphql/index.js b/app/assets/javascripts/static_site_editor/graphql/index.js index 093fbf10c35..0a5d8c07ad9 100644 --- a/app/assets/javascripts/static_site_editor/graphql/index.js +++ b/app/assets/javascripts/static_site_editor/graphql/index.js @@ -2,8 +2,8 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; import createDefaultClient from '~/lib/graphql'; import typeDefs from './typedefs.graphql'; - import fileResolver from './resolvers/file'; +import submitContentChangesResolver from './resolvers/submit_content_changes'; Vue.use(VueApollo); @@ -13,6 +13,9 @@ const createApolloProvider = appData => { Project: { file: fileResolver, }, + Mutation: { + submitContentChanges: submitContentChangesResolver, + }, }, { typeDefs, diff --git a/app/assets/javascripts/static_site_editor/graphql/mutations/submit_content_changes.mutation.graphql b/app/assets/javascripts/static_site_editor/graphql/mutations/submit_content_changes.mutation.graphql new file mode 100644 index 00000000000..2840d419966 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/graphql/mutations/submit_content_changes.mutation.graphql @@ -0,0 +1,7 @@ +mutation submitContentChanges($input: SubmitContentChangesInput) { + submitContentChanges(input: $input) @client { + branch + commit + mergeRequest + } +} diff --git a/app/assets/javascripts/static_site_editor/graphql/queries/app_data.query.graphql b/app/assets/javascripts/static_site_editor/graphql/queries/app_data.query.graphql index 5400e12f9e1..fdbf4459aee 100644 --- a/app/assets/javascripts/static_site_editor/graphql/queries/app_data.query.graphql +++ b/app/assets/javascripts/static_site_editor/graphql/queries/app_data.query.graphql @@ -3,6 +3,7 @@ query appData { isSupportedContent project sourcePath + username, returnUrl } } diff --git a/app/assets/javascripts/static_site_editor/graphql/queries/saved_content_meta.query.graphql b/app/assets/javascripts/static_site_editor/graphql/queries/saved_content_meta.query.graphql new file mode 100644 index 00000000000..c29b6f93b81 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/graphql/queries/saved_content_meta.query.graphql @@ -0,0 +1,3 @@ +query savedContentMeta { + savedContentMeta @client +} diff --git a/app/assets/javascripts/static_site_editor/graphql/resolvers/submit_content_changes.js b/app/assets/javascripts/static_site_editor/graphql/resolvers/submit_content_changes.js new file mode 100644 index 00000000000..6c4e3a4d973 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/graphql/resolvers/submit_content_changes.js @@ -0,0 +1,24 @@ +import submitContentChanges from '../../services/submit_content_changes'; +import savedContentMetaQuery from '../queries/saved_content_meta.query.graphql'; + +const submitContentChangesResolver = ( + _, + { input: { project: projectId, username, sourcePath, content } }, + { cache }, +) => { + return submitContentChanges({ projectId, username, sourcePath, content }).then( + savedContentMeta => { + cache.writeQuery({ + query: savedContentMetaQuery, + data: { + savedContentMeta: { + __typename: 'SavedContentMeta', + ...savedContentMeta, + }, + }, + }); + }, + ); +}; + +export default submitContentChangesResolver; diff --git a/app/assets/javascripts/static_site_editor/graphql/typedefs.graphql b/app/assets/javascripts/static_site_editor/graphql/typedefs.graphql index af01b699388..59da2e27144 100644 --- a/app/assets/javascripts/static_site_editor/graphql/typedefs.graphql +++ b/app/assets/javascripts/static_site_editor/graphql/typedefs.graphql @@ -3,8 +3,15 @@ type File { content: String! } -extend type Project { - file(path: ID!): File +type SavedContentField { + label: String! + url: String! +} + +type SavedContentMeta { + mergeRequest: SavedContentField! + commit: SavedContentField! + branch: SavedContentField! } type AppData { @@ -15,6 +22,22 @@ type AppData { username: String! } +type SubmitContentChangesInput { + project: String! + sourcePath: String! + content: String! + username: String! +} + +extend type Project { + file(path: ID!): File +} + extend type Query { appData: AppData! + savedContentMeta: SavedContentMeta +} + +extend type Mutation { + submitContentChanges(input: SubmitContentChangesInput!): SavedContentMeta } diff --git a/app/assets/javascripts/static_site_editor/pages/home.vue b/app/assets/javascripts/static_site_editor/pages/home.vue index d1b9e1e407c..f65b648acd6 100644 --- a/app/assets/javascripts/static_site_editor/pages/home.vue +++ b/app/assets/javascripts/static_site_editor/pages/home.vue @@ -1,14 +1,14 @@ <script> -import { mapState, mapActions } from 'vuex'; import SkeletonLoader from '../components/skeleton_loader.vue'; import EditArea from '../components/edit_area.vue'; import InvalidContentMessage from '../components/invalid_content_message.vue'; import SubmitChangesError from '../components/submit_changes_error.vue'; -import { SUCCESS_ROUTE } from '../router/constants'; import appDataQuery from '../graphql/queries/app_data.query.graphql'; import sourceContentQuery from '../graphql/queries/source_content.query.graphql'; +import submitContentChangesMutation from '../graphql/mutations/submit_content_changes.mutation.graphql'; import createFlash from '~/flash'; import { LOAD_CONTENT_ERROR } from '../constants'; +import { SUCCESS_ROUTE } from '../router/constants'; export default { components: { @@ -44,8 +44,14 @@ export default { }, }, }, + data() { + return { + content: null, + submitChangesError: null, + isSavingChanges: false, + }; + }, computed: { - ...mapState(['isSavingChanges', 'submitChangesError']), isLoadingContent() { return this.$apollo.queries.sourceContent.loading; }, @@ -54,11 +60,37 @@ export default { }, }, methods: { - ...mapActions(['setContent', 'submitChanges', 'dismissSubmitChangesError']), + onDismissError() { + this.submitChangesError = null; + }, onSubmit({ content }) { - this.setContent(content); + this.content = content; + this.submitChanges(); + }, + submitChanges() { + this.isSavingChanges = true; - return this.submitChanges().then(() => this.$router.push(SUCCESS_ROUTE)); + this.$apollo + .mutate({ + mutation: submitContentChangesMutation, + variables: { + input: { + project: this.appData.project, + username: this.appData.username, + sourcePath: this.appData.sourcePath, + content: this.content, + }, + }, + }) + .then(() => { + this.$router.push(SUCCESS_ROUTE); + }) + .catch(e => { + this.submitChangesError = e.message; + }) + .finally(() => { + this.isSavingChanges = false; + }); }, }, }; @@ -71,7 +103,7 @@ export default { v-if="submitChangesError" :error="submitChangesError" @retry="submitChanges" - @dismiss="dismissSubmitChangesError" + @dismiss="onDismissError" /> <edit-area v-if="isContentLoaded" diff --git a/app/assets/javascripts/static_site_editor/pages/success.vue b/app/assets/javascripts/static_site_editor/pages/success.vue index a28e9a17564..123683b2833 100644 --- a/app/assets/javascripts/static_site_editor/pages/success.vue +++ b/app/assets/javascripts/static_site_editor/pages/success.vue @@ -1,5 +1,6 @@ <script> -import { mapState } from 'vuex'; +import savedContentMetaQuery from '../graphql/queries/saved_content_meta.query.graphql'; +import appDataQuery from '../graphql/queries/app_data.query.graphql'; import SavedChangesMessage from '../components/saved_changes_message.vue'; import { HOME_ROUTE } from '../router/constants'; @@ -7,8 +8,13 @@ export default { components: { SavedChangesMessage, }, - computed: { - ...mapState(['savedContentMeta', 'returnUrl']), + apollo: { + savedContentMeta: { + query: savedContentMetaQuery, + }, + appData: { + query: appDataQuery, + }, }, created() { if (!this.savedContentMeta) { @@ -23,7 +29,7 @@ export default { :branch="savedContentMeta.branch" :commit="savedContentMeta.commit" :merge-request="savedContentMeta.mergeRequest" - :return-url="returnUrl" + :return-url="appData.returnUrl" /> </div> </template> |