Skip to content

Commit

Permalink
editable mode for dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Jul 10, 2024
1 parent 7d3d0b7 commit 06b0975
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
31 changes: 19 additions & 12 deletions app/packages/core/src/plugins/SchemaIO/components/DashboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default function DashboardView(props: ViewPropsType) {
const { schema, path, data, layout } = props;
const { properties } = schema as ObjectSchemaType;
const propertiesAsArray = [];
const allow_addition = schema.view.allow_addition;
const allow_deletion = schema.view.allow_deletion;

for (const property in properties) {
propertiesAsArray.push({ id: property, ...properties[property] });
Expand Down Expand Up @@ -150,6 +152,9 @@ export default function DashboardView(props: ViewPropsType) {
}));

if (!propertiesAsArray.length) {
if (!allow_addition) {
return null;
}
return <AddItemCTA onAdd={onAddItem} />;
}
const finalLayout = [
Expand Down Expand Up @@ -199,17 +204,19 @@ export default function DashboardView(props: ViewPropsType) {
>
<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>
{allow_deletion && (
<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}
Expand All @@ -224,7 +231,7 @@ export default function DashboardView(props: ViewPropsType) {
})}
</GridLayout>
</Box>
<AddItemButton key="add-item" onAddItem={onAddItem} />
{allow_addition && <AddItemButton key="add-item" onAddItem={onAddItem} />}
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function SliderView(props) {
valueLabelDisplay="auto"
defaultValue={data}
onChange={(e, value: string) => {
onChange(path, type === "number" ? parseFloat(value) : value);
onChange(path, type === "number" ? parseFloat(value) : value, schema);
setUserChanged();
}}
ref={sliderRef}
Expand Down
9 changes: 9 additions & 0 deletions fiftyone/operators/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,15 @@ class DashboardView(View):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.allow_addition = kwargs.get("allow_addition", True)
self.allow_deletion = kwargs.get("allow_deletion", True)

def to_json(self):
return {
**super().to_json(),
"allow_addition": self.allow_addition,
"allow_deletion": self.allow_deletion,
}


class DrawerView(View):
Expand Down

0 comments on commit 06b0975

Please sign in to comment.