ydb-ui-components 2.3.0 → 2.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.3.0...v2.4.0) (2022-07-28)
4
+
5
+
6
+ ### Features
7
+
8
+ * **NavigationTree:** virtualized render ([7388ff5](https://github.com/ydb-platform/ydb-ui-components/commit/7388ff5a5b05ffa30b86fb4ae2d8e52a7bd9dad8))
9
+ * **TreeView:** a prop to determine tree view nesting level ([2e5d42a](https://github.com/ydb-platform/ydb-ui-components/commit/2e5d42abf78e81fdd61747958822dc3b96eab42f))
10
+
3
11
  ## [2.3.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.2.0...v2.3.0) (2022-07-18)
4
12
 
5
13
 
@@ -1,3 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import './EmptyView.scss';
3
- export declare function EmptyView(): JSX.Element;
3
+ interface EmptyViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function EmptyView({ level }: EmptyViewProps): JSX.Element;
7
+ export {};
@@ -19,10 +19,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
 
20
20
  const b = (0, _bemCnLite.default)('ydb-navigation-tree-view-empty');
21
21
 
22
- function EmptyView() {
22
+ function EmptyView(_ref) {
23
+ let {
24
+ level
25
+ } = _ref;
23
26
  return /*#__PURE__*/_react.default.createElement(_TreeView.TreeView, {
24
27
  name: /*#__PURE__*/_react.default.createElement("span", {
25
28
  className: b()
26
- }, (0, _i18n.default)('label_empty'))
29
+ }, (0, _i18n.default)('label_empty')),
30
+ level: level
27
31
  });
28
32
  }
@@ -1,3 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import './ErrorView.scss';
3
- export declare function ErrorView(): JSX.Element;
3
+ interface ErrorViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function ErrorView({ level }: ErrorViewProps): JSX.Element;
7
+ export {};
@@ -19,10 +19,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
 
20
20
  const b = (0, _bemCnLite.default)('ydb-navigation-tree-view-error');
21
21
 
22
- function ErrorView() {
22
+ function ErrorView(_ref) {
23
+ let {
24
+ level
25
+ } = _ref;
23
26
  return /*#__PURE__*/_react.default.createElement(_TreeView.TreeView, {
24
27
  name: /*#__PURE__*/_react.default.createElement("span", {
25
28
  className: b()
26
- }, (0, _i18n.default)('label_error'))
29
+ }, (0, _i18n.default)('label_error')),
30
+ level: level
27
31
  });
28
32
  }
@@ -1,3 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import './LoaderView.scss';
3
- export declare function LoaderView(): JSX.Element;
3
+ interface LoaderViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function LoaderView({ level }: LoaderViewProps): JSX.Element;
7
+ export {};
@@ -19,12 +19,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
 
20
20
  const b = (0, _bemCnLite.default)('ydb-navigation-tree-view-loader');
21
21
 
22
- function LoaderView() {
22
+ function LoaderView(_ref) {
23
+ let {
24
+ level
25
+ } = _ref;
23
26
  return /*#__PURE__*/_react.default.createElement(_TreeView.TreeView, {
24
27
  name: /*#__PURE__*/_react.default.createElement("div", {
25
28
  className: b()
26
29
  }, /*#__PURE__*/_react.default.createElement(_uikit.Spin, {
27
30
  size: "xs"
28
- }))
31
+ })),
32
+ level: level
29
33
  });
30
34
  }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { NavigationTreeProps } from './types';
2
+ import type { NavigationTreeProps } from './types';
3
3
  export type { NavigationTreeProps };
4
- export declare function NavigationTree({ rootState: partialRootState, fetchPath, getActions, activePath, onActivePathUpdate, cache, }: NavigationTreeProps): JSX.Element;
4
+ export declare function NavigationTree({ rootState: partialRootState, fetchPath, getActions, activePath, onActivePathUpdate, cache, virtualize, }: NavigationTreeProps): JSX.Element;
@@ -7,14 +7,45 @@ exports.NavigationTree = NavigationTree;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _reactList = _interopRequireDefault(require("react-list"));
11
+
10
12
  var _state = require("./state");
