-
Notifications
You must be signed in to change notification settings - Fork 22
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
🐾 Update to PF5 - part II - onSelect, onToggle event handlers #1221
Conversation
c944633
to
5763175
Compare
const onToggle: ( | ||
isExpanded: boolean, | ||
event: | ||
| Event | ||
| React.KeyboardEvent<Element> | ||
| React.MouseEvent<Element, MouseEvent> | ||
| React.ChangeEvent<Element>, | ||
) => void = (isExpanded) => { | ||
setIsActionMenuOpen(isExpanded); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onSelectForSource: ( | |
const onSelectSource: ( |
}); | ||
}; | ||
|
||
const onSelectForDestination: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onSelectForDestination: ( | |
const onSelectDestination: ( |
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); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
}; |
9009859
to
2a8e1a3
Compare
|
||
const onToggle: ( | ||
isExpanded: boolean, | ||
event: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 )
There was a problem hiding this comment.
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.
2a8e1a3
to
6776415
Compare
@@ -54,6 +55,29 @@ export const MappingListItem: FC<MappingListItemProps> = ({ | |||
deleteMapping({ source, destination }); | |||
}; | |||
|
|||
const onSelectForSource: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const onSelectForSource: ( | |
const onSelectSource: ( |
}); | ||
}; | ||
|
||
const onSelectForDestination: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]>
6776415
to
590d459
Compare
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.