ydb-ui-components 3.6.0 → 4.0.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.
Files changed (84) hide show
  1. package/build/cjs/components/NavigationTree/EmptyView/EmptyView.d.ts +1 -1
  2. package/build/cjs/components/NavigationTree/EmptyView/EmptyView.js +12 -28
  3. package/build/cjs/components/NavigationTree/ErrorView/ErrorView.d.ts +1 -1
  4. package/build/cjs/components/NavigationTree/ErrorView/ErrorView.js +12 -28
  5. package/build/cjs/components/NavigationTree/LoaderView/LoaderView.d.ts +1 -1
  6. package/build/cjs/components/NavigationTree/LoaderView/LoaderView.js +11 -30
  7. package/build/cjs/components/NavigationTree/NavigationTree.js +36 -116
  8. package/build/cjs/components/NavigationTree/NavigationTreeNode.d.ts +2 -2
  9. package/build/cjs/components/NavigationTree/NavigationTreeNode.js +86 -173
  10. package/build/cjs/components/NavigationTree/i18n/index.d.ts +1 -1
  11. package/build/cjs/components/NavigationTree/i18n/index.js +7 -25
  12. package/build/cjs/components/NavigationTree/index.d.ts +1 -1
  13. package/build/cjs/components/NavigationTree/index.js +3 -30
  14. package/build/cjs/components/NavigationTree/state.d.ts +31 -5
  15. package/build/cjs/components/NavigationTree/state.js +58 -122
  16. package/build/cjs/components/NavigationTree/types.d.ts +3 -3
  17. package/build/cjs/components/NavigationTree/types.js +1 -4
  18. package/build/cjs/components/NavigationTree/utils.d.ts +1 -1
  19. package/build/cjs/components/NavigationTree/utils.js +42 -72
  20. package/build/cjs/components/TreeView/TreeView.d.ts +2 -2
  21. package/build/cjs/components/TreeView/TreeView.js +43 -104
  22. package/build/cjs/components/TreeView/index.js +3 -17
  23. package/build/cjs/components/icons/ColumnTable.js +6 -22
  24. package/build/cjs/components/icons/Database.js +6 -20
  25. package/build/cjs/components/icons/ExternalDataSource.js +6 -22
  26. package/build/cjs/components/icons/ExternalTable.js +6 -22
  27. package/build/cjs/components/icons/Folder.js +6 -20
  28. package/build/cjs/components/icons/FolderOpen.js +6 -20
  29. package/build/cjs/components/icons/Index.js +6 -22
  30. package/build/cjs/components/icons/Table.js +6 -22
  31. package/build/cjs/components/icons/Topic.js +6 -36
  32. package/build/cjs/index.d.ts +0 -1
  33. package/build/cjs/index.js +4 -43
  34. package/build/cjs/utils/cn.d.ts +1 -0
  35. package/build/cjs/utils/cn.js +5 -0
  36. package/build/esm/components/NavigationTree/EmptyView/EmptyView.d.ts +1 -1
  37. package/build/esm/components/NavigationTree/EmptyView/EmptyView.js +7 -13
  38. package/build/esm/components/NavigationTree/ErrorView/ErrorView.d.ts +1 -1
  39. package/build/esm/components/NavigationTree/ErrorView/ErrorView.js +7 -13
  40. package/build/esm/components/NavigationTree/LoaderView/LoaderView.d.ts +1 -1
  41. package/build/esm/components/NavigationTree/LoaderView/LoaderView.js +6 -14
  42. package/build/esm/components/NavigationTree/NavigationTree.js +29 -98
  43. package/build/esm/components/NavigationTree/NavigationTreeNode.d.ts +2 -2
  44. package/build/esm/components/NavigationTree/NavigationTreeNode.js +76 -142
  45. package/build/esm/components/NavigationTree/i18n/index.d.ts +1 -1
  46. package/build/esm/components/NavigationTree/i18n/index.js +3 -6
  47. package/build/esm/components/NavigationTree/index.d.ts +1 -1
  48. package/build/esm/components/NavigationTree/index.js +0 -1
  49. package/build/esm/components/NavigationTree/state.d.ts +31 -5
  50. package/build/esm/components/NavigationTree/state.js +51 -106
  51. package/build/esm/components/NavigationTree/types.d.ts +3 -3
  52. package/build/esm/components/NavigationTree/types.js +1 -1
  53. package/build/esm/components/NavigationTree/utils.d.ts +1 -1
  54. package/build/esm/components/NavigationTree/utils.js +37 -62
  55. package/build/esm/components/TreeView/TreeView.d.ts +2 -2
  56. package/build/esm/components/TreeView/TreeView.js +38 -84
  57. package/build/esm/components/TreeView/index.js +1 -1
  58. package/build/esm/components/icons/ColumnTable.js +3 -12
  59. package/build/esm/components/icons/Database.js +3 -10
  60. package/build/esm/components/icons/ExternalDataSource.js +3 -12
  61. package/build/esm/components/icons/ExternalTable.js +3 -12
  62. package/build/esm/components/icons/Folder.js +3 -10
  63. package/build/esm/components/icons/FolderOpen.js +3 -10
  64. package/build/esm/components/icons/Index.js +3 -12
  65. package/build/esm/components/icons/Table.js +3 -12
  66. package/build/esm/components/icons/Topic.js +3 -26
  67. package/build/esm/index.d.ts +0 -1
  68. package/build/esm/index.js +0 -1
  69. package/build/esm/utils/cn.d.ts +1 -0
  70. package/build/esm/utils/cn.js +2 -0
  71. package/package.json +52 -29
  72. package/CHANGELOG.md +0 -233
  73. package/build/cjs/components/i18n.d.ts +0 -2
  74. package/build/cjs/components/i18n.js +0 -19
  75. package/build/cjs/utils/configure.d.ts +0 -12
  76. package/build/cjs/utils/configure.js +0 -42
  77. package/build/cjs/utils/index.d.ts +0 -1
  78. package/build/cjs/utils/index.js +0 -19
  79. package/build/esm/components/i18n.d.ts +0 -2
  80. package/build/esm/components/i18n.js +0 -9
  81. package/build/esm/utils/configure.d.ts +0 -12
  82. package/build/esm/utils/configure.js +0 -26
  83. package/build/esm/utils/index.d.ts +0 -1
  84. package/build/esm/utils/index.js +0 -1
