Skip to content

refactor(compass-crud): turn cell renderer into a functional component COMPASS-9387 #7027

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gagik
Copy link
Contributor

@gagik gagik commented Jun 16, 2025

This refactor will enable the cell renderer to more naturally use the useContextMenus hook.

Most of the code was quite old and written with class components in mind. This tries to keep changes minimal but also untangles some of the harder to follow logic with different states of a cell.

@gagik gagik requested a review from a team as a code owner June 16, 2025 16:04
@gagik gagik added the no release notes Fix or feature not for release notes label Jun 16, 2025
@gagik gagik force-pushed the gagik/cell-render-refactor branch from 7656961 to f31490c Compare June 16, 2025 16:21
@gagik gagik marked this pull request as draft June 16, 2025 16:31
@gagik gagik changed the title refactor: turn cell renderer into a functional component refactor(compass-crud): turn cell renderer into a functional component Jun 17, 2025
@gagik gagik marked this pull request as ready for review June 17, 2025 11:11
@gagik gagik changed the title refactor(compass-crud): turn cell renderer into a functional component refactor(compass-crud): turn cell renderer into a functional component COMPASS-9387 Jun 17, 2025
<IconButton
className={undoButtonClass}
// @ts-expect-error TODO: size="small" is not an acceptable size
size="small"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we have a resolution for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't look like it and I don't see any tickets that would indicate that lg team is planning to add that variant even though the Icon component itself supports it. We already wrap the IconButton component for other reasons, might as well extend it a bit more to support the small size, at least temporarily, seems like the only thing passing small here does at the moment is just making it so that the width / height sizes that leafygreen would otherwise apply to the button are not applied

onUndo,
onExpand,
}) => {
const [, forceUpdate] = useReducer((x: number) => x + 1, 0);
Copy link
Collaborator

@gribnoysup gribnoysup Jun 17, 2025

Choose a reason for hiding this comment

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

Not that you need to, it's a one liner, but we do have useForceUpdate in compass-components 🙂 (Althought I don't remember if we export it or not)

event.stopPropagation();
this.props.drillDown(this.props.node.data.hadronDocument, this.element);
}
}, [element]);
Copy link
Collaborator

@gribnoysup gribnoysup Jun 17, 2025

Choose a reason for hiding this comment

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

This memo on element here (and probably in most other places where you have this as a dep for hooks) is an issue: element reference itself is stable, and so even though you have the subscription to the element change events that call forceUpdate, the values are still kept intact by the memo logic. As a repro you can try editing an array and then reverting the changes, you can observe that the length stays the same on revert (and the same works currently on main):

Kapture 2025-06-17 at 17 44 52

// `ag-grid` renders this component outside of the context chain
// so we re-supply the dark mode theme here.
<LeafyGreenProvider darkMode={darkMode}>
<div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's maybe a diff making it harder to understand for me, but is there any specific reason we added a div here?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants