Skip to content

feat/COMPASS-9656 add field selected state and field click handler #112

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

Merged
merged 5 commits into from
Aug 18, 2025

Conversation

Anemy
Copy link
Member

@Anemy Anemy commented Aug 15, 2025

External Links

Description

Adds an onFieldClick prop to the Diagram. This is called when a field is clicked. Also this adds selected and selectable props to the NodeField. We have some new styles around the selected state.

Notes for Reviewers

Eventually we'll be adding multi-select and multi-field dragging. That'll require some state to track the selected fields. I'm thinking the hook added useFieldSelection is going to form a basis for that.
A good reference is how react flow does some of their node dragging. It's worth noting though that they have a controlled and uncontrolled approach, and we'll only need to do controlled.

Haven't done much with styled components, so any tips there would be helpful! Was reading https://styled-components.com/docs/basics#passed-props and looking at the existing code, but I may have done a pattern we want to avoid unknowingly.

📸 Screenshots/Screencasts

select.fields.mp4
Screenshot 2025-08-15 at 2 19 28 AM

id: FieldId;
nodeId: string;
},
) => void;
Copy link
Collaborator

@paula-stacho paula-stacho Aug 15, 2025

Choose a reason for hiding this comment

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

I know we said that sending id is fine as we'd provide a default value, but the value might not be unique and I see that the other handlers (Node or Edge) by reactflow actually send the full Node/Edge. Does something speak against doing the same?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that it would help against the non-uniqueness necessarily, unless the field contains something identifying. So I'm more swayed by the consistency now

Copy link
Member Author

Choose a reason for hiding this comment

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

I've found keeping interfaces minimal by reducing the passing of unneeded information can be beneficial to reducing coupling and reliance on stale or duplicated data down the line. I think React Flow sends the whole edge or node as a result of them allowing a lot of the diagramming state to be uncontrolled. In our case the consumer of this diagramming package is controlling the data and the state of the fields so they already have all of the information.

@paula-stacho
Copy link
Collaborator

Looks amazing! 😍

One issue I stumbled upon - when I select a parent, I can't change the selection to the child (also the hover is stuck on the parent)

Screen.Recording.2025-08-15.at.15.10.27.mov

nodeType={nodeType}
isHovering={isHovering}
previewGroupArea={previewGroupArea[getPreviewId(i, name)] || DEFAULT_PREVIEW_GROUP_AREA}
selectedGroupHeight={selectedGroupHeight?.[getSelectedId(i, name)]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we even need the name, could this be just index? Or is this better for debugging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, I went with name and index to align it with the previewGroupArea implementation. No strong preference there, and I'm not sure on the reason for having name. Maybe @lchans knows? I'm happy to remove it as it would simplify things!

Copy link
Collaborator

Choose a reason for hiding this comment

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

It handles duplicate names at different depths

@paula-stacho
Copy link
Collaborator

How difficult would it be to connect this to onSelectionChange? We don't use this callback in Compass, but Relational Migrator does use it. We could at least create a follow up on this.

@Anemy
Copy link
Member Author

Anemy commented Aug 15, 2025

@paula-stacho Connecting this to onSelectionChange wouldn't be much work, that being said I don't think we should until we have a need for it. Given that Relational Migrator isn't using these fields selection events it would go unused.

Copy link
Collaborator

@lchans lchans left a comment

Choose a reason for hiding this comment

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

The key icons on the left seem to have shrunk a bit 🤔 Nevermind I think it's just the global stying of the stories which we can fix up. Linked this branch in RM and everything looks good from our end!

let idAccumulator: string[];
let lastDepth = 0;
// Used to build a string array id based on field depth.
function idFromDepthAccumulator(name: string, depth?: number) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity what's the purpose of this function when we can just define the id ourselves in the story? Do we plan on using this in other places in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

I imagine we'll probably use it when we add stories with field dragging down the line. That being said it was a quick add with the intention of using the already defined fields without changing them. Happy to remove it and define the id ourselves if that would make reading through easier.

Copy link
Collaborator

@paula-stacho paula-stacho left a comment

Choose a reason for hiding this comment

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

Awesome! 🎉

@Anemy Anemy merged commit ae15c97 into main Aug 18, 2025
5 checks passed
@Anemy Anemy deleted the feat/COMPASS-9656-add-field-selection-handlers branch August 18, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants