@gisce/react-ooui 0.7.1 → 0.8.1
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/dist/index.js +11 -3
- package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
- package/dist/widgets/base/one2many/One2manyInput.js.map +1 -1
- package/dist/widgets/views/Form.d.ts.map +1 -1
- package/dist/widgets/views/Form.js +48 -15
- package/dist/widgets/views/Form.js.map +1 -1
- package/dist/widgets/views/Graph/GraphChart.js +1 -0
- package/dist/widgets/views/Graph/GraphChart.js.map +1 -1
- package/dist/widgets/views/SearchTree.d.ts.map +1 -1
- package/dist/widgets/views/SearchTree.js +4 -2
- package/dist/widgets/views/SearchTree.js.map +1 -1
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/dist/widgets/views/Tree.js +11 -1
- package/dist/widgets/views/Tree.js.map +1 -1
- package/package.json +2 -2
- package/src/widgets/base/one2many/One2manyInput.tsx +0 -1
- package/src/widgets/views/Form.tsx +52 -8
- package/src/widgets/views/Graph/GraphChart.tsx +1 -0
- package/src/widgets/views/SearchTree.tsx +4 -2
- package/src/widgets/views/Tree.tsx +17 -1
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
useContext,
|
|
8
8
|
} from "react";
|
|
9
|
-
import { Form as FormOoui } from "@gisce/ooui";
|
|
9
|
+
import { Form as FormOoui, parseContext } from "@gisce/ooui";
|
|
10
10
|
import {
|
|
11
11
|
Form as AntForm,
|
|
12
12
|
Button,
|
|
@@ -115,6 +115,7 @@ function Form(props: FormProps, ref: any) {
|
|
|
115
115
|
const [fields, setFields] = useState<any>();
|
|
116
116
|
const formModalContext = useContext(FormModalContext) as FormModalContextType;
|
|
117
117
|
const [containerWidth, setContainerWidth] = useState<any>();
|
|
118
|
+
const [defaultGetCalled, setDefaultGetCalled] = useState<boolean>(false);
|
|
118
119
|
|
|
119
120
|
const createdId = useRef<number>();
|
|
120
121
|
const originalFormValues = useRef<any>({});
|
|
@@ -182,6 +183,15 @@ function Form(props: FormProps, ref: any) {
|
|
|
182
183
|
fetchData();
|
|
183
184
|
}, [id, model, valuesProps, formViewProps, visible]);
|
|
184
185
|
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (defaultGetCalled) {
|
|
188
|
+
checkFieldsChanges({
|
|
189
|
+
elementHasLostFocus: true,
|
|
190
|
+
});
|
|
191
|
+
setDefaultGetCalled(false);
|
|
192
|
+
}
|
|
193
|
+
}, [defaultGetCalled]);
|
|
194
|
+
|
|
185
195
|
const onSubmitSucceed = (id?: number, values?: any, formValues?: any) => {
|
|
186
196
|
setFormHasChanges?.(false);
|
|
187
197
|
setFormIsSaving?.(false);
|
|
@@ -337,6 +347,7 @@ function Form(props: FormProps, ref: any) {
|
|
|
337
347
|
let values;
|
|
338
348
|
let _fields;
|
|
339
349
|
let _arch;
|
|
350
|
+
let hasDefaultGetCalled;
|
|
340
351
|
|
|
341
352
|
setFormIsLoading?.(true);
|
|
342
353
|
setError(undefined);
|
|
@@ -352,10 +363,13 @@ function Form(props: FormProps, ref: any) {
|
|
|
352
363
|
if (valuesProps) {
|
|
353
364
|
values = valuesProps;
|
|
354
365
|
} else {
|
|
355
|
-
|
|
366
|
+
({
|
|
367
|
+
values,
|
|
368
|
+
defaultGetCalled: hasDefaultGetCalled,
|
|
369
|
+
} = await fetchValuesFromApi({
|
|
356
370
|
fields: _fields,
|
|
357
371
|
arch: _arch!,
|
|
358
|
-
});
|
|
372
|
+
}));
|
|
359
373
|
}
|
|
360
374
|
|
|
361
375
|
if (actionDomain) {
|
|
@@ -365,9 +379,18 @@ function Form(props: FormProps, ref: any) {
|
|
|
365
379
|
originalFormValues.current = processValues(values, _fields);
|
|
366
380
|
|
|
367
381
|
parseForm({ fields: _fields, arch: _arch!, values });
|
|
368
|
-
assignNewValuesToForm({
|
|
382
|
+
assignNewValuesToForm({
|
|
383
|
+
values,
|
|
384
|
+
fields: _fields,
|
|
385
|
+
reset: true,
|
|
386
|
+
isDefaultGet: hasDefaultGetCalled,
|
|
387
|
+
});
|
|
369
388
|
setFormIsLoading?.(false);
|
|
370
389
|
setFormHasChanges?.(false);
|
|
390
|
+
|
|
391
|
+
if (hasDefaultGetCalled) {
|
|
392
|
+
setDefaultGetCalled(true);
|
|
393
|
+
}
|
|
371
394
|
};
|
|
372
395
|
|
|
373
396
|
function setOriginalValue(field: string, value: any) {
|
|
@@ -420,10 +443,12 @@ function Form(props: FormProps, ref: any) {
|
|
|
420
443
|
values: newValues,
|
|
421
444
|
fields,
|
|
422
445
|
reset,
|
|
446
|
+
isDefaultGet = false,
|
|
423
447
|
}: {
|
|
424
448
|
values: any;
|
|
425
449
|
fields: any;
|
|
426
450
|
reset: boolean;
|
|
451
|
+
isDefaultGet?: boolean;
|
|
427
452
|
}) => {
|
|
428
453
|
const currentValues = reset ? {} : antForm.getFieldsValue(true);
|
|
429
454
|
const mergedValues = { ...currentValues, ...newValues };
|
|
@@ -440,7 +465,10 @@ function Form(props: FormProps, ref: any) {
|
|
|
440
465
|
};
|
|
441
466
|
});
|
|
442
467
|
|
|
443
|
-
|
|
468
|
+
if (!isDefaultGet) {
|
|
469
|
+
lastAssignedValues.current = valuesProcessed;
|
|
470
|
+
}
|
|
471
|
+
|
|
444
472
|
antForm.setFields(fieldsToUpdate);
|
|
445
473
|
};
|
|
446
474
|
|
|
@@ -452,6 +480,8 @@ function Form(props: FormProps, ref: any) {
|
|
|
452
480
|
arch: string;
|
|
453
481
|
}) => {
|
|
454
482
|
let values = {};
|
|
483
|
+
let defaultGetCalled = false;
|
|
484
|
+
|
|
455
485
|
if (getCurrentId()!) {
|
|
456
486
|
values = (
|
|
457
487
|
await ConnectionProvider.getHandler().readObjects({
|
|
@@ -476,8 +506,9 @@ function Form(props: FormProps, ref: any) {
|
|
|
476
506
|
} else {
|
|
477
507
|
setAttachments?.([]);
|
|
478
508
|
values = await getDefaultValues(fields);
|
|
509
|
+
defaultGetCalled = true;
|
|
479
510
|
}
|
|
480
|
-
return values;
|
|
511
|
+
return { values, defaultGetCalled };
|
|
481
512
|
};
|
|
482
513
|
|
|
483
514
|
const submitApi = async (options?: { callOnSubmitSucceed?: boolean }) => {
|
|
@@ -771,7 +802,20 @@ function Form(props: FormProps, ref: any) {
|
|
|
771
802
|
) {
|
|
772
803
|
onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
|
|
773
804
|
} else if (response.type) {
|
|
774
|
-
|
|
805
|
+
let responseContext = {};
|
|
806
|
+
|
|
807
|
+
if (response.context) {
|
|
808
|
+
responseContext = parseContext({
|
|
809
|
+
context: response.context,
|
|
810
|
+
fields,
|
|
811
|
+
values: getValues(),
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
await runAction({
|
|
816
|
+
actionData: response,
|
|
817
|
+
context: { ...context, ...responseContext },
|
|
818
|
+
});
|
|
775
819
|
} else {
|
|
776
820
|
await fetchValues();
|
|
777
821
|
}
|
|
@@ -822,9 +866,9 @@ function Form(props: FormProps, ref: any) {
|
|
|
822
866
|
fields,
|
|
823
867
|
values: getValues(),
|
|
824
868
|
context: {
|
|
825
|
-
...context,
|
|
826
869
|
...parentContext,
|
|
827
870
|
...formOoui?.context,
|
|
871
|
+
...context,
|
|
828
872
|
},
|
|
829
873
|
onRefreshParentValues: () => {
|
|
830
874
|
fetchValues();
|
|
@@ -439,9 +439,11 @@ function SearchTree(props: Props, ref: any) {
|
|
|
439
439
|
});
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
-
function changeSelectedRowKeys(
|
|
442
|
+
function changeSelectedRowKeys(selectedRowKeys: any[]) {
|
|
443
|
+
const selectedRowItems = getResults().filter((entry: any) =>
|
|
444
|
+
selectedRowKeys.includes(entry.id)
|
|
445
|
+
);
|
|
443
446
|
setSelectedRowItems?.(selectedRowItems);
|
|
444
|
-
const selectedRowKeys = selectedRowItems.map((entry: any) => entry.id);
|
|
445
447
|
onChangeSelectedRowKeys?.(selectedRowKeys);
|
|
446
448
|
}
|
|
447
449
|
|
|
@@ -30,7 +30,17 @@ type Props = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const booleanComponentFn = (value: boolean): React.ReactElement => {
|
|
33
|
-
return
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
style={{
|
|
36
|
+
display: "flex",
|
|
37
|
+
justifyContent: "center",
|
|
38
|
+
alignContent: "center",
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
<Checkbox defaultChecked={value} disabled />
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
34
44
|
};
|
|
35
45
|
|
|
36
46
|
const many2OneComponentFn = (m2oField: any): React.ReactElement => {
|
|
@@ -61,6 +71,10 @@ const floatTimeComponent = (value: number): React.ReactElement => {
|
|
|
61
71
|
return <>{parseFloatToString(value)}</>;
|
|
62
72
|
};
|
|
63
73
|
|
|
74
|
+
const numberComponent = (value: number): React.ReactElement => {
|
|
75
|
+
return <div style={{ textAlign: "right" }}>{value}</div>;
|
|
76
|
+
};
|
|
77
|
+
|
|
64
78
|
const imageComponent = (value: string): React.ReactElement => {
|
|
65
79
|
return (
|
|
66
80
|
<img
|
|
@@ -109,6 +123,8 @@ function Tree(props: Props): React.ReactElement {
|
|
|
109
123
|
progressbar: progressBarComponentFn,
|
|
110
124
|
float_time: floatTimeComponent,
|
|
111
125
|
image: imageComponent,
|
|
126
|
+
integer: numberComponent,
|
|
127
|
+
float: numberComponent,
|
|
112
128
|
});
|
|
113
129
|
|
|
114
130
|
setColumns(columns);
|