@teselagen/ui 0.3.47 → 0.3.48
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/index.cjs.js +239 -212
- package/index.es.js +240 -213
- package/package.json +2 -1
- package/src/DataTable/index.js +67 -4
- package/src/UploadCsvWizard.js +2 -23
- package/src/index.js +3 -2
- package/src/throwFormError.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teselagen/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.48",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@blueprintjs/datetime": "3.23.19",
|
|
17
17
|
"@blueprintjs/icons": "3.33.0",
|
|
18
18
|
"@blueprintjs/select": "3.18.11",
|
|
19
|
+
"@teselagen/react-table": "6.10.16",
|
|
19
20
|
"axios": "^0.21.1",
|
|
20
21
|
"bluebird": "3.7.2",
|
|
21
22
|
"buffer": "5.7.1",
|
package/src/DataTable/index.js
CHANGED
|
@@ -27,7 +27,8 @@ import {
|
|
|
27
27
|
omitBy,
|
|
28
28
|
times,
|
|
29
29
|
some,
|
|
30
|
-
isFunction
|
|
30
|
+
isFunction,
|
|
31
|
+
every
|
|
31
32
|
} from "lodash";
|
|
32
33
|
import joinUrl from "url-join";
|
|
33
34
|
|
|
@@ -87,6 +88,7 @@ import { validateTableWideErrors } from "./validateTableWideErrors";
|
|
|
87
88
|
import { editCellHelper } from "./editCellHelper";
|
|
88
89
|
import { getCellVal } from "./getCellVal";
|
|
89
90
|
import { getVals } from "./getVals";
|
|
91
|
+
import { throwFormError } from "../throwFormError";
|
|
90
92
|
enablePatches();
|
|
91
93
|
|
|
92
94
|
const PRIMARY_SELECTED_VAL = "main_cell";
|
|
@@ -99,6 +101,8 @@ class DataTable extends React.Component {
|
|
|
99
101
|
if (this.props.helperProp) {
|
|
100
102
|
this.props.helperProp.addEditableTableEntities =
|
|
101
103
|
this.addEditableTableEntities;
|
|
104
|
+
this.props.helperProp.getEditableTableInfoAndThrowFormError =
|
|
105
|
+
this.getEditableTableInfoAndThrowFormError;
|
|
102
106
|
}
|
|
103
107
|
this.hotkeyEnabler = withHotkeys({
|
|
104
108
|
moveUpARow: {
|
|
@@ -798,7 +802,12 @@ class DataTable extends React.Component {
|
|
|
798
802
|
const { change, schema } = computePresets(this.props);
|
|
799
803
|
change(
|
|
800
804
|
"reduxFormCellValidation",
|
|
801
|
-
validateTableWideErrors({
|
|
805
|
+
validateTableWideErrors({
|
|
806
|
+
entities,
|
|
807
|
+
schema,
|
|
808
|
+
newCellValidate,
|
|
809
|
+
props: this.props
|
|
810
|
+
})
|
|
802
811
|
);
|
|
803
812
|
};
|
|
804
813
|
handleDeleteCell = () => {
|
|
@@ -2991,8 +3000,13 @@ class DataTable extends React.Component {
|
|
|
2991
3000
|
indexToStartAt: entities.length
|
|
2992
3001
|
}
|
|
2993
3002
|
);
|
|
2994
|
-
|
|
2995
|
-
|
|
3003
|
+
if (every(entities, "_isClean")) {
|
|
3004
|
+
forEach(newEnts, (e, i) => {
|
|
3005
|
+
entities[i] = e;
|
|
3006
|
+
});
|
|
3007
|
+
} else {
|
|
3008
|
+
entities.splice(entities.length, 0, ...newEnts);
|
|
3009
|
+
}
|
|
2996
3010
|
|
|
2997
3011
|
this.updateValidation(entities, {
|
|
2998
3012
|
...reduxFormCellValidation,
|
|
@@ -3000,6 +3014,35 @@ class DataTable extends React.Component {
|
|
|
3000
3014
|
});
|
|
3001
3015
|
});
|
|
3002
3016
|
};
|
|
3017
|
+
getEditableTableInfoAndThrowFormError = () => {
|
|
3018
|
+
const { schema, reduxFormEntities, reduxFormCellValidation } =
|
|
3019
|
+
computePresets(this.props);
|
|
3020
|
+
const { entsToUse, validationToUse } = removeCleanRows(
|
|
3021
|
+
reduxFormEntities,
|
|
3022
|
+
reduxFormCellValidation
|
|
3023
|
+
);
|
|
3024
|
+
const validationWTableErrs = validateTableWideErrors({
|
|
3025
|
+
entities: entsToUse,
|
|
3026
|
+
schema,
|
|
3027
|
+
newCellValidate: validationToUse
|
|
3028
|
+
});
|
|
3029
|
+
|
|
3030
|
+
if (!entsToUse?.length) {
|
|
3031
|
+
throwFormError(
|
|
3032
|
+
"Please add at least one row to the table before submitting."
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3035
|
+
const invalid =
|
|
3036
|
+
isEmpty(validationWTableErrs) || !some(validationWTableErrs, v => v)
|
|
3037
|
+
? undefined
|
|
3038
|
+
: validationWTableErrs;
|
|
3039
|
+
|
|
3040
|
+
if (invalid) {
|
|
3041
|
+
throwFormError("Please fix the errors in the table before submitting.");
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
return entsToUse;
|
|
3045
|
+
};
|
|
3003
3046
|
|
|
3004
3047
|
insertRows = ({ above, numRows = 1, appendToBottom } = {}) => {
|
|
3005
3048
|
const { entities = [], reduxFormCellValidation } = computePresets(
|
|
@@ -3744,3 +3787,23 @@ const formatPasteData = ({ schema, newVal, path }) => {
|
|
|
3744
3787
|
}
|
|
3745
3788
|
return newVal;
|
|
3746
3789
|
};
|
|
3790
|
+
|
|
3791
|
+
export function removeCleanRows(reduxFormEntities, reduxFormCellValidation) {
|
|
3792
|
+
const toFilterOut = {};
|
|
3793
|
+
const entsToUse = (reduxFormEntities || []).filter(e => {
|
|
3794
|
+
if (!(e._isClean || isEntityClean(e))) return true;
|
|
3795
|
+
else {
|
|
3796
|
+
toFilterOut[getIdOrCodeOrIndex(e)] = true;
|
|
3797
|
+
return false;
|
|
3798
|
+
}
|
|
3799
|
+
});
|
|
3800
|
+
|
|
3801
|
+
const validationToUse = {};
|
|
3802
|
+
forEach(reduxFormCellValidation, (v, k) => {
|
|
3803
|
+
const [rowId] = k.split(":");
|
|
3804
|
+
if (!toFilterOut[rowId]) {
|
|
3805
|
+
validationToUse[k] = v;
|
|
3806
|
+
}
|
|
3807
|
+
});
|
|
3808
|
+
return { entsToUse, validationToUse };
|
|
3809
|
+
}
|
package/src/UploadCsvWizard.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Callout, Icon, Intent, Tab, Tabs } from "@blueprintjs/core";
|
|
|
4
4
|
import immer from "immer";
|
|
5
5
|
import { observer } from "mobx-react";
|
|
6
6
|
import "./UploadCsvWizard.css";
|
|
7
|
-
import {
|
|
7
|
+
import { isFunction } from "lodash";
|
|
8
8
|
import { compose } from "recompose";
|
|
9
9
|
import SimpleStepViz from "./SimpleStepViz";
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
@@ -12,11 +12,10 @@ import { tgFormValueSelector } from "./utils/tgFormValues";
|
|
|
12
12
|
import { some } from "lodash";
|
|
13
13
|
import { times } from "lodash";
|
|
14
14
|
import DialogFooter from "./DialogFooter";
|
|
15
|
-
import DataTable, {
|
|
15
|
+
import DataTable, { removeCleanRows } from "./DataTable";
|
|
16
16
|
import wrapDialog from "./wrapDialog";
|
|
17
17
|
import { omit } from "lodash";
|
|
18
18
|
import { connect } from "react-redux";
|
|
19
|
-
import getIdOrCodeOrIndex from "./DataTable/utils/getIdOrCodeOrIndex";
|
|
20
19
|
import { MatchHeaders } from "./MatchHeaders";
|
|
21
20
|
import { isEmpty } from "lodash";
|
|
22
21
|
import { addSpecialPropToAsyncErrs } from "./FormComponents/tryToMatchSchemas";
|
|
@@ -703,26 +702,6 @@ async function asyncValidateHelper(
|
|
|
703
702
|
}
|
|
704
703
|
}
|
|
705
704
|
|
|
706
|
-
export function removeCleanRows(reduxFormEntities, reduxFormCellValidation) {
|
|
707
|
-
const toFilterOut = {};
|
|
708
|
-
const entsToUse = (reduxFormEntities || []).filter(e => {
|
|
709
|
-
if (!(e._isClean || isEntityClean(e))) return true;
|
|
710
|
-
else {
|
|
711
|
-
toFilterOut[getIdOrCodeOrIndex(e)] = true;
|
|
712
|
-
return false;
|
|
713
|
-
}
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
const validationToUse = {};
|
|
717
|
-
forEach(reduxFormCellValidation, (v, k) => {
|
|
718
|
-
const [rowId] = k.split(":");
|
|
719
|
-
if (!toFilterOut[rowId]) {
|
|
720
|
-
validationToUse[k] = v;
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
return { entsToUse, validationToUse };
|
|
724
|
-
}
|
|
725
|
-
|
|
726
705
|
function maybeStripIdFromEntities(ents, validateAgainstSchema) {
|
|
727
706
|
let toRet;
|
|
728
707
|
if (validateAgainstSchema?.fields?.some(({ path }) => path === "id")) {
|
package/src/index.js
CHANGED
|
@@ -17,19 +17,20 @@ export {
|
|
|
17
17
|
} from "./DataTable/utils/withSelectedEntities";
|
|
18
18
|
export {
|
|
19
19
|
default as DataTable,
|
|
20
|
-
ConnectedPagingTool as PagingTool
|
|
20
|
+
ConnectedPagingTool as PagingTool,
|
|
21
|
+
removeCleanRows
|
|
21
22
|
} from "./DataTable";
|
|
22
23
|
|
|
23
24
|
export { default as getIdOrCodeOrIndex } from "./DataTable/utils/getIdOrCodeOrIndex";
|
|
24
25
|
export { default as convertSchema } from "./DataTable/utils/convertSchema";
|
|
25
26
|
export { default as Loading } from "./Loading";
|
|
27
|
+
export { throwFormError } from "./throwFormError";
|
|
26
28
|
export { default as AdvancedOptions } from "./AdvancedOptions";
|
|
27
29
|
export { default as TgSelect } from "./TgSelect";
|
|
28
30
|
export { default as wrapDialog } from "./wrapDialog";
|
|
29
31
|
export { default as PromptUnsavedChanges } from "./PromptUnsavedChanges";
|
|
30
32
|
export { default as BlueprintError } from "./BlueprintError";
|
|
31
33
|
export { default as DropdownButton } from "./DropdownButton";
|
|
32
|
-
export { removeCleanRows } from "./UploadCsvWizard";
|
|
33
34
|
export { default as DialogFooter } from "./DialogFooter";
|
|
34
35
|
export { default as adHoc } from "./utils/adHoc";
|
|
35
36
|
export { default as IntentText } from "./IntentText";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SubmissionError } from "redux-form";
|
|
2
|
+
|
|
3
|
+
export const throwFormError = error => {
|
|
4
|
+
if (error.message) {
|
|
5
|
+
console.error("error:", error);
|
|
6
|
+
}
|
|
7
|
+
const errorToUse = error.message
|
|
8
|
+
? { _error: error.message }
|
|
9
|
+
: typeof error === "string"
|
|
10
|
+
? { _error: error }
|
|
11
|
+
: error;
|
|
12
|
+
if (!errorToUse._error) {
|
|
13
|
+
errorToUse._error = "Error Submitting Form";
|
|
14
|
+
}
|
|
15
|
+
throw new SubmissionError(errorToUse);
|
|
16
|
+
};
|