Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

🐾 Update to PF5 - part II - onSelect, onToggle event handlers #1221

Merged

Conversation

sgratch
Copy link
Collaborator

@sgratch sgratch commented Jun 18, 2024

Reference: #1098

For avoiding uncaught PF 4 -> PF 5 migration errors, this PR named and typed (i.e. (add type to function signature) all onSelect, onToggle callbacks appearances which use parameters.

@yaacov yaacov added the enhancement Categorizes issue or PR as related to a new feature. label Jun 18, 2024
@yaacov yaacov added this to the 2.7.0 milestone Jun 18, 2024
@yaacov yaacov changed the title Update to PF5 - part II - onSelect, onToggle event handlers 🐾 Update to PF5 - part II - onSelect, onToggle event handlers Jun 18, 2024
@sgratch sgratch force-pushed the onSelect_onToggle_event_handler_for_pf5 branch from c944633 to 5763175 Compare June 18, 2024 22:57
@sgratch sgratch requested a review from yaacov June 18, 2024 23:16
Comment on lines 70 to 75
const onToggle: (
isExpanded: boolean,
event:
| Event
| React.KeyboardEvent<Element>
| React.MouseEvent<Element, MouseEvent>
| React.ChangeEvent<Element>,
) => void = (isExpanded) => {
setIsActionMenuOpen(isExpanded);
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onToggle: (
isExpanded: boolean,
event:
| Event
| React.KeyboardEvent<Element>
| React.MouseEvent<Element, MouseEvent>
| React.ChangeEvent<Element>,
) => void = (isExpanded) => {
setIsActionMenuOpen(isExpanded);
};
// define once for all onToggle handlers
export type ToggleEvent =
| Event
| React.KeyboardEvent<Element>
| React.MouseEvent<Element, MouseEvent>
| React.ChangeEvent<Element>;
const onToggle: (isExpanded: boolean, event: ToggleEvent) => void = (isExpanded) => {
setIsActionMenuOpen(isExpanded);
};

@@ -52,6 +53,30 @@ export const MappingListItem: FC<MappingListItemProps> = ({
const { t } = useForkliftTranslation();
const [isSrcOpen, setToggleSrcOpen] = useToggle(false);
const [isTrgOpen, setToggleTrgOpen] = useToggle(false);

const onSelectForSource: (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onSelectForSource: (
const onSelectSource: (

});
};

const onSelectForDestination: (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onSelectForDestination: (
const onSelectDestination: (

Comment on lines 68 to 83
const onSelect: (
event: React.MouseEvent<Element, MouseEvent> | React.ChangeEvent<Element>,
value: string | SelectOptionObject,
isPlaceholder?: boolean,
) => void = (event, value, isPlaceholder) => {
if (isPlaceholder) {
return;
}
// behave as Console's AutocompleteInput used i.e. to filter pods by label
if (!hasFilter(value)) {
addFilter(value);
}
setExpanded(false);
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onSelect: (
event: React.MouseEvent<Element, MouseEvent> | React.ChangeEvent<Element>,
value: string | SelectOptionObject,
isPlaceholder?: boolean,
) => void = (event, value, isPlaceholder) => {
if (isPlaceholder) {
return;
}
// behave as Console's AutocompleteInput used i.e. to filter pods by label
if (!hasFilter(value)) {
addFilter(value);
}
setExpanded(false);
};
export type SelectEvent = React.MouseEvent<Element, MouseEvent> | React.ChangeEvent<Element>;
export type SelectValue = string | SelectOptionObject;
const onSelect: (event: SelectEvent, value: SelectValue, isPlaceholder?: boolean) => void = (event, value, isPlaceholder) => {
if (isPlaceholder) {
return;
}
// behave as Console's AutocompleteInput used i.e. to filter pods by label
if (!hasFilter(value)) {
addFilter(value);
}
setExpanded(false);
};

@sgratch sgratch force-pushed the onSelect_onToggle_event_handler_for_pf5 branch 2 times, most recently from 9009859 to 2a8e1a3 Compare July 3, 2024 12:32
@sgratch sgratch requested a review from yaacov July 3, 2024 12:58

const onToggle: (
isExpanded: boolean,
event:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
event:
event: ToggleEvent

@@ -67,12 +67,25 @@ const ActionsAsDropdown = ({
const history = useHistory();
const [isActionMenuOpen, setIsActionMenuOpen] = useState(false);
const isPlain = variant === 'kebab';

// define once for all onToggle handlers
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// define once for all onToggle handlers
/**
* @typedef {Object} ToggleEvent
* @description Represents the possible event types that can be used for toggling actions.
*
* @property {Event} Event - A standard DOM event.
* @property {React.KeyboardEvent<Element>} React.KeyboardEvent - A React-specific keyboard event.
* @property {React.MouseEvent<Element, MouseEvent>} React.MouseEvent - A React-specific mouse event.
* @property {React.ChangeEvent<Element>} React.ChangeEvent - A React-specific change event.
*/

the define once for all onToggle handlers comment I suggested in my previous review was to help clarify why we need this type definition, when we actually write the code, we can do better. p.s. you did not use in in other onToggle handlers, please do use in in all onToggle handlers ( see https://github.com/kubev2v/forklift-console-plugin/pull/1221/files#r1665219359 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't like this fix since it manipulates the callbacks function signatures, but if you insist and think it is nicer then ok. I made the change in all relevant places now.

@sgratch sgratch force-pushed the onSelect_onToggle_event_handler_for_pf5 branch from 2a8e1a3 to 6776415 Compare July 4, 2024 12:47
@sgratch sgratch requested a review from yaacov July 4, 2024 12:55
@@ -54,6 +55,29 @@ export const MappingListItem: FC<MappingListItemProps> = ({
deleteMapping({ source, destination });
};

const onSelectForSource: (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onSelectForSource: (
const onSelectSource: (

});
};

const onSelectForDestination: (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const onSelectForDestination: (
const onSelectDestination: (

Reference: kubev2v#1098

For avoiding uncaught PF 4 -> PF 5 migration errors, this PR named and typed (i.e. (add type to function
signature) all onSelect, onToggle callbacks appearances which use parameters.

Signed-off-by: Sharon Gratch <[email protected]>
@sgratch sgratch force-pushed the onSelect_onToggle_event_handler_for_pf5 branch from 6776415 to 590d459 Compare July 7, 2024 14:08
@sgratch sgratch requested a review from yaacov July 7, 2024 14:16
@yaacov yaacov merged commit c4a3a5c into kubev2v:main Jul 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants