@bigbinary/neeto-folders-frontend 2.0.8 → 2.0.10

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/cjs/hooks.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var useFolderActions = require('../useFolderActions-ibifd0ZD.js');
3
+ var useFolderActions = require('../useFolderActions-Ok2WR6Ht.js');
4
4
  require('@babel/runtime/helpers/defineProperty');
5
5
  require('i18next');
6
6
  require('@bigbinary/neeto-cist');
@@ -3,11 +3,11 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
3
3
  import { shallow } from 'zustand/shallow';
4
4
  import { useQueryClient } from '@tanstack/react-query';
5
5
  import { useQueryParams, useStateWithDependency } from '@bigbinary/neeto-commons-frontend/react-utils';
6
- import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
6
+ import { buildUrl, showThumbsUpToastr } from '@bigbinary/neeto-commons-frontend/utils';
7
7
  import Alert from '@bigbinary/neetoui/Alert';
8
8
  import { useTranslation as useTranslation$1, Trans } from 'react-i18next';
9
9
  import { useHistory, Link, NavLink } from 'react-router-dom';
10
- import { c as useFolderStore, d as useDestroyFolder, a as useFolders, e as useFetchFolders, f as useCreateFolder, g as useUpdateFolder, h as useReorderFolders, D as DEFAULT_CONFIG, u as useFolder, b as useFolderActions } from './useFolderActions-Cckopfet.js';
10
+ import { c as useFolderStore, d as useDestroyFolder, a as useFolders, e as useFetchFolders, f as useCreateFolder, g as useUpdateFolder, h as useReorderFolders, D as DEFAULT_CONFIG, u as useFolder, b as useFolderActions } from './useFolderActions-DQUMayG_.js';
11
11
  import { QUERY_KEYS } from './constants.js';
12
12
  import { p as pathToFolder, t as treeToMap, m as measureDepth, a as mapToTree, b as mapToSortedTree } from './index-CO0LgS5v.js';
13
13
  import { a as isActiveFolder, m as mapObj, g as getActiveFolderId, i as isArray } from './internal-B2c8gwOa.js';
@@ -17,6 +17,7 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
17
17
  import _regeneratorRuntime from '@babel/runtime/regenerator';
18
18
  import React, { createElement, forwardRef, useMemo, useState, useId, useEffect, startTransition } from 'react';
19
19
  import Typography from '@bigbinary/neetoui/Typography';
20
+ import Spinner from '@bigbinary/neetoui/Spinner';
20
21
  import Input from '@bigbinary/neetoui/formik/Input';
21
22
  import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
22
23
  import Form from '@bigbinary/neetoui/formik/Form';
@@ -347,7 +348,8 @@ var AddEditPane = function AddEditPane(_ref) {
347
348
  type = _useFolderStore.type,
348
349
  item = _useFolderStore.item;
349
350
  var _useFetchFolders = useFetchFolders(config),
350
- folders = _useFetchFolders.data;
351
+ folders = _useFetchFolders.data,
352
+ isFetching = _useFetchFolders.isFetching;
351
353
  var _useCreateFolder = useCreateFolder(config),
352
354
  createFolder = _useCreateFolder.mutate;
353
355
  var _useUpdateFolder = useUpdateFolder(config),
@@ -361,38 +363,59 @@ var AddEditPane = function AddEditPane(_ref) {
361
363
  var isValidParent = (activeFolder === null || activeFolder === void 0 ? void 0 : activeFolder.meta.depth) < config.maxDepth;
362
364
  var parentId = isValidParent ? activeFolder.id : null;
363
365
  var extraAttributes = config.extraAttributes;
366
+ var handleError = function handleError(setStatus, error) {
367
+ var response = error.response;
368
+ if (response && response.data && response.data.errors) {
369
+ setStatus(response.data.errors);
370
+ }
371
+ };
364
372
  var onSubmitForm = /*#__PURE__*/function () {
365
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
366
- var payload;
373
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, _ref2) {
374
+ var setStatus, payload, reactQueryOptions, config;
367
375
  return _regeneratorRuntime.wrap(function _callee$(_context) {
368
376
  while (1) switch (_context.prev = _context.next) {
369
377
  case 0:
378
+ setStatus = _ref2.setStatus;
370
379
  payload = createPayload(values, extraAttributes);
380
+ reactQueryOptions = {
381
+ onSuccess: function onSuccess() {
382
+ showThumbsUpToastr();
383
+ onClose();
384
+ },
385
+ onError: function onError(error) {
386
+ return handleError(setStatus, error);
387
+ }
388
+ };
389
+ config = {
390
+ showToastr: false
391
+ };
371
392
  if (!isEditing) {
372
- _context.next = 6;
393
+ _context.next = 9;
373
394
  break;
374
395
  }
375
- _context.next = 4;
396
+ _context.next = 7;
376
397
  return updateFolder({
377
398
  id: item.id,
378
- payload: payload
379
- });
380
- case 4:
381
- _context.next = 8;
399
+ payload: payload,
400
+ config: config
401
+ }, reactQueryOptions);
402
+ case 7:
403
+ _context.next = 11;
382
404
  break;
383
- case 6:
384
- _context.next = 8;
385
- return createFolder(payload);
386
- case 8:
387
- onClose();
388
405
  case 9:
406
+ _context.next = 11;
407
+ return createFolder({
408
+ payload: payload,
409
+ config: config
410
+ }, reactQueryOptions);
411
+ case 11:
389
412
  case "end":
390
413
  return _context.stop();
391
414
  }
392
415
  }, _callee);
393
416
  }));
