@performant-software/semantic-components 1.0.4-beta.4 → 1.0.4-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@performant-software/semantic-components",
3
- "version": "1.0.4-beta.4",
3
+ "version": "1.0.4-beta.6",
4
4
  "description": "A package of shared components based on the Semantic UI Framework.",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
@@ -12,7 +12,7 @@
12
12
  "build": "webpack --mode production && flow-copy-source -v src types"
13
13
  },
14
14
  "dependencies": {
15
- "@performant-software/shared-components": "^1.0.4-beta.4",
15
+ "@performant-software/shared-components": "^1.0.4-beta.6",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "citeproc": "^2.4.62",
@@ -85,13 +85,19 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
85
85
  const [items, setItems] = useState([]);
86
86
  const [uploadCount, setUploadCount] = useState(0);
87
87
  const [uploading, setUploading] = useState(false);
88
- // const [statuses, setStatuses] = useState({});
88
+ const [statuses, setStatuses] = useState({});
89
89
 
90
90
  /**
91
91
  * Sets the <code>hasErrors</code> value to <code>true</code> if at least one item on the state contains errors.
92
92
  */
93
93
  const hasErrors = useMemo(() => !!_.find(items, (item) => !_.isEmpty(item.errors)), [items]);
94
94
 
95
+ /**
96
+ * Sets the <code>hasUploadErrors</code> value to <code>true</code> if at least one file uploaded with
97
+ * an error status.
98
+ */
99
+ const hasUploaderErrors = useMemo(() => _.find(_.values(statuses), (status) => status === Status.error), [statuses]);
100
+
95
101
  /**
96
102
  * Calls the <code>onAddFile</code> prop for each item in the passed collection of files and adds them
97
103
  * to the items on the state.
@@ -157,13 +163,9 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
157
163
  *
158
164
  * @type {function(*, *): void}
159
165
  */
160
- // const setStatus = useCallback((index, status, message = null) => (
161
- // setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: { status, message } }))
162
- // ));
163
-
164
- const setStatus = useCallback((item, status, message = null) => (
165
- setItems(_.map(items, (i) => (i !== item ? i : { ...i, status, errors: [message] })))
166
- ), [items]);
166
+ const setStatus = useCallback((index, status) => (
167
+ setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: status }))
168
+ ));
167
169
 
168
170
  /**
169
171
  * Iterates of the list of items and sequentially calls the <code>onSave</code> prop for each.
@@ -175,7 +177,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
175
177
  const item = items[i];
176
178
 
177
179
  // Update the status for the item
178
- setStatus(i, Status.processing);
180
+ setStatus(item, Status.processing);
179
181
 
180
182
  let error;
181
183
 
@@ -189,9 +191,9 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
189
191
 
190
192
  // Update the status for the item
191
193
  if (error) {
192
- setStatus(i, Status.error, error.message);
194
+ setStatus(item, Status.error);
193
195
  } else {
194
- setStatus(i, Status.complete);
196
+ setStatus(item, Status.complete);
195
197
  }
196
198
 
197
199
  // Update the upload count
@@ -373,6 +375,13 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
373
375
  </Message.List>
374
376
  </Message>
375
377
  )}
378
+ { hasUploaderErrors && (
379
+ <Message
380
+ content={i18n.t('FileUploadModal.errors.upload.content')}
381
+ header={i18n.t('FileUploadModal.errors.upload.header')}
382
+ error
383
+ />
384
+ )}
376
385
  <FileUpload
377
386
  onFilesAdded={onAddFiles}
378
387
  />
package/src/i18n/en.json CHANGED
@@ -129,7 +129,11 @@
129
129
  "FileUploadModal": {
130
130
  "errors": {
131
131
  "header": "There was an error processing your files",
132
- "required": "File {{filename}} - The following fields are required: {{fields}}"
132
+ "required": "File {{filename}} - The following fields are required: {{fields}}",
133
+ "upload": {
134
+ "content": "Check the status on each file to see which were unsuccessful.",
135
+ "header": "Some of the files did not upload"
136
+ }
133
137
  },
134
138
  "loader": "Uploading files...",
135
139
  "title": "Upload Files"
@@ -85,13 +85,19 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
85
85
  const [items, setItems] = useState([]);
86
86
  const [uploadCount, setUploadCount] = useState(0);
87
87
  const [uploading, setUploading] = useState(false);
88
- // const [statuses, setStatuses] = useState({});
88
+ const [statuses, setStatuses] = useState({});
89
89
 
90
90
  /**
91
91
  * Sets the <code>hasErrors</code> value to <code>true</code> if at least one item on the state contains errors.
92
92
  */
93
93
  const hasErrors = useMemo(() => !!_.find(items, (item) => !_.isEmpty(item.errors)), [items]);
94
94
 
95
+ /**
96
+ * Sets the <code>hasUploadErrors</code> value to <code>true</code> if at least one file uploaded with
97
+ * an error status.
98
+ */
99
+ const hasUploaderErrors = useMemo(() => _.find(_.values(statuses), (status) => status === Status.error), [statuses]);
100
+
95
101
  /**
96
102
  * Calls the <code>onAddFile</code> prop for each item in the passed collection of files and adds them
97
103
  * to the items on the state.
@@ -157,13 +163,9 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
157
163
  *
158
164
  * @type {function(*, *): void}
159
165
  */
160
- // const setStatus = useCallback((index, status, message = null) => (
161
- // setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: { status, message } }))
162
- // ));
163
-
164
- const setStatus = useCallback((item, status, message = null) => (
165
- setItems(_.map(items, (i) => (i !== item ? i : { ...i, status, errors: [message] })))
166
- ), [items]);
166
+ const setStatus = useCallback((index, status) => (
167
+ setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: status }))
168
+ ));
167
169
 
168
170
  /**
169
171
  * Iterates of the list of items and sequentially calls the <code>onSave</code> prop for each.
@@ -175,7 +177,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
175
177
  const item = items[i];
176
178
 
177
179
  // Update the status for the item
178
- setStatus(i, Status.processing);
180
+ setStatus(item, Status.processing);
179
181
 
180
182
  let error;
181
183
 
@@ -189,9 +191,9 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
189
191
 
190
192
  // Update the status for the item
191
193
  if (error) {
192
- setStatus(i, Status.error, error.message);
194
+ setStatus(item, Status.error);
193
195
  } else {
194
- setStatus(i, Status.complete);
196
+ setStatus(item, Status.complete);
195
197
  }
196
198
 
197
199
  // Update the upload count
@@ -373,6 +375,13 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
373
375
  </Message.List>
374
376
  </Message>
375
377
  )}
378
+ { hasUploaderErrors && (
379
+ <Message
380
+ content={i18n.t('FileUploadModal.errors.upload.content')}
381
+ header={i18n.t('FileUploadModal.errors.upload.header')}
382
+ error
383
+ />
384
+ )}
376
385
  <FileUpload
377
386
  onFilesAdded={onAddFiles}
378
387
  />