From cee5f94c951296187612cb7653c6d22cee49a8dc Mon Sep 17 00:00:00 2001 From: Joachim Schuler Date: Fri, 13 Dec 2024 12:08:40 -0500 Subject: [PATCH] wip --- .../actions/PlanActionsDropdownItems.tsx | 30 +++++++++++-------- .../modals/PlanVMsEditModal.tsx | 2 +- .../ProvidersUpdateVmMigrationPage.tsx | 1 - .../migrate/components/PlansUpdateForm.tsx | 1 - 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/forklift-console-plugin/src/modules/Plans/actions/PlanActionsDropdownItems.tsx b/packages/forklift-console-plugin/src/modules/Plans/actions/PlanActionsDropdownItems.tsx index 3d22954f5..23e22ddf6 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/actions/PlanActionsDropdownItems.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/actions/PlanActionsDropdownItems.tsx @@ -1,10 +1,12 @@ import React from 'react'; -import { DropdownItemLink } from 'src/components/actions/DropdownItemLink'; +import { isPlanEditable } from 'src/modules/Plans/utils'; +import { PlanVMsEditModal } from 'src/modules/Plans/views/details/tabs/VirtualMachines/modals'; +import { useGetDeleteAndEditAccessReview } from 'src/modules/Providers/hooks'; import { useModal } from 'src/modules/Providers/modals'; -import { getResourceUrl } from 'src/modules/Providers/utils/helpers'; import { useForkliftTranslation } from 'src/utils/i18n'; -import { PlanModel, PlanModelRef } from '@kubev2v/types'; +import { PlanModel /*PlanModelRef*/ } from '@kubev2v/types'; +import { useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk'; import { DropdownItem } from '@patternfly/react-core/deprecated'; import { @@ -26,21 +28,21 @@ import { export const PlanActionsDropdownItems = ({ data }: PlanActionsDropdownItemsProps) => { const { t } = useForkliftTranslation(); const { showModal } = useModal(); + const [activeNamespace] = useActiveNamespace(); + const permissions = useGetDeleteAndEditAccessReview({ + model: PlanModel, + namespace: activeNamespace, + }); const { obj: plan } = data; - const planURL = getResourceUrl({ - reference: PlanModelRef, - name: plan?.metadata?.name, - namespace: plan?.metadata?.namespace, - }); - const phase = getPlanPhase(data); const canStart = canPlanStart(plan); const canReStart = canPlanReStart(plan); const isWarmAndExecuting = plan?.spec?.warm && isPlanExecuting(plan); const isArchived = isPlanArchived(plan); + const canEditPlan = permissions.canPatch && isPlanEditable(plan); const buttonStartLabel = canReStart ? t('Restart migration') : t('Start migration'); @@ -67,9 +69,13 @@ export const PlanActionsDropdownItems = ({ data }: PlanActionsDropdownItemsProps }; return [ - + showModal()} + isDisabled={!canEditPlan} + > {t('Edit Plan')} - , + , {buttonStartLabel} @@ -111,4 +117,4 @@ export const PlanActionsDropdownItems = ({ data }: PlanActionsDropdownItemsProps interface PlanActionsDropdownItemsProps { data: PlanData; -} +} \ No newline at end of file diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/modals/PlanVMsEditModal.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/modals/PlanVMsEditModal.tsx index 2e7af81d5..279b1c8af 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/modals/PlanVMsEditModal.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/modals/PlanVMsEditModal.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { PlanEditAction } from 'src/modules/Plans/utils/types/PlanEditAction'; -import { PlanEditPage } from 'src/modules/Plans/views/create/PlanEditPage'; +import { PlanEditPage } from 'src/modules/Plans/views/edit/PlanEditPage'; import { useModal } from 'src/modules/Providers/modals'; import { useInventoryVms } from 'src/modules/Providers/views'; import { useForkliftTranslation } from 'src/utils/i18n'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/ProvidersUpdateVmMigrationPage.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/ProvidersUpdateVmMigrationPage.tsx index 45b82832e..ccf5a7a19 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/ProvidersUpdateVmMigrationPage.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/ProvidersUpdateVmMigrationPage.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { PlanEditAction } from 'src/modules/Plans/utils/types/PlanEditAction'; import { PlanMappingsSectionState } from 'src/modules/Plans/views/details/tabs/Mappings/PlanMappingsSection'; import { LoadingDots } from '@kubev2v/common'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/PlansUpdateForm.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/PlansUpdateForm.tsx index ac4875ba6..80f3c918f 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/PlansUpdateForm.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/migrate/components/PlansUpdateForm.tsx @@ -1,7 +1,6 @@ import React, { ReactNode } from 'react'; import { FilterableSelect } from 'src/components'; import SectionHeading from 'src/components/headers/SectionHeading'; -import { PlanEditAction } from 'src/modules/Plans/utils/types/PlanEditAction'; import { PlanMappingsInitSection } from 'src/modules/Plans/views/details/tabs/Mappings/PlanMappings'; import { PlanMappingsSectionState } from 'src/modules/Plans/views/details/tabs/Mappings/PlanMappingsSection'; import { useForkliftTranslation } from 'src/utils/i18n';