Skip to content

Commit

Permalink
feat: pass gridLayout setting for each group (#220)
Browse files Browse the repository at this point in the history
* feat: pass gridLayout setting for each group

* fix: added deep check for gridLayout item prop
  • Loading branch information
flops authored Nov 21, 2024
1 parent af61e22 commit f148978
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export const DashKitGroupsShowcase: React.FC = () => {
[config],
);

const context = React.useMemo(
() => ({editModeHeader: headerInteractions}),
[headerInteractions],
);

return (
<DashKitDnDWrapper
onDragStart={() => {
Expand Down Expand Up @@ -328,7 +333,7 @@ export const DashKitGroupsShowcase: React.FC = () => {
overlayMenuItems={overlayMenuItems}
onDragStart={updateConfigOrder}
onResizeStart={updateConfigOrder}
context={{editModeHeader: headerInteractions}}
context={context}
/>
<ActionPanel items={items} />
</DemoRow>
Expand Down
2 changes: 2 additions & 0 deletions src/components/GridItem/GridItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const windowFocusObserver = new WindowFocusObserver();
class GridItem extends React.PureComponent {
static propTypes = {
adjustWidgetLayout: PropTypes.func.isRequired,
gridLayout: PropTypes.object,
id: PropTypes.string,
item: PropTypes.object,
isDragging: PropTypes.bool,
Expand Down Expand Up @@ -222,6 +223,7 @@ class GridItem extends React.PureComponent {
forwardedPluginRef={this.props.forwardedPluginRef}
onItemMountChange={this.props.onItemMountChange}
onItemRender={this.props.onItemRender}
gridLayout={this.props.gridLayout}
/>
</div>
{!noOverlay && this.renderOverlay()}
Expand Down
6 changes: 4 additions & 2 deletions src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export default class GridLayout extends React.PureComponent {
return false;
};

renderTemporaryPlaceholder() {
renderTemporaryPlaceholder(gridLayout) {
const {temporaryLayout, noOverlay, draggableHandleClassName} = this.context;

if (!temporaryLayout || !temporaryLayout.dragProps) {
Expand All @@ -572,6 +572,7 @@ export default class GridLayout extends React.PureComponent {
isPlaceholder={true}
noOverlay={noOverlay}
withCustomHandle={Boolean(draggableHandleClassName)}
gridLayout={gridLayout}
/>
);
}
Expand Down Expand Up @@ -662,10 +663,11 @@ export default class GridLayout extends React.PureComponent {
withCustomHandle={Boolean(draggableHandleClassName)}
onItemMountChange={onItemMountChange}
onItemRender={onItemRender}
gridLayout={properties}
/>
);
})}
{this.renderTemporaryPlaceholder()}
{this.renderTemporaryPlaceholder(properties)}
</Layout>
);
}
Expand Down
18 changes: 13 additions & 5 deletions src/hocs/prepareItem.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';

import isEqual from 'lodash/isEqual';
import PropTypes from 'prop-types';

import {DashKitContext} from '../context/DashKitContext';

export function prepareItem(Component) {
return class PrepareItem extends React.Component {
static propTypes = {
gridLayout: PropTypes.object,
adjustWidgetLayout: PropTypes.func.isRequired,
layout: PropTypes.array,
id: PropTypes.string,
Expand Down Expand Up @@ -45,7 +47,8 @@ export function prepareItem(Component) {

_currentRenderProps = {};
getRenderProps = () => {
const {id, width, height, item, adjustWidgetLayout, layout, isPlaceholder} = this.props;
const {id, width, height, item, adjustWidgetLayout, layout, isPlaceholder, gridLayout} =
this.props;
const {itemsState, itemsParams, registerManager, settings, context, editMode} =
this.context;
const {data, defaults, namespace} = item;
Expand All @@ -64,14 +67,19 @@ export function prepareItem(Component) {
settings,
context,
layout,
gridLayout: registerManager.gridLayout,
gridLayout: gridLayout || registerManager.gridLayout,
adjustWidgetLayout,
isPlaceholder,
};

const changedProp = Object.entries(rendererProps).find(
([key, value]) => this._currentRenderProps[key] !== value,
);
const changedProp = Object.entries(rendererProps).find(([key, value]) => {
// Checking gridLayoout deep as groups gridProperties method has tendancy to creat new objects
if (key === 'gridLayout') {
return !isEqual(this._currentRenderProps[key], value);
}

return this._currentRenderProps[key] !== value;
});

if (changedProp) {
this._currentRenderProps = rendererProps;
Expand Down

0 comments on commit f148978

Please sign in to comment.