diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/assets/javascripts/static_site_editor | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/assets/javascripts/static_site_editor')
5 files changed, 66 insertions, 12 deletions
diff --git a/app/assets/javascripts/static_site_editor/components/edit_area.vue b/app/assets/javascripts/static_site_editor/components/edit_area.vue index 69eabfe5339..b47126cdeb3 100644 --- a/app/assets/javascripts/static_site_editor/components/edit_area.vue +++ b/app/assets/javascripts/static_site_editor/components/edit_area.vue @@ -60,6 +60,7 @@ export default { }, data() { return { + formattedMarkdown: null, parsedSource: parseSourceFile(this.preProcess(true, this.content)), editorMode: EDITOR_TYPES.wysiwyg, hasMatter: false, @@ -140,10 +141,14 @@ export default { onSubmit() { const preProcessedContent = this.preProcess(false, this.parsedSource.content()); this.$emit('submit', { + formattedMarkdown: this.formattedMarkdown, content: preProcessedContent, images: this.$options.imageRepository.getAll(), }); }, + onEditorLoad({ formattedMarkdown }) { + this.formattedMarkdown = formattedMarkdown; + }, }, }; </script> @@ -167,6 +172,7 @@ export default { @modeChange="onModeChange" @input="onInputChange" @uploadImage="onUploadImage" + @load="onEditorLoad" /> <unsaved-changes-confirm-dialog :modified="isSaveable" /> <publish-toolbar diff --git a/app/assets/javascripts/static_site_editor/constants.js b/app/assets/javascripts/static_site_editor/constants.js index faa4026c064..4cabd943e22 100644 --- a/app/assets/javascripts/static_site_editor/constants.js +++ b/app/assets/javascripts/static_site_editor/constants.js @@ -15,10 +15,21 @@ export const LOAD_CONTENT_ERROR = __( 'An error ocurred while loading your content. Please try again.', ); +export const DEFAULT_FORMATTING_CHANGES_COMMIT_MESSAGE = s__( + 'StaticSiteEditor|Automatic formatting changes', +); + +export const DEFAULT_FORMATTING_CHANGES_COMMIT_DESCRIPTION = s__( + 'StaticSiteEditor|Markdown formatting preferences introduced by the Static Site Editor', +); + export const DEFAULT_HEADING = s__('StaticSiteEditor|Static site editor'); export const TRACKING_ACTION_CREATE_COMMIT = 'create_commit'; export const TRACKING_ACTION_CREATE_MERGE_REQUEST = 'create_merge_request'; export const TRACKING_ACTION_INITIALIZE_EDITOR = 'initialize_editor'; +export const USAGE_PING_TRACKING_ACTION_CREATE_COMMIT = 'static_site_editor_commits'; +export const USAGE_PING_TRACKING_ACTION_CREATE_MERGE_REQUEST = 'static_site_editor_merge_requests'; + export const MR_META_LOCAL_STORAGE_KEY = 'sse-merge-request-meta-storage-key'; 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 index 4137ede49c6..1bd79d40071 100644 --- 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 @@ -4,7 +4,17 @@ import savedContentMetaQuery from '../queries/saved_content_meta.query.graphql'; const submitContentChangesResolver = ( _, - { input: { project: projectId, username, sourcePath, content, images, mergeRequestMeta } }, + { + input: { + project: projectId, + username, + sourcePath, + content, + images, + mergeRequestMeta, + formattedMarkdown, + }, + }, { cache }, ) => { return submitContentChanges({ @@ -14,6 +24,7 @@ const submitContentChangesResolver = ( content, images, mergeRequestMeta, + formattedMarkdown, }).then(savedContentMeta => { const data = produce(savedContentMeta, draftState => { return { diff --git a/app/assets/javascripts/static_site_editor/pages/home.vue b/app/assets/javascripts/static_site_editor/pages/home.vue index 68943113c14..1e52e73294e 100644 --- a/app/assets/javascripts/static_site_editor/pages/home.vue +++ b/app/assets/javascripts/static_site_editor/pages/home.vue @@ -53,6 +53,7 @@ export default { return { content: null, images: null, + formattedMarkdown: null, submitChangesError: null, isSavingChanges: false, }; @@ -79,9 +80,10 @@ export default { onDismissError() { this.submitChangesError = null; }, - onPrepareSubmit({ content, images }) { + onPrepareSubmit({ formattedMarkdown, content, images }) { this.content = content; this.images = images; + this.formattedMarkdown = formattedMarkdown; this.isSavingChanges = true; this.$refs.editMetaModal.show(); @@ -110,6 +112,7 @@ export default { username: this.appData.username, sourcePath: this.appData.sourcePath, content: this.content, + formattedMarkdown: this.formattedMarkdown, images: this.images, mergeRequestMeta, }, 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 index 8623a671a7d..e57028ea05a 100644 --- a/app/assets/javascripts/static_site_editor/services/submit_content_changes.js +++ b/app/assets/javascripts/static_site_editor/services/submit_content_changes.js @@ -10,6 +10,10 @@ import { SUBMIT_CHANGES_MERGE_REQUEST_ERROR, TRACKING_ACTION_CREATE_COMMIT, TRACKING_ACTION_CREATE_MERGE_REQUEST, + USAGE_PING_TRACKING_ACTION_CREATE_COMMIT, + USAGE_PING_TRACKING_ACTION_CREATE_MERGE_REQUEST, + DEFAULT_FORMATTING_CHANGES_COMMIT_MESSAGE, + DEFAULT_FORMATTING_CHANGES_COMMIT_DESCRIPTION, } from '../constants'; const createBranch = (projectId, branch) => @@ -45,22 +49,24 @@ const createImageActions = (images, markdown) => { return actions; }; -const commitContent = (projectId, message, branch, sourcePath, content, images) => { +const createUpdateSourceFileAction = (sourcePath, content) => [ + convertObjectPropsToSnakeCase({ + action: 'update', + filePath: sourcePath, + content, + }), +]; + +const commit = (projectId, message, branch, actions) => { Tracking.event(document.body.dataset.page, TRACKING_ACTION_CREATE_COMMIT); + Api.trackRedisCounterEvent(USAGE_PING_TRACKING_ACTION_CREATE_COMMIT); return Api.commitMultiple( projectId, convertObjectPropsToSnakeCase({ branch, commitMessage: message, - actions: [ - convertObjectPropsToSnakeCase({ - action: 'update', - filePath: sourcePath, - content, - }), - ...createImageActions(images, content), - ], + actions, }), ).catch(() => { throw new Error(SUBMIT_CHANGES_COMMIT_ERROR); @@ -75,6 +81,7 @@ const createMergeRequest = ( targetBranch = DEFAULT_TARGET_BRANCH, ) => { Tracking.event(document.body.dataset.page, TRACKING_ACTION_CREATE_MERGE_REQUEST); + Api.trackRedisCounterEvent(USAGE_PING_TRACKING_ACTION_CREATE_MERGE_REQUEST); return Api.createProjectMergeRequest( projectId, @@ -96,6 +103,7 @@ const submitContentChanges = ({ content, images, mergeRequestMeta, + formattedMarkdown, }) => { const branch = generateBranchName(username); const { title: mergeRequestTitle, description: mergeRequestDescription } = mergeRequestMeta; @@ -103,10 +111,25 @@ const submitContentChanges = ({ return createBranch(projectId, branch) .then(({ data: { web_url: url } }) => { + const message = `${DEFAULT_FORMATTING_CHANGES_COMMIT_MESSAGE}\n\n${DEFAULT_FORMATTING_CHANGES_COMMIT_DESCRIPTION}`; + Object.assign(meta, { branch: { label: branch, url } }); - return commitContent(projectId, mergeRequestTitle, branch, sourcePath, content, images); + return formattedMarkdown + ? commit( + projectId, + message, + branch, + createUpdateSourceFileAction(sourcePath, formattedMarkdown), + ) + : meta; }) + .then(() => + commit(projectId, mergeRequestTitle, branch, [ + ...createUpdateSourceFileAction(sourcePath, content), + ...createImageActions(images, content), + ]), + ) .then(({ data: { short_id: label, web_url: url } }) => { Object.assign(meta, { commit: { label, url } }); |