@bigbinary/neeto-fields-frontend 1.3.3 → 1.3.5

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
@@ -1,9 +1,9 @@
1
1
  import React, { useContext, useState, useRef, useEffect, useMemo, useLayoutEffect, useCallback, createContext, memo, useReducer } from 'react';
2
2
  import { Checkbox as Checkbox$1, TimePicker, DatePicker, Select, Input, Textarea, Typography, Pane, Label, Button as Button$1, Dropdown, Tab, Alert, NoData, Table, Spinner } from '@bigbinary/neetoui';
3
- import { isNotEmpty, renameKeys, capitalize as capitalize$1, findBy, filterBy, toLabelAndValue, slugify, humanize, truncate, countBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
3
+ import { isNotEmpty, renameKeys, capitalize as capitalize$1, findBy, filterBy, toLabelAndValue, slugify, humanize, countBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
4
4
  import { values, isNotNil, isNil, isEmpty, prop, pluck, clone as clone$1, pipe, mergeAll, omit, map, pick, assoc, any, head } from 'ramda';
5
5
  import { useFormikContext, useField, FieldArray } from 'formik';
6
- import { useFuncDebounce, useDebounce, handleMetaClick } from '@bigbinary/neeto-commons-frontend/react-utils';
6
+ import { useFuncDebounce, useMutationWithInvalidation, useDebounce, handleMetaClick } from '@bigbinary/neeto-commons-frontend/react-utils';
7
7
  import * as yup from 'yup';
8
8
  import { joinHyphenCase, buildUrl, getQueryParams } from '@bigbinary/neeto-commons-frontend/utils';
9
9
  import { Check, Delete, MenuHorizontal, Info, Reorder } from '@bigbinary/neeto-icons';
@@ -11,7 +11,7 @@ import { Button, ActionBlock as ActionBlock$1, Input as Input$1, Select as Selec
11
11
  import { DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
12
12
  import Container from '@bigbinary/neeto-molecules/Container';
13
13
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
14
- import { useQuery, useQueryClient, useMutation } from 'react-query';
14
+ import { useQuery } from 'react-query';
15
15
  import axios from 'axios';
16
16
  import { v4 } from 'uuid';
17
17
  import { Link, useHistory } from 'react-router-dom';
@@ -6507,17 +6507,9 @@ var useFetchFields = function useFetchFields(_ref, options) {
6507
6507
  }, options));
6508
6508
  };
6509
6509
  var useCreateField = function useCreateField(options) {
6510
- var queryClient = useQueryClient();
6511
- return useMutation(fieldsApi.create, _objectSpread$9(_objectSpread$9({}, options), {}, {
6512
- onSuccess: function onSuccess() {
6513
- var _options$onSuccess;
6514
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6515
- args[_key] = arguments[_key];
6516
- }
6517
- options === null || options === void 0 ? void 0 : (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call.apply(_options$onSuccess, [options].concat(args));
6518
- queryClient.invalidateQueries(FIELDS);
6519
- }
6520
- }));
6510
+ return useMutationWithInvalidation(fieldsApi.create, _objectSpread$9({
6511
+ keysToInvalidate: [FIELDS]
6512
+ }, options));
6521
6513
  };
6522
6514
  var useShowField = function useShowField(_ref2, options) {
6523
6515
  var fieldId = _ref2.fieldId,
@@ -6541,37 +6533,18 @@ var useFetchDependencies = function useFetchDependencies(_ref3, options) {
6541
6533
  }, options);
6542
6534
  };
6543
6535
  var useUpdateField = function useUpdateField(options) {
6544
- var queryClient = useQueryClient();
6545
- return useMutation(fieldsApi.update, _objectSpread$9(_objectSpread$9({}, options), {}, {
6546
- onSuccess: function onSuccess() {
6547
- var _options$onSuccess2;
6548
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
6549
- args[_key2] = arguments[_key2];
6550
- }
6551
- options === null || options === void 0 ? void 0 : (_options$onSuccess2 = options.onSuccess) === null || _options$onSuccess2 === void 0 ? void 0 : _options$onSuccess2.call.apply(_options$onSuccess2, [options].concat(args));
6552
- queryClient.invalidateQueries(FIELDS);
6553
- }
6554
- }));
6536
+ return useMutationWithInvalidation(fieldsApi.update, _objectSpread$9({
6537
+ keysToInvalidate: [FIELDS]
6538
+ }, options));
6555
6539
  };
