Skip to content

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?

@gagik gagik changed the title refactor(compass-crud): turn cell renderer into a functional component COMPASS-9387 refactor(compass-crud): turn cell renderer into a functional component Jul 3, 2025
@Copilot Copilot AI review requested due to automatic review settings September 3, 2025 12:24
@gagik gagik added the no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion) label Sep 3, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This refactors the CellRenderer component from a class component to a functional component to enable the use of React hooks, particularly the useContextMenus hook. The changes maintain the same functionality while improving the code structure.

  • Converts the class-based CellRenderer to a functional component using React hooks
  • Extracts cell content rendering into a separate CellContent component for better separation of concerns
  • Moves shared useForceUpdate hook to a common location for reuse across components

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

File Description
packages/compass-crud/src/components/table-view/cell-renderer.tsx Main refactor converting class component to functional component with hooks
packages/compass-components/src/index.ts Exports useForceUpdate hook from the common hooks directory
packages/compass-components/src/components/document-list/element.tsx Updates import path for useForceUpdate hook
packages/compass-components/src/components/document-list/document.tsx Updates import path for useForceUpdate hook

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +125 to +127
const handleElementEvent = useCallback(() => {
forceUpdate();
}, []);
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The handleElementEvent callback is missing the forceUpdate dependency in its dependency array, which could lead to stale closures.

Suggested change
const handleElementEvent = useCallback(() => {
forceUpdate();
}, []);
}, [forceUpdate]);

Copilot uses AI. Check for mistakes.

Comment on lines +330 to +335
[
element,
node.data.hadronDocument,
elementRemoved,
elementAdded,
elementTypeChanged,
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The handleUndo callback is missing cellState in its dependency array, but cellState is used in the function logic to determine which action to take.

Suggested change
[
element,
node.data.hadronDocument,
elementRemoved,
elementAdded,
elementTypeChanged,
elementTypeChanged,
cellState,

Copilot uses AI. Check for mistakes.

Comment on lines +205 to +209
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
element,
element?.currentType,
element?.currentValue,
Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The eslint-disable comment suggests there may be dependency issues with the renderContent useCallback. Consider reviewing if all dependencies are properly included or if the callback structure needs adjustment.

Suggested change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
element,
element?.currentType,
element?.currentValue,
}, [
element,

Copilot uses AI. Check for mistakes.

@gribnoysup gribnoysup marked this pull request as draft September 3, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no release notes Fix or feature not for release notes no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants