Skip to content
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

Enable renaming object name from Object Tree #619

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions packages/base/src/panelview/objecttree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ interface IStates {
selectedNodes: string[];
clientId: number | null; // ID of the yjs client
id: string; // ID of the component, it is used to identify which component
editingNode: TreeNodeId | null;
editingNodeValue: string | null;
//is the source of awareness updates.
openNodes: (number | string)[];
}
Expand Down Expand Up @@ -154,7 +156,9 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
selectedNodes: [],
clientId: null,
id: uuid(),
openNodes: []
openNodes: [],
editingNode: null,
editingNodeValue: ''
};
this.props.cpModel.jcadModel?.sharedObjectsChanged.connect(
this._sharedJcadModelChanged
Expand Down Expand Up @@ -464,8 +468,61 @@ class ObjectTreeReact extends React.Component<IProps, IStates> {
textOverflow: 'ellipsis',
overflowX: 'hidden'
}}
onClick={() => this.setState({ editingNode: opts.node.id })}
>
{opts.node.label}
{this.state.editingNode === opts.node.id ? (
<input
type="text"
value={this.state.editingNodeValue || opts.node.label}
autoFocus
onBlur={() => this.setState({ editingNode: null })}
onChange={e =>
this.setState({ editingNodeValue: e.target.value })
}
onKeyDown={e => {
if (e.key === 'Enter') {
console.log(
'Updated name:',
this.state.editingNodeValue
);
const updatedName = this.state.editingNodeValue;
const objectName = opts.node.id;

if (this.props.cpModel.mainViewModel) {
const obj =
this.props.cpModel.jcadModel?.sharedModel.getObjectByName(
objectName as string
);
if (obj) {
this.props.cpModel.sharedModel?.updateObjectByName(
Copy link
Member

@martinRenou martinRenou Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We not only need to update the specific object, but we also need to go through all objects and see if they depend on it. All objects have a dependency parameter which is a list of object it depends on, by name. And operators are applying their operation based of the objects names.

I believe it's easier to tackle this renaming task once #200 is done. We wouldn't need to do that work I'm describing above because the list of dependencies would be a list of UUIDs. And operators would be defined based of UUIDs.

I would suggest we put this renaming PR on hold while #200 is not tackled.

objectName as string,
{
data: {
key: 'name',
value: updatedName
}
}
);
}
}
this.setState({
editingNode: null,
editingNodeValue: null
});
}
}}
style={{
width: '100%',
background: 'transparent',
border: 'none',
outline: 'none',
fontSize: 'inherit',
color: 'inherit'
}}
/>
) : (
opts.node.label
)}
</span>
{opts.type === 'leaf' ? (
<div style={{ display: 'flex' }}>
Expand Down
Loading