ydb-ui-components 2.0.2 → 2.3.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 +21 -0
- package/README.md +30 -0
- package/build/components/NavigationTree/NavigationTree.js +1 -7
- package/build/components/NavigationTree/NavigationTreeDirectory.js +1 -1
- package/build/components/NavigationTree/NavigationTreeNode.js +3 -5
- package/build/components/NavigationTree/i18n/index.js +4 -2
- package/build/components/NavigationTree/state.d.ts +2 -1
- package/build/components/NavigationTree/state.js +11 -8
- package/build/components/NavigationTree/types.d.ts +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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.3.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.2.0...v2.3.0) (2022-07-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **i18n:** add configure function ([c48e58e](https://github.com/ydb-platform/ydb-ui-components/commit/c48e58e33e361cf4f507190cd0a8d0a896975fb1))
|
|
9
|
+
|
|
10
|
+
## [2.2.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.1.0...v2.2.0) (2022-07-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **NavigationTree:** add index and index_table node types! ([d6ed6ba](https://github.com/ydb-platform/ydb-ui-components/commit/d6ed6bae7e882a6217d4205f931ac3704b8ed9f6))
|
|
16
|
+
|
|
17
|
+
## [2.1.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.2...v2.1.0) (2022-06-28)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **NavigationTree:** explicitly specify expandable nodes ([1791d59](https://github.com/ydb-platform/ydb-ui-components/commit/1791d59d4ed5b27050fdbd9c29500c4fe916f631))
|
|
23
|
+
|
|
3
24
|
### [2.0.2](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.1...v2.0.2) (2022-05-30)
|
|
4
25
|
|
|
5
26
|
|
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
|
+
```
|
|
@@ -15,12 +15,6 @@ var _NavigationTreeDirectory = require("./NavigationTreeDirectory");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
18
|
function NavigationTree(_ref) {
|
|
25
19
|
let {
|
|
26
20
|
rootState: partialRootState,
|
|
@@ -32,7 +26,7 @@ function NavigationTree(_ref) {
|
|
|
32
26
|
} = _ref;
|
|
33
27
|
|
|
34
28
|
const [state, dispatch] = _react.default.useReducer(_state.reducer, {
|
|
35
|
-
[partialRootState.path]:
|
|
29
|
+
[partialRootState.path]: (0, _state.getNodeState)(partialRootState)
|
|
36
30
|
});
|
|
37
31
|
|
|
38
32
|
const rootState = state[partialRootState.path];
|
|
@@ -76,7 +76,7 @@ function NavigationTreeDirectory(_ref) {
|
|
|
76
76
|
const childPath = `${path}/${childName}`;
|
|
77
77
|
let children;
|
|
78
78
|
|
|
79
|
-
if (state[childPath].
|
|
79
|
+
if (state[childPath].expandable) {
|
|
80
80
|
children = /*#__PURE__*/_react.default.createElement(NavigationTreeDirectory, {
|
|
81
81
|
state: state,
|
|
82
82
|
dispatch: dispatch,
|
|
@@ -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
|
});
|
|
@@ -45,10 +47,6 @@ function renderIcon(type, collapsed) {
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
function isArrowVisible(type) {
|
|
49
|
-
return type === 'database' || type === 'directory';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
50
|
function NavigationTreeNode(_ref) {
|
|
53
51
|
let {
|
|
54
52
|
path,
|
|
@@ -86,7 +84,7 @@ function NavigationTreeNode(_ref) {
|
|
|
86
84
|
collapsed: nodeState.collapsed,
|
|
87
85
|
active: active,
|
|
88
86
|
actions: actions,
|
|
89
|
-
hasArrow:
|
|
87
|
+
hasArrow: nodeState.expandable,
|
|
90
88
|
onClick: handleClick,
|
|
91
89
|
onArrowClick: handleArrowClick
|
|
92
90
|
}, children);
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { NavigationTreeState } from './types';
|
|
1
|
+
import { NavigationTreeNodeState, NavigationTreeNodePartialState, NavigationTreeState } from './types';
|
|
2
2
|
export declare enum NavigationTreeActionType {
|
|
3
3
|
ToggleCollapsed = "toggle-collapsed",
|
|
4
4
|
StartLoading = "start-loading",
|
|
@@ -15,4 +15,5 @@ export declare function getDefaultNodeState(): {
|
|
|
15
15
|
error: boolean;
|
|
16
16
|
children: never[];
|
|
17
17
|
};
|
|
18
|
+
export declare function getNodeState(partialState: NavigationTreeNodePartialState): NavigationTreeNodeState;
|
|
18
19
|
export declare function reducer(state: NavigationTreeState | undefined, action: NavigationTreeAction): NavigationTreeState;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.NavigationTreeActionType = void 0;
|
|
7
7
|
exports.getDefaultNodeState = getDefaultNodeState;
|
|
8
|
+
exports.getNodeState = getNodeState;
|
|
8
9
|
exports.reducer = reducer;
|
|
9
10
|
|
|
10
11
|
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; }
|
|
@@ -32,6 +33,12 @@ function getDefaultNodeState() {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
function getNodeState(partialState) {
|
|
37
|
+
return _objectSpread(_objectSpread({}, getDefaultNodeState()), {}, {
|
|
38
|
+
expandable: partialState.type === 'database' || partialState.type === 'directory'
|
|
39
|
+
}, partialState);
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
function reducer() {
|
|
36
43
|
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
44
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -75,21 +82,17 @@ function reducer() {
|
|
|
75
82
|
for (const item of action.payload.data) {
|
|
76
83
|
var _state$path$collapsed, _state$path;
|
|
77
84
|
|
|
78
|
-
const path = `${action.payload.path}/${item.name}`;
|
|
79
|
-
const name = item.name;
|
|
80
|
-
const type = item.type; // expand the tree according to the active path
|
|
85
|
+
const path = `${action.payload.path}/${item.name}`; // expand the tree according to the active path
|
|
81
86
|
// prioritize the existing state to expand the tree only on first load
|
|
82
87
|
|
|
83
88
|
const {
|
|
84
89
|
activePath = ''
|
|
85
90
|
} = action.payload;
|
|
86
91
|
const 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(`${path}/`);
|
|
87
|
-
newState[path] = _objectSpread(_objectSpread({},
|
|
92
|
+
newState[path] = getNodeState(_objectSpread(_objectSpread({}, item), {}, {
|
|
88
93
|
collapsed,
|
|
89
|
-
path
|
|
90
|
-
|
|
91
|
-
type
|
|
92
|
-
});
|
|
94
|
+
path
|
|
95
|
+
}));
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -1,8 +1,10 @@
|
|
|
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;
|
|
6
|
+
/** determined by type by default */
|
|
7
|
+
expandable?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export interface NavigationTreeState {
|
|
8
10
|
[path: string]: NavigationTreeNodeState;
|
|
@@ -11,14 +13,17 @@ export interface NavigationTreeNodeState {
|
|
|
11
13
|
path: string;
|
|
12
14
|
name: string;
|
|
13
15
|
type: NavigationTreeNodeType;
|
|
16
|
+
/** determined by type by default */
|
|
17
|
+
expandable?: boolean;
|
|
14
18
|
collapsed: boolean;
|
|
15
19
|
loading: boolean;
|
|
16
20
|
loaded: boolean;
|
|
17
21
|
error: boolean;
|
|
18
22
|
children: string[];
|
|
19
23
|
}
|
|
24
|
+
export declare type NavigationTreeNodePartialState = Omit<NavigationTreeNodeState, 'loading' | 'loaded' | 'error' | 'children'>;
|
|
20
25
|
export interface NavigationTreeProps<D = any> {
|
|
21
|
-
rootState:
|
|
26
|
+
rootState: NavigationTreeNodePartialState;
|
|
22
27
|
fetchPath: (path: string) => Promise<NavigationTreeDataItem[]>;
|
|
23
28
|
getActions?: (path: string, type: NavigationTreeNodeType) => DropdownMenuItemMixed<D>[];
|
|
24
29
|
activePath?: string;
|
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");
|