ydb-ui-components 2.1.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 +22 -0
- package/README.md +30 -0
- package/build/components/NavigationTree/EmptyView/EmptyView.d.ts +5 -1
- package/build/components/NavigationTree/EmptyView/EmptyView.js +6 -2
- package/build/components/NavigationTree/ErrorView/ErrorView.d.ts +5 -1
- package/build/components/NavigationTree/ErrorView/ErrorView.js +6 -2
- package/build/components/NavigationTree/LoaderView/LoaderView.d.ts +5 -1
- package/build/components/NavigationTree/LoaderView/LoaderView.js +6 -2
- package/build/components/NavigationTree/NavigationTree.d.ts +2 -2
- package/build/components/NavigationTree/NavigationTree.js +64 -20
- package/build/components/NavigationTree/NavigationTreeNode.d.ts +5 -2
- package/build/components/NavigationTree/NavigationTreeNode.js +54 -4
- package/build/components/NavigationTree/i18n/index.js +4 -2
- package/build/components/NavigationTree/state.d.ts +4 -2
- package/build/components/NavigationTree/state.js +24 -0
- package/build/components/NavigationTree/types.d.ts +8 -1
- package/build/components/NavigationTree/utils.d.ts +6 -0
- package/build/components/NavigationTree/utils.js +63 -0
- package/build/components/TreeView/TreeView.css +2 -0
- package/build/components/TreeView/TreeView.d.ts +2 -1
- package/build/components/TreeView/TreeView.js +7 -2
- package/build/components/i18n.d.ts +0 -1
- package/build/components/i18n.js +9 -7
- package/build/index.d.ts +1 -0
- package/build/index.js +15 -1
- package/build/utils/configure.d.ts +12 -0
- package/build/utils/configure.js +38 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +19 -0
- package/package.json +3 -1
- package/build/components/NavigationTree/NavigationTreeDirectory.d.ts +0 -14
- package/build/components/NavigationTree/NavigationTreeDirectory.js +0 -106
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
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
|
+
|
|
11
|
+
## [2.3.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.2.0...v2.3.0) (2022-07-18)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **i18n:** add configure function ([c48e58e](https://github.com/ydb-platform/ydb-ui-components/commit/c48e58e33e361cf4f507190cd0a8d0a896975fb1))
|
|
17
|
+
|
|
18
|
+
## [2.2.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.1.0...v2.2.0) (2022-07-05)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* **NavigationTree:** add index and index_table node types! ([d6ed6ba](https://github.com/ydb-platform/ydb-ui-components/commit/d6ed6bae7e882a6217d4205f931ac3704b8ed9f6))
|
|
24
|
+
|
|
3
25
|
## [2.1.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.2...v2.1.0) (2022-06-28)
|
|
4
26
|
|
|
5
27
|
|
package/README.md
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
1
|
# ydb-ui-components
|
|
2
|
+
|
|
3
|
+
A set of React components used in YDB interfaces.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install --save-dev ydb-ui-components @yandex-cloud/uikit @yandex-cloud/i18n @yandex-cloud/browserslist-config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## I18N
|
|
12
|
+
|
|
13
|
+
Some components contain prepared text. For changing language use `configure` function.
|
|
14
|
+
|
|
15
|
+
**index.js**
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import {configure} from 'ydb-ui-components';
|
|
19
|
+
|
|
20
|
+
configure({
|
|
21
|
+
lang: 'en',
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
To start the dev storybook
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
npm run start
|
|
31
|
+
```
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
@@ -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
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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,
|
|
16
|
+
export declare function NavigationTreeNode({ path, fetchPath, activePath, state, level, dispatch, children, onActivate, getActions, cache, }: NavigationTreeNodeProps): JSX.Element;
|
|
@@ -29,6 +29,7 @@ function renderIcon(type, collapsed) {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
case 'directory':
|
|
32
|
+
case 'index':
|
|
32
33
|
return collapsed ? /*#__PURE__*/_react.default.createElement(_Folder.FolderIcon, {
|
|
33
34
|
height: 14
|
|
34
35
|
}) : /*#__PURE__*/_react.default.createElement(_FolderOpen.FolderOpenIcon, {
|
|
@@ -36,6 +37,7 @@ function renderIcon(type, collapsed) {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
case 'table':
|
|
40
|
+
case 'index_table':
|
|
39
41
|
return /*#__PURE__*/_react.default.createElement(_Table.TableIcon, {
|
|
40
42
|
height: 14
|
|
41
43
|
});
|
|
@@ -48,15 +50,62 @@ function renderIcon(type, collapsed) {
|
|
|
48
50
|
function NavigationTreeNode(_ref) {
|
|
49
51
|
let {
|
|
50
52
|
path,
|
|
53
|
+
fetchPath,
|
|
54
|
+
activePath,
|
|
51
55
|
state,
|
|
56
|
+
level,
|
|
52
57
|
dispatch,
|
|
53
58
|
children,
|
|
54
|
-
active,
|
|
55
59
|
onActivate,
|
|
56
|
-
getActions
|
|
60
|
+
getActions,
|
|
61
|
+
cache
|
|
57
62
|
} = _ref;
|
|
58
63
|
const nodeState = state[path];
|
|
59
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
|
+
|
|
60
109
|
const handleClick = _react.default.useCallback(() => {
|
|
61
110
|
if (onActivate) {
|
|
62
111
|
onActivate(path);
|
|
@@ -80,10 +129,11 @@ function NavigationTreeNode(_ref) {
|
|
|
80
129
|
name: nodeState.name,
|
|
81
130
|
icon: renderIcon(nodeState.type, nodeState.collapsed),
|
|
82
131
|
collapsed: nodeState.collapsed,
|
|
83
|
-
active:
|
|
132
|
+
active: nodeState.path === activePath,
|
|
84
133
|
actions: actions,
|
|
85
134
|
hasArrow: nodeState.expandable,
|
|
86
135
|
onClick: handleClick,
|
|
87
|
-
onArrowClick: handleArrowClick
|
|
136
|
+
onArrowClick: handleArrowClick,
|
|
137
|
+
level: level
|
|
88
138
|
}, children);
|
|
89
139
|
}
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _i18n = require("../../i18n");
|
|
9
9
|
|
|
10
|
+
var _utils = require("../../../utils");
|
|
11
|
+
|
|
10
12
|
var _en = _interopRequireDefault(require("./en.json"));
|
|
11
13
|
|
|
12
14
|
var _ru = _interopRequireDefault(require("./ru.json"));
|
|
@@ -15,9 +17,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
17
|
|
|
16
18
|
const COMPONENT = 'ydb-navigation-tree';
|
|
17
19
|
|
|
18
|
-
_i18n.i18n.registerKeyset(
|
|
20
|
+
_i18n.i18n.registerKeyset(_utils.Lang.En, COMPONENT, _en.default);
|
|
19
21
|
|
|
20
|
-
_i18n.i18n.registerKeyset(
|
|
22
|
+
_i18n.i18n.registerKeyset(_utils.Lang.Ru, COMPONENT, _ru.default);
|
|
21
23
|
|
|
22
24
|
var _default = _i18n.i18n.keyset(COMPONENT);
|
|
23
25
|
|
|
@@ -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
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DropdownMenuItemMixed } from '@yandex-cloud/uikit';
|
|
2
|
-
export declare type NavigationTreeNodeType = 'database' | 'directory' | 'table';
|
|
2
|
+
export declare type NavigationTreeNodeType = 'database' | 'directory' | 'table' | 'index_table' | 'index';
|
|
3
3
|
export interface NavigationTreeDataItem {
|
|
4
4
|
name: string;
|
|
5
5
|
type: NavigationTreeNodeType;
|
|
@@ -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/build/components/i18n.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "I18N", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _i18n.I18N;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
6
|
exports.i18n = void 0;
|
|
13
7
|
|
|
14
8
|
var _i18n = require("@yandex-cloud/i18n");
|
|
15
9
|
|
|
10
|
+
var _configure = require("../utils/configure");
|
|
11
|
+
|
|
16
12
|
const i18n = new _i18n.I18N();
|
|
17
|
-
exports.i18n = i18n;
|
|
13
|
+
exports.i18n = i18n;
|
|
14
|
+
i18n.setLang((0, _configure.getConfig)().lang || _configure.Lang.En);
|
|
15
|
+
(0, _configure.subscribeConfigure)(config => {
|
|
16
|
+
if (config.lang) {
|
|
17
|
+
i18n.setLang(config.lang);
|
|
18
|
+
}
|
|
19
|
+
});
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -41,4 +41,18 @@ Object.keys(_TreeView).forEach(function (key) {
|
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
var _i18n = require("./components/i18n");
|
|
44
|
+
var _i18n = require("./components/i18n");
|
|
45
|
+
|
|
46
|
+
var _utils = require("./utils");
|
|
47
|
+
|
|
48
|
+
Object.keys(_utils).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
51
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
52
|
+
Object.defineProperty(exports, key, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _utils[key];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum Lang {
|
|
2
|
+
Ru = "ru",
|
|
3
|
+
En = "en"
|
|
4
|
+
}
|
|
5
|
+
interface Config {
|
|
6
|
+
lang?: Lang;
|
|
7
|
+
}
|
|
8
|
+
declare type Subscriber = (config: Config) => void;
|
|
9
|
+
export declare const configure: (newConfig: Config) => void;
|
|
10
|
+
export declare const subscribeConfigure: (sub: Subscriber) => () => void;
|
|
11
|
+
export declare const getConfig: () => Config;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.subscribeConfigure = exports.getConfig = exports.configure = exports.Lang = void 0;
|
|
7
|
+
let Lang;
|
|
8
|
+
exports.Lang = Lang;
|
|
9
|
+
|
|
10
|
+
(function (Lang) {
|
|
11
|
+
Lang["Ru"] = "ru";
|
|
12
|
+
Lang["En"] = "en";
|
|
13
|
+
})(Lang || (exports.Lang = Lang = {}));
|
|
14
|
+
|
|
15
|
+
let subs = [];
|
|
16
|
+
const config = {};
|
|
17
|
+
|
|
18
|
+
const configure = newConfig => {
|
|
19
|
+
Object.assign(config, newConfig);
|
|
20
|
+
subs.forEach(sub => {
|
|
21
|
+
sub(config);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.configure = configure;
|
|
26
|
+
|
|
27
|
+
const subscribeConfigure = sub => {
|
|
28
|
+
subs.push(sub);
|
|
29
|
+
return () => {
|
|
30
|
+
subs = subs.filter(item => item !== sub);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.subscribeConfigure = subscribeConfigure;
|
|
35
|
+
|
|
36
|
+
const getConfig = () => config;
|
|
37
|
+
|
|
38
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { configure, Lang } from './configure';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Lang", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _configure.Lang;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "configure", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _configure.configure;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _configure = require("./configure");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ydb-ui-components",
|
|
3
|
-
"version": "2.
|
|
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
|
-
}
|