@gisce/react-ooui 0.7.2 → 0.8.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.
@@ -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
- values = await fetchValuesFromApi({
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({ values, fields: _fields, reset: true });
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
- lastAssignedValues.current = valuesProcessed;
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
- await runAction({ actionData: response, context });
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();
@@ -94,6 +94,7 @@ function getGraphProps(props: GetGraphPropsType) {
94
94
  graphProps.isGroup = isGroup;
95
95
 
96
96
  if (isStack) {
97
+ graphProps.isStack = true;
97
98
  graphProps.groupField = "stacked";
98
99
  }
99
100
  }
@@ -439,9 +439,11 @@ function SearchTree(props: Props, ref: any) {
439
439
  });
440
440
  };
441
441
 
442
- function changeSelectedRowKeys(selectedRowItems: any[]) {
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