@gravity-ui/dashkit 8.16.0 → 8.17.1

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonSize, ButtonView, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import type { ConfigItem, ConfigLayout, ItemState, PluginBase, StringParams } from '../../shared';
3
+ import { type ConfigItem, type ConfigLayout, type ItemState, type ItemsStateAndParamsBase, type PluginBase, type StringParams } from '../../shared';
4
4
  import { MenuItem } from '../../typings';
5
5
  export declare enum OverlayControlsPosition {
6
6
  TopRight = "top_right",
@@ -44,6 +44,8 @@ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults'
44
44
  w: number;
45
45
  h: number;
46
46
  };
47
+ targetId?: string;
48
+ targetInnerId?: string;
47
49
  };
48
50
  export type PreparedCopyItemOptions<C extends object = {}> = PreparedCopyItemOptionsArg & {
49
51
  copyContext?: C;
@@ -52,8 +54,8 @@ type DashKitCtx = React.Context<{
52
54
  overlayControls?: Record<string, OverlayControlItem[]>;
53
55
  context: Record<string, any>;
54
56
  menu: MenuItem[];
57
+ itemsStateAndParams: ItemsStateAndParamsBase;
55
58
  itemsParams: Record<string, StringParams>;
56
- itemsState: Record<string, ItemState>;
57
59
  editItem: (item: ConfigItem) => void;
58
60
  removeItem: (id: string) => void;
59
61
  getLayoutItem: (id: string) => ConfigLayout | void;
@@ -9,6 +9,7 @@ const noop_1 = tslib_1.__importDefault(require("lodash/noop"));
9
9
  const constants_1 = require("../../constants");
10
10
  const DashKitContext_1 = require("../../context/DashKitContext");
11
11
  const i18n_1 = require("../../i18n");
12
+ const shared_1 = require("../../shared");
12
13
  const cn_1 = require("../../utils/cn");
13
14
  const b = (0, cn_1.cn)(constants_1.OVERLAY_CONTROLS_CLASS_NAME);
14
15
  var OverlayControlsPosition;
@@ -81,6 +82,13 @@ class OverlayControls extends react_1.default.Component {
81
82
  var _a, _b, _c;
82
83
  const { configItem } = this.props;
83
84
  const correspondedItemLayout = this.context.getLayoutItem(configItem.id);
85
+ let targetInnerId;
86
+ if ((0, shared_1.isItemWithTabs)(this.props.configItem)) {
87
+ targetInnerId = (0, shared_1.resolveItemInnerId)({
88
+ item: this.props.configItem,
89
+ itemsStateAndParams: this.context.itemsStateAndParams,
90
+ });
91
+ }
84
92
  let options = {
85
93
  timestamp: Date.now(),
86
94
  data: configItem.data,
@@ -91,6 +99,8 @@ class OverlayControls extends react_1.default.Component {
91
99
  w: correspondedItemLayout.w,
92
100
  h: correspondedItemLayout.h,
93
101
  },
102
+ targetId: this.props.configItem.id,
103
+ targetInnerId,
94
104
  };
95
105
  if (typeof ((_a = this.context.context) === null || _a === void 0 ? void 0 : _a.getPreparedCopyItemOptions) === 'function') {
96
106
  options = this.context.context.getPreparedCopyItemOptions(options);
@@ -175,11 +185,12 @@ class OverlayControls extends react_1.default.Component {
175
185
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(constants_1.MenuItems).includes(String(item)));
176
186
  }
177
187
  renderDropdownMenu(isOnlyOneItem) {
188
+ var _a;
178
189
  const { view, size, onItemClick } = this.props;
179
- const { menu: contextMenu, itemsParams, itemsState } = this.context;
190
+ const { menu: contextMenu, itemsParams, itemsStateAndParams } = this.context;
180
191
  const configItem = this.props.configItem;
181
192
  const itemParams = itemsParams[configItem.id];
182
- const itemState = itemsState[configItem.id];
193
+ const itemState = ((_a = itemsStateAndParams[configItem.id]) === null || _a === void 0 ? void 0 : _a.state) || {};
183
194
  const menu = (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.length) > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU;
184
195
  const isDefaultMenu = this.isDefaultMenu(menu);
185
196
  const items = isDefaultMenu
@@ -378,19 +378,19 @@ function useMemoStateContext(props) {
378
378
  overlayControls: props.overlayControls,
379
379
  context: props.context,
380
380
  menu: overlayMenuItems,
381
- itemsParams: itemsParams,
382
- itemsState: itemsState,
381
+ itemsStateAndParams: props.itemsStateAndParams,
382
+ itemsParams,
383
383
  editItem: props.onItemEdit,
384
384
  removeItem: onItemRemove,
385
385
  getLayoutItem: getLayoutItem,
386
386
  }), [
387
- itemsParams,
388
- itemsState,
387
+ props.overlayControls,
389
388
  props.context,
389
+ props.itemsStateAndParams,
390
390
  props.onItemEdit,
391
- onItemRemove,
392
- props.overlayControls,
393
391
  overlayMenuItems,
392
+ itemsParams,
393
+ onItemRemove,
394
394
  getLayoutItem,
395
395
  ]);
396
396
  return { controlsContextValue, dashkitContextValue };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonSize, ButtonView, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import type { ConfigItem, ConfigLayout, ItemState, PluginBase, StringParams } from '../../shared';
3
+ import { type ConfigItem, type ConfigLayout, type ItemState, type ItemsStateAndParamsBase, type PluginBase, type StringParams } from '../../shared';
4
4
  import { MenuItem } from '../../typings';
5
5
  import './OverlayControls.css';
6
6
  export declare enum OverlayControlsPosition {
@@ -45,6 +45,8 @@ type PreparedCopyItemOptionsArg = Pick<ConfigItem, 'data' | 'type' | 'defaults'
45
45
  w: number;
46
46
  h: number;
47
47
  };
48
+ targetId?: string;
49
+ targetInnerId?: string;
48
50
  };
49
51
  export type PreparedCopyItemOptions<C extends object = {}> = PreparedCopyItemOptionsArg & {
50
52
  copyContext?: C;
@@ -53,8 +55,8 @@ type DashKitCtx = React.Context<{
53
55
  overlayControls?: Record<string, OverlayControlItem[]>;
54
56
  context: Record<string, any>;
55
57
  menu: MenuItem[];
58
+ itemsStateAndParams: ItemsStateAndParamsBase;
56
59
  itemsParams: Record<string, StringParams>;
57
- itemsState: Record<string, ItemState>;
58
60
  editItem: (item: ConfigItem) => void;
59
61
  removeItem: (id: string) => void;
60
62
  getLayoutItem: (id: string) => ConfigLayout | void;
@@ -5,6 +5,7 @@ import noop from 'lodash/noop';
5
5
  import { COPIED_WIDGET_STORE_KEY, DRAGGABLE_CANCEL_CLASS_NAME, MenuItems, OVERLAY_CONTROLS_CLASS_NAME, OVERLAY_ICON_SIZE, } from '../../constants';
6
6
  import { DashkitOvelayControlsContext } from '../../context/DashKitContext';
7
7
  import { i18n } from '../../i18n';
8
+ import { isItemWithTabs, resolveItemInnerId, } from '../../shared';
8
9
  import { cn } from '../../utils/cn';
9
10
  import './OverlayControls.css';
10
11
  const b = cn(OVERLAY_CONTROLS_CLASS_NAME);
@@ -78,6 +79,13 @@ class OverlayControls extends React.Component {
78
79
  var _a, _b, _c;
79
80
  const { configItem } = this.props;
80
81
  const correspondedItemLayout = this.context.getLayoutItem(configItem.id);
82
+ let targetInnerId;
83
+ if (isItemWithTabs(this.props.configItem)) {
84
+ targetInnerId = resolveItemInnerId({
85
+ item: this.props.configItem,
86
+ itemsStateAndParams: this.context.itemsStateAndParams,
87
+ });
88
+ }
81
89
  let options = {
82
90
  timestamp: Date.now(),
83
91
  data: configItem.data,
@@ -88,6 +96,8 @@ class OverlayControls extends React.Component {
88
96
  w: correspondedItemLayout.w,
89
97
  h: correspondedItemLayout.h,
90
98
  },
99
+ targetId: this.props.configItem.id,
100
+ targetInnerId,
91
101
  };
92
102
  if (typeof ((_a = this.context.context) === null || _a === void 0 ? void 0 : _a.getPreparedCopyItemOptions) === 'function') {
93
103
  options = this.context.context.getPreparedCopyItemOptions(options);
@@ -172,11 +182,12 @@ class OverlayControls extends React.Component {
172
182
  return menu === null || menu === void 0 ? void 0 : menu.every((item) => Object.values(MenuItems).includes(String(item)));
173
183
  }
174
184
  renderDropdownMenu(isOnlyOneItem) {
185
+ var _a;
175
186
  const { view, size, onItemClick } = this.props;
176
- const { menu: contextMenu, itemsParams, itemsState } = this.context;
187
+ const { menu: contextMenu, itemsParams, itemsStateAndParams } = this.context;
177
188
  const configItem = this.props.configItem;
178
189
  const itemParams = itemsParams[configItem.id];
179
- const itemState = itemsState[configItem.id];
190
+ const itemState = ((_a = itemsStateAndParams[configItem.id]) === null || _a === void 0 ? void 0 : _a.state) || {};
180
191
  const menu = (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.length) > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU;
181
192
  const isDefaultMenu = this.isDefaultMenu(menu);
182
193
  const items = isDefaultMenu
@@ -375,19 +375,19 @@ function useMemoStateContext(props) {
375
375
  overlayControls: props.overlayControls,
376
376
  context: props.context,
377
377
  menu: overlayMenuItems,
378
- itemsParams: itemsParams,
379
- itemsState: itemsState,
378
+ itemsStateAndParams: props.itemsStateAndParams,
379
+ itemsParams,
380
380
  editItem: props.onItemEdit,
381
381
  removeItem: onItemRemove,
382
382
  getLayoutItem: getLayoutItem,
383
383
  }), [
384
- itemsParams,
385
- itemsState,
384
+ props.overlayControls,
386
385
  props.context,
386
+ props.itemsStateAndParams,
387
387
  props.onItemEdit,
388
- onItemRemove,
389
- props.overlayControls,
390
388
  overlayMenuItems,
389
+ itemsParams,
390
+ onItemRemove,
391
391
  getLayoutItem,
392
392
  ]);
393
393
  return { controlsContextValue, dashkitContextValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.16.0",
3
+ "version": "8.17.1",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {