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

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.3",
3
+ "version": "1.0.4-beta.4",
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.3",
15
+ "@performant-software/shared-components": "^1.0.4-beta.4",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "citeproc": "^2.4.62",
@@ -85,7 +85,7 @@ 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.
@@ -157,9 +157,13 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
157
157
  *
158
158
  * @type {function(*, *): void}
159
159
  */
160
- const setStatus = useCallback((index, status) => (
161
- setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: status }))
162
- ));
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]);
163
167
 
164
168
  /**
165
169
  * Iterates of the list of items and sequentially calls the <code>onSave</code> prop for each.
@@ -173,19 +177,19 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
173
177
  // Update the status for the item
174
178
  setStatus(i, Status.processing);
175
179
 
176
- let error = false;
180
+ let error;
177
181
 
178
182
  // Do the upload
179
183
  try {
180
184
  // eslint-disable-next-line no-await-in-loop
181
185
  await props.onSave(item);
182
186
  } catch (e) {
183
- error = true;
187
+ error = e;
184
188
  }
185
189
 
186
190
  // Update the status for the item
187
191
  if (error) {
188
- setStatus(i, Status.error);
192
+ setStatus(i, Status.error, error.message);
189
193
  } else {
190
194
  setStatus(i, Status.complete);
191
195
  }
@@ -391,7 +395,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
391
395
  >
392
396
  { props.strategy === Strategy.single && (
393
397
  <FileUploadStatus
394
- status={statuses[index]}
398
+ status={item.status}
395
399
  />
396
400
  )}
397
401
  </UploadItem>
@@ -85,7 +85,7 @@ 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.
@@ -157,9 +157,13 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
157
157
  *
158
158
  * @type {function(*, *): void}
159
159
  */
160
- const setStatus = useCallback((index, status) => (
161
- setStatuses((prevStatuses) => ({ ...prevStatuses, [index]: status }))
162
- ));
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]);
163
167
 
164
168
  /**
165
169
  * Iterates of the list of items and sequentially calls the <code>onSave</code> prop for each.
@@ -173,19 +177,19 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
173
177
  // Update the status for the item
174
178
  setStatus(i, Status.processing);
175
179
 
176
- let error = false;
180
+ let error;
177
181
 
178
182
  // Do the upload
179
183
  try {
180
184
  // eslint-disable-next-line no-await-in-loop
181
185
  await props.onSave(item);
182
186
  } catch (e) {
183
- error = true;
187
+ error = e;
184
188
  }
185
189
 
186
190
  // Update the status for the item
187
191
  if (error) {
188
- setStatus(i, Status.error);
192
+ setStatus(i, Status.error, error.message);
189
193
  } else {
190
194
  setStatus(i, Status.complete);
191
195
  }
@@ -391,7 +395,7 @@ const FileUploadModal: ComponentType<any> = (props: Props) => {
391
395
  >
392
396
  { props.strategy === Strategy.single && (
393
397
  <FileUploadStatus
394
- status={statuses[index]}
398
+ status={item.status}
395
399
  />
396
400
  )}
397
401
  </UploadItem>