11
13
 
14
+ var _utils = require("./utils");
15
+
12
16
  var _NavigationTreeNode = require("./NavigationTreeNode");
13
17
 
14
- var _NavigationTreeDirectory = require("./NavigationTreeDirectory");
18
+ var _LoaderView = require("./LoaderView/LoaderView");
19
+
20
+ var _ErrorView = require("./ErrorView/ErrorView");
21
+
22
+ var _EmptyView = require("./EmptyView/EmptyView");
15
23
 
16
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
25
 
26
+ const renderServiceNode = node => {
27
+ const key = `${node.path}|${node.status}`;
28
+
29
+ if (node.status === 'loading') {
30
+ return /*#__PURE__*/_react.default.createElement(_LoaderView.LoaderView, {
31
+ key: key,
32
+ level: node.level
33
+ });
34
+ }
35
+
36
+ if (node.status === 'error') {
37
+ return /*#__PURE__*/_react.default.createElement(_ErrorView.ErrorView, {
38
+ key: key,
39
+ level: node.level
40
+ });
41
+ }
42
+
43
+ return /*#__PURE__*/_react.default.createElement(_EmptyView.EmptyView, {
44
+ key: key,
45
+ level: node.level
46
+ });
47
+ };
48
+
18
49
  function NavigationTree(_ref) {
19
50
  let {
20
51
  rootState: partialRootState,
@@ -22,29 +53,42 @@ function NavigationTree(_ref) {
22
53
  getActions,
23
54
  activePath,
24
55
  onActivePathUpdate,
25
- cache = true
56
+ cache = true,
57
+ virtualize = false
26
58
  } = _ref;
27
59
 
28
60
  const [state, dispatch] = _react.default.useReducer(_state.reducer, {
29
61
  [partialRootState.path]: (0, _state.getNodeState)(partialRootState)
30
62
  });
31
63
 
32
- const rootState = state[partialRootState.path];
33
- return /*#__PURE__*/_react.default.createElement(_NavigationTreeNode.NavigationTreeNode, {
34
- path: rootState.path,
35
- state: state,
36
- dispatch: dispatch,
37
- active: rootState.path === activePath,
38
- onActivate: onActivePathUpdate,
39
- getActions: getActions
40
- }, /*#__PURE__*/_react.default.createElement(_NavigationTreeDirectory.NavigationTreeDirectory, {
41
- state: state,
42
- dispatch: dispatch,
43
- path: rootState.path,
44
- fetchPath: fetchPath,
45
- activePath: activePath,
46
- onItemActivate: onActivePathUpdate,
47
- getActions: getActions,
48
- cache: cache
49
- }));
64
+ const nodesList = _react.default.useMemo(() => (0, _state.selectTreeAsList)(state, partialRootState.path), [state]);
65
+
66
+ const renderNode = node => {
67
+ return /*#__PURE__*/_react.default.createElement(_NavigationTreeNode.NavigationTreeNode, {
68
+ key: node.path,
69
+ state: state,
70
+ path: node.path,
71
+ activePath: activePath,
72
+ fetchPath: fetchPath,
73
+ dispatch: dispatch,
74
+ onActivate: onActivePathUpdate,
75
+ getActions: getActions,
76
+ cache: cache,
77
+ level: node.level
78
+ });
79
+ };
80
+
81
+ const renderVirtualizedTree = () => /*#__PURE__*/_react.default.createElement(_reactList.default, {
82
+ type: "uniform",
83
+ length: nodesList.length,
84
+ useStaticSize: true,
85
+ itemRenderer: index => {
86
+ const node = nodesList[index];
87
+ return (0, _utils.isServiceNode)(node) ? renderServiceNode(node) : renderNode(node);
88
+ }
89
+ });
90
+
91
+ const renderSimpleTree = () => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, nodesList.map(node => (0, _utils.isServiceNode)(node) ? renderServiceNode(node) : renderNode(node)));
92
+
93
+ return virtualize ? renderVirtualizedTree() : renderSimpleTree();
50
94
  }
