2022-12-10 22:14:31 +01:00
|
|
|
import { WrapperType } from '../../../../types/wrapper';
|
2022-12-18 21:50:08 +01:00
|
|
|
import Widgets from '../../../../widgets';
|
|
|
|
|
import { IWidget, IWidgetDefinition } from '../../../../widgets/widgets';
|
2022-12-10 22:14:31 +01:00
|
|
|
import { Tiles } from '../../Tiles/tilesDefinitions';
|
|
|
|
|
import { GridstackTileWrapper } from '../../Tiles/TileWrapper';
|
|
|
|
|
import { useGridstack } from '../gridstack/use-gridstack';
|
|
|
|
|
|
|
|
|
|
interface DashboardWrapperProps {
|
|
|
|
|
wrapper: WrapperType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DashboardWrapper = ({ wrapper }: DashboardWrapperProps) => {
|
2022-12-19 17:03:39 +01:00
|
|
|
const { refs, items, widgets } = useGridstack('wrapper', wrapper.id);
|
2022-12-10 22:14:31 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="grid-stack grid-stack-wrapper"
|
|
|
|
|
style={{ transitionDuration: '0s' }}
|
|
|
|
|
data-wrapper={wrapper.id}
|
|
|
|
|
ref={refs.wrapper}
|
|
|
|
|
>
|
2022-12-18 22:27:01 +01:00
|
|
|
{items?.map((app) => {
|
|
|
|
|
const { component: TileComponent, ...tile } = Tiles['app'];
|
2022-12-10 22:14:31 +01:00
|
|
|
return (
|
|
|
|
|
<GridstackTileWrapper
|
2022-12-18 22:27:01 +01:00
|
|
|
id={app.id}
|
|
|
|
|
type="app"
|
|
|
|
|
key={app.id}
|
|
|
|
|
itemRef={refs.items.current[app.id]}
|
2022-12-10 22:14:31 +01:00
|
|
|
{...tile}
|
2022-12-18 22:27:01 +01:00
|
|
|
{...app.shape.location}
|
|
|
|
|
{...app.shape.size}
|
2022-12-10 22:14:31 +01:00
|
|
|
>
|
2022-12-18 22:27:01 +01:00
|
|
|
<TileComponent className="grid-stack-item-content" app={app} />
|
2022-12-10 22:14:31 +01:00
|
|
|
</GridstackTileWrapper>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2022-12-19 17:03:39 +01:00
|
|
|
{widgets.map((widget) => {
|
|
|
|
|
const definition = Widgets[widget.id as keyof typeof Widgets] as
|
|
|
|
|
| IWidgetDefinition
|
|
|
|
|
| undefined;
|
|
|
|
|
if (!definition) return null;
|
2022-12-10 22:14:31 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<GridstackTileWrapper
|
2022-12-19 17:03:39 +01:00
|
|
|
type="widget"
|
|
|
|
|
key={widget.id}
|
|
|
|
|
itemRef={refs.items.current[widget.id]}
|
|
|
|
|
id={definition.id}
|
|
|
|
|
{...definition.gridstack}
|
|
|
|
|
{...widget.shape.location}
|
|
|
|
|
{...widget.shape.size}
|
2022-12-10 22:14:31 +01:00
|
|
|
>
|
2022-12-19 17:03:39 +01:00
|
|
|
<definition.component className="grid-stack-item-content" widget={widget} />
|
2022-12-10 22:14:31 +01:00
|
|
|
</GridstackTileWrapper>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|