@@ -1,153 +1,87 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import React from 'react';
2
- import { NavigationTreeActionType } from './state';
3
+ import { TreeView } from '../TreeView/TreeView';
4
+ import { ColumnTableIcon } from '../icons/ColumnTable';
3
5
  import { DatabaseIcon } from '../icons/Database';
6
+ import { ExternalDataSourceIcon } from '../icons/ExternalDataSource';
7
+ import { ExternalTableIcon } from '../icons/ExternalTable';
4
8
  import { FolderIcon } from '../icons/Folder';
5
9
  import { FolderOpenIcon } from '../icons/FolderOpen';
10
+ import { IndexIcon } from '../icons/Index';
6
11
  import { TableIcon } from '../icons/Table';
7
12
  import { TopicIcon } from '../icons/Topic';
8
- import { IndexIcon } from '../icons/Index';
9
- import { ColumnTableIcon } from '../icons/ColumnTable';
10
- import { ExternalTableIcon } from '../icons/ExternalTable';
11
- import { ExternalDataSourceIcon } from '../icons/ExternalDataSource';
12
- import { TreeView } from '../TreeView/TreeView';
13
-
13
+ import { NavigationTreeActionType } from './state';
14
14
  function renderIcon(type, collapsed) {
15
- switch (type) {
16
- case 'database':
17
- // this icon is larger than the others, therefore 14 for a better fit
18
- return /*#__PURE__*/React.createElement(DatabaseIcon, {
19
- height: 14
20
- });
21
-
22
- case 'directory':
23
- return collapsed ? /*#__PURE__*/React.createElement(FolderIcon, {
24
- height: 16
25
- }) : /*#__PURE__*/React.createElement(FolderOpenIcon, {
26
- height: 16
27
- });
28
-
29
- case 'index':
30
- return /*#__PURE__*/React.createElement(IndexIcon, {
31
- height: 16
32
- });
33
-
34
- case 'table':
35
- case 'index_table':
36
- return /*#__PURE__*/React.createElement(TableIcon, {
37
- height: 16
38
- });
39
-
40
- case 'column_table':
41
- return /*#__PURE__*/React.createElement(ColumnTableIcon, {
42
- height: 16
43
- });
44
-
45
- case 'stream':
46
- case 'topic':
47
- return /*#__PURE__*/React.createElement(TopicIcon, {
48
- height: 16
49
- });
50
-
51
- case 'external_table':
52
- return /*#__PURE__*/React.createElement(ExternalTableIcon, {
53
- height: 16
54
- });
55
-
56
- case 'external_data_source':
57
- return /*#__PURE__*/React.createElement(ExternalDataSourceIcon, {
58
- height: 16
59
- });
60
-
61
- default:
62
- return null;
63
- }
15
+ switch (type) {
16
+ case 'database':
17
+ // this icon is larger than the others, therefore 14 for a better fit
18
+ return _jsx(DatabaseIcon, { height: 14 });
19
+ case 'directory':
20
+ return collapsed ? _jsx(FolderIcon, { height: 16 }) : _jsx(FolderOpenIcon, { height: 16 });
21
+ case 'index':
22
+ return _jsx(IndexIcon, { height: 16 });
23
+ case 'table':
24
+ case 'index_table':
25
+ return _jsx(TableIcon, { height: 16 });
26
+ case 'column_table':
27
+ return _jsx(ColumnTableIcon, { height: 16 });
28
+ case 'stream':
29
+ case 'topic':
30
+ return _jsx(TopicIcon, { height: 16 });
31
+ case 'external_table':
32
+ return _jsx(ExternalTableIcon, { height: 16 });
33
+ case 'external_data_source':
34
+ return _jsx(ExternalDataSourceIcon, { height: 16 });
35
+ default:
36
+ return null;
37
+ }
64
38
  }
