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,5 +1,6 @@
## Unreleased

* [Make `IActionParamForRun.closeContextMenu` optional](https://github.com/flower-platform/react-timeline-10000/pull/104)
* [Add `nowMarkerLiveUpdate` property that live updates the now marker](https://github.com/flower-platform/react-timeline-10000/pull/108)
* [Fix scrollbars that hide content on gantt/table](https://github.com/flower-platform/react-timeline-10000/pull/103)
* [Drag to create can start on top of an existing item](https://github.com/flower-platform/react-timeline-10000/pull/101)
Expand Down
12 changes: 2 additions & 10 deletions src/components/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React from 'react';
import { Menu, Popup, StrictPopupProps } from 'semantic-ui-react';
import { Menu, Popup } from 'semantic-ui-react';
import { IAction, IActionParamForRun } from './IAction';
import { TestsAreDemoCheat, createTestids } from '@famiprog-foundation/tests-are-demo';
import _ from 'lodash';

export type Point = { x: number, y: number };

type Position = StrictPopupProps["position"];

type IParamsForAction = {
selection: any[];
position?: Position;
[key: string]: any;
}
interface ContextMenuProps {
actions: IAction[];

paramsForAction: IParamsForAction;
paramsForAction: IActionParamForRun;
/**
* if undefined => the menu is closed else {x, y} position where the menu should open
*/
Expand Down
17 changes: 14 additions & 3 deletions src/components/ContextMenu/IAction.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import React from "react"
import { IconProps, SemanticShorthandItem } from "semantic-ui-react"
import { IconProps, SemanticShorthandItem, StrictPopupProps } from "semantic-ui-react"
import { Point } from "./ContextMenu"

// TODO RM34271 let's get rid of IActionParamForRun. It overcomplicates the inheritance. We'll have here closeContextMenu() that won't do anything.
// export interface IActionParam<S> {
// selection: S[]
type Position = StrictPopupProps["position"];

export interface IActionParam {
selection: any[]
}

export interface IActionParamForRun extends IActionParam {
closeContextMenu: () => void,

/**
* Function to close the context menu.
* This is marked as optional because users will pass their actionParamForRun without this field.
* However, it will ALWAYS be populated internally by the ContextMenu component before being passed to action handlers.
*/
closeContextMenu?: () => void,

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

Making closeContextMenu optional is a breaking change for consumers of this library. Any action implementation that calls params.closeContextMenu() will now fail if the function is not provided. Previously, its presence was guaranteed by the type definition.

All call sites within consumer code will need to be updated to check for the existence of closeContextMenu before calling it, for example:

if (params.closeContextMenu) {
    params.closeContextMenu();
}

or using optional chaining:

params.closeContextMenu?.();

If this breaking change is intentional, it should be clearly documented in the pull request description and reflected in the package's versioning (e.g., a major version bump).

An alternative to making it optional, which would not be a breaking change, is to ensure it's always provided, even if it's a no-op function (() => {}) in contexts where there's no menu to close. This seems to align with the suggestion in the TODO comment on line 5 of this file.

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.

This is always populated internally in ContextMenu before passed to handlers. I have added a comment on top of this property


/**
* By default the context menu closes immediately after the action is run
* If the user wants to avoid the closing of the menu after action runs he needs to set this property to true
Expand All @@ -23,6 +30,10 @@ export interface IActionParamForRun extends IActionParam {
* It contains the mouse coordinates, obtained from onClick event of an action
*/
eventPoint?: Point

position?: Position;

[key: string]: any;
}

// TODO RM34271 CS: for the moment it's not clear why we need this. It's not used by the lib. And currently, the task of opening
Expand Down