diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 09:09:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 09:09:41 +0300 |
commit | 187ee320b39af22929d74c5a2d9b0650bf50a09b (patch) | |
tree | ff04eab6c7914f6408c4f637f863fc07aa409cdc /app/assets/javascripts/static_site_editor | |
parent | a7dc052b7e01aee680d130274c79da9bfa459272 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/static_site_editor')
8 files changed, 52 insertions, 6 deletions
diff --git a/app/assets/javascripts/static_site_editor/components/publish_toolbar.vue b/app/assets/javascripts/static_site_editor/components/publish_toolbar.vue index 83b50b2f8eb..7f00fb71b04 100644 --- a/app/assets/javascripts/static_site_editor/components/publish_toolbar.vue +++ b/app/assets/javascripts/static_site_editor/components/publish_toolbar.vue @@ -1,9 +1,10 @@ <script> -import { GlNewButton } from '@gitlab/ui'; +import { GlNewButton, GlLoadingIcon } from '@gitlab/ui'; export default { components: { GlNewButton, + GlLoadingIcon, }, props: { saveable: { @@ -11,12 +12,22 @@ export default { required: false, default: false, }, + savingChanges: { + type: Boolean, + required: false, + default: false, + }, }, }; </script> <template> <div class="d-flex bg-light border-top justify-content-between align-items-center py-3 px-4"> - <gl-new-button variant="success" :disabled="!saveable"> + <gl-loading-icon :class="{ invisible: !savingChanges }" size="md" /> + <gl-new-button + variant="success" + :disabled="!saveable || savingChanges" + @click="$emit('submit')" + > {{ __('Submit Changes') }} </gl-new-button> </div> diff --git a/app/assets/javascripts/static_site_editor/components/static_site_editor.vue b/app/assets/javascripts/static_site_editor/components/static_site_editor.vue index 80a55d5ee11..e711510ba44 100644 --- a/app/assets/javascripts/static_site_editor/components/static_site_editor.vue +++ b/app/assets/javascripts/static_site_editor/components/static_site_editor.vue @@ -12,14 +12,14 @@ export default { Toolbar, }, computed: { - ...mapState(['content', 'isLoadingContent']), + ...mapState(['content', 'isLoadingContent', 'isSavingChanges']), ...mapGetters(['isContentLoaded', 'contentChanged']), }, mounted() { this.loadContent(); }, methods: { - ...mapActions(['loadContent', 'setContent']), + ...mapActions(['loadContent', 'setContent', 'submitChanges']), }, }; </script> @@ -41,7 +41,11 @@ export default { :value="content" @input="setContent" /> - <toolbar :saveable="contentChanged" /> + <toolbar + :saveable="contentChanged" + :saving-changes="isSavingChanges" + @submit="submitChanges" + /> </div> </div> </template> diff --git a/app/assets/javascripts/static_site_editor/index.js b/app/assets/javascripts/static_site_editor/index.js index 22f96a60df0..3d40f3918a4 100644 --- a/app/assets/javascripts/static_site_editor/index.js +++ b/app/assets/javascripts/static_site_editor/index.js @@ -6,7 +6,7 @@ const initStaticSiteEditor = el => { const { projectId, path: sourcePath } = el.dataset; const store = createStore({ - initialState: { projectId, sourcePath }, + initialState: { projectId, sourcePath, username: window.gon.current_username }, }); return new Vue({ diff --git a/app/assets/javascripts/static_site_editor/services/submit_content_changes.js b/app/assets/javascripts/static_site_editor/services/submit_content_changes.js new file mode 100644 index 00000000000..6b0d8c74ff7 --- /dev/null +++ b/app/assets/javascripts/static_site_editor/services/submit_content_changes.js @@ -0,0 +1,4 @@ +// TODO implement +const submitContentChanges = () => new Promise(resolve => setTimeout(resolve, 1000)); + +export default submitContentChanges; diff --git a/app/assets/javascripts/static_site_editor/store/actions.js b/app/assets/javascripts/static_site_editor/store/actions.js index 141148de1e0..c57ef86f6ef 100644 --- a/app/assets/javascripts/static_site_editor/store/actions.js +++ b/app/assets/javascripts/static_site_editor/store/actions.js @@ -3,6 +3,7 @@ import { __ } from '~/locale'; import * as mutationTypes from './mutation_types'; import loadSourceContent from '~/static_site_editor/services/load_source_content'; +import submitContentChanges from '~/static_site_editor/services/submit_content_changes'; export const loadContent = ({ commit, state: { sourcePath, projectId } }) => { commit(mutationTypes.LOAD_CONTENT); @@ -19,4 +20,15 @@ export const setContent = ({ commit }, content) => { commit(mutationTypes.SET_CONTENT, content); }; +export const submitChanges = ({ state: { projectId, content, sourcePath, username }, commit }) => { + commit(mutationTypes.SUBMIT_CHANGES); + + return submitContentChanges({ content, projectId, sourcePath, username }) + .then(data => commit(mutationTypes.SUBMIT_CHANGES_SUCCESS, data)) + .catch(error => { + commit(mutationTypes.SUBMIT_CHANGES_ERROR); + createFlash(error.message); + }); +}; + export default () => {}; diff --git a/app/assets/javascripts/static_site_editor/store/mutation_types.js b/app/assets/javascripts/static_site_editor/store/mutation_types.js index 2bb201f5d24..35eb35ebbe9 100644 --- a/app/assets/javascripts/static_site_editor/store/mutation_types.js +++ b/app/assets/javascripts/static_site_editor/store/mutation_types.js @@ -2,3 +2,6 @@ export const LOAD_CONTENT = 'loadContent'; export const RECEIVE_CONTENT_SUCCESS = 'receiveContentSuccess'; export const RECEIVE_CONTENT_ERROR = 'receiveContentError'; export const SET_CONTENT = 'setContent'; +export const SUBMIT_CHANGES = 'submitChanges'; +export const SUBMIT_CHANGES_SUCCESS = 'submitChangesSuccess'; +export const SUBMIT_CHANGES_ERROR = 'submitChangesError'; diff --git a/app/assets/javascripts/static_site_editor/store/mutations.js b/app/assets/javascripts/static_site_editor/store/mutations.js index 8b8bacf35c2..f98177bbc18 100644 --- a/app/assets/javascripts/static_site_editor/store/mutations.js +++ b/app/assets/javascripts/static_site_editor/store/mutations.js @@ -16,4 +16,15 @@ export default { [types.SET_CONTENT](state, content) { state.content = content; }, + [types.SUBMIT_CHANGES](state) { + state.isSavingChanges = true; + }, + [types.SUBMIT_CHANGES_SUCCESS](state, meta) { + state.savedContentMeta = meta; + state.isSavingChanges = false; + state.originalContent = state.content; + }, + [types.SUBMIT_CHANGES_ERROR](state) { + state.isSavingChanges = false; + }, }; diff --git a/app/assets/javascripts/static_site_editor/store/state.js b/app/assets/javascripts/static_site_editor/store/state.js index 1ae11b3343d..e457fde591a 100644 --- a/app/assets/javascripts/static_site_editor/store/state.js +++ b/app/assets/javascripts/static_site_editor/store/state.js @@ -1,4 +1,5 @@ const createState = (initialState = {}) => ({ + username: null, projectId: null, sourcePath: null, |