@bigbinary/neeto-tags-frontend 0.0.31 → 0.0.33

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
@@ -16,13 +16,14 @@ import React, { createContext, useContext, createElement, isValidElement, cloneE
16
16
  import _classCallCheck$1 from '@babel/runtime/helpers/classCallCheck';
17
17
  import _createClass$1 from '@babel/runtime/helpers/createClass';
18
18
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
19
+ import _extends from '@babel/runtime/helpers/extends';
20
+ import { Plus, MenuHorizontal } from '@bigbinary/neeto-icons';
21
+ import { Typography, Tag, Select, Button, Dropdown, Toastr, Pane, PageLoader, Table, Alert, Input as Input$1, Modal } from '@bigbinary/neetoui';
19
22
  import { useHistory, Switch, Route } from 'react-router-dom';
20
23
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
21
- import { Tag, Dropdown, Toastr, Pane, Typography, Button, PageLoader, Table, Alert, Input as Input$1, Modal } from '@bigbinary/neetoui';
22
24
  import * as yup from 'yup';
23
- import { MenuHorizontal } from '@bigbinary/neeto-icons';
24
25
  import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
25
- import _extends from '@babel/runtime/helpers/esm/extends';
26
+ import _extends$1 from '@babel/runtime/helpers/esm/extends';
26
27
  import ReactDOM from 'react-dom';
27
28
  import axios from 'axios';
28
29
  import { Container, Header, SubHeader, Scrollable, MenuBar } from '@bigbinary/neetoui/layouts';
@@ -3483,6 +3484,81 @@ instance.use(initReactI18next).init({
3483
3484
  }
3484
3485
  });
3485
3486
 
3487
+ /**
3488
+ * A component that helps to manage tags.
3489
+ * Renders selected tags, has dropdown to list down available tags
3490
+ * and allows user to remove tags from the list.
3491
+ */
3492
+ var Tags$2 = function Tags(_ref) {
3493
+ var _ref$label = _ref.label,
3494
+ label = _ref$label === void 0 ? "" : _ref$label,
3495
+ allTags = _ref.allTags,
3496
+ selectedTags = _ref.selectedTags,
3497
+ onTagSelect = _ref.onTagSelect,
3498
+ onTagCreate = _ref.onTagCreate,
3499
+ onTagDelete = _ref.onTagDelete,
3500
+ tagProps = _ref.tagProps,
3501
+ selectProps = _ref.selectProps,
3502
+ buttonProps = _ref.buttonProps;
3503
+
3504
+ var _useState = useState(false),
3505
+ _useState2 = _slicedToArray(_useState, 2),
3506
+ addTag = _useState2[0],
3507
+ setAddTag = _useState2[1];
3508
+
3509
+ var tags = useMemo(function () {
3510
+ if (!allTags) return [];
3511
+ if (!selectedTags) return allTags;
3512
+ var selectedTagValues = selectedTags.map(function (_ref2) {
3513
+ var value = _ref2.value;
3514
+ return value;
3515
+ });
3516
+ return allTags.filter(function (_ref3) {
3517
+ var value = _ref3.value;
3518
+ return !selectedTagValues.includes(value);
3519
+ });
3520
+ });
3521
+ return /*#__PURE__*/React.createElement("div", {
3522
+ className: "neeto-ui-tags-wrapper"
3523
+ }, label && /*#__PURE__*/React.createElement(Typography, {
3524
+ style: "h6",
3525
+ weight: "bold",
3526
+ className: "neeto-ui-text-gray-500 neeto-ui-mb-4"
3527
+ }, label), !!selectedTags.length && /*#__PURE__*/React.createElement("div", {
3528
+ className: "neeto-ui-flex neeto-ui-mb-2 neeto-ui-flex-row neeto-ui-flex-wrap neeto-ui-items-start neeto-ui-justify-start"
3529
+ }, selectedTags === null || selectedTags === void 0 ? void 0 : selectedTags.map(function (tag, index) {
3530
+ return /*#__PURE__*/React.createElement(Tag, _extends({
3531
+ key: "".concat(index, "-").concat(tag.label),
3532
+ label: tag.label,
3533
+ style: "primary",
3534
+ onClose: function onClose() {
3535
+ return onTagDelete(tag);
3536
+ },
3537
+ className: "neeto-ui-mb-2 neeto-ui-mr-2"
3538
+ }, tagProps));
3539
+ })), addTag ? /*#__PURE__*/React.createElement(Select, _extends({
3540
+ isCreateable: true,
3541
+ placeholder: "Select or Create tag",
3542
+ options: tags,
3543
+ onChange: function onChange(e) {
3544
+ setAddTag(false);
3545
+ onTagSelect(e);
3546
+ },
3547
+ onCreateOption: function onCreateOption(e) {
3548
+ setAddTag(false);
3549
+ onTagCreate(e);
3550
+ }
3551
+ }, selectProps)) : /*#__PURE__*/React.createElement(Button, _extends({
3552
+ size: "small",
3553
+ style: "link",
3554
+ label: "New Tag",
3555
+ icon: Plus,
3556
+ onClick: function onClick() {
3557
+ return setAddTag(true);
3558
+ }
3559
+ }, buttonProps)));
3560
+ };
3561
+
3486
3562
  var DEFAULT_PAGE_INDEX = 1;
