Skip to content

Commit

Permalink
fix: add dnd context in dashkit with groups if there is no dnd wreppe…
Browse files Browse the repository at this point in the history
…r presented
  • Loading branch information
flops committed Dec 5, 2024
1 parent 13676f8 commit 15e0b6b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/DashKit/DashKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import noop from 'lodash/noop';
import pick from 'lodash/pick';

import {DEFAULT_GROUP, DEFAULT_NAMESPACE} from '../../constants';
import {DashKitDnDContext} from '../../context/DashKitContext';
import type {
Config,
ConfigItem,
Expand All @@ -27,6 +28,7 @@ import {
SettingsProps,
} from '../../typings';
import {RegisterManager, UpdateManager, reflowLayout} from '../../utils';
import {DashKitDnDWrapper} from '../DashKitDnDWrapper/DashKitDnDWrapper';
import DashKitView from '../DashKitView/DashKitView';
import GridLayout from '../GridLayout/GridLayout';
import {OverlayControlItem, OverlayControlsCtxShape} from '../OverlayControls/OverlayControls';
Expand Down Expand Up @@ -97,7 +99,7 @@ const getReflowGroupsConfig = (groups: DashKitGroup[] = []) => {
};
};

export class DashKit extends React.PureComponent<DashKitInnerProps> {
export class DashKit extends React.Component<DashKitInnerProps> {
static defaultProps: DashKitDefaultProps = {
onItemEdit: noop,
onChange: noop,
Expand All @@ -114,6 +116,8 @@ export class DashKit extends React.PureComponent<DashKitInnerProps> {
focusable: false,
};

static contextType = DashKitDnDContext;

static registerPlugins(...plugins: Plugin[]) {
plugins.forEach((plugin) => {
registerManager.registerPlugin(plugin);
Expand Down Expand Up @@ -204,7 +208,15 @@ export class DashKit extends React.PureComponent<DashKitInnerProps> {
metaRef = React.createRef<GridLayout>();

render() {
return <DashKitView registerManager={registerManager} ref={this.metaRef} {...this.props} />;
const content = (
<DashKitView registerManager={registerManager} ref={this.metaRef} {...this.props} />
);

if (!this.context && this.props.groups) {
return <DashKitDnDWrapper>{content}</DashKitDnDWrapper>;
}

return content;
}

getItemsMeta() {
Expand Down

0 comments on commit 15e0b6b

Please sign in to comment.