ydb-ui-components 3.3.1 → 3.5.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 (115) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/{components → cjs/components}/NavigationTree/EmptyView/EmptyView.css +1 -1
  3. package/build/cjs/components/NavigationTree/ErrorView/ErrorView.css +3 -0
  4. package/build/{components → cjs/components}/TreeView/TreeView.css +6 -6
  5. package/build/esm/components/NavigationTree/EmptyView/EmptyView.css +4 -0
  6. package/build/esm/components/NavigationTree/EmptyView/EmptyView.d.ts +7 -0
  7. package/build/esm/components/NavigationTree/EmptyView/EmptyView.js +15 -0
  8. package/build/esm/components/NavigationTree/ErrorView/ErrorView.css +3 -0
  9. package/build/esm/components/NavigationTree/ErrorView/ErrorView.d.ts +7 -0
  10. package/build/esm/components/NavigationTree/ErrorView/ErrorView.js +15 -0
  11. package/build/esm/components/NavigationTree/LoaderView/LoaderView.css +7 -0
  12. package/build/esm/components/NavigationTree/LoaderView/LoaderView.d.ts +7 -0
  13. package/build/esm/components/NavigationTree/LoaderView/LoaderView.js +17 -0
  14. package/build/esm/components/NavigationTree/NavigationTree.d.ts +4 -0
  15. package/build/esm/components/NavigationTree/NavigationTree.js +103 -0
  16. package/build/esm/components/NavigationTree/NavigationTreeNode.d.ts +17 -0
  17. package/build/esm/components/NavigationTree/NavigationTreeNode.js +153 -0
  18. package/build/esm/components/NavigationTree/i18n/en.json +4 -0
  19. package/build/esm/components/NavigationTree/i18n/index.d.ts +2 -0
  20. package/build/esm/components/NavigationTree/i18n/index.js +8 -0
  21. package/build/esm/components/NavigationTree/i18n/ru.json +4 -0
  22. package/build/esm/components/NavigationTree/index.d.ts +2 -0
  23. package/build/esm/components/NavigationTree/index.js +2 -0
  24. package/build/esm/components/NavigationTree/state.d.ts +21 -0
  25. package/build/esm/components/NavigationTree/state.js +118 -0
  26. package/build/esm/components/NavigationTree/types.d.ts +41 -0
  27. package/build/esm/components/NavigationTree/types.js +1 -0
  28. package/build/esm/components/NavigationTree/utils.d.ts +6 -0
  29. package/build/esm/components/NavigationTree/utils.js +68 -0
  30. package/build/esm/components/TreeView/TreeView.css +90 -0
  31. package/build/esm/components/TreeView/TreeView.d.ts +18 -0
  32. package/build/esm/components/TreeView/TreeView.js +86 -0
  33. package/build/esm/components/TreeView/index.d.ts +1 -0
  34. package/build/esm/components/TreeView/index.js +1 -0
  35. package/build/esm/components/i18n.d.ts +2 -0
  36. package/build/esm/components/i18n.js +9 -0
  37. package/build/esm/components/icons/ColumnTable.d.ts +2 -0
  38. package/build/esm/components/icons/ColumnTable.js +14 -0
  39. package/build/esm/components/icons/Database.d.ts +2 -0
  40. package/build/esm/components/icons/Database.js +12 -0
  41. package/build/esm/components/icons/ExternalDataSource.d.ts +2 -0
  42. package/build/esm/components/icons/ExternalDataSource.js +14 -0
  43. package/build/esm/components/icons/ExternalTable.d.ts +2 -0
  44. package/build/esm/components/icons/ExternalTable.js +14 -0
  45. package/build/esm/components/icons/Folder.d.ts +2 -0
  46. package/build/esm/components/icons/Folder.js +12 -0
  47. package/build/esm/components/icons/FolderOpen.d.ts +2 -0
  48. package/build/esm/components/icons/FolderOpen.js +12 -0
  49. package/build/esm/components/icons/Index.d.ts +2 -0
  50. package/build/esm/components/icons/Index.js +14 -0
  51. package/build/esm/components/icons/Table.d.ts +2 -0
  52. package/build/esm/components/icons/Table.js +14 -0
  53. package/build/esm/components/icons/Topic.d.ts +2 -0
  54. package/build/esm/components/icons/Topic.js +28 -0
  55. package/build/esm/index.d.ts +3 -0
  56. package/build/esm/index.js +3 -0
  57. package/build/esm/utils/configure.d.ts +12 -0
  58. package/build/esm/utils/configure.js +26 -0
  59. package/build/esm/utils/index.d.ts +1 -0
  60. package/build/esm/utils/index.js +1 -0
  61. package/package.json +13 -5
  62. package/build/components/NavigationTree/ErrorView/ErrorView.css +0 -3
  63. /package/build/{components → cjs/components}/NavigationTree/EmptyView/EmptyView.d.ts +0 -0
  64. /package/build/{components → cjs/components}/NavigationTree/EmptyView/EmptyView.js +0 -0
  65. /package/build/{components → cjs/components}/NavigationTree/ErrorView/ErrorView.d.ts +0 -0
  66. /package/build/{components → cjs/components}/NavigationTree/ErrorView/ErrorView.js +0 -0
  67. /package/build/{components → cjs/components}/NavigationTree/LoaderView/LoaderView.css +0 -0
  68. /package/build/{components → cjs/components}/NavigationTree/LoaderView/LoaderView.d.ts +0 -0
  69. /package/build/{components → cjs/components}/NavigationTree/LoaderView/LoaderView.js +0 -0
  70. /package/build/{components → cjs/components}/NavigationTree/NavigationTree.d.ts +0 -0
  71. /package/build/{components → cjs/components}/NavigationTree/NavigationTree.js +0 -0
  72. /package/build/{components → cjs/components}/NavigationTree/NavigationTreeNode.d.ts +0 -0
  73. /package/build/{components → cjs/components}/NavigationTree/NavigationTreeNode.js +0 -0
  74. /package/build/{components → cjs/components}/NavigationTree/i18n/en.json +0 -0
  75. /package/build/{components → cjs/components}/NavigationTree/i18n/index.d.ts +0 -0
  76. /package/build/{components → cjs/components}/NavigationTree/i18n/index.js +0 -0
  77. /package/build/{components → cjs/components}/NavigationTree/i18n/ru.json +0 -0
  78. /package/build/{components → cjs/components}/NavigationTree/index.d.ts +0 -0
  79. /package/build/{components → cjs/components}/NavigationTree/index.js +0 -0
  80. /package/build/{components → cjs/components}/NavigationTree/state.d.ts +0 -0
  81. /package/build/{components → cjs/components}/NavigationTree/state.js +0 -0
  82. /package/build/{components → cjs/components}/NavigationTree/types.d.ts +0 -0
  83. /package/build/{components → cjs/components}/NavigationTree/types.js +0 -0
  84. /package/build/{components → cjs/components}/NavigationTree/utils.d.ts +0 -0
  85. /package/build/{components → cjs/components}/NavigationTree/utils.js +0 -0
  86. /package/build/{components → cjs/components}/TreeView/TreeView.d.ts +0 -0
  87. /package/build/{components → cjs/components}/TreeView/TreeView.js +0 -0
  88. /package/build/{components → cjs/components}/TreeView/index.d.ts +0 -0
  89. /package/build/{components → cjs/components}/TreeView/index.js +0 -0
  90. /package/build/{components → cjs/components}/i18n.d.ts +0 -0
  91. /package/build/{components → cjs/components}/i18n.js +0 -0
  92. /package/build/{components → cjs/components}/icons/ColumnTable.d.ts +0 -0
  93. /package/build/{components → cjs/components}/icons/ColumnTable.js +0 -0
  94. /package/build/{components → cjs/components}/icons/Database.d.ts +0 -0
  95. /package/build/{components → cjs/components}/icons/Database.js +0 -0
  96. /package/build/{components → cjs/components}/icons/ExternalDataSource.d.ts +0 -0
  97. /package/build/{components → cjs/components}/icons/ExternalDataSource.js +0 -0
  98. /package/build/{components → cjs/components}/icons/ExternalTable.d.ts +0 -0
  99. /package/build/{components → cjs/components}/icons/ExternalTable.js +0 -0
  100. /package/build/{components → cjs/components}/icons/Folder.d.ts +0 -0
  101. /package/build/{components → cjs/components}/icons/Folder.js +0 -0
  102. /package/build/{components → cjs/components}/icons/FolderOpen.d.ts +0 -0
  103. /package/build/{components → cjs/components}/icons/FolderOpen.js +0 -0
  104. /package/build/{components → cjs/components}/icons/Index.d.ts +0 -0
  105. /package/build/{components → cjs/components}/icons/Index.js +0 -0
  106. /package/build/{components → cjs/components}/icons/Table.d.ts +0 -0
  107. /package/build/{components → cjs/components}/icons/Table.js +0 -0
  108. /package/build/{components → cjs/components}/icons/Topic.d.ts +0 -0
  109. /package/build/{components → cjs/components}/icons/Topic.js +0 -0
  110. /package/build/{index.d.ts → cjs/index.d.ts} +0 -0
  111. /package/build/{index.js → cjs/index.js} +0 -0
  112. /package/build/{utils → cjs/utils}/configure.d.ts +0 -0
  113. /package/build/{utils → cjs/utils}/configure.js +0 -0
  114. /package/build/{utils → cjs/utils}/index.d.ts +0 -0
  115. /package/build/{utils → cjs/utils}/index.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.5.0](https://github.com/ydb-platform/ydb-ui-components/compare/v3.4.0...v3.5.0) (2023-12-12)
4
+
5
+
6
+ ### Features
7
+
8
+ * update to uikit5 ([#62](https://github.com/ydb-platform/ydb-ui-components/issues/62)) ([03cf678](https://github.com/ydb-platform/ydb-ui-components/commit/03cf6786f27ed433a040cb4d2ad70764eaa8e4b1))
9
+
10
+ ## [3.4.0](https://github.com/ydb-platform/ydb-ui-components/compare/v3.3.1...v3.4.0) (2023-10-23)
11
+
12
+
13
+ ### Features
14
+
15
+ * build with both cjs and esm as targets ([#60](https://github.com/ydb-platform/ydb-ui-components/issues/60)) ([7b29759](https://github.com/ydb-platform/ydb-ui-components/commit/7b297599bb1129a40dc6797fcf0673165dd52a42))
16
+
3
17
  ## [3.3.1](https://github.com/ydb-platform/ydb-ui-components/compare/v3.3.0...v3.3.1) (2023-08-09)
4
18
 
5
19
 
@@ -1,4 +1,4 @@
1
1
  .ydb-navigation-tree-view-empty {
2
- color: var(--yc-color-text-secondary);
2
+ color: var(--g-color-text-secondary);
3
3
  font-style: italic;
4
4
  }
@@ -0,0 +1,3 @@
1
+ .ydb-navigation-tree-view-error {
2
+ color: var(--g-color-text-danger);
3
+ }
@@ -12,21 +12,21 @@
12
12
  height: 24px;
13
13
  padding-left: calc(24px * var(--ydb-tree-view-level));
14
14
  padding-right: 3px;
15
- border-bottom: 1px solid var(--yc-color-line-solid);
15
+ border-bottom: 1px solid var(--g-color-line-generic-solid);
16
16
  cursor: pointer;
17
17
  }
18
18
  .ydb-tree-view__item:hover {
19
- background-color: var(--yc-color-base-simple-hover);
19
+ background-color: var(--g-color-base-simple-hover);
20
20
  }
21
21
  .ydb-tree-view__item:hover .ydb-tree-view__actions {
22
22
  display: flex;
23
23
  }
24
24
  .ydb-tree-view__item_active {
25
25
  font-weight: bold;
26
- background-color: var(--yc-color-base-selection);
26
+ background-color: var(--g-color-base-selection);
27
27
  }
28
28
  .ydb-tree-view__item_active:hover {
29
- background-color: var(--yc-color-base-selection-hover);
29
+ background-color: var(--g-color-base-selection-hover);
30
30
  }
31
31
  .ydb-tree-view__content {
32
32
  flex-grow: 1;
@@ -41,7 +41,7 @@
41
41
  justify-content: center;
42
42
  width: 24px;
43
43
  height: 24px;
44
- color: var(--yc-color-text-hint);
44
+ color: var(--g-color-text-hint);
45
45
  }
46
46
  .ydb-tree-view__icon svg {
47
47
  display: block;
@@ -64,7 +64,7 @@
64
64
  cursor: pointer;
65
65
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6 12" width="6" height="12"><path d="M0.192529 10.7483C-0.0845649 11.0562 -0.0596061 11.5304 0.248276 11.8075C0.556159 12.0846 1.03038 12.0596 1.30747 11.7517L0.192529 10.7483ZM5.25 6.25L5.80747 6.75172C6.06418 6.46649 6.06418 6.0335 5.80747 5.74828L5.25 6.25ZM1.30747 0.748277C1.03038 0.440394 0.556159 0.415435 0.248276 0.69253C-0.0596065 0.969624 -0.0845653 1.44384 0.192529 1.75172L1.30747 0.748277ZM1.30747 11.7517L5.80747 6.75172L4.69253 5.74828L0.192529 10.7483L1.30747 11.7517ZM5.80747 5.74828L1.30747 0.748277L0.192529 1.75172L4.69253 6.75172L5.80747 5.74828Z" fill="rgba(0, 0, 0, 0.85)"/></svg>') no-repeat center center;
66
66
  }
67
- .yc-root_theme_dark .ydb-tree-view .tree-view_arrow {
67
+ .g-root_theme_dark .ydb-tree-view .tree-view_arrow {
68
68
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 6 12" width="6" height="12"><path d="M0.192529 10.7483C-0.0845649 11.0562 -0.0596061 11.5304 0.248276 11.8075C0.556159 12.0846 1.03038 12.0596 1.30747 11.7517L0.192529 10.7483ZM5.25 6.25L5.80747 6.75172C6.06418 6.46649 6.06418 6.0335 5.80747 5.74828L5.25 6.25ZM1.30747 0.748277C1.03038 0.440394 0.556159 0.415435 0.248276 0.69253C-0.0596065 0.969624 -0.0845653 1.44384 0.192529 1.75172L1.30747 0.748277ZM1.30747 11.7517L5.80747 6.75172L4.69253 5.74828L0.192529 10.7483L1.30747 11.7517ZM5.80747 5.74828L1.30747 0.748277L0.192529 1.75172L4.69253 6.75172L5.80747 5.74828Z" fill="rgba(255, 255, 255, 0.85)"/></svg>') no-repeat center center;
69
69
  }
70
70
  .ydb-tree-view .tree-view_arrow:not(.tree-view_arrow-collapsed) {
@@ -0,0 +1,4 @@
1
+ .ydb-navigation-tree-view-empty {
2
+ color: var(--g-color-text-secondary);
3
+ font-style: italic;
4
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import './EmptyView.scss';
3
+ interface EmptyViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function EmptyView({ level }: EmptyViewProps): JSX.Element;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import block from 'bem-cn-lite';
3
+ import i18n from '../i18n';
4
+ import { TreeView } from '../../TreeView/TreeView';
5
+ import './EmptyView.css';
6
+ var b = block('ydb-navigation-tree-view-empty');
7
+ export function EmptyView(_ref) {
8
+ var level = _ref.level;
9
+ return /*#__PURE__*/React.createElement(TreeView, {
10
+ name: /*#__PURE__*/React.createElement("span", {
11
+ className: b()
12
+ }, i18n('label_empty')),
13
+ level: level
14
+ });
15
+ }
@@ -0,0 +1,3 @@
1
+ .ydb-navigation-tree-view-error {
2
+ color: var(--g-color-text-danger);
3
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import './ErrorView.scss';
3
+ interface ErrorViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function ErrorView({ level }: ErrorViewProps): JSX.Element;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import block from 'bem-cn-lite';
3
+ import i18n from '../i18n';
4
+ import { TreeView } from '../../TreeView/TreeView';
5
+ import './ErrorView.css';
6
+ var b = block('ydb-navigation-tree-view-error');
7
+ export function ErrorView(_ref) {
8
+ var level = _ref.level;
9
+ return /*#__PURE__*/React.createElement(TreeView, {
10
+ name: /*#__PURE__*/React.createElement("span", {
11
+ className: b()
12
+ }, i18n('label_error')),
13
+ level: level
14
+ });
15
+ }
@@ -0,0 +1,7 @@
1
+ .ydb-navigation-tree-view-loader {
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ width: 20px;
6
+ height: 24px;
7
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import './LoaderView.scss';
3
+ interface LoaderViewProps {
4
+ level?: number;
5
+ }
6
+ export declare function LoaderView({ level }: LoaderViewProps): JSX.Element;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import block from 'bem-cn-lite';
3
+ import { Spin } from '@gravity-ui/uikit';
4
+ import { TreeView } from '../../TreeView/TreeView';
5
+ import './LoaderView.css';
6
+ var b = block('ydb-navigation-tree-view-loader');
7
+ export function LoaderView(_ref) {
8
+ var level = _ref.level;
9
+ return /*#__PURE__*/React.createElement(TreeView, {
10
+ name: /*#__PURE__*/React.createElement("div", {
11
+ className: b()
12
+ }, /*#__PURE__*/React.createElement(Spin, {
13
+ size: "xs"
14
+ })),
15
+ level: level
16
+ });
17
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { NavigationTreeProps } from './types';
3
+ export type { NavigationTreeProps };
4
+ export declare function NavigationTree({ rootState: partialRootState, fetchPath, getActions, renderAdditionalNodeElements, activePath, onActivePathUpdate, cache, virtualize, }: NavigationTreeProps): JSX.Element;
@@ -0,0 +1,103 @@
1
+ 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; }
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+
7
+ 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); }
8
+
9
+ 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; }
10
+
11
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
+
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+
15
+ import React from 'react';
16
+ import ReactList from 'react-list';
17
+ import { reducer, getNodeState, selectTreeAsList } from './state';
18
+ import { isServiceNode } from './utils';
19
+ import { NavigationTreeNode } from './NavigationTreeNode';
20
+ import { LoaderView } from './LoaderView/LoaderView';
21
+ import { ErrorView } from './ErrorView/ErrorView';
22
+ import { EmptyView } from './EmptyView/EmptyView';
23
+
24
+ var renderServiceNode = function renderServiceNode(node) {
25
+ var key = "".concat(node.path, "|").concat(node.status);
26
+
27
+ if (node.status === 'loading') {
28
+ return /*#__PURE__*/React.createElement(LoaderView, {
29
+ key: key,
30
+ level: node.level
31
+ });
32
+ }
33
+
34
+ if (node.status === 'error') {
35
+ return /*#__PURE__*/React.createElement(ErrorView, {
36
+ key: key,
37
+ level: node.level
38
+ });
39
+ }
40
+
41
+ return /*#__PURE__*/React.createElement(EmptyView, {
42
+ key: key,
43
+ level: node.level
44
+ });
45
+ };
46
+
47
+ export function NavigationTree(_ref) {
48
+ var partialRootState = _ref.rootState,
49
+ fetchPath = _ref.fetchPath,
50
+ getActions = _ref.getActions,
51
+ renderAdditionalNodeElements = _ref.renderAdditionalNodeElements,
52
+ activePath = _ref.activePath,
53
+ onActivePathUpdate = _ref.onActivePathUpdate,
54
+ _ref$cache = _ref.cache,
55
+ cache = _ref$cache === void 0 ? true : _ref$cache,
56
+ _ref$virtualize = _ref.virtualize,
57
+ virtualize = _ref$virtualize === void 0 ? false : _ref$virtualize;
58
+
59
+ var _React$useReducer = React.useReducer(reducer, _defineProperty({}, partialRootState.path, getNodeState(partialRootState))),
60
+ _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
61
+ state = _React$useReducer2[0],
62
+ dispatch = _React$useReducer2[1];
63
+
64
+ var nodesList = React.useMemo(function () {
65
+ return selectTreeAsList(state, partialRootState.path);
66
+ }, [state]);
67
+
68
+ var renderNode = function renderNode(node) {
69
+ return /*#__PURE__*/React.createElement(NavigationTreeNode, {
70
+ key: node.path,
71
+ state: state,
72
+ path: node.path,
73
+ activePath: activePath,
74
+ fetchPath: fetchPath,
75
+ dispatch: dispatch,
76
+ onActivate: onActivePathUpdate,
77
+ getActions: getActions,
78
+ renderAdditionalNodeElements: renderAdditionalNodeElements,
79
+ cache: cache,
80
+ level: node.level
81
+ });
82
+ };
83
+
84
+ var renderVirtualizedTree = function renderVirtualizedTree() {
85
+ return /*#__PURE__*/React.createElement(ReactList, {
86
+ type: "uniform",
87
+ length: nodesList.length,
88
+ useStaticSize: true,
89
+ itemRenderer: function itemRenderer(index) {
90
+ var node = nodesList[index];
91
+ return isServiceNode(node) ? renderServiceNode(node) : renderNode(node);
92
+ }
93
+ });
94
+ };
95
+
96
+ var renderSimpleTree = function renderSimpleTree() {
97
+ return /*#__PURE__*/React.createElement(React.Fragment, null, nodesList.map(function (node) {
98
+ return isServiceNode(node) ? renderServiceNode(node) : renderNode(node);
99
+ }));
100
+ };
101
+
102
+ return virtualize ? renderVirtualizedTree() : renderSimpleTree();
103
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { NavigationTreeState, NavigationTreeProps } from './types';
3
+ import { NavigationTreeAction } from './state';
4
+ export interface NavigationTreeNodeProps {
5
+ path: string;
6
+ fetchPath: NavigationTreeProps['fetchPath'];
7
+ activePath?: string;
8
+ state: NavigationTreeState;
9
+ level?: number;
10
+ dispatch: React.Dispatch<NavigationTreeAction>;
11
+ children?: React.ReactNode;
12
+ onActivate?: (path: string) => void;
13
+ getActions?: NavigationTreeProps['getActions'];
14
+ renderAdditionalNodeElements?: NavigationTreeProps['renderAdditionalNodeElements'];
15
+ cache?: boolean;
16
+ }
17
+ export declare function NavigationTreeNode({ path, fetchPath, activePath, state, level, dispatch, children, onActivate, getActions, renderAdditionalNodeElements, cache, }: NavigationTreeNodeProps): JSX.Element;
@@ -0,0 +1,153 @@
1
+ import React from 'react';
2
+ import { NavigationTreeActionType } from './state';
3
+ import { DatabaseIcon } from '../icons/Database';
4
+ import { FolderIcon } from '../icons/Folder';
5
+ import { FolderOpenIcon } from '../icons/FolderOpen';
6
+ import { TableIcon } from '../icons/Table';
7
+ 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
+
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
+ }
64
+ }
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) {
82
+ dispatch({
83
+ type: NavigationTreeActionType.ResetNode,
84
+ payload: {
85
+ path: path
86
+ }
87
+ });
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
118
+ }
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
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "label_error": "Error",
3
+ "label_empty": "No data"
4
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: (key: string, params?: import("@gravity-ui/i18n").Params | undefined) => string;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { i18n } from '../../i18n';
2
+ import { Lang } from '../../../utils';
3
+ import en from './en.json';
4
+ 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);
@@ -0,0 +1,4 @@
1
+ {
2
+ "label_error": "Ошибка",
3
+ "label_empty": "Нет данных"
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from './NavigationTree';
2
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ export * from './NavigationTree';
2
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ import type { NavigationTreeNodeState, NavigationTreeNodePartialState, NavigationTreeState, NavigationTreeServiceNode } from './types';
2
+ export declare enum NavigationTreeActionType {
3
+ ToggleCollapsed = "toggle-collapsed",
4
+ StartLoading = "start-loading",
5
+ FinishLoading = "finish-loading",
6
+ ResetNode = "reset-node"
7
+ }
8
+ export interface NavigationTreeAction {
9
+ type: NavigationTreeActionType;
10
+ payload: any;
11
+ }
12
+ export declare function getDefaultNodeState(): {
13
+ collapsed: boolean;
14
+ loading: boolean;
15
+ loaded: boolean;
16
+ error: boolean;
17
+ children: never[];
18
+ };
19
+ export declare function getNodeState(partialState: NavigationTreeNodePartialState): NavigationTreeNodeState;
20
+ export declare function reducer(state: NavigationTreeState | undefined, action: NavigationTreeAction): NavigationTreeState;
21
+ export declare function selectTreeAsList(state: NavigationTreeState, rootPath: string): (NavigationTreeNodeState | NavigationTreeServiceNode)[];
@@ -0,0 +1,118 @@
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
+ import { getServiceNode, traverseDFS } from './utils';
14
+ export var NavigationTreeActionType;
15
+
16
+ (function (NavigationTreeActionType) {
17
+ NavigationTreeActionType["ToggleCollapsed"] = "toggle-collapsed";
18
+ NavigationTreeActionType["StartLoading"] = "start-loading";
19
+ NavigationTreeActionType["FinishLoading"] = "finish-loading";
20
+ NavigationTreeActionType["ResetNode"] = "reset-node";
21
+ })(NavigationTreeActionType || (NavigationTreeActionType = {}));
22
+
23
+ export function getDefaultNodeState() {
24
+ return {
25
+ collapsed: true,
26
+ loading: false,
27
+ loaded: false,
28
+ error: false,
29
+ children: []
30
+ };
31
+ }
32
+ export function getNodeState(partialState) {
33
+ return _objectSpread(_objectSpread({}, getDefaultNodeState()), {}, {
34
+ expandable: partialState.type === 'database' || partialState.type === 'directory'
35
+ }, partialState);
36
+ }
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
+ }));
87
+ }
88
+ } catch (err) {
89
+ _iterator.e(err);
90
+ } finally {
91
+ _iterator.f();
92
+ }
93
+ }
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
+ }
104
+ }
105
+ 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
+ }