3487
3563
  var DEFAULT_PAGE_SIZE = 10;
3488
3564
  var COMMON_COLUMNS = [{
@@ -3649,40 +3725,40 @@ function parseQueryArgs(arg1, arg2, arg3) {
3649
3725
  }
3650
3726
 
3651
3727
  if (typeof arg2 === 'function') {
3652
- return _extends({}, arg3, {
3728
+ return _extends$1({}, arg3, {
3653
3729
  queryKey: arg1,
3654
3730
  queryFn: arg2
3655
3731
  });
3656
3732
  }
3657
3733
 
3658
- return _extends({}, arg2, {
3734
+ return _extends$1({}, arg2, {
3659
3735
  queryKey: arg1
3660
3736
  });
3661
3737
  }
3662
3738
  function parseMutationArgs(arg1, arg2, arg3) {
3663
3739
  if (isQueryKey(arg1)) {
3664
3740
  if (typeof arg2 === 'function') {
3665
- return _extends({}, arg3, {
3741
+ return _extends$1({}, arg3, {
3666
3742
  mutationKey: arg1,
3667
3743
  mutationFn: arg2
3668
3744
  });
3669
3745
  }
3670
3746
 
3671
- return _extends({}, arg2, {
3747
+ return _extends$1({}, arg2, {
3672
3748
  mutationKey: arg1
3673
3749
  });
3674
3750
  }
3675
3751
 
3676
3752
  if (typeof arg1 === 'function') {
3677
- return _extends({}, arg2, {
3753
+ return _extends$1({}, arg2, {
3678
3754
  mutationFn: arg1
3679
3755
  });
3680
3756
  }
3681
3757
 
3682
- return _extends({}, arg1);
3758
+ return _extends$1({}, arg1);
3683
3759
  }
3684
3760
  function parseFilterArgs(arg1, arg2, arg3) {
3685
- return isQueryKey(arg1) ? [_extends({}, arg2, {
3761
+ return isQueryKey(arg1) ? [_extends$1({}, arg2, {
3686
3762
  queryKey: arg1
3687
3763
  }), arg3] : [arg1 || {}, arg2];
3688
3764
  }
@@ -4414,7 +4490,7 @@ var Query = /*#__PURE__*/function () {
4414
4490
  _proto.setOptions = function setOptions(options) {
4415
4491
  var _this$options$cacheTi;
4416
4492
 
4417
- this.options = _extends({}, this.defaultOptions, options);
4493
+ this.options = _extends$1({}, this.defaultOptions, options);
4418
4494
  this.meta = options == null ? void 0 : options.meta; // Default to 5 minutes if not cache time is set
4419
4495
 
4420
4496
  this.cacheTime = Math.max(this.cacheTime || 0, (_this$options$cacheTi = this.options.cacheTime) != null ? _this$options$cacheTi : 5 * 60 * 1000);
@@ -4814,22 +4890,22 @@ var Query = /*#__PURE__*/function () {
4814
4890
 
4815
4891
  switch (action.type) {
4816
4892
  case 'failed':
4817
- return _extends({}, state, {
4893
+ return _extends$1({}, state, {
4818
4894
  fetchFailureCount: state.fetchFailureCount + 1
4819
4895
  });
4820
4896
 
4821
4897
  case 'pause':
4822
- return _extends({}, state, {
4898
+ return _extends$1({}, state, {
4823
4899
  isPaused: true
4824
4900
  });
4825
4901
 
4826
4902
  case 'continue':
4827
- return _extends({}, state, {
4903
+ return _extends$1({}, state, {
4828
4904
  isPaused: false
4829
4905
  });
4830
4906
 
4831
4907
  case 'fetch':
4832
- return _extends({}, state, {
4908
+ return _extends$1({}, state, {
4833
4909
  fetchFailureCount: 0,
4834
4910
  fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
4835
4911
  isFetching: true,
@@ -4840,7 +4916,7 @@ var Query = /*#__PURE__*/function () {
4840
4916
  });
4841
4917
 
4842
4918
  case 'success':
4843
- return _extends({}, state, {
4919
+ return _extends$1({}, state, {
4844
4920
  data: action.data,
4845
4921
  dataUpdateCount: state.dataUpdateCount + 1,
4846
4922
  dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
@@ -4856,10 +4932,10 @@ var Query = /*#__PURE__*/function () {
4856
4932
  var error = action.error;
4857
4933
 
4858
4934
  if (isCancelledError(error) && error.revert && this.revertState) {
4859
- return _extends({}, this.revertState);
4935
+ return _extends$1({}, this.revertState);
4860
4936
  }
4861
4937
 
4862
- return _extends({}, state, {
4938
+ return _extends$1({}, state, {
4863
4939
  error: error,
4864
4940
  errorUpdateCount: state.errorUpdateCount + 1,
4865
4941
  errorUpdatedAt: Date.now(),
@@ -4870,12 +4946,12 @@ var Query = /*#__PURE__*/function () {
4870
4946
  });
4871
4947
 
4872
4948
  case 'invalidate':
4873
- return _extends({}, state, {
4949
+ return _extends$1({}, state, {
4874
4950
  isInvalidated: true
4875
4951
  });
4876
4952
 
4877
4953
  case 'setState':
4878
- return _extends({}, state, action.state);
4954
+ return _extends$1({}, state, action.state);
4879
4955
 
4880
4956
  default:
4881
4957
  return state;
@@ -5031,7 +5107,7 @@ var QueryCache = /*#__PURE__*/function (_Subscribable) {
5031
5107
  // CLASS
5032
5108
  var Mutation = /*#__PURE__*/function () {
5033
5109
  function Mutation(config) {
5034
- this.options = _extends({}, config.defaultOptions, config.options);
5110
+ this.options = _extends$1({}, config.defaultOptions, config.options);
5035
5111
  this.mutationId = config.mutationId;
5036
5112
  this.mutationCache = config.mutationCache;
5037
5113
  this.observers = [];
@@ -5206,22 +5282,22 @@ function getDefaultState() {
5206
5282
  function reducer(state, action) {
5207
5283
  switch (action.type) {
5208
5284
  case 'failed':
5209
- return _extends({}, state, {
5285
+ return _extends$1({}, state, {
5210
5286
  failureCount: state.failureCount + 1
5211
5287
  });
5212
5288
 
5213
5289
  case 'pause':
5214
- return _extends({}, state, {
5290
+ return _extends$1({}, state, {
5215
5291
  isPaused: true
5216
5292
  });
5217
5293
 
5218
5294
  case 'continue':
5219
- return _extends({}, state, {
5295
+ return _extends$1({}, state, {
5220
5296
  isPaused: false
5221
5297
  });
5222
5298
 
5223
5299
  case 'loading':
5224
- return _extends({}, state, {
5300
+ return _extends$1({}, state, {
5225
5301
  context: action.context,
5226
5302
  data: undefined,
5227
5303
  error: null,
@@ -5231,7 +5307,7 @@ function reducer(state, action) {
5231
5307
  });
5232
5308
 
5233
5309
  case 'success':
5234
- return _extends({}, state, {
5310
+ return _extends$1({}, state, {
5235
5311
  data: action.data,
5236
5312
  error: null,
5237
5313
  status: 'success',
@@ -5239,7 +5315,7 @@ function reducer(state, action) {
5239
5315
  });
5240
5316
 
5241
5317
  case 'error':
5242
- return _extends({}, state, {
5318
+ return _extends$1({}, state, {
5243
5319
  data: undefined,
5244
5320
  error: action.error,
5245
5321
  failureCount: state.failureCount + 1,
@@ -5248,7 +5324,7 @@ function reducer(state, action) {
5248
5324
  });
5249
5325
 
5250
5326
  case 'setState':
5251
- return _extends({}, state, action.state);
5327
+ return _extends$1({}, state, action.state);
5252
5328
 
5253
5329
  default:
5254
5330
  return state;
@@ -5542,7 +5618,7 @@ var QueryClient = /*#__PURE__*/function () {
5542
5618
  };
5543
5619
 
5544
5620
  _proto.isMutating = function isMutating(filters) {
5545
- return this.mutationCache.findAll(_extends({}, filters, {
5621
+ return this.mutationCache.findAll(_extends$1({}, filters, {
5546
5622
  fetching: true
5547
5623
  })).length;
5548
5624
  };
@@ -5606,7 +5682,7 @@ var QueryClient = /*#__PURE__*/function () {
5606
5682
 
5607
5683
  var queryCache = this.queryCache;
5608
5684
 
5609
- var refetchFilters = _extends({}, filters, {
5685
+ var refetchFilters = _extends$1({}, filters, {
5610
5686
  active: true
5611
5687
  });
5612
5688
 
@@ -5648,7 +5724,7 @@ var QueryClient = /*#__PURE__*/function () {
5648
5724
  filters = _parseFilterArgs5[0],
5649
5725
  options = _parseFilterArgs5[1];
5650
5726
 
5651
- var refetchFilters = _extends({}, filters, {
5727
+ var refetchFilters = _extends$1({}, filters, {
5652
5728
  // if filters.refetchActive is not provided and filters.active is explicitly false,
5653
5729
  // e.g. invalidateQueries({ active: false }), we don't want to refetch active queries
5654
5730
  active: (_ref3 = (_filters$refetchActiv = filters.refetchActive) != null ? _filters$refetchActiv : filters.active) != null ? _ref3 : true,
@@ -5673,7 +5749,7 @@ var QueryClient = /*#__PURE__*/function () {
5673
5749
 
5674
5750
  var promises = notifyManager.batch(function () {
5675
5751
  return _this6.queryCache.findAll(filters).map(function (query) {
5676
- return query.fetch(undefined, _extends({}, options, {
5752
+ return query.fetch(undefined, _extends$1({}, options, {
5677
5753
  meta: {
5678
5754
  refetchPage: filters == null ? void 0 : filters.refetchPage
5679
5755
  }
@@ -5801,7 +5877,7 @@ var QueryClient = /*#__PURE__*/function () {
5801
5877
  return options;
5802
5878
  }
5803
5879
 
5804
- var defaultedOptions = _extends({}, this.defaultOptions.queries, this.getQueryDefaults(options == null ? void 0 : options.queryKey), options, {
5880
+ var defaultedOptions = _extends$1({}, this.defaultOptions.queries, this.getQueryDefaults(options == null ? void 0 : options.queryKey), options, {
5805
5881
  _defaulted: true
5806
5882
  });
5807
5883
 
@@ -5821,7 +5897,7 @@ var QueryClient = /*#__PURE__*/function () {
5821
5897
  return options;
5822
5898
  }
5823
5899
 
5824
- return _extends({}, this.defaultOptions.mutations, this.getMutationDefaults(options == null ? void 0 : options.mutationKey), options, {
5900
+ return _extends$1({}, this.defaultOptions.mutations, this.getMutationDefaults(options == null ? void 0 : options.mutationKey), options, {
5825
5901
  _defaulted: true
5826
5902
  });
5827
5903
  };
@@ -5993,7 +6069,7 @@ var QueryObserver = /*#__PURE__*/function (_Subscribable) {
5993
6069
  };
5994
6070
 
5995
6071
  _proto.refetch = function refetch(options) {
5996
- return this.fetch(_extends({}, options, {
6072
+ return this.fetch(_extends$1({}, options, {
5997
6073
  meta: {
5998
6074
  refetchPage: options == null ? void 0 : options.refetchPage
5999
6075
  }
@@ -6277,7 +6353,7 @@ var QueryObserver = /*#__PURE__*/function (_Subscribable) {
6277
6353
  defaultNotifyOptions.listeners = true;
6278
6354
  }
6279
6355
 
6280
- this.notify(_extends({}, defaultNotifyOptions, notifyOptions));
6356
+ this.notify(_extends$1({}, defaultNotifyOptions, notifyOptions));
6281
6357
  };
6282
6358
 
6283
6359
  _proto.updateQuery = function updateQuery() {
@@ -6445,7 +6521,7 @@ var MutationObserver = /*#__PURE__*/function (_Subscribable) {
6445
6521
  this.currentMutation.removeObserver(this);
6446
6522
  }
6447
6523
 
6448
- this.currentMutation = this.client.getMutationCache().build(this.client, _extends({}, this.options, {
6524
+ this.currentMutation = this.client.getMutationCache().build(this.client, _extends$1({}, this.options, {
6449
6525
  variables: typeof variables !== 'undefined' ? variables : this.options.variables
6450
6526
  }));
6451
6527
  this.currentMutation.addObserver(this);
@@ -6455,7 +6531,7 @@ var MutationObserver = /*#__PURE__*/function (_Subscribable) {
6455
6531
  _proto.updateResult = function updateResult() {
6456
6532
  var state = this.currentMutation ? this.currentMutation.state : getDefaultState();
6457
6533
 
6458
- var result = _extends({}, state, {
6534
+ var result = _extends$1({}, state, {
6459
6535
  isLoading: state.status === 'loading',
6460
6536
  isSuccess: state.status === 'success',
6461
6537
  isError: state.status === 'error',
@@ -6622,7 +6698,7 @@ function useMutation(arg1, arg2, arg3) {
6622
6698
  throw currentResult.error;
6623
6699
  }
6624
6700
 
6625
- return _extends({}, currentResult, {
6701
+ return _extends$1({}, currentResult, {
6626
6702
  mutate: mutate,
6627
6703
  mutateAsync: currentResult.mutate
6628
6704
  });
@@ -7743,5 +7819,5 @@ var App = function App(_ref) {
7743
7819
  });
7744
7820
  };
7745
7821
 
7746
- export { App as NeetoTags, refetchTags };
7822
+ export { App as NeetoTags, Tags$2 as TagsComponent, refetchTags };
7747
7823
  //# sourceMappingURL=index.js.map