Skip to content
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
1 change: 1 addition & 0 deletions packages/module/src/WidgetLayout/GridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const GridLayout = ({
key={'grid-' + layoutVariant}
layout={internalTemplate[layoutVariant]}
width={effectiveWidth}
className={activeLayout.length === 0 ? 'pf-v6-widget-grid--empty' : undefined}
droppingItem={droppingItemTemplate}
gridConfig={{
cols: columns[layoutVariant],
Expand Down
16 changes: 14 additions & 2 deletions packages/module/src/WidgetLayout/__tests__/GridLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
// so we replace it with a pass-through that renders children and triggers onLayoutChange
jest.mock('react-grid-layout', () => {
const React = require('react');
const MockGridLayout = ({ children, onLayoutChange, layout }: {
const MockGridLayout = ({ children, onLayoutChange, layout, className }: {
children: React.ReactNode;
onLayoutChange?: (layout: unknown[]) => void;
layout?: unknown[];
className?: string;
[key: string]: unknown;
}) => {
const calledRef = React.useRef(false);
Expand All @@ -22,7 +23,7 @@ jest.mock('react-grid-layout', () => {
onLayoutChange?.(layout || []);
}
});
return <div data-testid="mock-grid-layout">{children}</div>;
return <div data-testid="mock-grid-layout" className={className}>{children}</div>;
};
return {
__esModule: true,
Expand Down Expand Up @@ -212,6 +213,17 @@ describe('GridLayout', () => {
});

describe('droppingWidgetType', () => {
it('marks an empty dashboard grid as the drop target', () => {
render(
<GridLayout
widgetMapping={widgetMapping}
template={emptyTemplate}
droppingWidgetType="widget-a"
/>
);
expect(screen.getByTestId('mock-grid-layout')).toHaveClass('pf-v6-widget-grid--empty');
});

it('hides empty state when a widget is being dropped', () => {
render(
<GridLayout
Expand Down
7 changes: 6 additions & 1 deletion packages/module/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@
}

.pf-v6-widget-layout-container {
--pf-v6-widget-layout--empty-min-height: calc(var(--pf-t--global--spacer--4xl) * 2);
position: relative;
width: 100%;
min-height: 200px;
min-height: var(--pf-v6-widget-layout--empty-min-height);
}

.pf-v6-widget-grid--empty {
min-height: var(--pf-v6-widget-layout--empty-min-height);
}

.pf-v6-widget-grid-tile::before {
Expand Down
Loading