@bigbinary/neeto-folders-frontend 2.0.5 → 2.0.7

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,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var useFolderActions = require('../useFolderActions-D8xGNhk0.js');
3
+ var useFolderActions = require('../useFolderActions-ibifd0ZD.js');
4
4
  require('@babel/runtime/helpers/defineProperty');
5
5
  require('i18next');
6
6
  require('@bigbinary/neeto-cist');
7
- require('../internal-CS6_tPWL.js');
7
+ require('../internal-CXN78HoA.js');
8
8
  require('ramda');
9
9
  require('react-router-dom');
10
10
  require('zustand/shallow');
package/dist/cjs/utils.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  require('ramda');
4
- var utils = require('../index-BFO1zYNo.js');
4
+ var utils = require('../index-hg5oms4a.js');
5
5
  require('@babel/runtime/helpers/defineProperty');
6
6
  require('@bigbinary/neeto-cist');
7
- require('../internal-CS6_tPWL.js');
7
+ require('../internal-CXN78HoA.js');
8
8
  require('react-router-dom');
9
9
 
10
10
 
@@ -7,10 +7,10 @@ import { buildUrl } 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-BLpmmlOf.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-Cckopfet.js';
11
11
  import { QUERY_KEYS } from './constants.js';
12
- import { p as pathToFolder, t as treeToMap, m as measureDepth, a as mapToTree, b as mapToSortedTree } from './index-Cq1DyvVr.js';
13
- import { a as isActiveFolder, g as getActiveFolderId, i as isArray } from './internal-G6z0jIQe.js';
12
+ import { p as pathToFolder, t as treeToMap, m as measureDepth, a as mapToTree, b as mapToSortedTree } from './index-CO0LgS5v.js';
13
+ import { a as isActiveFolder, m as mapObj, g as getActiveFolderId, i as isArray } from './internal-B2c8gwOa.js';
14
14
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
15
15
  import Pane from '@bigbinary/neetoui/Pane';
16
16
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
@@ -31,7 +31,6 @@ import classNames from 'classnames';
31
31
  import { useField } from 'formik';
32
32
  import Down from '@bigbinary/neeto-icons/Down';
33
33
  import Label from '@bigbinary/neetoui/Label';
34
- import { values, isEmpty, assoc } from 'ramda';
35
34
  import useHotkeys from '@bigbinary/neeto-hotkeys';
36
35
  import Button from '@bigbinary/neetoui/Button';
37
36
  import { noop, isNotPresent } from '@bigbinary/neeto-cist';
@@ -39,6 +38,7 @@ import Radio from '@bigbinary/neetoui/Radio';
39
38
  import { useDraggable, useDroppable, DndContext, DragOverlay, useSensors, useSensor, PointerSensor } from '@dnd-kit/core';
40
39
  import Reorder from '@bigbinary/neeto-icons/Reorder';
41
40
  import Toastr from '@bigbinary/neetoui/Toastr';
41
+ import { isEmpty, assoc } from 'ramda';
42
42
  import { createPortal } from 'react-dom';
43
43
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
44
44
  import Checkbox from '@bigbinary/neetoui/Checkbox';
@@ -102,6 +102,7 @@ var FoldersAlerts = function FoldersAlerts(_ref) {
102
102
  };
103
103
  var onConfirmDelete = function onConfirmDelete() {
104
104
  var onSuccess = function onSuccess() {
105
+ var _config$onUpdateSucce;
105
106
  var isActive = isActiveFolder(config, item.sid);
106
107
  // Invalidates items and folder details. Refetch only if not active folder.
107
108
  var invalidationKeys = [].concat(_toConsumableArray(config.invalidationKeys), [[QUERY_KEYS.FOLDERS, config.type, QUERY_KEYS.DETAILS]]);
@@ -119,6 +120,7 @@ var FoldersAlerts = function FoldersAlerts(_ref) {
119
120
  })) : "/";
120
121
  history.replace(redirectUrl);
121
122
  }
123
+ (_config$onUpdateSucce = config.onUpdateSuccess) === null || _config$onUpdateSucce === void 0 || _config$onUpdateSucce.call(config);
122
124
  };