@@ -3,11 +3,14 @@ import { NavigationTreeState, NavigationTreeProps } from './types';
3
3
  import { NavigationTreeAction } from './state';
4
4
  export interface NavigationTreeNodeProps {
5
5
  path: string;
6
+ fetchPath: NavigationTreeProps['fetchPath'];
7
+ activePath?: string;
6
8
  state: NavigationTreeState;
9
+ level?: number;
7
10
  dispatch: React.Dispatch<NavigationTreeAction>;
8
11
  children?: React.ReactNode;
9
- active?: boolean;
10
12
  onActivate?: (path: string) => void;
11
13
  getActions?: NavigationTreeProps['getActions'];
14
+ cache?: boolean;
12
15
  }
13
- export declare function NavigationTreeNode({ path, state, dispatch, children, active, onActivate, getActions, }: NavigationTreeNodeProps): JSX.Element;
16
+ export declare function NavigationTreeNode({ path, fetchPath, activePath, state, level, dispatch, children, onActivate, getActions, cache, }: NavigationTreeNodeProps): JSX.Element;
@@ -50,15 +50,62 @@ function renderIcon(type, collapsed) {
50
50
  function NavigationTreeNode(_ref) {
51
51
  let {
52
52
  path,
53
+ fetchPath,
54
+ activePath,
53
55
  state,
56
+ level,
54
57
  dispatch,
55
58
  children,
56
- active,
57
59
  onActivate,
58
- getActions
60
+ getActions,
61
+ cache
59
62
  } = _ref;
60
63
  const nodeState = state[path];
61
64
 
65
+ _react.default.useEffect(() => {
66
+ if (nodeState.collapsed) {
67
+ if (!cache) {
68
+ dispatch({
69
+ type: _state.NavigationTreeActionType.ResetNode,
70
+ payload: {
71
+ path
72
+ }
73
+ });
74
+ }
75
+
76
+ return;
77
+ }
78
+
79
+ if (nodeState.loaded || nodeState.loading) {
80
+ return;
81
+ }
82
+
83
+ dispatch({
84
+ type: _state.NavigationTreeActionType.StartLoading,
85
+ payload: {
86
+ path
87
+ }
88
+ });
89
+ fetchPath(path).then(data => {
90
+ dispatch({
91
+ type: _state.NavigationTreeActionType.FinishLoading,
92
+ payload: {
93
+ path,
94
+ activePath,
95
+ data
96
+ }
97
+ });
98
+ }).catch(error => {
99
+ dispatch({
100
+ type: _state.NavigationTreeActionType.FinishLoading,
101
+ payload: {
102
+ path,
103
+ error
104
+ }
105
+ });
106
+ });
107
+ }, [nodeState.collapsed]);
108
+
62
109
  const handleClick = _react.default.useCallback(() => {
63
110
  if (onActivate) {
64
111
  onActivate(path);
@@ -82,10 +129,11 @@ function NavigationTreeNode(_ref) {
82
129
  name: nodeState.name,
83
130
  icon: renderIcon(nodeState.type, nodeState.collapsed),
84
131
  collapsed: nodeState.collapsed,
85
- active: active,
132
+ active: nodeState.path === activePath,
86
133
  actions: actions,
87
134
  hasArrow: nodeState.expandable,
88
135
  onClick: handleClick,
89
- onArrowClick: handleArrowClick
136
+ onArrowClick: handleArrowClick,
137
+ level: level
90
138
  }, children);
91
139
  }
@@ -1,8 +1,9 @@
1
- import { NavigationTreeNodeState, NavigationTreeNodePartialState, NavigationTreeState } from './types';
1
+ import type { NavigationTreeNodeState, NavigationTreeNodePartialState, NavigationTreeState, NavigationTreeServiceNode } from './types';
2
2
  export declare enum NavigationTreeActionType {
3
3
  ToggleCollapsed = "toggle-collapsed",
4
4
  StartLoading = "start-loading",
5
- FinishLoading = "finish-loading"
5
+ FinishLoading = "finish-loading",
6
+ ResetNode = "reset-node"
6
7
  }
7
8
  export interface NavigationTreeAction {
8
9
  type: NavigationTreeActionType;
@@ -17,3 +18,4 @@ export declare function getDefaultNodeState(): {
17
18
  };
18
19
  export declare function getNodeState(partialState: NavigationTreeNodePartialState): NavigationTreeNodeState;
19
20
  export declare function reducer(state: NavigationTreeState | undefined, action: NavigationTreeAction): NavigationTreeState;
21
+ export declare function selectTreeAsList(state: NavigationTreeState, rootPath: string): (NavigationTreeNodeState | NavigationTreeServiceNode)[];
@@ -7,6 +7,9 @@ exports.NavigationTreeActionType = void 0;
7
7
  exports.getDefaultNodeState = getDefaultNodeState;
8
8
  exports.getNodeState = getNodeState;
9
9
  exports.reducer = reducer;
10
+ exports.selectTreeAsList = selectTreeAsList;
11
+
12
+ var _utils = require("./utils");
10
13
 
11
14
  function ownKeys(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; }
12
15
 
@@ -21,6 +24,7 @@ exports.NavigationTreeActionType = NavigationTreeActionType;
21
24
  NavigationTreeActionType["ToggleCollapsed"] = "toggle-collapsed";
22
25
  NavigationTreeActionType["StartLoading"] = "start-loading";
23
26
  NavigationTreeActionType["FinishLoading"] = "finish-loading";
27
+ NavigationTreeActionType["ResetNode"] = "reset-node";
24
28
  })(NavigationTreeActionType || (exports.NavigationTreeActionType = NavigationTreeActionType = {}));
25
29
 
26
30
  function getDefaultNodeState() {
@@ -99,7 +103,27 @@ function reducer() {
99
103
  return newState;
100
104
  }
101
105
 
106
+ case NavigationTreeActionType.ResetNode:
107
+ return _objectSpread(_objectSpread({}, state), {}, {
108
+ [action.payload.path]: _objectSpread(_objectSpread({}, state[action.payload.path]), getDefaultNodeState())
109
+ });
110
+
102
111
  default:
103
112
  return state;
104
113
  }
114
+ }
115
+
116
+ function selectTreeAsList(state, rootPath) {
117
+ const list = [];
118
+ (0, _utils.traverseDFS)(state, rootPath, (node, level) => {
119
+ list.push(_objectSpread(_objectSpread({}, node), {}, {
120
+ level
121
+ }));
122
+ const serviceNode = (0, _utils.getServiceNode)(node, level);
123
+
124
+ if (serviceNode) {
125
+ list.push(serviceNode);
126
+ }
127
+ });
128
+ return list;
105
129
  }
@@ -20,6 +20,12 @@ export interface NavigationTreeNodeState {
20
20
  loaded: boolean;
21
21
  error: boolean;
22
22
  children: string[];
23
+ level?: number;
24
+ }
25
+ export interface NavigationTreeServiceNode {
26
+ path: string;
27
+ status: 'loading' | 'error' | 'empty';
28
+ level?: number;
23
29
  }
24
30
  export declare type NavigationTreeNodePartialState = Omit<NavigationTreeNodeState, 'loading' | 'loaded' | 'error' | 'children'>;
25
31
  export interface NavigationTreeProps<D = any> {
@@ -29,4 +35,5 @@ export interface NavigationTreeProps<D = any> {
29
35
  activePath?: string;
30
36
  onActivePathUpdate?: (activePath: string) => void;
31
37
  cache?: boolean;
38
+ virtualize?: boolean;
32
39
  }
@@ -0,0 +1,6 @@
1
+ import type { NavigationTreeNodeState, NavigationTreeServiceNode, NavigationTreeState } from './types';
2
+ export declare function isServiceNode(node: NavigationTreeNodeState | NavigationTreeServiceNode): node is NavigationTreeServiceNode;
3
+ export declare function getServiceNode(node: NavigationTreeNodeState, level: number): NavigationTreeServiceNode | void;
4
+ declare type TraverseDFSVisit = (node: NavigationTreeNodeState, level: number, path: string, state: NavigationTreeState) => void;
5
+ export declare function traverseDFS(state: NavigationTreeState, path: string, visit: TraverseDFSVisit, level?: number): void;
6
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getServiceNode = getServiceNode;
7
+ exports.isServiceNode = isServiceNode;
8
+ exports.traverseDFS = traverseDFS;
9
+
10
+ function isServiceNode(node) {
11
+ return 'status' in node;
12
+ }
13
+
14
+ function getServiceNode(node, level) {
15
+ if (node.collapsed) {
16
+ return undefined;
17
+ }
18
+
19
+ if (node.loading) {
20
+ return {
21
+ path: node.path,
22
+ status: 'loading',
23
+ level: level + 1
24
+ };
25
+ }
26
+
27
+ if (node.error) {
28
+ return {
29
+ path: node.path,
30
+ status: 'error',
31
+ level: level + 1
32
+ };
33
+ }
34
+
35
+ if (node.loaded && node.children.length === 0) {
36
+ return {
37
+ path: node.path,
38
+ status: 'empty',
39
+ level: level + 1
40
+ };
41
+ }
42
+
43
+ return undefined;
44
+ }
45
+
46
+ function traverseDFS(state, path, visit) {
47
+ let level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
48
+ const currentNode = state[path];
49
+
50
+ if (!currentNode) {
51
+ return;
52
+ }
53
+
54
+ visit(currentNode, level, path, state);
55
+
56
+ if (currentNode.collapsed) {
57
+ return;
58
+ }
59
+
60
+ for (const childPath of currentNode.children) {
61
+ traverseDFS(state, `${path}/${childPath}`, visit, level + 1);
62
+ }
63
+ }
@@ -1,4 +1,5 @@
1
1
  .ydb-tree-view {
2
+ --ydb-tree-view-level: 0;
2
3
  font-size: 13px;
3
4
  line-height: 18px;
4
5
  }
@@ -9,6 +10,7 @@
9
10
  display: flex;
10
11
  align-items: center;
11
12
  height: 24px;
13
+ padding-left: calc(24px * var(--ydb-tree-view-level));
12
14
  padding-right: 3px;
13
15
  border-bottom: 1px solid var(--yc-color-line-solid);
14
16
  cursor: pointer;
@@ -12,5 +12,6 @@ export interface TreeViewProps {
12
12
  onArrowClick?: () => void;
13
13
  hasArrow?: boolean;
14
14
  actions?: DropdownMenuItemMixed<any>[];
15
+ level?: number;
15
16
  }
16
- export declare function TreeView({ children, name, title, icon, collapsed, active, onClick, onArrowClick, hasArrow, actions, }: TreeViewProps): JSX.Element;
17
+ export declare function TreeView({ children, name, title, icon, collapsed, active, onClick, onArrowClick, hasArrow, actions, level, }: TreeViewProps): JSX.Element;
@@ -17,6 +17,7 @@ require("./TreeView.css");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
+ const TREE_LEVEL_CSS_VAR = '--ydb-tree-view-level';
20
21
  const b = (0, _bemCnLite.default)('ydb-tree-view');
21
22
 
22
23
  function TreeView(_ref) {
@@ -30,7 +31,8 @@ function TreeView(_ref) {
30
31
  onClick,
31
32
  onArrowClick,
32
33
  hasArrow = false,
33
- actions
34
+ actions,
35
+ level
34
36
  } = _ref;
35
37
 
36
38
  const rootRef = _react.default.useRef(null);
@@ -82,7 +84,10 @@ function TreeView(_ref) {
82
84
  ref: rootRef,
83
85
  className: b({
84
86
  'no-arrow': !hasArrow
85
- })
87
+ }),
88
+ style: {
89
+ [TREE_LEVEL_CSS_VAR]: level
90
+ }
86
91
  }, /*#__PURE__*/_react.default.createElement(_reactTreeview.default, {
87
92
  collapsed: collapsed,
88
93
  itemClassName: b('item', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-ui-components",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "bem-cn-lite": "^4.1.0",
27
+ "react-list": "^0.8.17",
27
28
  "react-treeview": "^0.4.7"
28
29
  },
29
30
  "devDependencies": {
@@ -36,6 +37,7 @@
36
37
  "@storybook/addon-essentials": "^6.4.19",
37
38
  "@storybook/preset-scss": "^1.0.3",
38
39
  "@storybook/react": "^6.4.19",
40
+ "@types/react-list": "^0.8.7",
39
41
  "@types/react-treeview": "^0.4.3",
40
42
  "@yandex-cloud/browserslist-config": "^1.0.1",
41
43
  "@yandex-cloud/eslint-config": "^1.0.0",
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { NavigationTreeState, NavigationTreeProps } from './types';
3
- import { NavigationTreeAction } from './state';
4
- export interface NavigationTreeDirectoryProps {
5
- state: NavigationTreeState;
6
- dispatch: React.Dispatch<NavigationTreeAction>;
7
- path: string;
8
- fetchPath: NavigationTreeProps['fetchPath'];
9
- activePath?: string;
10
- onItemActivate?: (itemPath: string) => void;
11
- getActions?: NavigationTreeProps['getActions'];
12
- cache?: boolean;
13
- }
14
- export declare function NavigationTreeDirectory({ state, dispatch, path, fetchPath, activePath, onItemActivate, getActions, cache, }: NavigationTreeDirectoryProps): JSX.Element;
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.NavigationTreeDirectory = NavigationTreeDirectory;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _state = require("./state");
11
-
12
- var _NavigationTreeNode = require("./NavigationTreeNode");
13
-
14
- var _LoaderView = require("./LoaderView/LoaderView");
15
-
16
- var _ErrorView = require("./ErrorView/ErrorView");
17
-
18
- var _EmptyView = require("./EmptyView/EmptyView");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function NavigationTreeDirectory(_ref) {
23
- let {
24
- state,
25
- dispatch,
26
- path,
27
- fetchPath,
28
- activePath,
29
- onItemActivate,
30
- getActions,
31
- cache
32
- } = _ref;
33
- const nodeState = state[path];
34
-
35
- _react.default.useEffect(() => {
36
- if (nodeState.loaded && cache || nodeState.loading) {
37
- return;
38
- }
39
-
40
- dispatch({
41
- type: _state.NavigationTreeActionType.StartLoading,
42
- payload: {
43
- path
44
- }
45
- });
46
- fetchPath(path).then(data => {
47
- dispatch({
48
- type: _state.NavigationTreeActionType.FinishLoading,
49
- payload: {
50
- path,
51
- activePath,
52
- data
53
- }
54
- });
55
- }).catch(error => {
56
- dispatch({
57
- type: _state.NavigationTreeActionType.FinishLoading,
58
- payload: {
59
- path,
60
- error
61
- }
62
- });
63
- });
64
- }, []);
65
-
66
- if (nodeState.loading) {
67
- return /*#__PURE__*/_react.default.createElement(_LoaderView.LoaderView, null);
68
- }
69
-
70
- if (nodeState.error) {
71
- return /*#__PURE__*/_react.default.createElement(_ErrorView.ErrorView, null);
72
- }
73
-
74
- if (nodeState.loaded && nodeState.children.length > 0) {
75
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, nodeState.children.map(childName => {
76
- const childPath = `${path}/${childName}`;
77
- let children;
78
-
79
- if (state[childPath].expandable) {
80
- children = /*#__PURE__*/_react.default.createElement(NavigationTreeDirectory, {
81
- state: state,
82
- dispatch: dispatch,
83
- path: childPath,
84
- fetchPath: fetchPath,
85
- activePath: activePath,
86
- onItemActivate: onItemActivate,
87
- getActions: getActions,
88
- cache: cache
89
- });
90
- }
91
-
92
- return /*#__PURE__*/_react.default.createElement(_NavigationTreeNode.NavigationTreeNode, {
93
- key: childPath,
94
- path: childPath,
95
- state: state,
96
- dispatch: dispatch,
97
- active: childPath === activePath,
98
- onActivate: onItemActivate,
99
- getActions: getActions,
100
- children: children
101
- });
102
- }));
103
- }
104
-
105
- return /*#__PURE__*/_react.default.createElement(_EmptyView.EmptyView, null);
106
- }