-
Notifications
You must be signed in to change notification settings - Fork 591
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
DashboardView #4557
Merged
Merged
DashboardView #4557
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
61538ba
init dashboard component
ritch d6d08a7
refactor CustomPanel onload
ritch a61215e
fix state issue
ritch 7d3d0b7
add button for dashboard
ritch 06b0975
editable mode for dashboards
ritch fe6a4c5
minor cleanup
ritch 7e1a497
fix resize handles for dashboard items
imanjra 9a5b9ae
Merge pull request #4577 from voxel51/dashboard-comp-im-x1
ritch 6e58092
fix panel state and data ops
ritch acb91dd
cleanup panel state ops docs
ritch 2358d83
add batch_set_data util for panels
ritch 830c789
dashboard improvements
ritch e22eb80
fix scatter plot events
ritch f5d7454
Merge branch 'develop' into dashboard-comp
imanjra 9f558b2
Merge branch 'develop' into dashboard-comp
imanjra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
app/packages/core/src/plugins/SchemaIO/components/DashboardView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import { | ||
Box, | ||
BoxProps, | ||
Typography, | ||
useTheme, | ||
styled, | ||
IconButton, | ||
} from "@mui/material"; | ||
import React, { useState, useEffect, useCallback } from "react"; | ||
import { HeaderView } from "."; | ||
import { getComponentProps, getPath, getProps } from "../utils"; | ||
import { ObjectSchemaType, ViewPropsType } from "../utils/types"; | ||
import DynamicIO from "./DynamicIO"; | ||
import GridLayout from "react-grid-layout"; | ||
import CloseIcon from "@mui/icons-material/Close"; | ||
import "react-grid-layout/css/styles.css"; | ||
import "react-resizable/css/styles.css"; | ||
import usePanelEvent from "@fiftyone/operators/src/usePanelEvent"; | ||
import { usePanelId } from "@fiftyone/spaces"; | ||
|
||
export default function DashboardView(props: ViewPropsType) { | ||
const { schema, path, data, layout } = props; | ||
const { properties } = schema as ObjectSchemaType; | ||
const propertiesAsArray = []; | ||
|
||
for (const property in properties) { | ||
propertiesAsArray.push({ id: property, ...properties[property] }); | ||
} | ||
const panelId = usePanelId(); | ||
const triggerPanelEvent = usePanelEvent(); | ||
|
||
const onCloseItem = useCallback( | ||
({ id, path }) => { | ||
if (schema.view.on_close_item) { | ||
triggerPanelEvent(panelId, { | ||
operator: schema.view.on_close_item, | ||
params: { id, path }, | ||
}); | ||
} | ||
}, | ||
[panelId, props, schema.view.on_close_item, triggerPanelEvent] | ||
); | ||
const handleLayoutChange = useCallback( | ||
(layout: any) => { | ||
if (schema.view.on_layout_change) { | ||
triggerPanelEvent(panelId, { | ||
operator: schema.view.on_layout_change, | ||
params: { layout }, | ||
}); | ||
} | ||
}, | ||
[panelId, props, schema.view.on_layout_change, triggerPanelEvent] | ||
); | ||
const [isDragging, setIsDragging] = useState(false); | ||
const theme = useTheme(); | ||
|
||
const baseGridProps: BoxProps = {}; | ||
const MIN_ITEM_WIDTH = 400; | ||
const MIN_ITEM_HEIGHT = 300; // Setting minimum height for items | ||
const GRID_WIDTH = layout?.width; // Set based on your container's width | ||
const GRID_HEIGHT = layout?.height - 180; // Set based on your container's height - TODO remove button height hardcoded | ||
const COLS = Math.floor(GRID_WIDTH / MIN_ITEM_WIDTH); | ||
const ROWS = Math.ceil(propertiesAsArray.length / COLS); | ||
|
||
const viewLayout = schema.view.layout; | ||
const defaultLayout = propertiesAsArray.map((property, index) => { | ||
return { | ||
i: property.id, | ||
x: index % COLS, // Correctly position items in the grid | ||
y: Math.floor(index / COLS), // Correctly position items in the grid | ||
w: 1, | ||
h: 1, // Each item takes one row | ||
minW: 1, // Minimum width in grid units | ||
minH: Math.ceil(MIN_ITEM_HEIGHT / (GRID_HEIGHT / ROWS)), // Minimum height in grid units | ||
}; | ||
}); | ||
const gridLayout = viewLayout || defaultLayout; | ||
|
||
const DragHandle = styled(Box)(({ theme }) => ({ | ||
ritch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cursor: "move", | ||
backgroundColor: theme.palette.background.default, | ||
color: theme.palette.text.secondary, | ||
padding: theme.spacing(0.25), | ||
display: "flex", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
})); | ||
|
||
const ResizeHandle = styled("span")(({ theme }) => ({ | ||
ritch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
position: "absolute", | ||
width: 20, | ||
height: 20, | ||
bottom: 0, | ||
right: 0, | ||
backgroundColor: theme.palette.secondary.main, | ||
borderRadius: "50%", | ||
cursor: "se-resize", | ||
})); | ||
|
||
console.log("viewLayout", viewLayout); | ||
ritch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log("propertiesAsArray", propertiesAsArray); | ||
|
||
return ( | ||
<Box | ||
{...getComponentProps(props, "container")} | ||
sx={{ position: "relative", marginLeft: -0.5 }} | ||
ritch marked this conversation as resolved.
Show resolved
Hide resolved
ritch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<Box | ||
{...getProps(props, "grid", baseGridProps)} | ||
sx={{ position: "relative" }} | ||
> | ||
<GridLayout | ||
onLayoutChange={handleLayoutChange} | ||
layout={gridLayout} | ||
cols={COLS} | ||
rowHeight={GRID_HEIGHT / ROWS} // Dynamic row height | ||
width={GRID_WIDTH} | ||
onDragStart={() => setIsDragging(true)} | ||
onDragStop={() => setIsDragging(false)} | ||
isDraggable={!isDragging} | ||
isResizable={!isDragging} // Allow resizing | ||
draggableHandle=".drag-handle" // Specify the drag handle class | ||
> | ||
{propertiesAsArray.map((property) => { | ||
const { id } = property; | ||
const itemPath = getPath(path, id); | ||
const baseItemProps: BoxProps = { | ||
sx: { padding: 0.25, position: "relative" }, | ||
key: id, | ||
}; | ||
return ( | ||
<Box | ||
key={id} | ||
{...getProps( | ||
{ ...props, schema: property }, | ||
"item", | ||
baseItemProps | ||
)} | ||
> | ||
<DragHandle className="drag-handle"> | ||
<Typography>{property.title || id}</Typography> | ||
<IconButton | ||
size="small" | ||
onMouseDown={(e) => e.stopPropagation()} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
onCloseItem({ id, path: getPath(path, id) }); | ||
}} | ||
sx={{ color: theme.palette.text.secondary }} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</DragHandle> | ||
<DynamicIO | ||
{...props} | ||
schema={property} | ||
path={itemPath} | ||
data={data?.[id]} | ||
parentSchema={schema} | ||
relativePath={id} | ||
/> | ||
<ResizeHandle className="react-resizable-handle" /> | ||
</Box> | ||
); | ||
})} | ||
</GridLayout> | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,13 +82,19 @@ export function useCustomPanelHooks(props: CustomPanelProps): CustomPanelHooks { | |
}, [panelStateLocal?.loaded]); | ||
|
||
const onLoad = useCallback(() => { | ||
if (props.onLoad) { | ||
executeOperator(props.onLoad, { | ||
panel_id: panelId, | ||
panel_state: panelState?.state, | ||
}); | ||
if (props.onLoad && !isLoaded) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
executeOperator( | ||
props.onLoad, | ||
{ panel_id: panelId, panel_state: panelState?.state }, | ||
{ | ||
callback(result) { | ||
const { error: onLoadError } = result; | ||
setPanelStateLocal((s) => ({ ...s, onLoadError, loaded: true })); | ||
}, | ||
} | ||
); | ||
} | ||
}, [props.onLoad, panelId, panelState?.state]); | ||
}, [props.onLoad, panelId, panelState?.state, isLoaded, setPanelStateLocal]); | ||
useCtxChangePanelEvent( | ||
isLoaded, | ||
panelId, | ||
|
@@ -131,19 +137,7 @@ export function useCustomPanelHooks(props: CustomPanelProps): CustomPanelHooks { | |
); | ||
|
||
useEffect(() => { | ||
if (props.onLoad && !isLoaded) { | ||
executeOperator( | ||
props.onLoad, | ||
{ panel_id: panelId }, | ||
{ | ||
callback(result) { | ||
const { error: onLoadError } = result; | ||
setPanelStateLocal((s) => ({ ...s, onLoadError, loaded: true })); | ||
}, | ||
} | ||
); | ||
} | ||
|
||
onLoad(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At line 145, should we remove |
||
return () => { | ||
if (props.onUnLoad) | ||
executeOperator(props.onUnLoad, { panel_id: panelId }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hardcoding layout values.
Avoid hardcoding layout values like
GRID_HEIGHT
. Consider making these values configurable.Committable suggestion