Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased
* [Improving data-testids for actions](https://github.com/flower-platform/react-timeline-10000/pull/109)

## v2.12.0

Expand Down
4 changes: 2 additions & 2 deletions src/components/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ContextMenu extends React.Component<ContextMenuProps, { isOpened?:
}} open={(this.state.isOpened && visibleActions.length > 0)}>
<Menu className="rct9k-context-menu" secondary vertical>
{visibleActions.map((action: IAction) => {
const key = visibleActions.indexOf(action);
const key = (action.key instanceof Function ? action.key({ ...this.props.paramsForAction }) : action.key) || visibleActions.indexOf(action);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While this new logic for key is a great improvement for generating stable identifiers, it's not applied consistently. For actions that use renderInMenu (the else branch of the ternary operator on line 97), the React key prop is still being assigned the item's index (visibleActions.indexOf(action)) on line 112. This should be updated to use the new key variable to ensure consistent behavior and prevent potential rendering issues with React.

For example, line 112 should be changed to:

: React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: key, "data-testid": testids.menuItem + "_" + key })

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Frumoasa sugestie AI 😁

  • { ...this.props.paramsForAction} - de ce mai spargem odata obiectul si-l creem din nou, se poate da direct this.props.paramsForAction
  • key: key, la fel poate fi inlocuit doar cu key

return (!action.renderInMenu ?
<Menu.Item
data-testid={testids.menuItem + "_" + key}
Expand All @@ -109,7 +109,7 @@ export class ContextMenu extends React.Component<ContextMenuProps, { isOpened?:
}
}}>
</Menu.Item>
: React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: visibleActions.indexOf(action), "data-testid": testids.menuItem + "_" + key })
: React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: key, "data-testid": testids.menuItem + "_" + key })
);
})
}
Expand Down
1 change: 1 addition & 0 deletions src/components/ContextMenu/IAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface IAction {
isDisabled?: (param: IActionParam) => boolean,
icon?: SemanticShorthandItem<IconProps>,
label?: string | ((param: IActionParam) => string),
key?: string | ((param: IActionParam) => string),
/**
* Function that will be called when user will click this menu entry. Will receives as parameter the current selected items
*/
Expand Down