65
-
66
- export function NavigationTreeNode(_ref) {
67
- var path = _ref.path,
68
- fetchPath = _ref.fetchPath,
69
- activePath = _ref.activePath,
70
- state = _ref.state,
71
- level = _ref.level,
72
- dispatch = _ref.dispatch,
73
- children = _ref.children,
74
- onActivate = _ref.onActivate,
75
- getActions = _ref.getActions,
76
- renderAdditionalNodeElements = _ref.renderAdditionalNodeElements,
77
- cache = _ref.cache;
78
- var nodeState = state[path];
79
- React.useEffect(function () {
80
- if (nodeState.collapsed) {
81
- if (!cache) {
39
+ export function NavigationTreeNode({ path, fetchPath, activePath, state, level, dispatch, children, onActivate, getActions, renderAdditionalNodeElements, cache, }) {
40
+ const nodeState = state[path];
41
+ React.useEffect(() => {
42
+ if (nodeState.collapsed) {
43
+ if (!cache) {
44
+ dispatch({
45
+ type: NavigationTreeActionType.ResetNode,
46
+ payload: { path },
47
+ });
48
+ }
49
+ return;
50
+ }
51
+ if (nodeState.loaded || nodeState.loading) {
52
+ return;
53
+ }
82
54
  dispatch({
83
- type: NavigationTreeActionType.ResetNode,
84
- payload: {
85
- path: path
86
- }
55
+ type: NavigationTreeActionType.StartLoading,
56
+ payload: { path },
87
57
  });
88
- }
89
-
90
- return;
91
- }
92
-
93
- if (nodeState.loaded || nodeState.loading) {
94
- return;
95
- }
96
-
97
- dispatch({
98
- type: NavigationTreeActionType.StartLoading,
99
- payload: {
100
- path: path
101
- }
102
- });
103
- fetchPath(path).then(function (data) {
104
- dispatch({
105
- type: NavigationTreeActionType.FinishLoading,
106
- payload: {
107
- path: path,
108
- activePath: activePath,
109
- data: data
110
- }
111
- });
112
- })["catch"](function (error) {
113
- dispatch({
114
- type: NavigationTreeActionType.FinishLoading,
115
- payload: {
116
- path: path,
117
- error: error
58
+ fetchPath(path)
59
+ .then((data) => {
60
+ dispatch({
61
+ type: NavigationTreeActionType.FinishLoading,
62
+ payload: { path, activePath, data },
63
+ });
64
+ })
65
+ .catch((error) => {
66
+ dispatch({
67
+ type: NavigationTreeActionType.ErrorLoading,
68
+ payload: { path, error },
69
+ });
70
+ });
71
+ }, [nodeState.collapsed]);
72
+ const handleClick = React.useCallback(() => {
73
+ if (onActivate) {
74
+ onActivate(path);
118
75
  }
119
- });
120
- });
121
- }, [nodeState.collapsed]);
122
- var handleClick = React.useCallback(function () {
123
- if (onActivate) {
124
- onActivate(path);
125
- }
126
- }, [path, onActivate]);
127
- var handleArrowClick = React.useCallback(function () {
128
- dispatch({
129
- type: NavigationTreeActionType.ToggleCollapsed,
130
- payload: {
131
- path: path
132
- }
133
- });
134
- }, []);
135
- var additionalNodeElements = React.useMemo(function () {
136
- return renderAdditionalNodeElements === null || renderAdditionalNodeElements === void 0 ? void 0 : renderAdditionalNodeElements(nodeState.path, nodeState.type);
137
- }, [renderAdditionalNodeElements, nodeState]);
138
- var actions = React.useMemo(function () {
139
- return getActions === null || getActions === void 0 ? void 0 : getActions(nodeState.path, nodeState.type);
140
- }, [getActions, nodeState]);
141
- return /*#__PURE__*/React.createElement(TreeView, {
142
- name: nodeState.name,
143
- icon: renderIcon(nodeState.type, nodeState.collapsed),
144
- collapsed: nodeState.collapsed,
145
- active: nodeState.path === activePath,
146
- actions: actions,
147
- additionalNodeElements: additionalNodeElements,
148
- hasArrow: nodeState.expandable,
149
- onClick: handleClick,
150
- onArrowClick: handleArrowClick,
151
- level: level
152
- }, children);
153
- }
76
+ }, [path, onActivate]);
77
+ const handleArrowClick = React.useCallback(() => {
78
+ dispatch({ type: NavigationTreeActionType.ToggleCollapsed, payload: { path } });
79
+ }, [dispatch, path]);
80
+ const additionalNodeElements = React.useMemo(() => {
81
+ return renderAdditionalNodeElements === null || renderAdditionalNodeElements === void 0 ? void 0 : renderAdditionalNodeElements(nodeState.path, nodeState.type);
82
+ }, [renderAdditionalNodeElements, nodeState]);
83
+ const actions = React.useMemo(() => {
84
+ return getActions === null || getActions === void 0 ? void 0 : getActions(nodeState.path, nodeState.type);
85
+ }, [getActions, nodeState]);
86
+ return (_jsx(TreeView, { name: nodeState.name, icon: renderIcon(nodeState.type, nodeState.collapsed), collapsed: nodeState.collapsed, active: nodeState.path === activePath, actions: actions, additionalNodeElements: additionalNodeElements, hasArrow: nodeState.expandable, onClick: handleClick, onArrowClick: handleArrowClick, level: level, children: children }));
87
+ }
@@ -1,2 +1,2 @@
1
- declare const _default: (key: string, params?: import("@gravity-ui/i18n").Params | undefined) => string;
1
+ declare const _default: (key: "label_error" | "label_empty", params?: import("@gravity-ui/i18n").Params | undefined) => string;
2
2
  export default _default;
@@ -1,8 +1,5 @@
1
- import { i18n } from '../../i18n';
2
- import { Lang } from '../../../utils';
1
+ import { addComponentKeysets } from '@gravity-ui/uikit/i18n';
3
2
  import en from './en.json';
4
3
  import ru from './ru.json';
5
- var COMPONENT = 'ydb-navigation-tree';
6
- i18n.registerKeyset(Lang.En, COMPONENT, en);
7
- i18n.registerKeyset(Lang.Ru, COMPONENT, ru);
8
- export default i18n.keyset(COMPONENT);
4
+ const COMPONENT = 'ydb-navigation-tree';
5
+ export default addComponentKeysets({ en, ru }, COMPONENT);
@@ -1,2 +1,2 @@
1
1
  export * from './NavigationTree';
2
- export * from './types';
2
+ export type * from './types';
@@ -1,2 +1 @@
1
1
  export * from './NavigationTree';
2
- export * from './types';
@@ -1,14 +1,40 @@
1
- import type { NavigationTreeNodeState, NavigationTreeNodePartialState, NavigationTreeState, NavigationTreeServiceNode } from './types';
1
+ import type { NavigationTreeDataItem, NavigationTreeNodePartialState, NavigationTreeNodeState, NavigationTreeServiceNode, NavigationTreeState } from './types';
2
2
  export declare enum NavigationTreeActionType {
3
3
  ToggleCollapsed = "toggle-collapsed",
4
4
  StartLoading = "start-loading",
5
5
  FinishLoading = "finish-loading",
6
+ ErrorLoading = "error-loading",
6
7
  ResetNode = "reset-node"
7
8
  }
8
- export interface NavigationTreeAction {
9
- type: NavigationTreeActionType;
10
- payload: any;
11
- }
9
+ export type NavigationTreeAction = {
10
+ type: NavigationTreeActionType.ToggleCollapsed;
11
+ payload: {
12
+ path: string;
13
+ };
14
+ } | {
15
+ type: NavigationTreeActionType.StartLoading;
16
+ payload: {
17
+ path: string;
18
+ };
19
+ } | {
20
+ type: NavigationTreeActionType.FinishLoading;
21
+ payload: {
22
+ path: string;
23
+ activePath?: string;
24
+ data: NavigationTreeDataItem[];
25
+ };
26
+ } | {
27
+ type: NavigationTreeActionType.ErrorLoading;
28
+ payload: {
29
+ path: string;
30
+ error: unknown;
31
+ };
32
+ } | {
33
+ type: NavigationTreeActionType.ResetNode;
34
+ payload: {
35
+ path: string;
36
+ };
37
+ };
12
38
  export declare function getDefaultNodeState(): {
13
39
  collapsed: boolean;
14
40
  loading: boolean;
@@ -1,118 +1,63 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
- 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; }
8
-
9
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
-
11
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
-
13
1
  import { getServiceNode, traverseDFS } from './utils';
14
2
  export var NavigationTreeActionType;
15
-
16
3
  (function (NavigationTreeActionType) {
17
- NavigationTreeActionType["ToggleCollapsed"] = "toggle-collapsed";
18
- NavigationTreeActionType["StartLoading"] = "start-loading";
19
- NavigationTreeActionType["FinishLoading"] = "finish-loading";
20
- NavigationTreeActionType["ResetNode"] = "reset-node";
4
+ NavigationTreeActionType["ToggleCollapsed"] = "toggle-collapsed";
5
+ NavigationTreeActionType["StartLoading"] = "start-loading";
6
+ NavigationTreeActionType["FinishLoading"] = "finish-loading";
7
+ NavigationTreeActionType["ErrorLoading"] = "error-loading";
8
+ NavigationTreeActionType["ResetNode"] = "reset-node";
21
9
  })(NavigationTreeActionType || (NavigationTreeActionType = {}));
22
-
23
10
  export function getDefaultNodeState() {
24
- return {
25
- collapsed: true,
26
- loading: false,
27
- loaded: false,
28
- error: false,
29
- children: []
30
- };
11
+ return {
12
+ collapsed: true,
13
+ loading: false,
14
+ loaded: false,
15
+ error: false,
16
+ children: [],
17
+ };
31
18
  }
32
19
  export function getNodeState(partialState) {
33
- return _objectSpread(_objectSpread({}, getDefaultNodeState()), {}, {
34
- expandable: partialState.type === 'database' || partialState.type === 'directory'
35
- }, partialState);
20
+ return Object.assign(Object.assign(Object.assign({}, getDefaultNodeState()), { expandable: partialState.type === 'database' || partialState.type === 'directory' }), partialState);
36
21
  }
37
- export function reducer() {
38
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
39
- var action = arguments.length > 1 ? arguments[1] : undefined;
40
-
41
- switch (action.type) {
42
- case NavigationTreeActionType.ToggleCollapsed:
43
- return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, action.payload.path, _objectSpread(_objectSpread({}, state[action.payload.path]), {}, {
44
- collapsed: !state[action.payload.path].collapsed
45
- })));
46
-
47
- case NavigationTreeActionType.StartLoading:
48
- return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, action.payload.path, _objectSpread(_objectSpread({}, state[action.payload.path]), {}, {
49
- loading: true,
50
- loaded: false,
51
- error: false,
52
- children: []
53
- })));
54
-
55
- case NavigationTreeActionType.FinishLoading:
56
- {
57
- var newState = _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, action.payload.path, _objectSpread(_objectSpread({}, state[action.payload.path]), {}, {
58
- loading: false,
59
- loaded: Boolean(action.payload.data),
60
- error: Boolean(action.payload.error)
61
- })));
62
-
63
- if (action.payload.data) {
64
- newState[action.payload.path].children = action.payload.data.map(function (_ref) {
65
- var name = _ref.name;
66
- return name;
67
- });
68
-
69
- var _iterator = _createForOfIteratorHelper(action.payload.data),
70
- _step;
71
-
72
- try {
73
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
74
- var _state$path$collapsed, _state$path;
75
-
76
- var item = _step.value;
77
- var path = "".concat(action.payload.path, "/").concat(item.name); // expand the tree according to the active path
78
- // prioritize the existing state to expand the tree only on first load
79
-
80
- var _action$payload$activ = action.payload.activePath,
81
- activePath = _action$payload$activ === void 0 ? '' : _action$payload$activ;
82
- var collapsed = (_state$path$collapsed = (_state$path = state[path]) === null || _state$path === void 0 ? void 0 : _state$path.collapsed) !== null && _state$path$collapsed !== void 0 ? _state$path$collapsed : !activePath.startsWith("".concat(path, "/"));
83
- newState[path] = getNodeState(_objectSpread(_objectSpread({}, item), {}, {
84
- collapsed: collapsed,
85
- path: path
86
- }));
22
+ export function reducer(state = {}, action) {
23
+ var _a, _b;
24
+ switch (action.type) {
25
+ case NavigationTreeActionType.ToggleCollapsed:
26
+ return Object.assign(Object.assign({}, state), { [action.payload.path]: Object.assign(Object.assign({}, state[action.payload.path]), { collapsed: !state[action.payload.path].collapsed }) });
27
+ case NavigationTreeActionType.StartLoading:
28
+ return Object.assign(Object.assign({}, state), { [action.payload.path]: Object.assign(Object.assign({}, state[action.payload.path]), { loading: true, loaded: false, error: false, children: [] }) });
29
+ case NavigationTreeActionType.FinishLoading: {
30
+ const newState = Object.assign(Object.assign({}, state), { [action.payload.path]: Object.assign(Object.assign({}, state[action.payload.path]), { loading: false, loaded: Boolean(action.payload.data), error: false }) });
31
+ if (action.payload.data) {
32
+ newState[action.payload.path].children = action.payload.data.map(({ name }) => name);
33
+ for (const item of action.payload.data) {
34
+ const path = `${action.payload.path}/${item.name}`;
35
+ // expand the tree according to the active path
36
+ // prioritize the existing state to expand the tree only on first load
37
+ const { activePath = '' } = action.payload;
38
+ const collapsed = (_b = (_a = state[path]) === null || _a === void 0 ? void 0 : _a.collapsed) !== null && _b !== void 0 ? _b : !activePath.startsWith(`${path}/`);
39
+ newState[path] = getNodeState(Object.assign(Object.assign({}, item), { collapsed,
40
+ path }));
41
+ }
87
42
  }
88
- } catch (err) {
89
- _iterator.e(err);
90
- } finally {
91
- _iterator.f();
92
- }
43
+ return newState;
93
44
  }
94
-
95
- return newState;
96
- }
97
-
98
- case NavigationTreeActionType.ResetNode:
99
- return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, action.payload.path, _objectSpread(_objectSpread({}, state[action.payload.path]), getDefaultNodeState())));
100
-
101
- default:
102
- return state;
103
- }
45
+ case NavigationTreeActionType.ErrorLoading:
46
+ return Object.assign(Object.assign({}, state), { [action.payload.path]: Object.assign(Object.assign({}, state[action.payload.path]), { loading: false, loaded: false, error: true }) });
47
+ case NavigationTreeActionType.ResetNode:
48
+ return Object.assign(Object.assign({}, state), { [action.payload.path]: Object.assign(Object.assign({}, state[action.payload.path]), getDefaultNodeState()) });
49
+ default:
50
+ return state;
51
+ }
104
52
  }
105
53
  export function selectTreeAsList(state, rootPath) {
106
- var list = [];
107
- traverseDFS(state, rootPath, function (node, level) {
108
- list.push(_objectSpread(_objectSpread({}, node), {}, {
109
- level: level
110
- }));
111
- var serviceNode = getServiceNode(node, level);
112
-
113
- if (serviceNode) {
114
- list.push(serviceNode);
115
- }
116
- });
117
- return list;
118
- }
54
+ const list = [];
55
+ traverseDFS(state, rootPath, (node, level) => {
56
+ list.push(Object.assign(Object.assign({}, node), { level }));
57
+ const serviceNode = getServiceNode(node, level);
58
+ if (serviceNode) {
59
+ list.push(serviceNode);
60
+ }
61
+ });
62
+ return list;
63
+ }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { DropdownMenuItemMixed } from '@gravity-ui/uikit';
3
- export declare type NavigationTreeNodeType = 'database' | 'directory' | 'table' | 'column_table' | 'index_table' | 'index' | 'topic' | 'stream' | 'external_table' | 'external_data_source';
2
+ import type { DropdownMenuItemMixed } from '@gravity-ui/uikit';
3
+ export type NavigationTreeNodeType = 'database' | 'directory' | 'table' | 'column_table' | 'index_table' | 'index' | 'topic' | 'stream' | 'external_table' | 'external_data_source';
4
4
  export interface NavigationTreeDataItem {
5
5
  name: string;
6
6
  type: NavigationTreeNodeType;
@@ -28,7 +28,7 @@ export interface NavigationTreeServiceNode {
28
28
  status: 'loading' | 'error' | 'empty';
29
29
  level?: number;
30
30
  }
31
- export declare type NavigationTreeNodePartialState = Omit<NavigationTreeNodeState, 'loading' | 'loaded' | 'error' | 'children'>;
31
+ export type NavigationTreeNodePartialState = Omit<NavigationTreeNodeState, 'loading' | 'loaded' | 'error' | 'children'>;
32
32
  export interface NavigationTreeProps<D = any> {
33
33
  rootState: NavigationTreeNodePartialState;
34
34
  fetchPath: (path: string) => Promise<NavigationTreeDataItem[]>;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import type { NavigationTreeNodeState, NavigationTreeServiceNode, NavigationTreeState } from './types';
2
2
  export declare function isServiceNode(node: NavigationTreeNodeState | NavigationTreeServiceNode): node is NavigationTreeServiceNode;
3
3
  export declare function getServiceNode(node: NavigationTreeNodeState, level: number): NavigationTreeServiceNode | void;
4
- declare type TraverseDFSVisit = (node: NavigationTreeNodeState, level: number, path: string, state: NavigationTreeState) => void;
4
+ type TraverseDFSVisit = (node: NavigationTreeNodeState, level: number, path: string, state: NavigationTreeState) => void;
5
5
  export declare function traverseDFS(state: NavigationTreeState, path: string, visit: TraverseDFSVisit, level?: number): void;
6
6
  export {};
@@ -1,68 +1,43 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
1
  export function isServiceNode(node) {
8
- return 'status' in node;
2
+ return 'status' in node;
9
3
  }
10
4
  export function getServiceNode(node, level) {
11
- if (node.collapsed) {
5
+ if (node.collapsed) {
6
+ return undefined;
7
+ }
8
+ if (node.loading) {
9
+ return {
10
+ path: node.path,
11
+ status: 'loading',
12
+ level: level + 1,
13
+ };
14
+ }
15
+ if (node.error) {
16
+ return {
17
+ path: node.path,
18
+ status: 'error',
19
+ level: level + 1,
20
+ };
21
+ }
22
+ if (node.loaded && node.children.length === 0) {
23
+ return {
24
+ path: node.path,
25
+ status: 'empty',
26
+ level: level + 1,
27
+ };
28
+ }
12
29
  return undefined;
13
- }
14
-
15
- if (node.loading) {
16
- return {
17
- path: node.path,
18
- status: 'loading',
19
- level: level + 1
20
- };
21
- }
22
-
23
- if (node.error) {
24
- return {
25
- path: node.path,
26
- status: 'error',
27
- level: level + 1
28
- };
29
- }
30
-
31
- if (node.loaded && node.children.length === 0) {
32
- return {
33
- path: node.path,
34
- status: 'empty',
35
- level: level + 1
36
- };
37
- }
38
-
39
- return undefined;
40
30
  }
41
- export function traverseDFS(state, path, visit) {
42
- var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
43
- var currentNode = state[path];
44
-
45
- if (!currentNode) {
46
- return;
47
- }
48
-
49
- visit(currentNode, level, path, state);
50
-
51
- if (currentNode.collapsed) {
52
- return;
53
- }
54
-
55
- var _iterator = _createForOfIteratorHelper(currentNode.children),
56
- _step;
57
-
58
- try {
59
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
60
- var childPath = _step.value;
61
- traverseDFS(state, "".concat(path, "/").concat(childPath), visit, level + 1);
31
+ export function traverseDFS(state, path, visit, level = 0) {
32
+ const currentNode = state[path];
33
+ if (!currentNode) {
34
+ return;
62
35
  }
63
- } catch (err) {
64
- _iterator.e(err);
65
- } finally {
66
- _iterator.f();
67
- }
68
- }
36
+ visit(currentNode, level, path, state);
37
+ if (currentNode.collapsed) {
38
+ return;
39
+ }
40
+ for (const childPath of currentNode.children) {
41
+ traverseDFS(state, `${path}/${childPath}`, visit, level + 1);
42
+ }
43
+ }
@@ -1,6 +1,6 @@
1
- import { DropdownMenuItemMixed } from '@gravity-ui/uikit';
2
1
  import React from 'react';
3
- import './TreeView.scss';
2
+ import type { DropdownMenuItemMixed } from '@gravity-ui/uikit';
3
+ import './TreeView.css';
4
4
  export interface TreeViewProps {
5
5
  children?: React.ReactNode;
6
6
  name: React.ReactNode;