Add minimum width and height properties to dashboard components for better layout control

This commit is contained in:
Simon Larsen 2024-11-14 12:47:48 +00:00
parent eded26d92c
commit b826a78700
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
6 changed files with 50 additions and 16 deletions

View File

@ -8,4 +8,6 @@ export default interface DashboardBaseComponent {
leftInDashboardUnits: number; leftInDashboardUnits: number;
widthInDashboardUnits: number; widthInDashboardUnits: number;
heightInDashboardUnits: number; heightInDashboardUnits: number;
minWidthInDashboardUnits: number;
minHeightInDashboardUnits: number;
} }

View File

@ -14,6 +14,8 @@ export default class DashboardChartComponentUtil extends DashboardBaseComponentU
leftInDashboardUnits: 0, leftInDashboardUnits: 0,
componentId: ObjectID.generate(), componentId: ObjectID.generate(),
chartType: DashboardChartType.Line, chartType: DashboardChartType.Line,
minHeightInDashboardUnits: 3,
minWidthInDashboardUnits: 6
}; };
} }
} }

View File

@ -16,6 +16,8 @@ export default class DashboardTextComponentUtil extends DashboardBaseComponentUt
isBold: false, isBold: false,
isItalic: false, isItalic: false,
isUnderline: false, isUnderline: false,
minHeightInDashboardUnits: 1,
minWidthInDashboardUnits: 3
}; };
} }
} }

View File

@ -12,6 +12,8 @@ export default class DashboardValueComponentUtil extends DashboardBaseComponentU
topInDashboardUnits: 0, topInDashboardUnits: 0,
leftInDashboardUnits: 0, leftInDashboardUnits: 0,
componentId: ObjectID.generate(), componentId: ObjectID.generate(),
minHeightInDashboardUnits: 1,
minWidthInDashboardUnits: 1
}; };
} }
} }

View File

