Skip to content

Commit

Permalink
add edit mode for draggable items
Browse files Browse the repository at this point in the history
  • Loading branch information
sc420 committed Nov 2, 2023
1 parent 3498997 commit 84eb521
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
18 changes: 14 additions & 4 deletions interactive-computational-graph/src/components/AddNodesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import DraggableItem from "./DraggableItem";
interface AddNodesPanelProps {
onAddNode: (featureNodeType: FeatureNodeType) => void;
onAddOperation: () => void;
onEditOperation: (featureNodeType: FeatureNodeType) => void;
featureOperations: FeatureOperation[];
}

const AddNodesPanel: FunctionComponent<AddNodesPanelProps> = ({
onAddNode,
onAddOperation,
onEditOperation,
featureOperations,
}) => {
const simpleOperations = featureOperations.filter(
Expand Down Expand Up @@ -66,12 +68,16 @@ const AddNodesPanel: FunctionComponent<AddNodesPanelProps> = ({
<DraggableItem
featureNodeType={{ nodeType: "CONSTANT" }}
text="Constant"
onClick={onAddNode}
isEditing={false}
onClickItem={onAddNode}
onClickEditIcon={onEditOperation}
/>
<DraggableItem
featureNodeType={{ nodeType: "VARIABLE" }}
text="Variable"
onClick={onAddNode}
isEditing={false}
onClickItem={onAddNode}
onClickEditIcon={onEditOperation}
/>
</List>
</AccordionDetails>
Expand All @@ -96,7 +102,9 @@ const AddNodesPanel: FunctionComponent<AddNodesPanelProps> = ({
operationId: operation.id,
}}
text={operation.text}
onClick={onAddNode}
isEditing={false}
onClickItem={onAddNode}
onClickEditIcon={onEditOperation}
/>
))}
</List>
Expand All @@ -122,7 +130,9 @@ const AddNodesPanel: FunctionComponent<AddNodesPanelProps> = ({
operationId: operation.id,
}}
text={operation.text}
onClick={onAddNode}
isEditing={true}
onClickItem={onAddNode}
onClickEditIcon={onEditOperation}
/>
))}
{/* Add operation */}
Expand Down
30 changes: 24 additions & 6 deletions interactive-computational-graph/src/components/DraggableItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import DragHandleIcon from "@mui/icons-material/DragHandle";
import EditIcon from "@mui/icons-material/Edit";
import {
Icon,
IconButton,
ListItem,
ListItemButton,
Expand All @@ -11,13 +13,17 @@ import type FeatureNodeType from "../features/FeatureNodeType";
interface DraggableItemProps {
featureNodeType: FeatureNodeType;
text: string;
onClick: (featureNodeType: FeatureNodeType) => void;
isEditing: boolean;
onClickItem: (featureNodeType: FeatureNodeType) => void;
onClickEditIcon: (featureNodeType: FeatureNodeType) => void;
}

const DraggableItem: FunctionComponent<DraggableItemProps> = ({
featureNodeType,
text,
onClick,
isEditing,
onClickItem,
onClickEditIcon,
}) => {
const handleDragStart = useCallback(
(event: DragEvent): void => {
Expand All @@ -34,9 +40,21 @@ const DraggableItem: FunctionComponent<DraggableItemProps> = ({
<ListItem
disablePadding
secondaryAction={
<IconButton edge="end">
<DragHandleIcon />
</IconButton>
isEditing ? (
<IconButton
edge="end"
size="small"
onClick={() => {
onClickEditIcon(featureNodeType);
}}
>
<EditIcon />
</IconButton>
) : (
<Icon color="action">
<DragHandleIcon />
</Icon>
)
}
>
<ListItemButton
Expand All @@ -46,7 +64,7 @@ const DraggableItem: FunctionComponent<DraggableItemProps> = ({
handleDragStart(event);
}}
onClick={() => {
onClick(featureNodeType);
onClickItem(featureNodeType);
}}
>
<ListItemText primary={text} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface FeaturePanelProps {
explainDerivativeData: ExplainDerivativeData[];
onAddNode: (featureNodeType: FeatureNodeType) => void;
onAddOperation: () => void;
onEditOperation: (featureNodeType: FeatureNodeType) => void;
onClearSelection: () => void;
onSelectNode: (nodeId: string) => void;
}
Expand All @@ -29,6 +30,7 @@ const FeaturePanel: FunctionComponent<FeaturePanelProps> = ({
explainDerivativeData,
onAddNode,
onAddOperation,
onEditOperation,
onClearSelection,
onSelectNode,
}) => {
Expand All @@ -40,6 +42,7 @@ const FeaturePanel: FunctionComponent<FeaturePanelProps> = ({
featureOperations={featureOperations}
onAddNode={onAddNode}
onAddOperation={onAddOperation}
onEditOperation={onEditOperation}
/>
);
case "view-nodes":
Expand All @@ -60,6 +63,7 @@ const FeaturePanel: FunctionComponent<FeaturePanelProps> = ({
featureOperations={featureOperations}
onAddNode={onAddNode}
onAddOperation={onAddOperation}
onEditOperation={onEditOperation}
/>
);
case "examples":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ const GraphContainer: FunctionComponent<GraphContainerProps> = ({
setNextOperationId((nextOperationId) => nextOperationId + 1);
}, [nextOperationId]);

const handleEditOperation = useCallback(
(featureNodeType: FeatureNodeType) => {
// TODO(sc420): Open edit operation modal
console.log(featureNodeType);
},
[],
);

const handleClearSelection = useCallback(() => {
setReactFlowNodes((nodes) => deselectAllNodes(nodes));
}, []);
Expand Down Expand Up @@ -586,6 +594,7 @@ const GraphContainer: FunctionComponent<GraphContainerProps> = ({
explainDerivativeData={explainDerivativeData}
onAddNode={handleAddNode}
onAddOperation={handleAddOperation}
onEditOperation={handleEditOperation}
onClearSelection={handleClearSelection}
onSelectNode={handleSelectNode}
/>
Expand Down

0 comments on commit 84eb521

Please sign in to comment.