@performant-software/semantic-components 1.0.4-beta.0 → 1.0.4-beta.2

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.0",
3
+ "version": "1.0.4-beta.2",
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.0",
15
+ "@performant-software/shared-components": "^1.0.4-beta.2",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "citeproc": "^2.4.62",
@@ -11,7 +11,8 @@ import {
11
11
  Dimmer,
12
12
  Form,
13
13
  Item,
14
- Loader, Message,
14
+ Loader,
15
+ Message,
15
16
  Modal
16
17
  } from 'semantic-ui-react';
17
18
  import _ from 'underscore';
@@ -219,30 +220,40 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
219
220
  ), []);
220
221
 
221
222
  /**
222
- * Updates the passed item with the passed props.
223
+ * Validates the passed item.
223
224
  *
224
- * @type {(function(): void)|*}
225
+ * @type {function(*): *&{errors: []}}
225
226
  */
226
- const onUpload = useCallback(() => {
227
- // Set the uploading indicator
228
- setUploading(true);
227
+ const validateItem = useCallback((item) => {
228
+ const errors = [];
229
229
 
230
- // Upload the files
231
- onValidate()
232
- .then(() => (
233
- props.strategy === Strategy.batch
234
- ? onBatchUpload()
235
- : onSingleUpload()
236
- ))
237
- .finally(onComplete);
238
- }, [onBatchUpload, onComplete, onSingleUpload, props.strategy]);
230
+ _.each(_.keys(props.required), (key) => {
231
+ const value = item[key];
232
+ let invalid;
233
+
234
+ if (_.isNumber(value)) {
235
+ invalid = _.isEmpty(value.toString());
236
+ } else {
237
+ invalid = _.isEmpty(value);
238
+ }
239
+
240
+ if (invalid) {
241
+ errors.push(key);
242
+ }
243
+ });
244
+
245
+ return {
246
+ ...item,
247
+ errors
248
+ };
249
+ }, [props.required]);
239
250
 
240
251
  /**
241
252
  * Validates the items on the state.
242
253
  *
243
254
  * @type {function(): Promise<void>}
244
255
  */
245
- const onValidate = useCallback(() => {
256
+ const onValidate = useCallback(() => new Promise((resolve, reject) => {
246
257
  let error = false;
247
258
 
248
259
  setItems((prevItems) => _.map(prevItems, (item) => {
@@ -255,8 +266,31 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
255
266
  return valid;
256
267
  }));
257
268
 
258
- return error ? Promise.reject() : Promise.resolve();
259
- }, [items]);
269
+ if (error) {
270
+ reject();
271
+ } else {
272
+ resolve();
273
+ }
274
+ }), []);
275
+
276
+ /**
277
+ * Updates the passed item with the passed props.
278
+ *
279
+ * @type {(function(): void)|*}
280
+ */
281
+ const onUpload = useCallback(() => {
282
+ // Set the uploading indicator
283
+ setUploading(true);
284
+
285
+ // Upload the files
286
+ onValidate()
287
+ .then(() => (
288
+ props.strategy === Strategy.batch
289
+ ? onBatchUpload()
290
+ : onSingleUpload()
291
+ ))
292
+ .finally(onComplete);
293
+ }, [onBatchUpload, onComplete, onSingleUpload, onValidate, props.strategy]);
260
294
 
261
295
  /**
262
296
  * Renders the error message for the passed item.
@@ -268,7 +302,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
268
302
  return null;
269
303
  }
270
304
 
271
- const filename = !_.isEmpty(item.name) ? item.name : `File ${index}`;
305
+ const filename = !_.isEmpty(item.name) ? item.name : index;
272
306
  const fields = _.map(item.errors, (e) => props.required[e]).join(', ');
273
307
 
274
308
  return (
@@ -279,35 +313,6 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
279
313
  );
280
314
  }, []);
281
315
 
282
- /**
283
- * Validates the passed item.
284
- *
285
- * @type {function(*): *&{errors: []}}
286
- */
287
- const validateItem = useCallback((item) => {
288
- const errors = [];
289
-
290
- _.each(_.keys(props.required), (key) => {
291
- const value = item[key];
292
- let invalid;
293
-
294
- if (_.isNumber(value)) {
295
- invalid = _.isEmpty(value.toString());
296
- } else {
297
- invalid = _.isEmpty(value);
298
- }
299
-
300
- if (invalid) {
301
- errors.push(key);
302
- }
303
- });
304
-
305
- return {
306
- ...item,
307
- errors
308
- };
309
- }, [props.required]);
310
-
311
316
  /**
312
317
  * Memoization and case correction for the <code>itemComponent</code> prop.
313
318
  *
@@ -352,7 +357,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
352
357
  error
353
358
  >
354
359
  <Message.Header
355
- content={'An error occurred'}
360
+ content={i18n.t('FileUploadModal.errors.header')}
356
361
  />
357
362
  <Message.List>
358
363
  { _.map(items, renderMessageItem) }
@@ -391,7 +396,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
391
396
  <Modal.Actions>
392
397
  <Button
393
398
  content={i18n.t('Common.buttons.upload')}
394
- disabled={uploading || uploadCount > 0}
399
+ disabled={uploading || uploadCount > 0 || _.isEmpty(items)}
395
400
  icon='cloud upload'
396
401
  loading={uploading && !props.showPageLoader}
397
402
  onClick={onUpload}
package/src/i18n/en.json CHANGED
@@ -128,7 +128,8 @@
128
128
  },
129
129
  "FileUploadModal": {
130
130
  "errors": {
131
- "required": "{{filename}} - The following fields are required: {{fields}}"
131
+ "header": "There was an error processing your files",
132
+ "required": "File {{filename}} - The following fields are required: {{fields}}"
132
133
  },
133
134
  "loader": "Uploading files...",
134
135
  "title": "Upload Files"
@@ -11,7 +11,8 @@ import {
11
11
  Dimmer,
12
12
  Form,
13
13
  Item,
14
- Loader, Message,
14
+ Loader,
15
+ Message,
15
16
  Modal
16
17
  } from 'semantic-ui-react';
17
18
  import _ from 'underscore';
@@ -219,30 +220,40 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
219
220
  ), []);
220
221
 
221
222
  /**
222
- * Updates the passed item with the passed props.
223
+ * Validates the passed item.
223
224
  *
224
- * @type {(function(): void)|*}
225
+ * @type {function(*): *&{errors: []}}
225
226
  */
