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: extend grid properties #212

Merged
merged 10 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -31,7 +31,7 @@
const [editMode, setEditMode] = React.useState(true);

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

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

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
};

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

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

Check warning on line 96 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 94 column 12
setConfig(config);
}, []);

Expand All @@ -112,7 +112,12 @@
);
},
gridProperties: (props: ReactGridLayoutProps) => {
return {...props, compactType: 'horizontal-nowrap', maxRows: MAX_ROWS};
return {
...props,
compactType: 'horizontal-nowrap',
maxRows: MAX_ROWS,
noOverlay: true,
};
},
},
{
Expand All @@ -134,7 +139,7 @@

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

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

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'memo'
return memo;
}, {});
const maxOffset = config.layout
Expand Down
30 changes: 14 additions & 16 deletions src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,16 @@ export default class GridLayout extends React.PureComponent {

return (
<Layout
isDraggable={editMode}
isResizable={editMode}
// Group properties
{...properties}
key={`group_${group}`}
// Layout props
compactType={compactType}
layout={layout}
key={`group_${group}`}
isDraggable={editMode}
isResizable={editMode}
draggableCancel={`.${DRAGGABLE_CANCEL_CLASS_NAME}`}
{...(draggableHandleClassName
? {draggableHandle: `.${draggableHandleClassName}`}
: null)}
draggableHandle={draggableHandleClassName ? `.${draggableHandleClassName}` : null}
// Default callbacks
onDragStart={callbacks.onDragStart}
onDrag={callbacks.onDrag}
Expand All @@ -631,27 +629,27 @@ export default class GridLayout extends React.PureComponent {
hasSharedDragItem={hasSharedDragItem}
sharedDragPosition={currentDraggingElement?.cursorPosition}
isDragCaptured={isDragCaptured}
{...(outerDnDEnable
? {
isDroppable: true,
}
: null)}
isDroppable={Boolean(outerDnDEnable)}
>
{renderItems.map((item, i) => {
const isCurrentItem = currentDraggingElement?.item.id === item.id;
const keyId = item.id;
const isCurrentItem = currentDraggingElement?.item.id === keyId;
const isDraggedOut = isCurrentItem && this.state.draggedOut;
const isDragging = this.state.isDragging;
const itemNoOverlay =
'noOverlay' in properties ? properties.noOverlay : noOverlay;

return (
<GridItem
forwardedPluginRef={this.getMemoForwardRefCallback(offset + i)} // forwarded ref to plugin
key={item.id}
id={item.id}
key={keyId}
id={keyId}
item={item}
layout={layout}
adjustWidgetLayout={this.adjustWidgetLayout}
isDragging={this.state.isDragging}
isDragging={isDragging}
isDraggedOut={isDraggedOut}
noOverlay={noOverlay}
noOverlay={itemNoOverlay}
focusable={focusable}
withCustomHandle={Boolean(draggableHandleClassName)}
onItemMountChange={onItemMountChange}
Expand Down
7 changes: 4 additions & 3 deletions src/components/OverlayControls/OverlayControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class OverlayControls extends React.Component<OverlayControlsProps> {
const onItemClickHandler = typeof handler === 'function' ? handler : noop;
return (
<Button
key={index}
key={`control_${index}`}
view={view}
size={size}
title={title}
Expand Down Expand Up @@ -194,6 +194,7 @@ class OverlayControls extends React.Component<OverlayControlsProps> {

return (
<Button
key={'control_default'}
view={view}
size={size}
title={i18n('label_settings')}
Expand All @@ -210,13 +211,12 @@ class OverlayControls extends React.Component<OverlayControlsProps> {
const customLeftControls = this.getCustomLeftOverlayControls();
const hasCustomOverlayLeftControls = Boolean(customLeftControls.length);

const defaultControl = this.getDefaultControls();
const controls = hasCustomOverlayLeftControls
? customLeftControls.map(
(item: OverlayControlItem, index: number, items: OverlayControlItem[]) =>
this.renderControlsItem(item, index, items.length + 1),
)
: defaultControl;
: this.getDefaultControls();

const menu = this.renderMenu(controls === null);

Expand Down Expand Up @@ -319,6 +319,7 @@ class OverlayControls extends React.Component<OverlayControlsProps> {

return (
<DropdownMenu
key={'controls_dropdown'}
items={items}
renderSwitcher={(props) => (
<Button
Expand Down
6 changes: 5 additions & 1 deletion src/typings/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import type {OverlayCustomControlItem} from '../components/OverlayControls/Overl
import {MenuItems} from '../constants';
import {AdditionalWidgetLayout} from '../shared';

export type GridLayoutSettings = ReactGridLayout.ReactGridLayoutProps & {
noOverlay?: boolean;
};

export interface Settings {
gridLayout?: ReactGridLayout.ReactGridLayoutProps;
gridLayout?: GridLayoutSettings;
theme?: string;
isMobile?: boolean;
// @deprecated as it's possibly mutable property use Dashkit overlayMenuItems property instead
Expand Down
6 changes: 3 additions & 3 deletions src/typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {Layout, Layouts} from 'react-grid-layout';

import type {Config, ConfigItem, ConfigLayout} from '../shared';

import {GridLayoutSettings} from './common';

export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
id?: null;
namespace?: string;
Expand Down Expand Up @@ -40,14 +42,12 @@ export interface DashkitGroupRenderProps {
}

export type ReactGridLayoutProps = Omit<
ReactGridLayout.ReactGridLayoutProps,
GridLayoutSettings,
| 'children'
| 'compactType'
| 'innerRef'
| 'key'
| 'layout'
| 'isDraggable'
| 'isResizable'
| 'onDragStart'
| 'onDragStop'
| 'onResizeStart'
Expand Down
Loading