@gravity-ui/dashkit 8.10.0 → 8.10.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.
@@ -11,6 +11,11 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
11
11
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
12
  needSetDefault: any;
13
13
  }) => void;
14
+ onMountChange: (isMounted: any) => void;
15
+ _inited: boolean | undefined;
16
+ onBeforeLoad: () => () => void;
17
+ _isAsyncItem: boolean | undefined;
18
+ onLoad: () => void;
14
19
  render(): JSX.Element;
15
20
  }
16
21
  import React from 'react';
@@ -27,6 +27,33 @@ class MobileLayout extends react_1.default.PureComponent {
27
27
  });
28
28
  }
29
29
  };
30
+ this.onMountChange = (isMounted) => {
31
+ var _a, _b, _c, _d, _e, _f;
32
+ if (isMounted) {
33
+ this._inited = true;
34
+ (_b = (_a = this.context).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
35
+ isAsync: this._isAsyncItem,
36
+ isMounted: isMounted,
37
+ });
38
+ if (!this._isAsyncItem) {
39
+ (_d = (_c = this.context).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
40
+ }
41
+ }
42
+ else {
43
+ (_f = (_e = this.context).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
44
+ isAsync: this._isAsyncItem,
45
+ isMounted: isMounted,
46
+ });
47
+ }
48
+ };
49
+ this.onBeforeLoad = () => {
50
+ this._isAsyncItem = true;
51
+ return this.onLoad;
52
+ };
53
+ this.onLoad = () => {
54
+ var _a, _b;
55
+ (_b = (_a = this.context).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
56
+ };
30
57
  }
31
58
  componentDidUpdate(prevProps, prevState) {
32
59
  if (prevState.activeTabId !== this.context.config.id) {
@@ -46,7 +73,7 @@ class MobileLayout extends react_1.default.PureComponent {
46
73
  return (react_1.default.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
47
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) => {
48
75
  this.pluginsRefs[index] = pluginRef;
49
- } })));
76
+ }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
50
77
  })));
51
78
  }
52
79
  }
@@ -7,8 +7,8 @@ export declare const useCalcPropsLayout: (config: Config, registerManager: Regis
7
7
  x: number;
8
8
  y: number;
9
9
  parent?: string | undefined;
10
- minW: number;
11
- minH: number;
10
+ minW?: number | undefined;
11
+ minH?: number | undefined;
12
12
  maxW?: number | undefined;
13
13
  maxH?: number | undefined;
14
14
  }[];
@@ -9,10 +9,9 @@ export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
9
9
  export type SetConfigItem = ConfigItem | AddConfigItem;
10
10
  export type SetItemOptions = {
11
11
  excludeIds?: string[];
12
- };
13
- export type SetNewItemOptions = SetItemOptions & {
14
12
  updateLayout?: ConfigLayout[];
15
13
  };
