diff --git a/src/components/OverlayControls/OverlayControls.tsx b/src/components/OverlayControls/OverlayControls.tsx index 39d3ab2..776dae4 100644 --- a/src/components/OverlayControls/OverlayControls.tsx +++ b/src/components/OverlayControls/OverlayControls.tsx @@ -22,7 +22,16 @@ import { } from '../../constants'; import {DashkitOvelayControlsContext} from '../../context/DashKitContext'; import {i18n} from '../../i18n'; -import type {ConfigItem, ConfigLayout, ItemState, PluginBase, StringParams} from '../../shared'; +import { + type ConfigItem, + type ConfigLayout, + type ItemState, + type ItemsStateAndParamsBase, + type PluginBase, + type StringParams, + isItemWithTabs, + resolveItemInnerId, +} from '../../shared'; import {MenuItem, Settings} from '../../typings'; import {cn} from '../../utils/cn'; @@ -77,6 +86,8 @@ type PreparedCopyItemOptionsArg = Pick = PreparedCopyItemOptionsArg & { @@ -87,8 +98,8 @@ type DashKitCtx = React.Context<{ overlayControls?: Record; context: Record; menu: MenuItem[]; + itemsStateAndParams: ItemsStateAndParamsBase; itemsParams: Record; - itemsState: Record; editItem: (item: ConfigItem) => void; removeItem: (id: string) => void; getLayoutItem: (id: string) => ConfigLayout | void; @@ -251,11 +262,11 @@ class OverlayControls extends React.Component { } private renderDropdownMenu(isOnlyOneItem: boolean) { const {view, size, onItemClick} = this.props; - const {menu: contextMenu, itemsParams, itemsState} = this.context; + const {menu: contextMenu, itemsParams, itemsStateAndParams} = this.context; const configItem = this.props.configItem; const itemParams = itemsParams[configItem.id]; - const itemState = itemsState[configItem.id]; + const itemState = itemsStateAndParams[configItem.id]?.state || {}; const menu = contextMenu?.length > 0 ? contextMenu : DEFAULT_DROPDOWN_MENU; @@ -370,6 +381,15 @@ class OverlayControls extends React.Component { const {configItem} = this.props; const correspondedItemLayout = this.context.getLayoutItem(configItem.id); + let targetInnerId; + + if (isItemWithTabs(this.props.configItem)) { + targetInnerId = resolveItemInnerId({ + item: this.props.configItem, + itemsStateAndParams: this.context.itemsStateAndParams, + }); + } + let options: PreparedCopyItemOptions = { timestamp: Date.now(), data: configItem.data, @@ -380,6 +400,8 @@ class OverlayControls extends React.Component { w: correspondedItemLayout!.w, h: correspondedItemLayout!.h, }, + targetId: this.props.configItem.id, + targetInnerId, }; if (typeof this.context.context?.getPreparedCopyItemOptions === 'function') { diff --git a/src/hocs/withContext.js b/src/hocs/withContext.js index c15be22..070e7c4 100644 --- a/src/hocs/withContext.js +++ b/src/hocs/withContext.js @@ -493,20 +493,20 @@ function useMemoStateContext(props) { overlayControls: props.overlayControls, context: props.context, menu: overlayMenuItems, - itemsParams: itemsParams, - itemsState: itemsState, + itemsStateAndParams: props.itemsStateAndParams, + itemsParams, editItem: props.onItemEdit, removeItem: onItemRemove, getLayoutItem: getLayoutItem, }), [ - itemsParams, - itemsState, + props.overlayControls, props.context, + props.itemsStateAndParams, props.onItemEdit, - onItemRemove, - props.overlayControls, overlayMenuItems, + itemsParams, + onItemRemove, getLayoutItem, ], ); diff --git a/src/shared/modules/helpers.ts b/src/shared/modules/helpers.ts index 395a6cc..aad764d 100644 --- a/src/shared/modules/helpers.ts +++ b/src/shared/modules/helpers.ts @@ -184,6 +184,7 @@ export function resolveItemInnerId({ const {id} = item; const stateTabId: string | undefined = (itemsStateAndParams as ItemsStateAndParamsBase)[id] ?.state?.tabId; + const {tabs} = (item as ConfigItemWithTabs).data; if (stateTabId && tabs.some((tab) => tab.id === stateTabId)) { return stateTabId;