Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass gridLayout setting for each group #220

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
const [headerInteractions, setHeaderInteractions] = React.useState(true);

const onClick = () => {
console.log('click');

Check warning on line 37 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement

Check warning on line 37 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
};

const items = React.useMemo(
Expand Down Expand Up @@ -96,7 +96,7 @@
);
const [config, setConfig] = React.useState(getConfig(true));

const onChange = React.useCallback(({config}: {config: DashKitProps['config']}) => {

Check warning on line 99 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'config' is already declared in the upper scope on line 97 column 12

Check warning on line 99 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / build

'config' is already declared in the upper scope on line 97 column 12
setConfig(config);
}, []);

Expand Down Expand Up @@ -151,7 +151,7 @@

const overlayMenuItems = React.useMemo(() => {
const layoutById = config.layout.reduce<Record<string, ConfigLayout>>((memo, item) => {
memo[item.i] = item;

Check warning on line 154 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'memo'

Check warning on line 154 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'memo'
return memo;
}, {});
const maxOffset = config.layout
Expand Down Expand Up @@ -284,6 +284,11 @@
[config],
);

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

return (
<DashKitDnDWrapper
onDragStart={() => {
Expand Down Expand Up @@ -328,7 +333,7 @@
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
Loading