debian-mirror-gitlab/app/assets/javascripts/design_management/utils/error_messages.js

125 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { __, s__, n__, sprintf } from '~/locale';
export const ADD_DISCUSSION_COMMENT_ERROR = s__(
'DesignManagement|Could not add a new comment. Please try again.',
);
export const ADD_IMAGE_DIFF_NOTE_ERROR = s__(
'DesignManagement|Could not create new discussion. Please try again.',
);
export const UPDATE_IMAGE_DIFF_NOTE_ERROR = s__(
'DesignManagement|Could not update discussion. Please try again.',
);
export const UPDATE_NOTE_ERROR = s__('DesignManagement|Could not update note. Please try again.');
export const UPLOAD_DESIGN_ERROR = s__(
'DesignManagement|Error uploading a new design. Please try again.',
);
export const UPLOAD_DESIGN_INVALID_FILETYPE_ERROR = __(
'Could not upload your designs as one or more files uploaded are not supported.',
);
export const DESIGN_NOT_FOUND_ERROR = __('Could not find design.');
export const DESIGN_VERSION_NOT_EXIST_ERROR = __('Requested design version does not exist.');
export const EXISTING_DESIGN_DROP_MANY_FILES_MESSAGE = __(
'You can only upload one design when dropping onto an existing design.',
);
export const EXISTING_DESIGN_DROP_INVALID_FILENAME_MESSAGE = __(
'You must upload a file with the same file name when dropping onto an existing design.',
);
2020-10-24 23:57:45 +05:30
export const MOVE_DESIGN_ERROR = __(
'Something went wrong when reordering designs. Please try again',
);
2021-03-11 19:13:27 +05:30
export const CREATE_DESIGN_TODO_ERROR = __('Failed to create a to-do item for the design.');
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
export const CREATE_DESIGN_TODO_EXISTS_ERROR = __('There is already a to-do item for this design.');
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
export const DELETE_DESIGN_TODO_ERROR = __('Failed to remove a to-do item for the design.');
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
export const TOGGLE_TODO_ERROR = __('Failed to toggle the to-do status for the design.');
2020-11-24 15:15:51 +05:30
2021-11-18 22:05:49 +05:30
const DESIGN_UPLOAD_SKIPPED_MESSAGE = s__('DesignManagement|Upload skipped. %{reason}');
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
const MAX_SKIPPED_FILES_LISTINGS = 5;
2020-05-24 23:13:21 +05:30
/**
* Return warning message indicating that some (but not all) uploaded
* files were skipped.
* @param {Array<{ filename }>} skippedFiles
*/
2021-03-08 18:12:59 +05:30
const someDesignsSkippedMessage = (skippedFiles) => {
2021-11-18 22:05:49 +05:30
const skippedFilesList = skippedFiles
2020-05-24 23:13:21 +05:30
.slice(0, MAX_SKIPPED_FILES_LISTINGS)
.map(({ filename }) => filename)
2021-11-18 22:05:49 +05:30
.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,
});
2020-05-24 23:13:21 +05:30
};
2021-11-18 22:05:49 +05:30
export const designDeletionError = (designsCount = 1) => {
return n__(
'Failed to archive a design. Please try again.',
'Failed to archive designs. Please try again.',
designsCount,
);
2020-05-24 23:13:21 +05:30
};
/**
* Return warning message, if applicable, that one, some or all uploaded
* files were skipped.
* @param {Array<{ filename }>} uploadedDesigns
* @param {Array<{ filename }>} skippedFiles
*/
export const designUploadSkippedWarning = (uploadedDesigns, skippedFiles) => {
if (skippedFiles.length === 0) {
return null;
}
if (skippedFiles.length === uploadedDesigns.length) {
const { filename } = skippedFiles[0];
2021-11-18 22:05:49 +05:30
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,
});
2020-05-24 23:13:21 +05:30
}
return someDesignsSkippedMessage(skippedFiles);
};