From d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Oct 2021 08:43:02 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-4-stable-ee --- .../design_management/pages/design/index.vue | 2 +- .../javascripts/design_management/pages/index.vue | 2 +- .../design_management/utils/cache_update.js | 2 +- .../design_management/utils/error_messages.js | 72 +++++++++++++--------- 4 files changed, 47 insertions(+), 31 deletions(-) (limited to 'app/assets/javascripts/design_management') diff --git a/app/assets/javascripts/design_management/pages/design/index.vue b/app/assets/javascripts/design_management/pages/design/index.vue index 38ea5406c02..837320b9423 100644 --- a/app/assets/javascripts/design_management/pages/design/index.vue +++ b/app/assets/javascripts/design_management/pages/design/index.vue @@ -273,7 +273,7 @@ export default { this.onError(UPDATE_IMAGE_DIFF_NOTE_ERROR, e); }, onDesignDeleteError(e) { - this.onError(designDeletionError({ singular: true }), e); + this.onError(designDeletionError(), e); }, onResolveDiscussionError(e) { this.onError(UPDATE_IMAGE_DIFF_NOTE_ERROR, e); diff --git a/app/assets/javascripts/design_management/pages/index.vue b/app/assets/javascripts/design_management/pages/index.vue index e66ae822a34..5092c30aa60 100644 --- a/app/assets/javascripts/design_management/pages/index.vue +++ b/app/assets/javascripts/design_management/pages/index.vue @@ -255,7 +255,7 @@ export default { if (this.$route.query.version) this.$router.push({ name: DESIGNS_ROUTE_NAME }); }, onDesignDeleteError() { - const errorMessage = designDeletionError({ singular: this.selectedDesigns.length === 1 }); + const errorMessage = designDeletionError(this.selectedDesigns.length); createFlash({ message: errorMessage }); }, onDesignDropzoneError() { diff --git a/app/assets/javascripts/design_management/utils/cache_update.js b/app/assets/javascripts/design_management/utils/cache_update.js index 33c4fd5a7d9..c8f445bfb88 100644 --- a/app/assets/javascripts/design_management/utils/cache_update.js +++ b/app/assets/javascripts/design_management/utils/cache_update.js @@ -250,7 +250,7 @@ export const hasErrors = ({ errors = [] }) => errors?.length; */ export const updateStoreAfterDesignsDelete = (store, data, query, designs) => { if (hasErrors(data)) { - onError(data, designDeletionError({ singular: designs.length === 1 })); + onError(data, designDeletionError(designs.length)); } else { deleteDesignsFromStore(store, query, designs); addNewVersionToStore(store, query, data.version); diff --git a/app/assets/javascripts/design_management/utils/error_messages.js b/app/assets/javascripts/design_management/utils/error_messages.js index afee7e81791..981b50329b2 100644 --- a/app/assets/javascripts/design_management/utils/error_messages.js +++ b/app/assets/javascripts/design_management/utils/error_messages.js @@ -1,4 +1,3 @@ -/* eslint-disable @gitlab/require-string-literal-i18n-helpers */ import { __, s__, n__, sprintf } from '~/locale'; export const ADD_DISCUSSION_COMMENT_ERROR = s__( @@ -27,12 +26,6 @@ export const DESIGN_NOT_FOUND_ERROR = __('Could not find design.'); export const DESIGN_VERSION_NOT_EXIST_ERROR = __('Requested design version does not exist.'); -const DESIGN_UPLOAD_SKIPPED_MESSAGE = s__('DesignManagement|Upload skipped.'); - -const ALL_DESIGNS_SKIPPED_MESSAGE = `${DESIGN_UPLOAD_SKIPPED_MESSAGE} ${s__( - 'The designs you tried uploading did not change.', -)}`; - export const EXISTING_DESIGN_DROP_MANY_FILES_MESSAGE = __( 'You can only upload one design when dropping onto an existing design.', ); @@ -53,12 +46,9 @@ export const DELETE_DESIGN_TODO_ERROR = __('Failed to remove a to-do item for th export const TOGGLE_TODO_ERROR = __('Failed to toggle the to-do status for the design.'); -const MAX_SKIPPED_FILES_LISTINGS = 5; +const DESIGN_UPLOAD_SKIPPED_MESSAGE = s__('DesignManagement|Upload skipped. %{reason}'); -const oneDesignSkippedMessage = (filename) => - `${DESIGN_UPLOAD_SKIPPED_MESSAGE} ${sprintf(s__('DesignManagement|%{filename} did not change.'), { - filename, - })}`; +const MAX_SKIPPED_FILES_LISTINGS = 5; /** * Return warning message indicating that some (but not all) uploaded @@ -66,25 +56,40 @@ const oneDesignSkippedMessage = (filename) => * @param {Array<{ filename }>} skippedFiles */ const someDesignsSkippedMessage = (skippedFiles) => { - const designsSkippedMessage = `${DESIGN_UPLOAD_SKIPPED_MESSAGE} ${s__( - 'Some of the designs you tried uploading did not change:', - )}`; - - const moreText = sprintf(s__(`DesignManagement|and %{moreCount} more.`), { - moreCount: skippedFiles.length - MAX_SKIPPED_FILES_LISTINGS, - }); - - return `${designsSkippedMessage} ${skippedFiles + const skippedFilesList = skippedFiles .slice(0, MAX_SKIPPED_FILES_LISTINGS) .map(({ filename }) => filename) - .join(', ')}${skippedFiles.length > MAX_SKIPPED_FILES_LISTINGS ? `, ${moreText}` : '.'}`; + .join(', '); + + const uploadSkippedReason = + skippedFiles.length > MAX_SKIPPED_FILES_LISTINGS + ? sprintf( + s__( + 'DesignManagement|Some of the designs you tried uploading did not change: %{skippedFiles} and %{moreCount} more.', + ), + { + skippedFiles: skippedFilesList, + moreCount: skippedFiles.length - MAX_SKIPPED_FILES_LISTINGS, + }, + ) + : sprintf( + s__( + 'DesignManagement|Some of the designs you tried uploading did not change: %{skippedFiles}.', + ), + { skippedFiles: skippedFilesList }, + ); + + return sprintf(DESIGN_UPLOAD_SKIPPED_MESSAGE, { + reason: uploadSkippedReason, + }); }; -export const designDeletionError = ({ singular = true } = {}) => { - const design = singular ? __('a design') : __('designs'); - return sprintf(s__('Could not archive %{design}. Please try again.'), { - design, - }); +export const designDeletionError = (designsCount = 1) => { + return n__( + 'Failed to archive a design. Please try again.', + 'Failed to archive designs. Please try again.', + designsCount, + ); }; /** @@ -101,7 +106,18 @@ export const designUploadSkippedWarning = (uploadedDesigns, skippedFiles) => { if (skippedFiles.length === uploadedDesigns.length) { const { filename } = skippedFiles[0]; - return n__(oneDesignSkippedMessage(filename), ALL_DESIGNS_SKIPPED_MESSAGE, skippedFiles.length); + const uploadSkippedReason = sprintf( + n__( + 'DesignManagement|%{filename} did not change.', + 'DesignManagement|The designs you tried uploading did not change.', + skippedFiles.length, + ), + { filename }, + ); + + return sprintf(DESIGN_UPLOAD_SKIPPED_MESSAGE, { + reason: uploadSkippedReason, + }); } return someDesignsSkippedMessage(skippedFiles); -- cgit v1.2.1