394
- return function onSubmitForm(_x) {
395
- return _ref2.apply(this, arguments);
417
+ return function onSubmitForm(_x, _x2) {
418
+ return _ref3.apply(this, arguments);
396
419
  };
397
420
  }();
398
421
  var folderOptions = useMemo(function () {
@@ -403,6 +426,12 @@ var AddEditPane = function AddEditPane(_ref) {
403
426
  parentId: parentId
404
427
  }, extraAttributes);
405
428
  }, [isEditing, item, parentId, extraAttributes]);
429
+ if (isFetching) {
430
+ return /*#__PURE__*/jsx(Pane.Body, {
431
+ className: "flex items-center justify-center",
432
+ children: /*#__PURE__*/jsx(Spinner, {})
433
+ });
434
+ }
406
435
  return /*#__PURE__*/jsxs(Fragment, {
407
436
  children: [/*#__PURE__*/jsx(Pane.Header, {
408
437
  children: /*#__PURE__*/jsx(Typography, {
@@ -417,8 +446,8 @@ var AddEditPane = function AddEditPane(_ref) {
417
446
  validationSchema: FORM_VALIDATION_SCHEMA,
418
447
  onSubmit: onSubmitForm
419
448
  },
420
- children: function children(_ref3) {
421
- var dirty = _ref3.dirty;
449
+ children: function children(_ref4) {
450
+ var dirty = _ref4.dirty;
422
451
  return /*#__PURE__*/jsxs(Fragment, {
423
452
  children: [/*#__PURE__*/jsx(Pane.Body, {
424
453
  className: "pb-6",
@@ -601,7 +630,8 @@ var PaneBody = function PaneBody(_ref) {
601
630
  setFolderState = _useFolderStore.setFolderState;
602
631
  var _useFetchFolders = useFetchFolders(config),
603
632
  _useFetchFolders$data = _useFetchFolders.data,
604
- folders = _useFetchFolders$data === void 0 ? [] : _useFetchFolders$data;
633
+ folders = _useFetchFolders$data === void 0 ? [] : _useFetchFolders$data,
634
+ isFetching = _useFetchFolders.isFetching;
605
635
  var _useTranslation = useTranslation(config),
606
636
  t = _useTranslation.t;
607
637
  var _useFolderStore2 = useFolderStore(function (store) {
@@ -640,6 +670,12 @@ var PaneBody = function PaneBody(_ref) {
640
670
  mode: "global",
641
671
  enabled: !!type
642
672
  });
673
+ if (isFetching) {
674
+ return /*#__PURE__*/jsx(Pane.Body, {
675
+ className: "flex items-center justify-center",
676
+ children: /*#__PURE__*/jsx(Spinner, {})
677
+ });
678
+ }
643
679
  return /*#__PURE__*/jsxs(Fragment, {
644
680
  children: [/*#__PURE__*/jsxs(Pane.Header, {
645
681
  className: "flex items-center justify-between",
@@ -811,7 +847,8 @@ var RearrangeFoldersPane = function RearrangeFoldersPane(_ref) {
811
847
  var _useTranslation = useTranslation(config),
812
848
  t = _useTranslation.t;
813
849
  var _useFetchFolders = useFetchFolders(config),
814
- folders = _useFetchFolders.data;
850
+ folders = _useFetchFolders.data,
851
+ isFetching = _useFetchFolders.isFetching;
815
852
  var _useReorderFolders = useReorderFolders(config),
816
853
  reorderFolders = _useReorderFolders.mutate;
817
854
  var _useFolderStore = useFolderStore(function (store) {
@@ -880,6 +917,12 @@ var RearrangeFoldersPane = function RearrangeFoldersPane(_ref) {
880
917
  className: "neeto-ui-text-gray-500 relative -left-[0.3125rem] flex-shrink-0"
881
918
  })
882
919
  };
920
+ if (isFetching) {
921
+ return /*#__PURE__*/jsx(Pane.Body, {
922
+ className: "flex items-center justify-center",
923
+ children: /*#__PURE__*/jsx(Spinner, {})
924
+ });
925
+ }
883
926
  return /*#__PURE__*/jsxs(Fragment, {
884
927
  children: [/*#__PURE__*/jsx(Pane.Header, {
885
928
  children: /*#__PURE__*/jsx(Typography, {
@@ -1126,7 +1169,8 @@ var ReorderFoldersPane = function ReorderFoldersPane(_ref) {
1126
1169
  var _useTranslation = useTranslation(config),
1127
1170
  t = _useTranslation.t;
1128
1171
  var _useFetchFolders = useFetchFolders(config),
1129
- folders = _useFetchFolders.data;
1172
+ folders = _useFetchFolders.data,
1173
+ isFetching = _useFetchFolders.isFetching;
1130
1174
  var _useReorderFolders = useReorderFolders(config),
1131
1175
  reorderFolders = _useReorderFolders.mutate;
1132
1176
  var sensors = useSensors(useSensor(PointerSensor, sensorConfig));
@@ -1208,6 +1252,12 @@ var ReorderFoldersPane = function ReorderFoldersPane(_ref) {
1208
1252
  className: "neeto-ui-text-gray-500 relative -left-[0.3125rem] flex-shrink-0"
1209
1253
  })
1210
1254
  };
1255
+ if (isFetching) {
1256
+ return /*#__PURE__*/jsx(Pane.Body, {
1257
+ className: "flex items-center justify-center",
1258
+ children: /*#__PURE__*/jsx(Spinner, {})
1259
+ });
1260
+ }
1211
1261
  return /*#__PURE__*/jsxs(Fragment, {
1212
1262
  children: [/*#__PURE__*/jsx(Pane.Header, {
1213
1263
  children: /*#__PURE__*/jsx(Typography, {
@@ -1508,12 +1558,32 @@ var FoldersTree = function FoldersTree(_ref) {
1508
1558
  var _activeFolder$meta;
1509
1559
  if (!folders) return;
1510
1560
  // When active folder changes from external sources, update expanded keys to auto expand tree.
1511
- var expandedKeys = [];
1561
+ var updatedExpandedKeys = _toConsumableArray(expandedKeys);
1512
1562
  var map = treeToMap(folders, "sid");
1513
1563
  var activeFolder = map[activeFolderSid];
1514
1564
  var parentSid = activeFolder === null || activeFolder === void 0 || (_activeFolder$meta = activeFolder.meta) === null || _activeFolder$meta === void 0 || (_activeFolder$meta = _activeFolder$meta.parent) === null || _activeFolder$meta === void 0 ? void 0 : _activeFolder$meta.sid;
1515
- if (parentSid) expandedKeys.push(parentSid);
1516
- setExpandedKeys(expandedKeys);
1565
+ if (parentSid && !updatedExpandedKeys.includes(parentSid)) {
1566
+ updatedExpandedKeys.push(parentSid);
1567
+ }
1568
+ setExpandedKeys(updatedExpandedKeys);
1569
+ };
1570
+ var handleExpand = function handleExpand(keys, _ref2) {
1571
+ var expanded = _ref2.expanded,
1572
+ node = _ref2.node;
1573
+ if (expanded) {
1574
+ setExpandedKeys(keys);
1575
+ return;
1576
+ }
1577
+ var keysSet = new Set(keys);
1578
+ var _removeChildKeys = function removeChildKeys() {
1579
+ var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1580
+ children.forEach(function (child) {
1581
+ keysSet["delete"](child.sid);
1582
+ _removeChildKeys(child.children);
1583
+ });
1584
+ };
1585
+ _removeChildKeys(node.children);
1586
+ setExpandedKeys(_toConsumableArray(keysSet));
1517
1587
  };
1518
1588
  useEffect(function () {
1519
1589
  // Non urgent update.
@@ -1551,7 +1621,7 @@ var FoldersTree = function FoldersTree(_ref) {
1551
1621
  }))
1552
1622
  });
1553
1623
  },
1554
- onExpand: setExpandedKeys
1624
+ onExpand: handleExpand
1555
1625
  });
1556
1626
  };
1557
1627