ydb-ui-components 1.1.3 → 1.2.3

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,33 @@
1
1
  # Changelog
2
2
 
3
+ ### [1.2.3](https://github.com/ydb-platform/ydb-ui-components/compare/v1.2.2...v1.2.3) (2022-05-23)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **NavigationTree:** expand tree to initial active path ([6a84dfb](https://github.com/ydb-platform/ydb-ui-components/commit/6a84dfb8b89f8411bd5b11f7b18582ed547c6d0d))
9
+
10
+ ### [1.2.2](https://github.com/ydb-platform/ydb-ui-components/compare/v1.2.1...v1.2.2) (2022-05-23)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * add missing index file for TreeView ([7496d9b](https://github.com/ydb-platform/ydb-ui-components/commit/7496d9b7074d6ee5c2f280030ca38cc9373b0f34))
16
+
17
+ ### [1.2.1](https://github.com/ydb-platform/ydb-ui-components/compare/v1.2.0...v1.2.1) (2022-05-23)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * add missing component export ([9b71eb7](https://github.com/ydb-platform/ydb-ui-components/commit/9b71eb78f8c2adfd773e45edddc41ea97c64aa35))
23
+
24
+ ## [1.2.0](https://github.com/ydb-platform/ydb-ui-components/compare/v1.1.3...v1.2.0) (2022-05-23)
25
+
26
+
27
+ ### Features
28
+
29
+ * a param to always refetch nodes data ([6cee325](https://github.com/ydb-platform/ydb-ui-components/commit/6cee32581d0a16ecc8bb742eb8f2c27d2d9a1cad))
30
+
3
31
  ### [1.1.3](https://github.com/ydb-platform/ydb-ui-components/compare/v1.1.2...v1.1.3) (2022-05-23)
4
32
 
5
33
 
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import { NavigationTreeProps } from './types';
3
3
  export type { NavigationTreeProps };
4
- export declare function NavigationTree({ rootState: partialRootState, fetchPath, getActions, activePath, onActivePathUpdate, }: NavigationTreeProps): JSX.Element;
4
+ export declare function NavigationTree({ rootState: partialRootState, fetchPath, getActions, activePath, onActivePathUpdate, cache, }: NavigationTreeProps): JSX.Element;
@@ -27,7 +27,8 @@ function NavigationTree(_ref) {
27
27
  fetchPath,
28
28
  getActions,
29
29
  activePath,
30
- onActivePathUpdate
30
+ onActivePathUpdate,
31
+ cache = true
31
32
  } = _ref;
32
33
 
33
34
  const [state, dispatch] = _react.default.useReducer(_state.reducer, {
@@ -49,6 +50,7 @@ function NavigationTree(_ref) {
49
50
  fetchPath: fetchPath,
50
51
  activePath: activePath,
51
52
  onItemActivate: onActivePathUpdate,
52
- getActions: getActions
53
+ getActions: getActions,
54
+ cache: cache
53
55
  }));
54
56
  }
@@ -9,5 +9,6 @@ export interface NavigationTreeDirectoryProps {
9
9
  activePath?: string;
10
10
  onItemActivate?: (itemPath: string) => void;
11
11
  getActions?: NavigationTreeProps['getActions'];
12
+ cache?: boolean;
12
13
  }
13
- export declare function NavigationTreeDirectory({ state, dispatch, path, fetchPath, activePath, onItemActivate, getActions, }: NavigationTreeDirectoryProps): JSX.Element;
14
+ export declare function NavigationTreeDirectory({ state, dispatch, path, fetchPath, activePath, onItemActivate, getActions, cache, }: NavigationTreeDirectoryProps): JSX.Element;
@@ -27,36 +27,40 @@ function NavigationTreeDirectory(_ref) {
27
27
  fetchPath,
28
28
  activePath,
29
29
  onItemActivate,
30
- getActions
30
+ getActions,
31
+ cache
31
32
  } = _ref;
32
33
  const nodeState = state[path];
33
34
 
34
35
  _react.default.useEffect(() => {
35
- if (!nodeState.loaded && !nodeState.loading) {
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 => {
36
47
  dispatch({
37
- type: _state.NavigationTreeActionType.StartLoading,
48
+ type: _state.NavigationTreeActionType.FinishLoading,
38
49
  payload: {
39
- path
50
+ path,
51
+ activePath,
52
+ data
40
53
  }
41
54
  });
42
- fetchPath(path).then(data => {
43
- dispatch({
44
- type: _state.NavigationTreeActionType.FinishLoading,
45
- payload: {
46
- path,
47
- data
48
- }
49
- });
50
- }).catch(error => {
51
- dispatch({
52
- type: _state.NavigationTreeActionType.FinishLoading,
53
- payload: {
54
- path,
55
- error
56
- }
57
- });
55
+ }).catch(error => {
56
+ dispatch({
57
+ type: _state.NavigationTreeActionType.FinishLoading,
58
+ payload: {
59
+ path,
60
+ error
61
+ }
58
62
  });
59
- }
63
+ });
60
64
  }, []);
61
65
 
62
66
  if (nodeState.loading) {
@@ -80,7 +84,8 @@ function NavigationTreeDirectory(_ref) {
80
84
  fetchPath: fetchPath,
81
85
  activePath: activePath,
82
86
  onItemActivate: onItemActivate,
83
- getActions: getActions
87
+ getActions: getActions,
88
+ cache: cache
84
89
  });
85
90
  }
86
91
 
@@ -49,7 +49,8 @@ function reducer() {
49
49
  [action.payload.path]: _objectSpread(_objectSpread({}, state[action.payload.path]), {}, {
50
50
  loading: true,
51
51
  loaded: false,
52
- error: false
52
+ error: false,
53
+ children: []
53
54
  })
54
55
  });
55
56
 
@@ -72,10 +73,19 @@ function reducer() {
72
73
  });
73
74
 
74
75
  for (const item of action.payload.data) {
76
+ var _state$path$collapsed, _state$path;
77
+
75
78
  const path = `${action.payload.path}/${item.name}`;
76
79
  const name = item.name;
77
- const type = item.type;
80
+ const type = item.type; // expand the tree according to the active path
81
+ // prioritize the existing state to expand the tree only on first load
82
+
83
+ const {
84
+ activePath = ''
85
+ } = action.payload;
86
+ 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}/`);
78
87
  newState[path] = _objectSpread(_objectSpread({}, getDefaultNodeState()), {}, {
88
+ collapsed,
79
89
  path,
80
90
  name,
81
91
  type
@@ -23,4 +23,5 @@ export interface NavigationTreeProps<D = any> {
23
23
  getActions?: (path: string, type: NavigationTreeNodeType) => DropdownMenuItemMixed<D>[];
24
24
  activePath?: string;
25
25
  onActivePathUpdate?: (activePath: string) => void;
26
+ cache?: boolean;
26
27
  }
@@ -0,0 +1 @@
1
+ export * from './TreeView';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _TreeView = require("./TreeView");
8
+
9
+ Object.keys(_TreeView).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _TreeView[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _TreeView[key];
16
+ }
17
+ });
18
+ });
package/build/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './components/NavigationTree';
2
+ export * from './components/TreeView';
package/build/index.js CHANGED
@@ -15,4 +15,17 @@ Object.keys(_NavigationTree).forEach(function (key) {
15
15
  return _NavigationTree[key];
16
16
  }
17
17
  });
18
+ });
19
+
20
+ var _TreeView = require("./components/TreeView");
21
+
22
+ Object.keys(_TreeView).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _TreeView[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _TreeView[key];
29
+ }
30
+ });
18
31
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-ui-components",
3
- "version": "1.1.3",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",