ydb-ui-components 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.1.0...v2.2.0) (2022-07-05)
4
+
5
+
6
+ ### Features
7
+
8
+ * **NavigationTree:** add index and index_table node types! ([d6ed6ba](https://github.com/ydb-platform/ydb-ui-components/commit/d6ed6bae7e882a6217d4205f931ac3704b8ed9f6))
9
+
10
+ ## [2.1.0](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.2...v2.1.0) (2022-06-28)
11
+
12
+
13
+ ### Features
14
+
15
+ * **NavigationTree:** explicitly specify expandable nodes ([1791d59](https://github.com/ydb-platform/ydb-ui-components/commit/1791d59d4ed5b27050fdbd9c29500c4fe916f631))
16
+
17
+ ### [2.0.2](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.1...v2.0.2) (2022-05-30)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * add i18n export ([13a34e0](https://github.com/ydb-platform/ydb-ui-components/commit/13a34e0056a9fa42b5ad02fc41e5323af0ac98e9))
23
+
3
24
  ### [2.0.1](https://github.com/ydb-platform/ydb-ui-components/compare/v2.0.0...v2.0.1) (2022-05-26)
4
25
 
5
26
 
@@ -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]: _objectSpread(_objectSpread({}, (0, _state.getDefaultNodeState)()), partialRootState)
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].type === 'directory') {
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: isArrowVisible(nodeState.type),
87
+ hasArrow: nodeState.expandable,
90
88
  onClick: handleClick,
91
89
  onArrowClick: handleArrowClick
92
90
  }, children);
@@ -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({}, getDefaultNodeState()), {}, {
92
+ newState[path] = getNodeState(_objectSpread(_objectSpread({}, item), {}, {
88
93
  collapsed,
89
- path,
90
- name,
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: Omit<NavigationTreeNodeState, 'loading' | 'loaded' | 'error' | 'children'>;
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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './components/NavigationTree';
2
2
  export * from './components/TreeView';
3
+ export { i18n } from './components/i18n';
package/build/index.js CHANGED
@@ -3,11 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ i18n: true
8
+ };
9
+ Object.defineProperty(exports, "i18n", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _i18n.i18n;
13
+ }
14
+ });
6
15
 
7
16
  var _NavigationTree = require("./components/NavigationTree");
8
17
 
9
18
  Object.keys(_NavigationTree).forEach(function (key) {
10
19
  if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
11
21
  if (key in exports && exports[key] === _NavigationTree[key]) return;
12
22
  Object.defineProperty(exports, key, {
13
23
  enumerable: true,
@@ -21,6 +31,7 @@ var _TreeView = require("./components/TreeView");
21
31
 
22
32
  Object.keys(_TreeView).forEach(function (key) {
23
33
  if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
24
35
  if (key in exports && exports[key] === _TreeView[key]) return;
25
36
  Object.defineProperty(exports, key, {
26
37
  enumerable: true,
@@ -28,4 +39,6 @@ Object.keys(_TreeView).forEach(function (key) {
28
39
  return _TreeView[key];
29
40
  }
30
41
  });
31
- });
42
+ });
43
+
44
+ var _i18n = require("./components/i18n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-ui-components",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",