@bigbinary/neeto-fields-frontend 1.3.44 → 1.4.0-beta2

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 CHANGED
@@ -25,7 +25,7 @@ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
25
25
  import { useTranslation, Trans } from 'react-i18next';
26
26
  import Pane from '@bigbinary/neetoui/Pane';
27
27
  import Form from '@bigbinary/neetoui/formik/Form';
28
- import { useQuery } from 'react-query';
28
+ import { useQuery, keepPreviousData } from '@tanstack/react-query';
29
29
  import axios from 'axios';
30
30
  import { buildUrl, getQueryParams, dateFormat, hyphenize as hyphenize$1 } from '@bigbinary/neeto-commons-frontend/utils';
31
31
  import ActionBlock$1 from '@bigbinary/neetoui/formik/ActionBlock';
@@ -1488,51 +1488,58 @@ var useFetchFields = function useFetchFields(_ref, options) {
1488
1488
  var _ref$prefixQueryKeys = _ref.prefixQueryKeys,
1489
1489
  prefixQueryKeys = _ref$prefixQueryKeys === void 0 ? [] : _ref$prefixQueryKeys,
1490
1490
  params = _objectWithoutProperties(_ref, _excluded$4);
1491
- return useQuery([FIELDS].concat(_toConsumableArray(prefixQueryKeys), [params]), function () {
1492
- return fieldsApi.fetch(params);
1493
- }, _objectSpread$f({
1491
+ return useQuery(_objectSpread$f({
1492
+ queryKey: [FIELDS].concat(_toConsumableArray(prefixQueryKeys), [params]),
1493
+ queryFn: function queryFn() {
1494
+ return fieldsApi.fetch(params);
1495
+ },
1494
1496
  staleTime: DEFAULT_STALE_TIME
1495
1497
  }, options));
1496
1498
  };
1497
1499
  var useCreateField = function useCreateField(options) {
1498
1500
  return useMutationWithInvalidation(fieldsApi.create, _objectSpread$f({
1499
- keysToInvalidate: [FIELDS]
1501
+ keysToInvalidate: [[FIELDS]]
1500
1502
  }, options));
1501
1503
  };
1502
1504
  var useShowField = function useShowField(_ref2, options) {
1503
1505
  var fieldId = _ref2.fieldId,
1504
1506
  ownerId = _ref2.ownerId;
1505
- var queryKey = [FIELDS, fieldId];
1506
- return useQuery(queryKey, function () {
1507
- return fieldsApi.show({
1508
- fieldId: fieldId,
1509
- ownerId: ownerId
1510
- });
1511
- }, options);
1507
+ return useQuery(_objectSpread$f({
1508
+ queryKey: [FIELDS, fieldId],
1509
+ queryFn: function queryFn() {
1510
+ return fieldsApi.show({
1511
+ fieldId: fieldId,
1512
+ ownerId: ownerId
1513
+ });
1514
+ }
1515
+ }, options));
1512
1516
  };
1513
1517
  var useFetchDependencies = function useFetchDependencies(_ref3, options) {
1514
1518
  var fieldId = _ref3.fieldId,
1515
1519
  ownerId = _ref3.ownerId;
1516
- return useQuery([DEPENDENCIES, fieldId], function () {
1517
- return fieldsApi.dependencies({
1518
- fieldId: fieldId,
1519
- ownerId: ownerId
1520
- });
1521
- }, options);
1520
+ return useQuery(_objectSpread$f({
1521
+ queryKey: [DEPENDENCIES, fieldId],
1522
+ queryFn: function queryFn() {
1523
+ return fieldsApi.dependencies({
1524
+ fieldId: fieldId,
1525
+ ownerId: ownerId
1526
+ });
1527
+ }
1528
+ }, options));
1522
1529
  };
1523
1530
  var useUpdateField = function useUpdateField(options) {
1524
1531
  return useMutationWithInvalidation(fieldsApi.update, _objectSpread$f({
1525
- keysToInvalidate: [FIELDS]
1532
+ keysToInvalidate: [[FIELDS]]
1526
1533
  }, options));
1527
1534
  };
1528
1535
  var useDestroyField = function useDestroyField(options) {
1529
1536
  return useMutationWithInvalidation(fieldsApi.destroy, _objectSpread$f({
1530
- keysToInvalidate: [FIELDS]
1537
+ keysToInvalidate: [[FIELDS]]
1531
1538
  }, options));
1532
1539
  };
1533
1540
  var useReorderFields = function useReorderFields() {
1534
1541
  return useMutationWithInvalidation(fieldsApi.reorder, {
1535
- keysToInvalidate: [FIELDS]
1542
+ keysToInvalidate: [[FIELDS]]
1536
1543
  });
1537
1544
  };
1538
1545
 
@@ -1922,7 +1929,7 @@ var Add = function Add(_ref) {
1922
1929
  onSuccess: onMutationSuccess
1923
1930
  }),
1924
1931
  createField = _useCreateField.mutate,
1925
- isSubmitting = _useCreateField.isLoading;
1932
+ isSubmitting = _useCreateField.isPending;
1926
1933
  var filteredKinds = values(pick(allowedKinds, FIELD_KINDS));
1927
1934
  var handleSubmit = function handleSubmit(formValues) {
1928
1935
  var payload = buildPayload({
@@ -1999,7 +2006,7 @@ var Edit = function Edit(_ref) {
1999
2006
  }
2000
2007
  }),
2001
2008
  updateField = _useUpdateField.mutate,
2002
- isSubmitting = _useUpdateField.isLoading;
2009
+ isSubmitting = _useUpdateField.isPending;
2003
2010
  var handleSubmit = function handleSubmit(formValues) {
2004
2011
  var payload = buildPayload({
2005
2012
  formValues: formValues,
@@ -2789,7 +2796,9 @@ var configsApi = {
2789
2796
  function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2790
2797
  function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2791
2798
  var useFetchConfigs = function useFetchConfigs(options) {
2792
- return useQuery([QUERY_KEYS.CONFIGS], configsApi.fetchConfigs, _objectSpread$a({
2799
+ return useQuery(_objectSpread$a({
2800
+ queryKey: [QUERY_KEYS.CONFIGS],
2801
+ queryFn: configsApi.fetchConfigs,
2793
2802
  staleTime: DEFAULT_STALE_TIME
2794
2803
  }, options));
2795
2804
  };
@@ -2862,7 +2871,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
2862
2871
  };
2863
2872
  var _useFetchFields = useFetchFields(fieldParams, {
2864
2873
  enabled: !!resource,
2865
- keepPreviousData: true
2874
+ placeholderData: keepPreviousData
2866
2875
  }),
2867
2876
  _useFetchFields$data = _useFetchFields.data,
2868
2877
  _useFetchFields$data2 = _useFetchFields$data === void 0 ? {} : _useFetchFields$data,
@@ -2882,7 +2891,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
2882
2891
  }
2883
2892
  }),
2884
2893
  deleteField = _useDestroyField.mutate,
2885
- isDeleting = _useDestroyField.isLoading;
2894
+ isDeleting = _useDestroyField.isPending;
2886
2895
  var handleDelete = function handleDelete() {
2887
2896
  deleteField({
2888
2897
  fieldId: selectedField.id,
@@ -7487,7 +7496,7 @@ var ReorderPane = function ReorderPane(_ref) {
7487
7496
  resource = _getQueryParams.resource;
7488
7497
  var _useReorderFields = useReorderFields(),
7489
7498
  reorderField = _useReorderFields.mutate,
7490
- isSubmitting = _useReorderFields.isLoading;
7499
+ isSubmitting = _useReorderFields.isPending;
7491
7500
  var fieldParams = {
7492
7501
  resourceType: isEmpty(ownerId) ? resource : undefined,
7493
7502
  ownerId: ownerId,
@@ -7495,20 +7504,15 @@ var ReorderPane = function ReorderPane(_ref) {
7495
7504
  searchTerm: ""
7496
7505
  };
7497
7506
  var _useFetchFields = useFetchFields(fieldParams, {
7498
- enabled: !!resource && isOpen,
7499
- onSuccess: function onSuccess(_ref2) {
7500
- var fields = _ref2.fields;
7501
- setFields(fields);
7502
- initialStateRef.current = fields;
7503
- }
7507
+ enabled: !!resource && isOpen
7504
7508
  }),
7505
7509
  _useFetchFields$data = _useFetchFields.data,
7506
7510
  _useFetchFields$data2 = _useFetchFields$data === void 0 ? {} : _useFetchFields$data,
7507
7511
  _useFetchFields$data3 = _useFetchFields$data2.fields,
7508
7512
  allFields = _useFetchFields$data3 === void 0 ? [] : _useFetchFields$data3;
7509
- var handleDragEnd = function handleDragEnd(_ref3) {
7510
- var active = _ref3.active,
7511
- over = _ref3.over;
7513
+ var handleDragEnd = function handleDragEnd(_ref2) {
7514
+ var active = _ref2.active,
7515
+ over = _ref2.over;
7512
7516
  if (active.id !== over.id) {
7513
7517
  setFields(function (fields) {
7514
7518
  return arrayMove(fields, active.data.current.index, over.data.current.index);
@@ -7530,6 +7534,11 @@ var ReorderPane = function ReorderPane(_ref) {
7530
7534
  onSuccess: onClose
7531
7535
  });
7532
7536
  };
7537
+ useEffect(function () {
7538
+ if (isEmpty(allFields)) return;
7539
+ setFields(allFields);
7540
+ initialStateRef.current = allFields;
7541
+ }, [allFields]);
7533
7542
  return /*#__PURE__*/jsxs(Pane, {
7534
7543
  isOpen: isOpen,
7535
7544
  onClose: onClose,