@bigbinary/neeto-folders-frontend 2.0.9 → 2.0.11

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-69nKxJCT.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-Bjx-yzjp.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';
@@ -33,7 +34,7 @@ import Down from '@bigbinary/neeto-icons/Down';
33
34
  import Label from '@bigbinary/neetoui/Label';
34
35
  import useHotkeys from '@bigbinary/neeto-hotkeys';
35
36
  import Button from '@bigbinary/neetoui/Button';
36
- import { noop, isNotPresent } from '@bigbinary/neeto-cist';
37
+ import { hyphenate, noop, isNotPresent } from '@bigbinary/neeto-cist';
37
38
  import Radio from '@bigbinary/neetoui/Radio';
38
39
  import { useDraggable, useDroppable, DndContext, DragOverlay, useSensors, useSensor, PointerSensor } from '@dnd-kit/core';
39
40
  import Reorder from '@bigbinary/neeto-icons/Reorder';
@@ -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",
@@ -497,6 +526,7 @@ var Node = function Node(_ref, ref) {
497
526
  onClick: onClick,
498
527
  ref: ref
499
528
  })), {}, {
529
+ "data-cy": "".concat(hyphenate(folder.name), "-folder-node"),
500
530
  className: classNames("relative my-1 flex cursor-pointer items-center px-2 py-1", className),
501
531
  children: [icon, /*#__PURE__*/jsxs("div", {
502
532
  className: "ml-2",
@@ -569,6 +599,7 @@ var _SelectableNode = function SelectableNode(_ref) {
569
599
  readOnly: true,
570
600
  checked: selection === folder.id,
571
601
  className: "neeto-ui-radio__container",
602
+ "data-cy": "".concat(hyphenate(folder.name), "-folder-option"),
572
603
  name: "move-folder-option"
573
604
  }),
574
605
  onClick: isDisabled ? noop : function () {
@@ -601,7 +632,8 @@ var PaneBody = function PaneBody(_ref) {
601
632
  setFolderState = _useFolderStore.setFolderState;
602
633
  var _useFetchFolders = useFetchFolders(config),
603
634
  _useFetchFolders$data = _useFetchFolders.data,
604
- folders = _useFetchFolders$data === void 0 ? [] : _useFetchFolders$data;
635
+ folders = _useFetchFolders$data === void 0 ? [] : _useFetchFolders$data,
636
+ isFetching = _useFetchFolders.isFetching;
605
637
  var _useTranslation = useTranslation(config),
606
638
  t = _useTranslation.t;
607
639
  var _useFolderStore2 = useFolderStore(function (store) {
@@ -640,6 +672,12 @@ var PaneBody = function PaneBody(_ref) {
640
672
  mode: "global",
641
673
  enabled: !!type
642
674
  });
675
+ if (isFetching) {
676
+ return /*#__PURE__*/jsx(Pane.Body, {
677
+ className: "flex items-center justify-center",
678
+ children: /*#__PURE__*/jsx(Spinner, {})
679
+ });
680
+ }
643
681
  return /*#__PURE__*/jsxs(Fragment, {
644
682
  children: [/*#__PURE__*/jsxs(Pane.Header, {
645
683
  className: "flex items-center justify-between",
@@ -648,6 +686,7 @@ var PaneBody = function PaneBody(_ref) {
648
686
  children: t("moveToFolder.title")
649
687
  }), /*#__PURE__*/jsx(Button, {
650
688
  className: "mr-2",
689
+ "data-cy": "add-new-folder-button",
651
690
  label: t("folders.add"),
652
691
  style: "link",
653
692
  onClick: onAddFolder
@@ -672,23 +711,29 @@ var PaneBody = function PaneBody(_ref) {
672
711
  className: "space-x-2",
673
712
  children: [/*#__PURE__*/jsxs("div", {
674
713
  className: "flex flex-1 space-x-2",
675
- children: [/*#__PURE__*/jsx(Button, _objectSpread$8({
714
+ children: [/*#__PURE__*/jsx(Button, _objectSpread$8(_objectSpread$8({
676
715
  disabled: selection === undefined,
677
716
  label: t("common.save"),
678
717
  style: "primary",
679
718
  onClick: function onClick() {
680
719
  return onSubmit(selection);
681
720
  }
682
- }, submitButtonProps)), /*#__PURE__*/jsx(Button, _objectSpread$8({
721
+ }, submitButtonProps), {}, {
722
+ "data-cy": "save-changes-button"
723
+ })), /*#__PURE__*/jsx(Button, _objectSpread$8(_objectSpread$8({
683
724
  label: t("common.cancel"),
684
725
  style: "text",
685
726
  onClick: onClose
686
- }, cancelButtonProps))]
687
- }), onRemove && /*#__PURE__*/jsx(Button, _objectSpread$8({
727
+ }, cancelButtonProps), {}, {
728
+ "data-cy": "cancel-button"
729
+ }))]
730
+ }), onRemove && /*#__PURE__*/jsx(Button, _objectSpread$8(_objectSpread$8({
688
731
  label: t("moveToFolder.remove"),
689
732
  style: "tertiary",
690
733
  onClick: onRemove
691
- }, removeButtonProps))]
734
+ }, removeButtonProps), {}, {
735
+ "data-cy": "remove-from-folder-button"
736
+ }))]
692
737
  })]
693
738
  });
694
739
  };
@@ -811,7 +856,8 @@ var RearrangeFoldersPane = function RearrangeFoldersPane(_ref) {
811
856
  var _useTranslation = useTranslation(config),
812
857
  t = _useTranslation.t;
813
858
  var _useFetchFolders = useFetchFolders(config),
814
- folders = _useFetchFolders.data;
859
+ folders = _useFetchFolders.data,
860
+ isFetching = _useFetchFolders.isFetching;
815
861
  var _useReorderFolders = useReorderFolders(config),
816
862
  reorderFolders = _useReorderFolders.mutate;
817
863
  var _useFolderStore = useFolderStore(function (store) {
@@ -880,6 +926,12 @@ var RearrangeFoldersPane = function RearrangeFoldersPane(_ref) {
880
926
  className: "neeto-ui-text-gray-500 relative -left-[0.3125rem] flex-shrink-0"
881
927
  })
882
928
  };
929
+ if (isFetching) {
930
+ return /*#__PURE__*/jsx(Pane.Body, {
931
+ className: "flex items-center justify-center",
932
+ children: /*#__PURE__*/jsx(Spinner, {})
933
+ });
934
+ }
883
935
  return /*#__PURE__*/jsxs(Fragment, {
884
936
  children: [/*#__PURE__*/jsx(Pane.Header, {
885
937
  children: /*#__PURE__*/jsx(Typography, {
@@ -1126,7 +1178,8 @@ var ReorderFoldersPane = function ReorderFoldersPane(_ref) {
1126
1178
  var _useTranslation = useTranslation(config),
1127
1179
  t = _useTranslation.t;
1128
1180
  var _useFetchFolders = useFetchFolders(config),
1129
- folders = _useFetchFolders.data;
1181
+ folders = _useFetchFolders.data,
1182
+ isFetching = _useFetchFolders.isFetching;
1130
1183
  var _useReorderFolders = useReorderFolders(config),
1131
1184
  reorderFolders = _useReorderFolders.mutate;
1132
1185
  var sensors = useSensors(useSensor(PointerSensor, sensorConfig));
@@ -1208,6 +1261,12 @@ var ReorderFoldersPane = function ReorderFoldersPane(_ref) {
1208
1261
  className: "neeto-ui-text-gray-500 relative -left-[0.3125rem] flex-shrink-0"
1209
1262
  })
1210
1263
  };
1264
+ if (isFetching) {
1265
+ return /*#__PURE__*/jsx(Pane.Body, {
1266
+ className: "flex items-center justify-center",
1267
+ children: /*#__PURE__*/jsx(Spinner, {})
1268
+ });
1269
+ }
1211
1270
  return /*#__PURE__*/jsxs(Fragment, {
1212
1271
  children: [/*#__PURE__*/jsx(Pane.Header, {
1213
1272
  children: /*#__PURE__*/jsx(Typography, {
@@ -1355,6 +1414,7 @@ var FolderTile = function FolderTile(_ref) {
1355
1414
  metaInfo.push("".concat(folder.itemCount || 0, " ").concat(itemLabel).toLowerCase());
1356
1415
  return /*#__PURE__*/jsxs(Link, {
1357
1416
  className: "neeto-ui-bg-gray-50 neeto-ui-border-gray-200 neeto-ui-rounded-md hover:neeto-ui-border-primary-500 relative flex max-w-full items-start gap-2 border-2 p-3 transition-colors ease-in",
1417
+ "data-cy": "".concat(hyphenate(folder.name), "-folder-tile"),
1358
1418
  to: link,
1359
1419
  children: [/*#__PURE__*/jsx(Checkbox, {
1360
1420
  checked: isSelected,
@@ -1370,6 +1430,7 @@ var FolderTile = function FolderTile(_ref) {
1370
1430
  className: "flex min-w-0 flex-grow flex-col gap-2",
1371
1431
  children: [/*#__PURE__*/jsx(Typography, {
1372
1432
  className: "-mt-0.5 line-clamp-2 break-words pr-8",
1433
+ "data-cy": "folder-name",
1373
1434
  lineHeight: "snug",
1374
1435
  style: "body1",
1375
1436
  title: folder.name,
@@ -1420,6 +1481,7 @@ var FoldersList = function FoldersList(_ref) {
1420
1481
  children: t("folders.title")
1421
1482
  }), /*#__PURE__*/jsx("div", {
1422
1483
  className: "neeto-folders-grid-view-wrapper mb-10 grid w-full gap-4",
1484
+ "data-cy": "folders-list",
1423
1485
  children: subFolders.map(function (folder) {
1424
1486
  return /*#__PURE__*/createElement(FolderTile, {
1425
1487
  actions: actions,
@@ -1470,6 +1532,7 @@ var FolderNode = function FolderNode(_ref) {
1470
1532
  to: link,
1471
1533
  children: /*#__PURE__*/jsxs("div", {
1472
1534
  className: "flex items-center",
1535
+ "data-cy": "".concat(hyphenate(name), "-folder-sublink"),
1473
1536
  children: [/*#__PURE__*/jsx(Typography, {
1474
1537
  className: "line-clamp-1 block truncate",
1475
1538
  component: "span",