From fdaa1e7f9dbc25030bfbc38a0737c23ccac4712d Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Mon, 10 Jun 2024 09:40:25 +0300 Subject: [PATCH] Update to PF5 - part II - onClick event handler Reference: https://github.com/kubev2v/forklift-console-plugin/issues/1098 Seems like onClick event handler parameters was changed in PF5 for few of the components by enforcing the event handler as the first parameter (E.g. https://www.patternfly.org/components/chip/#chip while in our code we are not passing the event https://github.com/kubev2v/forklift-console-plugin/blob/686daff412d61c5e84c14f7b87fe2867038fc14b/packages/forklift-console-plugin/src/modules/Plans/views/create/components/ChipsToolbarProviders.tsx#L40). For avoiding uncaught migration errors, this PR named and typed all callback appearances, when possible Signed-off-by: Sharon Gratch --- .../NetworkMapActionsDropdownItems.tsx | 10 +-- .../componenets/NetworkMapsAddButton.tsx | 10 +-- .../components/MapsSection/MapsSection.tsx | 6 +- .../ProvidersSection/ProvidersSection.tsx | 6 +- .../components/ShowWelcomeCardButton.tsx | 7 +- .../Metrics/cards/MigrationsChartCard.tsx | 39 ++++----- .../Metrics/cards/VmMigrationsChartCard.tsx | 39 ++++----- .../actions/PlanActionsDropdownItems.tsx | 44 ++++++---- .../details/components/MappingListItem.tsx | 6 +- .../details/components/PlanPageHeadings.tsx | 19 ++-- .../views/details/tabs/Hooks/PlanHooks.tsx | 18 ++-- .../components/MigrationVMsCancelButton.tsx | 11 +-- .../components/PlanVMsDeleteButton.tsx | 10 +-- .../views/list/components/ActionsCell.tsx | 26 +++--- .../actions/ProviderActionsDropdownItems.tsx | 10 +-- .../Providers/modals/EditModal/EditModal.tsx | 6 +- .../CertificateUpload/CertificateUpload.tsx | 16 ++-- .../FetchCertificateModal.tsx | 11 ++- .../components/DetailsPage/DetailItem.tsx | 86 ++++++++++--------- .../views/create/ProvidersCreatePage.tsx | 6 +- .../components/EsxiProviderCreateForm.tsx | 10 +-- .../components/VCenterProviderCreateForm.tsx | 10 +-- .../components/edit/EsxiCredentialsEdit.tsx | 16 +++- .../edit/OpenshiftCredentialsEdit.tsx | 16 +++- .../edit/OpenstackCredentialsEdit.tsx | 10 +-- .../components/edit/OvirtCredentialsEdit.tsx | 16 +++- .../edit/VCenterCredentialsEdit.tsx | 16 ++-- .../Hosts/components/SelectNetworkButton.tsx | 13 +-- .../tabs/Networks/ProviderNetworks.tsx | 9 +- .../components/MigrationAction.tsx | 14 ++- .../list/components/ProvidersAddButton.tsx | 10 +-- .../migrate/components/MappingListItem.tsx | 6 +- .../StorageMapActionsDropdownItems.tsx | 10 +-- .../componenets/StorageMapsAddButton.tsx | 10 +-- .../components/MapsSection/MapsSection.tsx | 6 +- .../ProvidersSection/ProvidersSection.tsx | 6 +- 36 files changed, 305 insertions(+), 259 deletions(-) diff --git a/packages/forklift-console-plugin/src/modules/NetworkMaps/actions/NetworkMapActionsDropdownItems.tsx b/packages/forklift-console-plugin/src/modules/NetworkMaps/actions/NetworkMapActionsDropdownItems.tsx index 92864e911..733848b98 100644 --- a/packages/forklift-console-plugin/src/modules/NetworkMaps/actions/NetworkMapActionsDropdownItems.tsx +++ b/packages/forklift-console-plugin/src/modules/NetworkMaps/actions/NetworkMapActionsDropdownItems.tsx @@ -21,15 +21,15 @@ export const NetworkMapActionsDropdownItems = ({ data }: NetworkMapActionsDropdo namespace: networkMap?.metadata?.namespace, }); + const onClick = () => { + showModal(); + }; + return [ {t('Edit NetworkMap')} , - showModal()} - > + {t('Delete NetworkMap')} , ]; diff --git a/packages/forklift-console-plugin/src/modules/NetworkMaps/componenets/NetworkMapsAddButton.tsx b/packages/forklift-console-plugin/src/modules/NetworkMaps/componenets/NetworkMapsAddButton.tsx index c6b22d2d0..1b6e6431d 100644 --- a/packages/forklift-console-plugin/src/modules/NetworkMaps/componenets/NetworkMapsAddButton.tsx +++ b/packages/forklift-console-plugin/src/modules/NetworkMaps/componenets/NetworkMapsAddButton.tsx @@ -19,12 +19,12 @@ export const NetworkMapsAddButton: React.FC<{ namespace: string; dataTestId?: st namespaced: namespace !== undefined, }); + const onClick = () => { + history.push(`${NetworkMapsListURL}/~new`); + }; + return ( - ); diff --git a/packages/forklift-console-plugin/src/modules/NetworkMaps/views/details/components/MapsSection/MapsSection.tsx b/packages/forklift-console-plugin/src/modules/NetworkMaps/views/details/components/MapsSection/MapsSection.tsx index 69cf80b6d..07736b867 100644 --- a/packages/forklift-console-plugin/src/modules/NetworkMaps/views/details/components/MapsSection/MapsSection.tsx +++ b/packages/forklift-console-plugin/src/modules/NetworkMaps/views/details/components/MapsSection/MapsSection.tsx @@ -156,6 +156,10 @@ export const MapsSection: React.FC = ({ obj }) => { }); }; + const onClick = () => { + dispatch({ type: 'INIT', payload: obj }); + }; + return ( @@ -173,7 +177,7 @@ export const MapsSection: React.FC = ({ obj }) => { diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/MigrationVMsCancelButton.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/MigrationVMsCancelButton.tsx index fcc1c3539..795afe588 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/MigrationVMsCancelButton.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/MigrationVMsCancelButton.tsx @@ -13,16 +13,13 @@ export const MigrationVMsCancelButton: FC<{ }> = ({ selectedIds, migration }) => { const { t } = useForkliftTranslation(); const { showModal } = useModal(); + const onClick = () => { + showModal(); + }; return ( - diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/PlanVMsDeleteButton.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/PlanVMsDeleteButton.tsx index d3c1f69fc..09e79a221 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/PlanVMsDeleteButton.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/components/PlanVMsDeleteButton.tsx @@ -14,13 +14,13 @@ export const PlanVMsDeleteButton: FC<{ const { t } = useForkliftTranslation(); const { showModal } = useModal(); + const onClick = () => { + showModal(); + }; + return ( - diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/list/components/ActionsCell.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/list/components/ActionsCell.tsx index dcccdeaae..a75a4d885 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/list/components/ActionsCell.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/list/components/ActionsCell.tsx @@ -28,25 +28,23 @@ export const ActionsCell = ({ data }: CellProps) => { const buttonStartIcon = canReStart ? : ; const buttonCutoverIcon = ; + const onClickPlanStartMigration = () => { + showModal( + , + ); + }; + + const onClickPlanCutoverMigration = () => { + showModal(); + }; + return ( {canStart && ( - @@ -57,7 +55,7 @@ export const ActionsCell = ({ data }: CellProps) => { diff --git a/packages/forklift-console-plugin/src/modules/Providers/actions/ProviderActionsDropdownItems.tsx b/packages/forklift-console-plugin/src/modules/Providers/actions/ProviderActionsDropdownItems.tsx index 8db771679..9f6688f4d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/actions/ProviderActionsDropdownItems.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/actions/ProviderActionsDropdownItems.tsx @@ -20,6 +20,10 @@ export const ProviderActionsDropdownItems = ({ data }: ProviderActionsDropdownIt namespace: provider?.metadata?.namespace, }); + const onClick = () => { + showModal(); + }; + return [ {t('Edit Provider')} @@ -30,11 +34,7 @@ export const ProviderActionsDropdownItems = ({ data }: ProviderActionsDropdownIt {t('Migrate')} , - showModal()} - > + {t('Delete Provider')} , ]; diff --git a/packages/forklift-console-plugin/src/modules/Providers/modals/EditModal/EditModal.tsx b/packages/forklift-console-plugin/src/modules/Providers/modals/EditModal/EditModal.tsx index 806723412..9ba56ca32 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/modals/EditModal/EditModal.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/modals/EditModal/EditModal.tsx @@ -104,6 +104,10 @@ export const EditModal: React.FC = ({ } }, [resource, value]); + const onClick: (event: React.MouseEvent) => void = (event) => { + event.preventDefault(); + }; + /** * LabelIcon is a (?) icon that triggers a Popover component when clicked. */ @@ -112,7 +116,7 @@ export const EditModal: React.FC = ({ diff --git a/packages/forklift-console-plugin/src/modules/Providers/utils/components/CertificateUpload/FetchCertificateModal.tsx b/packages/forklift-console-plugin/src/modules/Providers/utils/components/CertificateUpload/FetchCertificateModal.tsx index eb88f7787..01dc5054d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/utils/components/CertificateUpload/FetchCertificateModal.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/utils/components/CertificateUpload/FetchCertificateModal.tsx @@ -21,6 +21,12 @@ export const FetchCertificateModal: FC<{ const success = !loading && !fetchError && !certError; const hasThumbprintChanged = existingCert && success && thumbprint !== calculateThumbprint(existingCert); + + const onClick = () => { + handleSave(certificate); + toggleModal(); + }; + return ( { - handleSave(certificate); - toggleModal(); - }} + onClick={onClick} isDisabled={!success || !isTrusted} > {t('Confirm')} diff --git a/packages/forklift-console-plugin/src/modules/Providers/utils/components/DetailsPage/DetailItem.tsx b/packages/forklift-console-plugin/src/modules/Providers/utils/components/DetailsPage/DetailItem.tsx index b4cfed03d..36e3799c5 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/utils/components/DetailsPage/DetailItem.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/utils/components/DetailsPage/DetailItem.tsx @@ -108,50 +108,52 @@ export const DescriptionTitleWithHelp: React.FC<{ crumbs, moreInfoLabel = 'More info:', moreInfoLink, -}) => ( - - {showHelpIconNextToTitle ? : null} - {title}} - bodyContent={ - - {helpContent} +}) => { + const onClick: (event: React.MouseEvent) => void = (event) => { + event.preventDefault(); + }; - {moreInfoLink && ( - - {moreInfoLabel}{' '} - - - - - )} + return ( + + {showHelpIconNextToTitle ? : null} + {title}} + bodyContent={ + + {helpContent} - {crumbs && crumbs.length > 0 && ( - - - {crumbs.map((c) => ( - {c} - ))} - - - )} - - } - > - {showHelpIconNextToTitle ? ( - - ) : ( - {title} - )} - - -); + {moreInfoLink && ( + + {moreInfoLabel}{' '} + + + + + )} + + {crumbs && crumbs.length > 0 && ( + + + {crumbs.map((c) => ( + {c} + ))} + + + )} + + } + > + {showHelpIconNextToTitle ? ( + + ) : ( + {title} + )} + + + ); +}; /** * Component for displaying title without a popover. diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx index 3fc93c1f2..2cd6fc3d3 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/ProvidersCreatePage.tsx @@ -211,6 +211,10 @@ export const ProvidersCreatePage: React.FC<{ namespace: namespace, }); + const onClick = () => { + history.push(providersListURL); + }; + return (
@@ -272,7 +276,7 @@ export const ProvidersCreatePage: React.FC<{ - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/EsxiProviderCreateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/EsxiProviderCreateForm.tsx index 9597407b3..c0fdd6023 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/EsxiProviderCreateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/EsxiProviderCreateForm.tsx @@ -117,6 +117,10 @@ export const EsxiProviderCreateForm: React.FC = ({ [provider], ); + const onClick: (event: React.MouseEvent) => void = (event) => { + event.preventDefault(); + }; + return (
= ({ bodyContent={vddkHelperTextPopover} alertSeverityVariant="info" > - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VCenterProviderCreateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VCenterProviderCreateForm.tsx index ac01cc88b..4b1957b2a 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VCenterProviderCreateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/create/components/VCenterProviderCreateForm.tsx @@ -117,6 +117,10 @@ export const VCenterProviderCreateForm: React.FC [provider], ); + const onClick: (event: React.MouseEvent) => void = (event) => { + event.preventDefault(); + }; + return ( bodyContent={vddkHelperTextPopover} alertSeverityVariant="info" > - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/EsxiCredentialsEdit.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/EsxiCredentialsEdit.tsx index f01138977..825e76b4a 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/EsxiCredentialsEdit.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/EsxiCredentialsEdit.tsx @@ -93,6 +93,16 @@ export const EsxiCredentialsEdit: React.FC = ({ secret, onCh dispatch({ type: 'TOGGLE_PASSWORD_HIDDEN' }); }; + const onClickEventPreventDef: (event: React.MouseEvent) => void = ( + event, + ) => { + event.preventDefault(); + }; + + const onClickTogglePassword = () => { + togglePasswordHidden(); + }; + return ( = ({ secret, onCh /> diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/OvirtCredentialsEdit.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/OvirtCredentialsEdit.tsx index 4c1994e3d..d60e209f7 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/OvirtCredentialsEdit.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/components/CredentialsSection/components/edit/OvirtCredentialsEdit.tsx @@ -99,6 +99,16 @@ export const OvirtCredentialsEdit: React.FC = ({ secret, onC dispatch({ type: 'TOGGLE_PASSWORD_HIDDEN' }); }; + const onClickEventPreventDef: (event: React.MouseEvent) => void = ( + event, + ) => { + event.preventDefault(); + }; + + const onClickTogglePassword = () => { + togglePasswordHidden(); + }; + return ( = ({ secret, onC /> @@ -181,11 +181,7 @@ export const VCenterCredentialsEdit: React.FC = ({ secret, o bodyContent={cacertHelperTextPopover} alertSeverityVariant="info" > - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Hosts/components/SelectNetworkButton.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Hosts/components/SelectNetworkButton.tsx index faefe810d..7bafc1a1f 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Hosts/components/SelectNetworkButton.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Hosts/components/SelectNetworkButton.tsx @@ -33,18 +33,13 @@ export const SelectNetworkButton: FC<{ }> = ({ selectedIds, provider, hostsData }) => { const { t } = useForkliftTranslation(); const { showModal } = useModal(); + const onClick = () => { + showModal(); + }; return ( - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Networks/ProviderNetworks.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Networks/ProviderNetworks.tsx index 410263507..aa4b1d00c 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Networks/ProviderNetworks.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/Networks/ProviderNetworks.tsx @@ -49,6 +49,9 @@ const ProviderNetworks_: React.FC = ({ obj }) => { isDefault: `${net.namespace}/${net.name}` === defaultNetwork, config: JSON.parse(net?.object?.spec?.config || '{}') as CnoConfig, })); + const onClick = () => { + showModal(); + }; return (
@@ -57,11 +60,7 @@ const ProviderNetworks_: React.FC = ({ obj }) => { {permissions.canPatch && (
-
diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/MigrationAction.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/MigrationAction.tsx index ed01d5ff1..b8e220492 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/MigrationAction.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/MigrationAction.tsx @@ -23,16 +23,14 @@ export const MigrationAction: FC<{ namespaced: namespace !== undefined, }); const { setData } = useCreateVmMigrationData(); + const onClick = () => { + setData({ selectedVms, provider }); + history.push(`${planListURL}/~new`); + }; + return ( - diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProvidersAddButton.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProvidersAddButton.tsx index abad92dca..d54127560 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProvidersAddButton.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/list/components/ProvidersAddButton.tsx @@ -19,12 +19,12 @@ export const ProvidersAddButton: React.FC<{ namespace: string; dataTestId?: stri namespaced: namespace !== undefined, }); + const onClick = () => { + history.push(`${providersListURL}/~new`); + }; + return ( - ); diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/MappingListItem.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/MappingListItem.tsx index ccbe4c255..d8461b872 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/MappingListItem.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/MappingListItem.tsx @@ -52,6 +52,10 @@ export const MappingListItem: FC = ({ const { t } = useForkliftTranslation(); const [isSrcOpen, setToggleSrcOpen] = useToggle(false); const [isTrgOpen, setToggleTrgOpen] = useToggle(false); + const onClick = () => { + deleteMapping({ source, destination }); + }; + return ( @@ -114,7 +118,7 @@ export const MappingListItem: FC = ({ aria-labelledby="" > ); diff --git a/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx b/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx index 40e446db8..f54ace5ed 100644 --- a/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx +++ b/packages/forklift-console-plugin/src/modules/StorageMaps/views/details/components/MapsSection/MapsSection.tsx @@ -145,6 +145,10 @@ export const MapsSection: React.FC = ({ obj }) => { }); }; + const onClick = () => { + dispatch({ type: 'INIT', payload: obj }); + }; + return ( @@ -162,7 +166,7 @@ export const MapsSection: React.FC = ({ obj }) => {