@dartech/arsenal-ui 1.4.22 → 1.4.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +29 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -810,7 +810,6 @@ const ControlAutocomplete = _a => {
810
810
  };
811
811
 
812
812
  function ControlQueryAutocomplete(_a) {
813
- var _b;
814
813
  var {
815
814
  name,
816
815
  label,
@@ -832,7 +831,7 @@ function ControlQueryAutocomplete(_a) {
832
831
  requiredErrorText = ''
833
832
  } = _a,
834
833
  autocompleteProps = __rest(_a, ["name", "label", "control", "required", "searchBy", "labelKey", "multiple", "disabled", "valueKey", "sortBy", "hideErrorMessage", "disableCloseOnSelect", "textFieldProps", "onChange", "queryFunction", "validate", "itemQueryFunction", "requiredErrorText"]);
835
- const _c = useController({
834
+ const _b = useController({
836
835
  control,
837
836
  name,
838
837
  defaultValue: multiple ? [] : null,
@@ -841,19 +840,19 @@ function ControlQueryAutocomplete(_a) {
841
840
  validate
842
841
  }
843
842
  }),
844
- _d = _c.field,
843
+ _c = _b.field,
845
844
  {
846
845
  ref,
847
846
  onChange: setFieldValue,
848
847
  value: formValue
849
- } = _d,
850
- fieldProps = __rest(_d, ["ref", "onChange", "value"]),
848
+ } = _c,
849
+ fieldProps = __rest(_c, ["ref", "onChange", "value"]),
851
850
  {
852
851
  fieldState: {
853
852
  error,
854
853
  isDirty
855
854
  }
856
- } = _c;
855
+ } = _b;
857
856
  const {
858
857
  getOptionLabel,
859
858
  isOptionEqualToValue,
@@ -862,6 +861,7 @@ function ControlQueryAutocomplete(_a) {
862
861
  valueKey,
863
862
  labelKey
864
863
  });
864
+ const [options, setOptions] = useState([]);
865
865
  const [open, setOpen] = useState(false);
866
866
  const [inputValue, setInputValue] = useState('');
867
867
  const [searchValue, setSearchValue] = useState('');
@@ -880,6 +880,11 @@ function ControlQueryAutocomplete(_a) {
880
880
  ignoreQueryPrefix: true
881
881
  });
882
882
  return queryFunction(params);
883
+ }, {
884
+ // keepPreviousData: true,
885
+ onSuccess(data) {
886
+ setOptions(state => [...state, ...data.collection]);
887
+ }
883
888
  });
884
889
  const debouncedChange = useDebounce(val => {
885
890
  setPage(0);
@@ -895,6 +900,7 @@ function ControlQueryAutocomplete(_a) {
895
900
  onChange(event, value);
896
901
  }
897
902
  }, [setFieldValue, onChange]);
903
+ console.log(isDirty, formValue, searchValue);
898
904
  useEffect(() => {
899
905
  if (!isDirty && formValue && itemQueryFunction) {
900
906
  let requestValue = formValue;
@@ -904,15 +910,15 @@ function ControlQueryAutocomplete(_a) {
904
910
  itemQueryFunction(requestValue).then(item => {
905
911
  setFieldValue(item);
906
912
  setInputValue(_get(item, labelKey));
907
- }).catch();
913
+ }).catch(console.error);
908
914
  }
909
915
  }, [formValue, isDirty, valueKey, labelKey, itemQueryFunction, setFieldValue]);
910
916
  const handleOnScroll = useCallback(event => {
911
917
  const listboxNode = event.currentTarget;
912
- if (listboxNode.scrollHeight - listboxNode.scrollTop - listboxNode.clientHeight <= 1 && (data === null || data === void 0 ? void 0 : data.collection.length) < (data === null || data === void 0 ? void 0 : data.totalItems)) {
918
+ if (listboxNode.scrollHeight - listboxNode.scrollTop - listboxNode.clientHeight <= 1 && options.length < (data === null || data === void 0 ? void 0 : data.totalItems)) {
913
919
  setPage(page => page + 1);
914
920
  }
915
- }, [data]);
921
+ }, [data, options]);
916
922
  const handleOpen = () => {
917
923
  setOpen(true);
918
924
  };
@@ -925,7 +931,7 @@ function ControlQueryAutocomplete(_a) {
925
931
  disablePortal: true,
926
932
  size: "small",
927
933
  readOnly: disabled,
928
- options: (_b = data === null || data === void 0 ? void 0 : data.collection) !== null && _b !== void 0 ? _b : [],
934
+ options: options,
929
935
  multiple: multiple,
930
936
  getOptionLabel: getOptionLabel,
931
937
  isOptionEqualToValue: isOptionEqualToValue,
@@ -1568,7 +1574,6 @@ const formatPropertyValue = (propertyType, value, params) => {
1568
1574
  break;
1569
1575
  }
1570
1576
  case PropertyType.JSON:
1571
- case PropertyType.ANY:
1572
1577
  try {
1573
1578
  if (typeof value !== 'string') {
1574
1579
  parsedValue = JSON.stringify(value);
@@ -1579,6 +1584,19 @@ const formatPropertyValue = (propertyType, value, params) => {
1579
1584
  parsedValue = null;
1580
1585
  }
1581
1586
  break;
1587
+ case PropertyType.ANY:
1588
+ try {
1589
+ if (typeof value === 'string') {
1590
+ parsedValue = JSON.parse(parsedValue);
1591
+ } else {
1592
+ parsedValue = value;
1593
+ }
1594
+ // parsedValue = JSON.parse(parsedValue as string);
1595
+ } catch (e) {
1596
+ // console.log(e);
1597
+ parsedValue = value;
1598
+ }
1599
+ break;
1582
1600
  case PropertyType.ENTITY:
1583
1601
  parsedValue = formatDefinitionData(params.properties, value);
1584
1602
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.22",
3
+ "version": "1.4.24",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"