Welcome to mirror list, hosted at ThFree Co, Russian Federation.

error_messages.js « utils « design_management « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 981b50329b276573ebe04fd912533673478acf47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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.',
);

export const MOVE_DESIGN_ERROR = __(
  'Something went wrong when reordering designs. Please try again',
);

export const CREATE_DESIGN_TODO_ERROR = __('Failed to create a to-do item for the design.');

export const CREATE_DESIGN_TODO_EXISTS_ERROR = __('There is already a to-do item for this design.');

export const DELETE_DESIGN_TODO_ERROR = __('Failed to remove a to-do item for the design.');

export const TOGGLE_TODO_ERROR = __('Failed to toggle the to-do status for the design.');

const DESIGN_UPLOAD_SKIPPED_MESSAGE = s__('DesignManagement|Upload skipped. %{reason}');

const MAX_SKIPPED_FILES_LISTINGS = 5;

/**
 * Return warning message indicating that some (but not all) uploaded
 * files were skipped.
 * @param {Array<{ filename }>} skippedFiles
 */
const someDesignsSkippedMessage = (skippedFiles) => {
  const skippedFilesList = skippedFiles
    .slice(0, MAX_SKIPPED_FILES_LISTINGS)
    .map(({ filename }) => filename)
    .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 = (designsCount = 1) => {
  return n__(
    'Failed to archive a design. Please try again.',
    'Failed to archive designs. Please try again.',
    designsCount,
  );
};

/**
 * 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];

    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);
};