@ -193,12 +193,18 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
} }
// get this in dashboard units., // get this in dashboard units.,
const widthInDashboardUnits: number = let widthInDashboardUnits: number =
GetDashboardComponentWidthInDashboardUnits( GetDashboardComponentWidthInDashboardUnits(
props.totalCurrentDashboardWidthInPx, props.totalCurrentDashboardWidthInPx,
newDashboardComponentwidthInPx, newDashboardComponentwidthInPx,
); );
// if this width is less than the min width then set it to min width
if (widthInDashboardUnits < component.minWidthInDashboardUnits) {
widthInDashboardUnits = component.minWidthInDashboardUnits;
}
// update the component // update the component
const newComponentProps: DashboardBaseComponent = { const newComponentProps: DashboardBaseComponent = {
...component, ...component,
@ -228,12 +234,18 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
} }
// get this in dashboard units // get this in dashboard units
const heightInDashboardUnits: number = let heightInDashboardUnits: number =
GetDashboardComponentHeightInDashboardUnits( GetDashboardComponentHeightInDashboardUnits(
props.totalCurrentDashboardWidthInPx, props.totalCurrentDashboardWidthInPx,
newDashboardComponentHeightInPx, newDashboardComponentHeightInPx,
); );
// if this height is less tan the min height then set it to min height
if (heightInDashboardUnits < component.minHeightInDashboardUnits) {
heightInDashboardUnits = component.minHeightInDashboardUnits;
}
// update the component // update the component
const newComponentProps: DashboardBaseComponent = { const newComponentProps: DashboardBaseComponent = {
...component, ...component,
@ -255,6 +267,14 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
return <></>; return <></>;
} }
let resizeCursorIcon: string = "cursor-ew-resize";
// if already at min width then change icon to e-resize
if (component.widthInDashboardUnits <= component.minWidthInDashboardUnits) {
resizeCursorIcon = "cursor-e-resize";
}
return ( return (
<div <div
style={{ style={{
@ -266,7 +286,7 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
window.addEventListener("mousemove", resizeWidth); window.addEventListener("mousemove", resizeWidth);
window.addEventListener("mouseup", stopResizeAndMove); window.addEventListener("mouseup", stopResizeAndMove);
}} }}
className="resize-width-element cursor-ew-resize absolute right-0 w-2 h-12 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer" className={`resize-width-element ${resizeCursorIcon} absolute right-0 w-2 h-12 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer`}
></div> ></div>
); );
}; };
@ -295,8 +315,8 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
stopResizeAndMove(); stopResizeAndMove();
}} }}
className="move-element cursor-move absolute w-4 h-4 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer" className="move-element cursor-move absolute w-4 h-4 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer"
onDragStart={(_event: React.DragEvent<HTMLDivElement>) => {}} onDragStart={(_event: React.DragEvent<HTMLDivElement>) => { }}
onDragEnd={(_event: React.DragEvent<HTMLDivElement>) => {}} onDragEnd={(_event: React.DragEvent<HTMLDivElement>) => { }}
></div> ></div>
); );
}; };
@ -306,6 +326,14 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
return <></>; return <></>;
} }
let resizeCursorIcon: string = "cursor-ns-resize";
// if already at min height then change icon to s-resize
if (component.heightInDashboardUnits <= component.minHeightInDashboardUnits) {
resizeCursorIcon = "cursor-s-resize";
}
return ( return (
<div <div
style={{ style={{
@ -317,7 +345,7 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
window.addEventListener("mousemove", resizeHeight); window.addEventListener("mousemove", resizeHeight);
window.addEventListener("mouseup", stopResizeAndMove); window.addEventListener("mouseup", stopResizeAndMove);
}} }}
className="resize-height-element cursor-ns-resize absolute bottom-0 left-0 w-12 h-2 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer" className={`resize-height-element ${resizeCursorIcon} absolute bottom-0 left-0 w-12 h-2 bg-blue-300 hover:bg-blue-400 rounded-full cursor-pointer`}
></div> ></div>
); );
}; };
@ -357,16 +385,14 @@ const DashboardBaseComponentElement: FunctionComponent<ComponentProps> = (
}} }}
style={{ style={{
margin: `${MarginForEachUnitInPx}px`, margin: `${MarginForEachUnitInPx}px`,
height: `${ height: `${GetDashboardUnitHeightInPx(props.totalCurrentDashboardWidthInPx) *
GetDashboardUnitHeightInPx(props.totalCurrentDashboardWidthInPx) * heightOfComponent +
heightOfComponent +
SpaceBetweenUnitsInPx * (heightOfComponent - 1) SpaceBetweenUnitsInPx * (heightOfComponent - 1)
}px`, }px`,
width: `${ width: `${GetDashboardUnitWidthInPx(props.totalCurrentDashboardWidthInPx) *
GetDashboardUnitWidthInPx(props.totalCurrentDashboardWidthInPx) * widthOfComponent +
widthOfComponent +
(SpaceBetweenUnitsInPx - 2) * (widthOfComponent - 1) (SpaceBetweenUnitsInPx - 2) * (widthOfComponent - 1)
}px`, }px`,
}} }}
ref={dashboardComponentRef} ref={dashboardComponentRef}
> >

View File

@ -118,14 +118,14 @@ const DashboardNavbar: FunctionComponent<ComponentProps> = (
)} )}
></NavBarItem> ></NavBarItem>
{/* <NavBarItem <NavBarItem
title="Dashboards" title="Dashboards"
activeRoute={RouteMap[PageMap.DASHBOARDS]} activeRoute={RouteMap[PageMap.DASHBOARDS]}
icon={IconProp.Window} icon={IconProp.Window}
route={RouteUtil.populateRouteParams( route={RouteUtil.populateRouteParams(
RouteMap[PageMap.DASHBOARDS] as Route, RouteMap[PageMap.DASHBOARDS] as Route,
)} )}
></NavBarItem> */} ></NavBarItem>
<NavBarItem <NavBarItem
title="More" title="More"