226
- const onUpload = useCallback(() => {
227
- // Set the uploading indicator
228
- setUploading(true);
227
+ const validateItem = useCallback((item) => {
228
+ const errors = [];
229
229
 
230
- // Upload the files
231
- onValidate()
232
- .then(() => (
233
- props.strategy === Strategy.batch
234
- ? onBatchUpload()
235
- : onSingleUpload()
236
- ))
237
- .finally(onComplete);
238
- }, [onBatchUpload, onComplete, onSingleUpload, props.strategy]);
230
+ _.each(_.keys(props.required), (key) => {
231
+ const value = item[key];
232
+ let invalid;
233
+
234
+ if (_.isNumber(value)) {
235
+ invalid = _.isEmpty(value.toString());
236
+ } else {
237
+ invalid = _.isEmpty(value);
238
+ }
239
+
240
+ if (invalid) {
241
+ errors.push(key);
242
+ }
243
+ });
244
+
245
+ return {
246
+ ...item,
247
+ errors
248
+ };
249
+ }, [props.required]);
239
250
 
240
251
  /**
241
252
  * Validates the items on the state.
242
253
  *
243
254
  * @type {function(): Promise<void>}
244
255
  */
245
- const onValidate = useCallback(() => {
256
+ const onValidate = useCallback(() => new Promise((resolve, reject) => {
246
257
  let error = false;
247
258
 
248
259
  setItems((prevItems) => _.map(prevItems, (item) => {
@@ -255,8 +266,31 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
255
266
  return valid;
256
267
  }));
257
268
 
258
- return error ? Promise.reject() : Promise.resolve();
259
- }, [items]);
269
+ if (error) {
270
+ reject();
271
+ } else {
272
+ resolve();
273
+ }
274
+ }), []);
275
+
276
+ /**
277
+ * Updates the passed item with the passed props.
278
+ *
279
+ * @type {(function(): void)|*}
280
+ */
281
+ const onUpload = useCallback(() => {
282
+ // Set the uploading indicator
283
+ setUploading(true);
284
+
285
+ // Upload the files
286
+ onValidate()
287
+ .then(() => (
288
+ props.strategy === Strategy.batch
289
+ ? onBatchUpload()
290
+ : onSingleUpload()
291
+ ))
292
+ .finally(onComplete);
293
+ }, [onBatchUpload, onComplete, onSingleUpload, onValidate, props.strategy]);
260
294
 
261
295
  /**
262
296
  * Renders the error message for the passed item.
@@ -268,7 +302,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
268
302
  return null;
269
303
  }
270
304
 
271
- const filename = !_.isEmpty(item.name) ? item.name : `File ${index}`;
305
+ const filename = !_.isEmpty(item.name) ? item.name : index;
272
306
  const fields = _.map(item.errors, (e) => props.required[e]).join(', ');
273
307
 
274
308
  return (
@@ -279,35 +313,6 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
279
313
  );
280
314
  }, []);
281
315
 
282
- /**
283
- * Validates the passed item.
284
- *
285
- * @type {function(*): *&{errors: []}}
286
- */
287
- const validateItem = useCallback((item) => {
288
- const errors = [];
289
-
290
- _.each(_.keys(props.required), (key) => {
291
- const value = item[key];
292
- let invalid;
293
-
294
- if (_.isNumber(value)) {
295
- invalid = _.isEmpty(value.toString());
296
- } else {
297
- invalid = _.isEmpty(value);
298
- }
299
-
300
- if (invalid) {
301
- errors.push(key);
302
- }
303
- });
304
-
305
- return {
306
- ...item,
307
- errors
308
- };
309
- }, [props.required]);
310
-
311
316
  /**
312
317
  * Memoization and case correction for the <code>itemComponent</code> prop.
313
318
  *
@@ -352,7 +357,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
352
357
  error
353
358
  >
354
359
  <Message.Header
355
- content={'An error occurred'}
360
+ content={i18n.t('FileUploadModal.errors.header')}
356
361
  />
357
362
  <Message.List>
358
363
  { _.map(items, renderMessageItem) }
@@ -391,7 +396,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
391
396
  <Modal.Actions>
392
397
  <Button
393
398
  content={i18n.t('Common.buttons.upload')}
394
- disabled={uploading || uploadCount > 0}
399
+ disabled={uploading || uploadCount > 0 || _.isEmpty(items)}
395
400
  icon='cloud upload'
396
401
  loading={uploading && !props.showPageLoader}
397
402
  onClick={onUpload}