diff --git a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx index 7b7d6420fd..0679d6e97e 100644 --- a/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx +++ b/app/packages/core/src/plugins/SchemaIO/components/TreeSelectionView.tsx @@ -3,6 +3,7 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import { Box, Checkbox, FormControlLabel, IconButton } from "@mui/material"; import React, { useEffect } from "react"; import { ViewPropsType } from "../utils/types"; +import { useUnboundState } from "@fiftyone/state"; interface CheckedState { [key: string]: { @@ -70,6 +71,8 @@ export default function TreeSelectionView(props: ViewPropsType) { const [checkedState, setCheckedState] = React.useState(initialCheckedState); + const unboundState = useUnboundState(checkedState); + // Initialize collapsed state for all parents const initialCollapsedState: CollapsedState = React.useMemo(() => { const state: CollapsedState = {}; @@ -192,6 +195,16 @@ export default function TreeSelectionView(props: ViewPropsType) { return idx === -1 ? 0 : idx + 1; }; + useEffect(() => { + const sampleIds = view?.data.flatMap(([parentId, children]) => { + return children.map((childId) => + typeof childId === "string" ? childId : childId[0] + ); + }); + onChange(path, sampleIds); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + // CheckboxView: Represents a single checkbox (either parent or child) function CheckboxView({ id, diff --git a/fiftyone/operators/types.py b/fiftyone/operators/types.py index 4559e477e3..6294eb6ed9 100644 --- a/fiftyone/operators/types.py +++ b/fiftyone/operators/types.py @@ -610,18 +610,16 @@ def tuple(self, name, *items, **kwargs): self.define_property(name, tuple_type, view=tuple_view, **kwargs) return tuple_type - def tree(self, name, *items, **kwargs): + def tree(self, name, **kwargs): """Defines a tree property on the object. - Args: name: the name of the property - *items: the types of the items in the tree Returns: a :class:`Tree` """ tree_selection_view = TreeSelectionView(**kwargs) - tree_type = Object(*items) + tree_type = List(String()) self.define_property( name, tree_type, view=tree_selection_view, **kwargs )