6556
6540
  var useDestroyField = function useDestroyField(options) {
6557
- var queryClient = useQueryClient();
6558
- return useMutation(fieldsApi.destroy, _objectSpread$9(_objectSpread$9({}, options), {}, {
6559
- onSuccess: function onSuccess() {
6560
- var _options$onSuccess3;
6561
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
6562
- args[_key3] = arguments[_key3];
6563
- }
6564
- options === null || options === void 0 ? void 0 : (_options$onSuccess3 = options.onSuccess) === null || _options$onSuccess3 === void 0 ? void 0 : _options$onSuccess3.call.apply(_options$onSuccess3, [options].concat(args));
6565
- queryClient.invalidateQueries(FIELDS);
6566
- }
6567
- }));
6541
+ return useMutationWithInvalidation(fieldsApi.destroy, _objectSpread$9({
6542
+ keysToInvalidate: [FIELDS]
6543
+ }, options));
6568
6544
  };
6569
6545
  var useReorderFields = function useReorderFields() {
6570
- var queryClient = useQueryClient();
6571
- return useMutation(fieldsApi.reorder, {
6572
- onSuccess: function onSuccess() {
6573
- queryClient.invalidateQueries(FIELDS);
6574
- }
6546
+ return useMutationWithInvalidation(fieldsApi.reorder, {
6547
+ keysToInvalidate: [FIELDS]
6575
6548
  });
6576
6549
  };
6577
6550
 
@@ -7851,7 +7824,8 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7851
7824
  inactiveFieldsCount = _useFetchFields$data2.inactiveFieldsCount,
7852
7825
  reorderable = _useFetchFields$data2.reorderable,
7853
7826
  isFieldsLoading = _useFetchFields.isLoading,
7854
- isFieldsFetching = _useFetchFields.isFetching;
7827
+ isFieldsFetching = _useFetchFields.isFetching,
7828
+ isFieldsFetched = _useFetchFields.isFetched;
7855
7829
  var _useDestroyField = useDestroyField({
7856
7830
  onSuccess: function onSuccess() {
7857
7831
  setIsDeleteAlertOpen(false);
@@ -7965,7 +7939,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7965
7939
  }, [menuItems, resource]);
7966
7940
  useEffect(function () {
7967
7941
  handleURLWithDefaultValues();
7968
- }, [isConfigsLoading, resources]);
7942
+ }, [isConfigsLoading, resources, resource, state]);
7969
7943
  useEffect(function () {
7970
7944
  setPageProps({
7971
7945
  pageIndex: DEFAULT_PAGE_INDEX,
@@ -7985,11 +7959,10 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7985
7959
  selectedMenu: resource,
7986
7960
  // resource will be ownerId if showOwnersInMenu is true, else it will be resourceType
7987
7961
  ownerId: ownerId,
7988
- isFieldsFetching: isFieldsFetching,
7989
- isFieldsLoading: isFieldsLoading,
7990
7962
  isDeleting: isDeleting,
7963
+ isFieldsFetching: isFieldsFetching,
7964
+ isFieldsFetched: isFieldsFetched,
7991
7965
  isScreenLoading: isScreenLoading,
7992
- isConfigsLoading: isConfigsLoading,
7993
7966
  isMenuBarNeeded: isMenuBarNeeded,
7994
7967
  showCountSubheader: showCountSubheader,
7995
7968
  handleDelete: handleDelete,
@@ -8045,7 +8018,8 @@ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if
8045
8018
  function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8046
8019
  var FieldsTable = function FieldsTable(_ref) {
8047
8020
  var totalCount = _ref.totalCount,
8048
- isLoading = _ref.isLoading,
8021
+ isFetched = _ref.isFetched,
8022
+ isFetching = _ref.isFetching,
8049
8023
  rowData = _ref.rowData,
8050
8024
  columnData = _ref.columnData,
8051
8025
  setIsPaneOpen = _ref.setIsPaneOpen,
@@ -8055,10 +8029,13 @@ var FieldsTable = function FieldsTable(_ref) {
8055
8029
  setPageProps = _ref.setPageProps;
8056
8030
  var _useTranslation = useTranslation(),
8057
8031
  t = _useTranslation.t;
8058
- var showNoDataScreen = !isLoading && isEmpty(rowData);
8032
+ var showNoDataScreen = isFetched && isEmpty(rowData);
8059
8033
  title = title.toLocaleLowerCase();
8060
8034
  var pageIndex = pageProps.pageIndex,
8061
8035
  pageSize = pageProps.pageSize;
8036
+ if (!isFetched && isEmpty(rowData)) {
8037
+ return /*#__PURE__*/React.createElement(PageLoader, null);
8038
+ }
8062
8039
  return /*#__PURE__*/React.createElement(TableWrapper, null, showNoDataScreen ? /*#__PURE__*/React.createElement("div", {
8063
8040
  className: "flex h-full w-full items-center justify-center"
8064
8041
  }, /*#__PURE__*/React.createElement(NoData, _extends({}, helpDocUrl && {
@@ -8081,7 +8058,7 @@ var FieldsTable = function FieldsTable(_ref) {
8081
8058
  totalCount: totalCount,
8082
8059
  currentPageNumber: pageIndex,
8083
8060
  defaultPageSize: pageSize,
8084
- loading: isLoading,
8061
+ loading: isFetching,
8085
8062
  handlePageChange: function handlePageChange(pageIndex) {
8086
8063
  return setPageProps(_objectSpread$3(_objectSpread$3({}, pageProps), {}, {
8087
8064
  pageIndex: pageIndex
@@ -8139,11 +8116,9 @@ var Header = function Header(_ref) {
8139
8116
  actionBlockProps = _objectWithoutProperties(_ref, _excluded);
8140
8117
  return /*#__PURE__*/React.createElement(NeetoUIHeader, {
8141
8118
  size: "small",
8119
+ breadcrumbs: breadcrumbs,
8142
8120
  searchProps: searchProps,
8143
8121
  actionBlock: /*#__PURE__*/React.createElement(ActionBlock, actionBlockProps),
8144
- breadcrumbs: [].concat(_toConsumableArray(breadcrumbs), [{
8145
- text: truncate(title, 50)
8146
- }]),
8147
8122
  title: /*#__PURE__*/React.createElement(TitleWithHelpLink, {
8148
8123
  helpUrl: helpDocUrl,
8149
8124
  title: title
@@ -8152,15 +8127,12 @@ var Header = function Header(_ref) {
8152
8127
  };
8153
8128
 
8154
8129
  var Menubar = function Menubar(_ref) {
8155
- var isConfigsLoading = _ref.isConfigsLoading,
8156
- menuBarItems = _ref.menuBarItems,
8130
+ var menuBarItems = _ref.menuBarItems,
8157
8131
  title = _ref.title;
8158
8132
  return /*#__PURE__*/React.createElement(MenuBar, {
8159
8133
  showMenu: true,
8160
8134
  title: title
8161
- }, isConfigsLoading ? /*#__PURE__*/React.createElement("div", {
8162
- className: "flex items-center justify-center"
8163
- }, /*#__PURE__*/React.createElement(Spinner, null)) : menuBarItems);
8135
+ }, menuBarItems);
8164
8136
  };
8165
8137
 
8166
8138
  function useCombinedRefs() {
@@ -12603,10 +12575,9 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
12603
12575
  selectedMenu = _useFieldsDashboard.selectedMenu,
12604
12576
  ownerId = _useFieldsDashboard.ownerId,
12605
12577
  isFieldsFetching = _useFieldsDashboard.isFieldsFetching,
12606
- isFieldsLoading = _useFieldsDashboard.isFieldsLoading,
12578
+ isFieldsFetched = _useFieldsDashboard.isFieldsFetched,
12607
12579
  isDeleting = _useFieldsDashboard.isDeleting,
12608
12580
  isScreenLoading = _useFieldsDashboard.isScreenLoading,
12609
- isConfigsLoading = _useFieldsDashboard.isConfigsLoading,
12610
12581
  isMenuBarNeeded = _useFieldsDashboard.isMenuBarNeeded,
12611
12582
  showCountSubheader = _useFieldsDashboard.showCountSubheader,
12612
12583
  handleDelete = _useFieldsDashboard.handleDelete,
@@ -12630,15 +12601,15 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
12630
12601
  title: headerDisplayTitle
12631
12602
  };
12632
12603
  return /*#__PURE__*/React.createElement(React.Fragment, null, isMenuBarNeeded && /*#__PURE__*/React.createElement(Menubar, {
12633
- isConfigsLoading: isConfigsLoading,
12634
12604
  menuBarItems: menuBarItems,
12635
12605
  title: title
12636
- }), isScreenLoading && isEmpty(fields) ? /*#__PURE__*/React.createElement("div", {
12637
- className: "flex h-screen w-full flex-grow items-center justify-center"
12638
- }, /*#__PURE__*/React.createElement(PageLoader, null)) : /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Header, headerProps), showStateFilter && stateFilterTabs, showCountSubheader && /*#__PURE__*/React.createElement(Subheader, {
12606
+ }), /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Header, headerProps), showStateFilter && stateFilterTabs, showCountSubheader && /*#__PURE__*/React.createElement(Subheader, {
12639
12607
  count: count
12640
- }), /*#__PURE__*/React.createElement(FieldsTable, {
12641
- isLoading: isFieldsFetching || isFieldsLoading,
12608
+ }), isScreenLoading ? /*#__PURE__*/React.createElement("div", {
12609
+ className: "flex h-screen w-full flex-grow items-center justify-center"
12610
+ }, /*#__PURE__*/React.createElement(PageLoader, null)) : /*#__PURE__*/React.createElement(FieldsTable, {
12611
+ isFetched: isFieldsFetched,
12612
+ isFetching: isFieldsFetching,
12642
12613
  rowData: isEmpty(rowData) ? fields : rowData,
12643
12614
  totalCount: count,
12644
12615
  columnData: columnData,
@@ -12706,40 +12677,19 @@ var fieldValuesApi = {
12706
12677
  function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12707
12678
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12708
12679
  var useCreateFieldValue = function useCreateFieldValue(options) {
12709
- var queryClient = useQueryClient();
12710
- return useMutation(fieldValuesApi.create, _objectSpread$2(_objectSpread$2({}, options), {}, {
12711
- onSuccess: function onSuccess() {
12712
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12713
- args[_key] = arguments[_key];
12714
- }
12715
- options === null || options === void 0 ? void 0 : options.onSuccess.apply(options, args);
12716
- queryClient.invalidateQueries([QUERY_KEYS.FIELD_VALUES]);
12717
- }
12718
- }));
12680
+ return useMutationWithInvalidation(fieldValuesApi.create, _objectSpread$2({
12681
+ keysToInvalidate: [[QUERY_KEYS.FIELD_VALUES]]
12682
+ }, options));
12719
12683
  };
12720
12684
  var useUpdateFieldValue = function useUpdateFieldValue(options) {
12721
- var queryClient = useQueryClient();
12722
- return useMutation(fieldValuesApi.update, _objectSpread$2(_objectSpread$2({}, options), {}, {
12723
- onSuccess: function onSuccess() {
12724
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
12725
- args[_key2] = arguments[_key2];
12726
- }
12727
- options === null || options === void 0 ? void 0 : options.onSuccess.apply(options, args);
12728
- queryClient.invalidateQueries([QUERY_KEYS.FIELD_VALUES]);
12729
- }
12730
- }));
12685
+ return useMutationWithInvalidation(fieldValuesApi.update, _objectSpread$2({
12686
+ keysToInvalidate: [[QUERY_KEYS.FIELD_VALUES]]
12687
+ }, options));
12731
12688
  };
12732
12689
  var useDeleteFieldValue = function useDeleteFieldValue(options) {
12733
- var queryClient = useQueryClient();
12734
- return useMutation(fieldValuesApi.destroy, _objectSpread$2(_objectSpread$2({}, options), {}, {
12735
- onSuccess: function onSuccess() {
12736
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
12737
- args[_key3] = arguments[_key3];
12738
- }
12739
- options === null || options === void 0 ? void 0 : options.onSuccess.apply(options, args);
12740
- queryClient.invalidateQueries([QUERY_KEYS.FIELD_VALUES]);
12741
- }
12742
- }));
12690
+ return useMutationWithInvalidation(fieldValuesApi.destroy, _objectSpread$2({
12691
+ keysToInvalidate: [[QUERY_KEYS.FIELD_VALUES]]
12692
+ }, options));
12743
12693
  };
12744
12694
 
12745
12695
  const useNavPrompt = ({