Skip to content

Conversation

@gribnoysup
Copy link
Collaborator

Having applyLayout as part of the UI logic instead of calculating it once during the initial processing of the diagram required a lot of disconnected code that was driven with hard to navigate React effects logic and extra state. As layout calculation doesn't really depend on actual DOM, we can make this logic part of the inital model generation removing the need for complicated effects from the code

@gribnoysup gribnoysup requested a review from a team as a code owner July 25, 2025 14:19
const actions = useContext(DrawerActionsContext);
const stableActions = useRef({
openDrawer(id: string) {
openDrawer: (id: string) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive-by to make sure eslint is not warning on unbound methods (those are safe to call unbound, this just makes it clear)

const diagramContainerRef = useRef<HTMLDivElement | null>(null);
const diagram = useDiagram();
const [areNodesReady, setAreNodesReady] = useState(false);
const diagram = useRef(useDiagram());
Copy link
Collaborator Author

@gribnoysup gribnoysup Jul 25, 2025

Choose a reason for hiding this comment

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

I was planning to debug weird flashing of the diagram on main more, but this was actually caused by effects that depend on diagram here and just removing applyLayout effect solved it. Jus to make sure we don't burn ourselves by this I'm making diagram hooks stable. The useDiagram hook returns a new object every render effectively causing every hook that depends on it to re-run every time, wrapping it in a ref works around that

Copy link
Collaborator Author

@gribnoysup gribnoysup Jul 25, 2025

Choose a reason for hiding this comment

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

No big changes in these methods (I called out the only one below), just moved them out of diagram-editor.tsx to a separate file so that I can share these between UI and analysis action

Comment on lines +61 to +67
const selection: Record<string, string[] | null | undefined> = {};
if (relationship?.[0].ns) {
selection[relationship[0].ns] = relationship[0].fields;
}
if (relationship?.[1].ns) {
selection[relationship[1].ns] = relationship[1].fields;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One small drive-by change here. Before you had to have both namespaces selected to have either of the fields to start showing up in UI, I adjusted it a bit to make sure that field selections start to show up as soon as possible when you have both namespace and field set

Comment on lines +150 to +156
// TODO: react-flow documentation suggests that we should be able to do this
// without unrelyable scheduling by calling the fitView after initial state
// is set, but for this we will need to make some changes to the diagramming
// package first
return rafraf(() => {
void diagram.current.fitView();
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will open a diagramming ticket for this

@gribnoysup gribnoysup merged commit 9476583 into main Jul 28, 2025
123 of 130 checks passed
@gribnoysup gribnoysup deleted the COMPASS-9487-layouting-as-part-of-processing branch July 28, 2025 09:03
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