123
125
  destroyFolder(item.id, {
124
126
  onSuccess: onSuccess,
@@ -264,7 +266,7 @@ var TreeSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
264
266
  return setTouched(true);
265
267
  },
266
268
  onChange: function onChange(value) {
267
- return setValue(value);
269
+ return setValue(value !== null && value !== void 0 ? value : null);
268
270
  }
269
271
  }, _objectSpread$b({
270
272
  disabled: disabled,
@@ -291,8 +293,8 @@ var TreeSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
291
293
  });
292
294
  TreeSelect.displayName = "TreeSelect";
293
295
 
294
- var createFolderOptions = function createFolderOptions(foldersMap, config) {
295
- return values(foldersMap).map(function (folder) {
296
+ var createFolderOptions = function createFolderOptions(foldersMap, activeFolder, config) {
297
+ return mapObj(foldersMap, function (folder) {
296
298
  var _folder$meta$parent;
297
299
  return {
298
300
  id: folder.id,
@@ -301,6 +303,8 @@ var createFolderOptions = function createFolderOptions(foldersMap, config) {
301
303
  pId: (_folder$meta$parent = folder.meta.parent) === null || _folder$meta$parent === void 0 ? void 0 : _folder$meta$parent.id,
302
304
  disabled: folder.meta.depth >= config.maxDepth
303
305
  };
306
+ }, function (folder) {
307
+ return folder.id !== (activeFolder === null || activeFolder === void 0 ? void 0 : activeFolder.id);
304
308
  });
305
309
  };
306
310
  var createInitialValues = function createInitialValues(defaults, extraAttrs) {
@@ -352,19 +356,11 @@ var AddEditPane = function AddEditPane(_ref) {
352
356
  var foldersMap = useMemo(function () {
353
357
  return treeToMap(folders, "sid");
354
358
  }, [folders]);
355
- var folderOptions = useMemo(function () {
356
- return createFolderOptions(foldersMap, config);
357
- }, [foldersMap]);
358
359
  var activeFolderSid = getActiveFolderId(config);
359
360
  var activeFolder = foldersMap[activeFolderSid];
360
361
  var isValidParent = (activeFolder === null || activeFolder === void 0 ? void 0 : activeFolder.meta.depth) < config.maxDepth;
361
362
  var parentId = isValidParent ? activeFolder.id : null;
362
363
  var extraAttributes = config.extraAttributes;
363
- var initialValues = useMemo(function () {
364
- return isEditing ? item : createInitialValues({
365
- parentId: parentId
366
- }, extraAttributes);
367
- }, [isEditing, item, parentId, extraAttributes]);
368
364
  var onSubmitForm = /*#__PURE__*/function () {
369
365
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(values) {
370
366
  var payload;
@@ -399,6 +395,14 @@ var AddEditPane = function AddEditPane(_ref) {
399
395
  return _ref2.apply(this, arguments);
400
396
  };
401
397
  }();
398
+ var folderOptions = useMemo(function () {
399
+ return createFolderOptions(foldersMap, item, config);
400
+ }, [foldersMap, item]);
401
+ var initialValues = useMemo(function () {
402
+ return isEditing ? item : createInitialValues({
403
+ parentId: parentId
404
+ }, extraAttributes);
405
+ }, [isEditing, item, parentId, extraAttributes]);
402
406
  return /*#__PURE__*/jsxs(Fragment, {
403
407
  children: [/*#__PURE__*/jsx(Pane.Header, {
404
408
  children: /*#__PURE__*/jsx(Typography, {
@@ -413,40 +417,46 @@ var AddEditPane = function AddEditPane(_ref) {
413
417
  validationSchema: FORM_VALIDATION_SCHEMA,
414
418
  onSubmit: onSubmitForm
415
419
  },
416
- children: /*#__PURE__*/jsxs(Fragment, {
417
- children: [/*#__PURE__*/jsx(Pane.Body, {
418
- className: "pb-6",
419
- children: /*#__PURE__*/jsxs("div", {
420
- className: "w-full space-y-5",
421
- children: [/*#__PURE__*/jsx(Input, {
422
- required: true,
423
- label: t("folders.name"),
424
- name: "name",
425
- ref: setFocusField
426
- }), /*#__PURE__*/jsx(ExtraAttributes, {
427
- attributes: extraAttributes
428
- }), /*#__PURE__*/jsxs("div", {
429
- children: [/*#__PURE__*/jsx(TreeSelect, {
430
- allowClear: true,
431
- showSearch: true,
432
- label: t("createFolder.parentTitle"),
433
- name: "parentId",
434
- treeData: folderOptions
435
- }), /*#__PURE__*/jsx(Typography, {
436
- className: "mt-1",
437
- style: "body3",
438
- children: t("createFolder.parentInfo")
420
+ children: function children(_ref3) {
421
+ var dirty = _ref3.dirty;
422
+ return /*#__PURE__*/jsxs(Fragment, {
423
+ children: [/*#__PURE__*/jsx(Pane.Body, {
424
+ className: "pb-6",
425
+ children: /*#__PURE__*/jsxs("div", {
426
+ className: "w-full space-y-5",
427
+ children: [/*#__PURE__*/jsx(Input, {
428
+ required: true,
429
+ label: t("folders.name"),
430
+ name: "name",
431
+ ref: setFocusField
432
+ }), /*#__PURE__*/jsx(ExtraAttributes, {
433
+ attributes: extraAttributes
434
+ }), /*#__PURE__*/jsxs("div", {
435
+ children: [/*#__PURE__*/jsx(TreeSelect, {
436
+ allowClear: true,
437
+ showSearch: true,
438
+ label: t("createFolder.parentTitle"),
439
+ name: "parentId",
440
+ treeData: folderOptions
441
+ }), /*#__PURE__*/jsx(Typography, {
442
+ className: "mt-1",
443
+ style: "body3",
444
+ children: t("createFolder.parentInfo")
445
+ })]
439
446
  })]
440
- })]
441
- })
442
- }), /*#__PURE__*/jsx(Pane.Footer, {
443
- children: /*#__PURE__*/jsx(ActionBlock, {
444
- cancelButtonProps: {
445
- onClick: onClose
446
- }
447
- })
448
- })]
449
- })
447
+ })
448
+ }), /*#__PURE__*/jsx(Pane.Footer, {
449
+ children: /*#__PURE__*/jsx(ActionBlock, {
450
+ cancelButtonProps: {
451
+ onClick: onClose
452
+ },
453
+ submitButtonProps: {
454
+ disabled: !dirty
455
+ }
456
+ })
457
+ })]
458
+ });
459
+ }
450
460
  })]
451
461
  });
452
462
  };
@@ -704,7 +714,11 @@ var MoveFolderPane = function MoveFolderPane(_ref) {
704
714
  id: item.id,
705
715
  payload: payload
706
716
  }, {
707
- onSuccess: onClose
717
+ onSuccess: function onSuccess() {
718
+ var _config$onUpdateSucce;
719
+ onClose();
720
+ (_config$onUpdateSucce = config.onUpdateSuccess) === null || _config$onUpdateSucce === void 0 || _config$onUpdateSucce.call(config);
721
+ }
708
722
  });
709
723
  };
710
724
  return /*#__PURE__*/jsx(PaneBody, {
@@ -850,7 +864,11 @@ var RearrangeFoldersPane = function RearrangeFoldersPane(_ref) {
850
864
  changes: changes
851
865
  };
852
866
  reorderFolders(payload, {
853
- onSuccess: onClose
867
+ onSuccess: function onSuccess() {
868
+ var _config$onUpdateSucce;
869
+ onClose();
870
+ (_config$onUpdateSucce = config.onUpdateSuccess) === null || _config$onUpdateSucce === void 0 || _config$onUpdateSucce.call(config);
871
+ }
854
872
  });
855
873
  };
856
874
  useHotkeys(["command+enter", "enter"], onSubmit, {
@@ -1174,7 +1192,11 @@ var ReorderFoldersPane = function ReorderFoldersPane(_ref) {
1174
1192
  changes: changes
1175
1193
  };
1176
1194
  reorderFolders(payload, {
1177
- onSuccess: onClose
1195
+ onSuccess: function onSuccess() {
1196
+ var _config$onUpdateSucce;
1197
+ onClose();
1198
+ (_config$onUpdateSucce = config.onUpdateSuccess) === null || _config$onUpdateSucce === void 0 || _config$onUpdateSucce.call(config);
1199
+ }
1178
1200
  });
1179
1201
  };
1180
1202
  useHotkeys(["command+enter", "enter"], onSubmit, {