@gravity-ui/dashkit 8.17.1 → 8.17.2

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.
@@ -3,14 +3,21 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
3
3
  constructor(props: any);
4
4
  constructor(props: any, context: any);
5
5
  pluginsRefs: any[];
6
+ sortedLayoutItems: any;
7
+ _memoLayout: any;
8
+ _memoForwardedPluginRef: any[];
9
+ _memoAdjustWidgetLayout: any[];
6
10
  state: {
7
11
  activeTabId: null;
8
12
  indexesOfItemsWithActiveAutoheight: {};
9
13
  };
10
14
  componentDidUpdate(prevProps: any, prevState: any): void;
15
+ getSortedLayoutItems(): any;
16
+ getMemoForwardRefCallback: (refIndex: any) => any;
11
17
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
18
  needSetDefault: any;
13
19
  }) => void;
20
+ getMemoAdjustWidgetLayout: (index: any) => any;
14
21
  onMountChange: (isMounted: any) => void;
15
22
  _inited: boolean | undefined;
16
23
  onBeforeLoad: () => () => void;
@@ -11,10 +11,21 @@ class MobileLayout extends react_1.default.PureComponent {
11
11
  constructor() {
12
12
  super(...arguments);
13
13
  this.pluginsRefs = [];
14
+ this._memoLayout = this.context.layout;
15
+ this._memoForwardedPluginRef = [];
16
+ this._memoAdjustWidgetLayout = [];
14
17
  this.state = {
15
18
  activeTabId: null,
16
19
  indexesOfItemsWithActiveAutoheight: {},
17
20
  };
21
+ this.getMemoForwardRefCallback = (refIndex) => {
22
+ if (!this._memoForwardedPluginRef[refIndex]) {
23
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
24
+ this.pluginsRefs[refIndex] = pluginRef;
25
+ };
26
+ }
27
+ return this._memoForwardedPluginRef[refIndex];
28
+ };
18
29
  this.adjustWidgetLayout = (index, { needSetDefault }) => {
19
30
  if (needSetDefault) {
20
31
  const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
@@ -27,6 +38,12 @@ class MobileLayout extends react_1.default.PureComponent {
27
38
  });
28
39
  }
29
40
  };
41
+ this.getMemoAdjustWidgetLayout = (index) => {
42
+ if (!this._memoAdjustWidgetLayout[index]) {
43
+ this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
44
+ }
45
+ return this._memoAdjustWidgetLayout[index];
46
+ };
30
47
  this.onMountChange = (isMounted) => {
31
48
  var _a, _b, _c, _d, _e, _f;
32
49
  if (isMounted) {
@@ -63,17 +80,23 @@ class MobileLayout extends react_1.default.PureComponent {
63
80
  });
64
81
  }
65
82
  }
83
+ getSortedLayoutItems() {
84
+ if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
85
+ return this.sortedLayoutItems;
86
+ }
87
+ this._memoLayout = this.context.layout;
88
+ const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
89
+ this.sortedLayoutItems = (0, helpers_1.getSortedConfigItems)(this.context.config, hasOrderId);
90
+ return this.sortedLayoutItems;
91
+ }
66
92
  render() {
67
93
  const { config, layout } = this.context;
68
94
  this.pluginsRefs.length = config.items.length;
69
- const hasOrderId = Boolean(config.items.find((item) => item.orderId));
70
- const sortedItems = (0, helpers_1.getSortedConfigItems)(config, hasOrderId);
95
+ const sortedItems = this.getSortedLayoutItems();
71
96
  return (react_1.default.createElement("div", { className: b() }, sortedItems.map((item, index) => {
72
97
  const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
73
98
  return (react_1.default.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
74
- react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
75
- this.pluginsRefs[index] = pluginRef;
76
- }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
99
+ react_1.default.createElement(Item_1.default, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
77
100
  })));
78
101
  }
79
102
  }
@@ -3,14 +3,21 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
3
3
  constructor(props: any);
4
4
  constructor(props: any, context: any);
5
5
  pluginsRefs: any[];
6
+ sortedLayoutItems: any;
7
+ _memoLayout: any;
8
+ _memoForwardedPluginRef: any[];
9
+ _memoAdjustWidgetLayout: any[];
6
10
  state: {
7
11
  activeTabId: null;
8
12
  indexesOfItemsWithActiveAutoheight: {};
9
13
  };
10
14
  componentDidUpdate(prevProps: any, prevState: any): void;
15
+ getSortedLayoutItems(): any;
16
+ getMemoForwardRefCallback: (refIndex: any) => any;
11
17
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
18
  needSetDefault: any;
13
19
  }) => void;
20
+ getMemoAdjustWidgetLayout: (index: any) => any;
14
21
  onMountChange: (isMounted: any) => void;
15
22
  _inited: boolean | undefined;
16
23
  onBeforeLoad: () => () => void;
@@ -9,10 +9,21 @@ class MobileLayout extends React.PureComponent {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this.pluginsRefs = [];
12
+ this._memoLayout = this.context.layout;
13
+ this._memoForwardedPluginRef = [];
14
+ this._memoAdjustWidgetLayout = [];
12
15
  this.state = {
13
16
  activeTabId: null,
14
17
  indexesOfItemsWithActiveAutoheight: {},
15
18
  };
19
+ this.getMemoForwardRefCallback = (refIndex) => {
20
+ if (!this._memoForwardedPluginRef[refIndex]) {
21
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
22
+ this.pluginsRefs[refIndex] = pluginRef;
23
+ };
24
+ }
25
+ return this._memoForwardedPluginRef[refIndex];
26
+ };
16
27
  this.adjustWidgetLayout = (index, { needSetDefault }) => {
17
28
  if (needSetDefault) {
18
29
  const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
@@ -25,6 +36,12 @@ class MobileLayout extends React.PureComponent {
25
36
  });
26
37
  }
27
38
  };
39
+ this.getMemoAdjustWidgetLayout = (index) => {
40
+ if (!this._memoAdjustWidgetLayout[index]) {
41
+ this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
42
+ }
43
+ return this._memoAdjustWidgetLayout[index];
44
+ };
28
45
  this.onMountChange = (isMounted) => {
29
46
  var _a, _b, _c, _d, _e, _f;
30
47
  if (isMounted) {
@@ -61,17 +78,23 @@ class MobileLayout extends React.PureComponent {
61
78
  });
62
79
  }
63
80
  }
81
+ getSortedLayoutItems() {
82
+ if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
83
+ return this.sortedLayoutItems;
84
+ }
85
+ this._memoLayout = this.context.layout;
86
+ const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
87
+ this.sortedLayoutItems = getSortedConfigItems(this.context.config, hasOrderId);
88
+ return this.sortedLayoutItems;
89
+ }
64
90
  render() {
65
91
  const { config, layout } = this.context;
66
92
  this.pluginsRefs.length = config.items.length;
67
- const hasOrderId = Boolean(config.items.find((item) => item.orderId));
68
- const sortedItems = getSortedConfigItems(config, hasOrderId);
93
+ const sortedItems = this.getSortedLayoutItems();
69
94
  return (React.createElement("div", { className: b() }, sortedItems.map((item, index) => {
70
95
  const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
71
96
  return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
72
- React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
73
- this.pluginsRefs[index] = pluginRef;
74
- }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
97
+ React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
75
98
  })));
76
99
  }
77
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.17.1",
3
+ "version": "8.17.2",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {