Skip to content

Commit f61d59f

Browse files
authored
Merge pull request #310 from fractal-analytics-platform/dataset-crud-updated
Added modal for creating/updating datasets
2 parents 2544775 + 52b534d commit f61d59f

File tree

7 files changed

+711
-342
lines changed

7 files changed

+711
-342
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Unreleased
44

5+
* Added new modal for create/update dataset feature (\#310).
56
* Standardized modal management to fix some bugs (\#306).
67
* Added proxy endpoints and refactored error propagation (\#288).
78
* Remove use of deployment-type `fractal-server` variable (\#298).

src/lib/common/errors.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,63 @@ export async function responseError(response) {
1414
* Used for example to handle the displaying of the error alert when using the ConfirmActionButton.
1515
*/
1616
export class AlertError extends Error {
17+
/** @type {null | { loc: string[], msg: string }} */
18+
simpleValidationMessage;
19+
1720
/**
1821
* @param {any} reason
22+
* @param {number|null} statusCode
1923
*/
20-
constructor(reason) {
24+
constructor(reason, statusCode = null) {
2125
super();
2226
this.reason = reason;
27+
this.simpleValidationMessage = getSimpleValidationMessage(reason, statusCode);
28+
}
29+
30+
/**
31+
* @param {string[]} loc expected location of the validation message
32+
* @returns {string | null} the validation message, if found
33+
*/
34+
getSimpleValidationMessage(...loc) {
35+
if (!this.simpleValidationMessage) {
36+
return null;
37+
}
38+
if (this.simpleValidationMessage.loc.length !== loc.length) {
39+
return null;
40+
}
41+
for (let i = 0; i < loc.length; i++) {
42+
if (this.simpleValidationMessage.loc[i] !== loc[i]) {
43+
return null;
44+
}
45+
}
46+
return this.simpleValidationMessage.msg;
47+
}
48+
}
49+
50+
/**
51+
* Detects if the error message is a simple validation message for one field.
52+
*
53+
* @param {any} reason
54+
* @param {number | null} statusCode
55+
* @returns {null | { loc: string[], msg: string }}
56+
*/
57+
function getSimpleValidationMessage(reason, statusCode) {
58+
if (
59+
statusCode !== 422 ||
60+
!('detail' in reason) ||
61+
!Array.isArray(reason.detail) ||
62+
reason.detail.length !== 1
63+
) {
64+
return null;
65+
}
66+
const err = reason.detail[0];
67+
if (!Array.isArray(err.loc) || !err.msg || err.type !== 'value_error') {
68+
return null;
2369
}
70+
return {
71+
loc: err.loc.length > 1 && err.loc[0] === 'body' ? err.loc.slice(1) : err.loc,
72+
msg: err.msg
73+
};
2474
}
2575

2676
/**

src/lib/components/common/StandardDismissableAlert.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
let timeout;
66
77
$: if (autoDismiss && message) {
8-
console.log(`alertMessage=${message}`)
98
if (timeout) {
109
clearTimeout(timeout);
1110
}

0 commit comments

Comments
 (0)