14
+ export type SetNewItemOptions = SetItemOptions;
16
15
  export interface DashkitGroupRenderProps {
17
16
  config: Config;
18
17
  editMode: boolean;
@@ -188,6 +188,104 @@ beforeEach(() => {
188
188
  jest.spyOn(console, 'warn').mockImplementation(jest.fn());
189
189
  });
190
190
  describe('UpdateManager', () => {
191
+ describe('addItem', () => {
192
+ it('add new item', () => {
193
+ expect(update_manager_1.UpdateManager.addItem({
194
+ item: {
195
+ data: {},
196
+ type: 'widget',
197
+ },
198
+ namespace: 'default',
199
+ layout: { h: 4, w: 4, x: 0, y: 0 },
200
+ config: config,
201
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 15, items: [
202
+ ...config.items,
203
+ {
204
+ id: 'EZ',
205
+ data: {},
206
+ type: 'widget',
207
+ namespace: 'default',
208
+ },
209
+ ], layout: [...config.layout, { h: 4, w: 4, x: 0, y: 32, i: 'EZ' }] }));
210
+ });
211
+ it('add new item excludeIds', () => {
212
+ expect(update_manager_1.UpdateManager.addItem({
213
+ item: {
214
+ data: {},
215
+ type: 'widget',
216
+ },
217
+ namespace: 'default',
218
+ layout: { h: 4, w: 4, x: 0, y: 0 },
219
+ config: config,
220
+ options: {
221
+ excludeIds: ['EZ'],
222
+ },
223
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 16, items: [
224
+ ...config.items,
225
+ {
226
+ id: '1n',
227
+ data: {},
228
+ type: 'widget',
229
+ namespace: 'default',
230
+ },
231
+ ], layout: [...config.layout, { h: 4, w: 4, x: 0, y: 32, i: '1n' }] }));
232
+ });
233
+ it('add new item with layout update', () => {
234
+ const updateLayout = [
235
+ { h: 4, i: 'al', w: 4, x: 8, y: 4 },
236
+ { h: 16, i: 'Q8', w: 12, x: 12, y: 4 },
237
+ { h: 2, i: 'L5', w: 8, x: 0, y: 6 },
238
+ { h: 2, i: 'C8', w: 8, x: 10, y: 34 },
239
+ { h: 2, i: 'lko', w: 8, x: 0, y: 16 },
240
+ { h: 2, i: 'qY', w: 8, x: 0, y: 28 },
241
+ ];
242
+ expect(update_manager_1.UpdateManager.addItem({
243
+ item: {
244
+ data: {},
245
+ type: 'widget',
246
+ },
247
+ namespace: 'default',
248
+ layout: { h: 4, w: 12, x: 0, y: 0 },
249
+ config: config,
250
+ options: {
251
+ updateLayout,
252
+ },
253
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 15, items: [
254
+ ...config.items,
255
+ {
256
+ id: 'EZ',
257
+ data: {},
258
+ type: 'widget',
259
+ namespace: 'default',
260
+ },
261
+ ], layout: [...updateLayout, { h: 4, w: 12, x: 0, y: 0, i: 'EZ' }] }));
262
+ });
263
+ });
264
+ describe('removeItem', () => {
265
+ it('remove item by id', () => {
266
+ const deleteId = 'lko';
267
+ expect(update_manager_1.UpdateManager.removeItem({ id: deleteId, config, itemsStateAndParams: {} })).toEqual({
268
+ config: Object.assign(Object.assign({}, config), { items: config.items.filter(({ id }) => id !== deleteId), layout: config.layout.filter(({ i }) => i !== deleteId) }),
269
+ itemsStateAndParams: {
270
+ __meta__: { queue: [], version: 2 },
271
+ },
272
+ });
273
+ });
274
+ it('remove item when items and layout not sorted', () => {
275
+ const deleteId = 'lko';
276
+ const configCopy = Object.assign(Object.assign({}, config), { layout: config.layout.reverse() });
277
+ expect(update_manager_1.UpdateManager.removeItem({
278
+ id: deleteId,
279
+ config: configCopy,
280
+ itemsStateAndParams: {},
281
+ })).toEqual({
282
+ config: Object.assign(Object.assign({}, config), { items: config.items.filter(({ id }) => id !== deleteId), layout: config.layout.filter(({ i }) => i !== deleteId) }),
283
+ itemsStateAndParams: {
284
+ __meta__: { queue: [], version: 2 },
285
+ },
286
+ });
287
+ });
288
+ });
191
289
  describe('changeStateAndParams', () => {
192
290
  it('control adds params to empty itemsStateAndParams: common control', () => {
193
291
  expect(update_manager_1.UpdateManager.changeStateAndParams({
@@ -5,8 +5,8 @@ interface RegisterManagerDefaultLayout {
5
5
  y: number;
6
6
  w: number;
7
7
  h: number;
8
- minW: number;
9
- minH: number;
8
+ minW?: number;
9
+ minH?: number;
10
10
  }
11
11
  export type RegisterManagerPluginLayout = RegisterManagerDefaultLayout & PluginDefaultLayout;
12
12
  export interface RegisterManagerPlugin extends Omit<Plugin, 'defaultLayout'> {
@@ -26,13 +26,13 @@ export declare class UpdateManager {
26
26
  namespace: string;
27
27
  layout: RegisterManagerPluginLayout;
28
28
  config: Config;
29
- options: SetNewItemOptions;
29
+ options?: SetNewItemOptions;
30
30
  }): Config;
31
31
  static editItem({ item, namespace, config, options, }: {
32
32
  item: ConfigItem;
33
33
  namespace: string;
34
34
  config: Config;
35
- options: SetItemOptions;
35
+ options?: SetItemOptions;
36
36
  }): Config;
37
37
  static removeItem({ id, config, itemsStateAndParams }: RemoveItemArg): {
38
38
  config: Config;
@@ -227,7 +227,7 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
227
227
  return (0, immutability_helper_1.default)(itemsStateAndParams, obj);
228
228
  }
229
229
  class UpdateManager {
230
- static addItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, layout, config, options, }) {
230
+ static addItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, layout, config, options = {}, }) {
231
231
  const salt = config.salt;
232
232
  const newItemData = getNewItemData({ item, config, salt, counter: config.counter, options });
233
233
  let counter = newItemData.counter;
@@ -260,7 +260,7 @@ class UpdateManager {
260
260
  });
261
261
  }
262
262
  }
263
- static editItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, config, options, }) {
263
+ static editItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, config, options = {}, }) {
264
264
  const itemIndex = config.items.findIndex(({ id }) => item.id === id);
265
265
  const { counter, data } = getNewItemData({
266
266
  item,
@@ -279,6 +279,7 @@ class UpdateManager {
279
279
  return removeItemVersion1({ id, config, itemsStateAndParams });
280
280
  }
281
281
  const itemIndex = config.items.findIndex((item) => item.id === id);
282
+ const layoutIndex = config.layout.findIndex((item) => item.i === id);
282
283
  const item = config.items[itemIndex];
283
284
  let itemIds = [id];
284
285
  if ((0, shared_1.isItemWithTabs)(item)) {
@@ -294,7 +295,7 @@ class UpdateManager {
294
295
  $splice: [[itemIndex, 1]],
295
296
  },
296
297
  layout: {
297
- $splice: [[itemIndex, 1]],
298
+ $splice: [[layoutIndex, 1]],
298
299
  },
299
300
  connections: {
300
301
  $set: connections,
@@ -11,6 +11,11 @@ export default class MobileLayout extends React.PureComponent<any, any, any> {
11
11
  adjustWidgetLayout: (index: any, { needSetDefault }: {
12
12
  needSetDefault: any;
13
13
  }) => void;
14
+ onMountChange: (isMounted: any) => void;
15
+ _inited: boolean | undefined;
16
+ onBeforeLoad: () => () => void;
17
+ _isAsyncItem: boolean | undefined;
18
+ onLoad: () => void;
14
19
  render(): JSX.Element;
15
20
  }
16
21
  import React from 'react';
@@ -25,6 +25,33 @@ class MobileLayout extends React.PureComponent {
25
25
  });
26
26
  }
27
27
  };
28
+ this.onMountChange = (isMounted) => {
29
+ var _a, _b, _c, _d, _e, _f;
30
+ if (isMounted) {
31
+ this._inited = true;
32
+ (_b = (_a = this.context).onItemMountChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item, {
33
+ isAsync: this._isAsyncItem,
34
+ isMounted: isMounted,
35
+ });
36
+ if (!this._isAsyncItem) {
37
+ (_d = (_c = this.context).onItemRender) === null || _d === void 0 ? void 0 : _d.call(_c, this.props.item);
38
+ }
39
+ }
40
+ else {
41
+ (_f = (_e = this.context).onItemMountChange) === null || _f === void 0 ? void 0 : _f.call(_e, this.props.item, {
42
+ isAsync: this._isAsyncItem,
43
+ isMounted: isMounted,
44
+ });
45
+ }
46
+ };
47
+ this.onBeforeLoad = () => {
48
+ this._isAsyncItem = true;
49
+ return this.onLoad;
50
+ };
51
+ this.onLoad = () => {
52
+ var _a, _b;
53
+ (_b = (_a = this.context).onItemRender) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
54
+ };
28
55
  }
29
56
  componentDidUpdate(prevProps, prevState) {
30
57
  if (prevState.activeTabId !== this.context.config.id) {
@@ -44,7 +71,7 @@ class MobileLayout extends React.PureComponent {
44
71
  return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
45
72
  React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.adjustWidgetLayout.bind(this, index), forwardedPluginRef: (pluginRef) => {
46
73
  this.pluginsRefs[index] = pluginRef;
47
- } })));
74
+ }, onMountChange: this.onMountChange, onBeforeLoad: this.onBeforeLoad })));
48
75
  })));
49
76
  }
50
77
  }
@@ -7,8 +7,8 @@ export declare const useCalcPropsLayout: (config: Config, registerManager: Regis
7
7
  x: number;
8
8
  y: number;
9
9
  parent?: string | undefined;
10
- minW: number;
11
- minH: number;
10
+ minW?: number | undefined;
11
+ minH?: number | undefined;
12
12
  maxW?: number | undefined;
13
13
  maxH?: number | undefined;
14
14
  }[];
@@ -9,10 +9,9 @@ export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
9
9
  export type SetConfigItem = ConfigItem | AddConfigItem;
10
10
  export type SetItemOptions = {
11
11
  excludeIds?: string[];
12
- };
13
- export type SetNewItemOptions = SetItemOptions & {
14
12
  updateLayout?: ConfigLayout[];
15
13
  };
14
+ export type SetNewItemOptions = SetItemOptions;
16
15
  export interface DashkitGroupRenderProps {
17
16
  config: Config;
18
17
  editMode: boolean;
@@ -186,6 +186,104 @@ beforeEach(() => {
186
186
  jest.spyOn(console, 'warn').mockImplementation(jest.fn());
187
187
  });
188
188
  describe('UpdateManager', () => {
189
+ describe('addItem', () => {
190
+ it('add new item', () => {
191
+ expect(UpdateManager.addItem({
192
+ item: {
193
+ data: {},
194
+ type: 'widget',
195
+ },
196
+ namespace: 'default',
197
+ layout: { h: 4, w: 4, x: 0, y: 0 },
198
+ config: config,
199
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 15, items: [
200
+ ...config.items,
201
+ {
202
+ id: 'EZ',
203
+ data: {},
204
+ type: 'widget',
205
+ namespace: 'default',
206
+ },
207
+ ], layout: [...config.layout, { h: 4, w: 4, x: 0, y: 32, i: 'EZ' }] }));
208
+ });
209
+ it('add new item excludeIds', () => {
210
+ expect(UpdateManager.addItem({
211
+ item: {
212
+ data: {},
213
+ type: 'widget',
214
+ },
215
+ namespace: 'default',
216
+ layout: { h: 4, w: 4, x: 0, y: 0 },
217
+ config: config,
218
+ options: {
219
+ excludeIds: ['EZ'],
220
+ },
221
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 16, items: [
222
+ ...config.items,
223
+ {
224
+ id: '1n',
225
+ data: {},
226
+ type: 'widget',
227
+ namespace: 'default',
228
+ },
229
+ ], layout: [...config.layout, { h: 4, w: 4, x: 0, y: 32, i: '1n' }] }));
230
+ });
231
+ it('add new item with layout update', () => {
232
+ const updateLayout = [
233
+ { h: 4, i: 'al', w: 4, x: 8, y: 4 },
234
+ { h: 16, i: 'Q8', w: 12, x: 12, y: 4 },
235
+ { h: 2, i: 'L5', w: 8, x: 0, y: 6 },
236
+ { h: 2, i: 'C8', w: 8, x: 10, y: 34 },
237
+ { h: 2, i: 'lko', w: 8, x: 0, y: 16 },
238
+ { h: 2, i: 'qY', w: 8, x: 0, y: 28 },
239
+ ];
240
+ expect(UpdateManager.addItem({
241
+ item: {
242
+ data: {},
243
+ type: 'widget',
244
+ },
245
+ namespace: 'default',
246
+ layout: { h: 4, w: 12, x: 0, y: 0 },
247
+ config: config,
248
+ options: {
249
+ updateLayout,
250
+ },
251
+ })).toEqual(Object.assign(Object.assign({}, config), { salt: '0.09852189776033704', counter: 15, items: [
252
+ ...config.items,
253
+ {
254
+ id: 'EZ',
255
+ data: {},
256
+ type: 'widget',
257
+ namespace: 'default',
258
+ },
259
+ ], layout: [...updateLayout, { h: 4, w: 12, x: 0, y: 0, i: 'EZ' }] }));
260
+ });
261
+ });
262
+ describe('removeItem', () => {
263
+ it('remove item by id', () => {
264
+ const deleteId = 'lko';
265
+ expect(UpdateManager.removeItem({ id: deleteId, config, itemsStateAndParams: {} })).toEqual({
266
+ config: Object.assign(Object.assign({}, config), { items: config.items.filter(({ id }) => id !== deleteId), layout: config.layout.filter(({ i }) => i !== deleteId) }),
267
+ itemsStateAndParams: {
268
+ __meta__: { queue: [], version: 2 },
269
+ },
270
+ });
271
+ });
272
+ it('remove item when items and layout not sorted', () => {
273
+ const deleteId = 'lko';
274
+ const configCopy = Object.assign(Object.assign({}, config), { layout: config.layout.reverse() });
275
+ expect(UpdateManager.removeItem({
276
+ id: deleteId,
277
+ config: configCopy,
278
+ itemsStateAndParams: {},
279
+ })).toEqual({
280
+ config: Object.assign(Object.assign({}, config), { items: config.items.filter(({ id }) => id !== deleteId), layout: config.layout.filter(({ i }) => i !== deleteId) }),
281
+ itemsStateAndParams: {
282
+ __meta__: { queue: [], version: 2 },
283
+ },
284
+ });
285
+ });
286
+ });
189
287
  describe('changeStateAndParams', () => {
190
288
  it('control adds params to empty itemsStateAndParams: common control', () => {
191
289
  expect(UpdateManager.changeStateAndParams({
@@ -5,8 +5,8 @@ interface RegisterManagerDefaultLayout {
5
5
  y: number;
6
6
  w: number;
7
7
  h: number;
8
- minW: number;
9
- minH: number;
8
+ minW?: number;
9
+ minH?: number;
10
10
  }
11
11
  export type RegisterManagerPluginLayout = RegisterManagerDefaultLayout & PluginDefaultLayout;
12
12
  export interface RegisterManagerPlugin extends Omit<Plugin, 'defaultLayout'> {
@@ -26,13 +26,13 @@ export declare class UpdateManager {
26
26
  namespace: string;
27
27
  layout: RegisterManagerPluginLayout;
28
28
  config: Config;
29
- options: SetNewItemOptions;
29
+ options?: SetNewItemOptions;
30
30
  }): Config;
31
31
  static editItem({ item, namespace, config, options, }: {
32
32
  item: ConfigItem;
33
33
  namespace: string;
34
34
  config: Config;
35
- options: SetItemOptions;
35
+ options?: SetItemOptions;
36
36
  }): Config;
37
37
  static removeItem({ id, config, itemsStateAndParams }: RemoveItemArg): {
38
38
  config: Config;
@@ -222,7 +222,7 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
222
222
  return update(itemsStateAndParams, obj);
223
223
  }
224
224
  export class UpdateManager {
225
- static addItem({ item, namespace = DEFAULT_NAMESPACE, layout, config, options, }) {
225
+ static addItem({ item, namespace = DEFAULT_NAMESPACE, layout, config, options = {}, }) {
226
226
  const salt = config.salt;
227
227
  const newItemData = getNewItemData({ item, config, salt, counter: config.counter, options });
228
228
  let counter = newItemData.counter;
@@ -255,7 +255,7 @@ export class UpdateManager {
255
255
  });
256
256
  }
257
257
  }
258
- static editItem({ item, namespace = DEFAULT_NAMESPACE, config, options, }) {
258
+ static editItem({ item, namespace = DEFAULT_NAMESPACE, config, options = {}, }) {
259
259
  const itemIndex = config.items.findIndex(({ id }) => item.id === id);
260
260
  const { counter, data } = getNewItemData({
261
261
  item,
@@ -274,6 +274,7 @@ export class UpdateManager {
274
274
  return removeItemVersion1({ id, config, itemsStateAndParams });
275
275
  }
276
276
  const itemIndex = config.items.findIndex((item) => item.id === id);
277
+ const layoutIndex = config.layout.findIndex((item) => item.i === id);
277
278
  const item = config.items[itemIndex];
278
279
  let itemIds = [id];
279
280
  if (isItemWithTabs(item)) {
@@ -289,7 +290,7 @@ export class UpdateManager {
289
290
  $splice: [[itemIndex, 1]],
290
291
  },
291
292
  layout: {
292
- $splice: [[itemIndex, 1]],
293
+ $splice: [[layoutIndex, 1]],
293
294
  },
294
295
  connections: {
295
296
  $set: connections,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.10.0",
3
+ "version": "8.10.2",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {