-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MTV-1686] Simplify/update migration plan status cell
Signed-off-by: Jeff Puzzo <[email protected]>
- Loading branch information
Showing
12 changed files
with
197 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/forklift-console-plugin/src/modules/Plans/hooks/usePlanMigration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
packages/forklift-console-plugin/src/modules/Plans/views/list/components/PlanStatusCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import React from 'react'; | ||
import { usePlanMigration } from 'src/modules/Plans/hooks'; | ||
import { PlanStartMigrationModal } from 'src/modules/Plans/modals'; | ||
import { | ||
getMigrationVmsCounts, | ||
getPlanPhase, | ||
isPlanArchived, | ||
isPlanExecuting, | ||
} from 'src/modules/Plans/utils'; | ||
import { useModal } from 'src/modules/Providers/modals'; | ||
import { getResourceUrl } from 'src/modules/Providers/utils'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { PlanModel, PlanModelRef } from '@kubev2v/types'; | ||
import { Button, Flex, FlexItem, Label, Spinner, Split, SplitItem } from '@patternfly/react-core'; | ||
import StartIcon from '@patternfly/react-icons/dist/esm/icons/play-icon'; | ||
|
||
import { CellProps } from './CellProps'; | ||
import { PlanStatusVmCount } from './PlanStatusVmCount'; | ||
|
||
type VmPipelineTask = { | ||
vmName: string; | ||
task: string; | ||
status: string; | ||
}; | ||
|
||
export const PlanStatusCell: React.FC<CellProps> = ({ data }) => { | ||
const { t } = useForkliftTranslation(); | ||
const { showModal } = useModal(); | ||
const plan = data?.obj; | ||
|
||
const vms = plan?.spec?.vms; | ||
const vmStatuses = plan?.status?.migration?.vms; | ||
const [lastMigration] = usePlanMigration(plan); | ||
|
||
const isWarmAndExecuting = plan.spec?.warm && isPlanExecuting(plan); | ||
const isWaitingForCutover = isWarmAndExecuting && !isPlanArchived(plan); | ||
|
||
const vmPipelineTasks = lastMigration?.status.vms?.reduce( | ||
(acc: VmPipelineTask[], migrationVm) => { | ||
migrationVm.pipeline.forEach((pipelineStep) => { | ||
acc.push({ vmName: migrationVm.name, task: pipelineStep.name, status: pipelineStep.phase }); | ||
}); | ||
|
||
return acc; | ||
}, | ||
[], | ||
); | ||
|
||
const phase = getPlanPhase(data); | ||
const isPlanLoading = !isWaitingForCutover && (phase === 'Running' || phase === 'Archiving'); | ||
const planURL = getResourceUrl({ | ||
reference: PlanModelRef, | ||
name: plan?.metadata?.name, | ||
namespace: plan?.metadata?.namespace, | ||
}); | ||
|
||
// All VM count links point to the same place for now, | ||
// but will be updated to target only affected VMs in the future. | ||
// Could possibly use a querystring to dictate a table filter for the list of VMs. | ||
const vmCountLinkPath = `${planURL}/vms`; | ||
|
||
if (phase === 'Ready') { | ||
return ( | ||
<Button | ||
variant="secondary" | ||
icon={<StartIcon />} | ||
onClick={() => | ||
showModal( | ||
<PlanStartMigrationModal resource={plan} model={PlanModel} title={t('Start')} />, | ||
) | ||
} | ||
> | ||
{t('Start')} | ||
</Button> | ||
); | ||
} | ||
|
||
const vmCount = getMigrationVmsCounts(vmStatuses); | ||
const completedVmPipelineTasks = vmPipelineTasks?.filter( | ||
(pipelineTask) => pipelineTask.status === 'Completed', | ||
); | ||
const progressValue = vmPipelineTasks?.length | ||
? (100 * completedVmPipelineTasks.length) / vmPipelineTasks.length | ||
: 0; | ||
|
||
return ( | ||
<Flex alignItems={{ default: 'alignItemsCenter' }} spaceItems={{ default: 'spaceItemsSm' }}> | ||
{isPlanLoading ? ( | ||
<Spinner size="md" /> | ||
) : phase === 'NotReady' ? ( | ||
t('Validating...') | ||
) : ( | ||
<Label isCompact>{phase}</Label> | ||
)} | ||
|
||
{progressValue !== 0 && isPlanLoading && ( | ||
<FlexItem className="pf-v5-u-font-size-sm">{Math.trunc(progressValue)}%</FlexItem> | ||
)} | ||
|
||
<Split hasGutter> | ||
{vmCount?.success > 0 && ( | ||
<SplitItem> | ||
<PlanStatusVmCount | ||
count={vmCount.success} | ||
status="success" | ||
linkPath={vmCountLinkPath} | ||
/> | ||
</SplitItem> | ||
)} | ||
|
||
{phase !== 'Running' && | ||
phase !== 'NotReady' && | ||
vms?.length && | ||
!vmCount?.error && | ||
!vmCount.success && ( | ||
<SplitItem> | ||
<PlanStatusVmCount count={vms.length} status="warning" linkPath={vmCountLinkPath} /> | ||
</SplitItem> | ||
)} | ||
|
||
{vmCount?.error > 0 && ( | ||
<SplitItem> | ||
<PlanStatusVmCount count={vmCount?.error} status="danger" linkPath={vmCountLinkPath} /> | ||
</SplitItem> | ||
)} | ||
</Split> | ||
</Flex> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
...ges/forklift-console-plugin/src/modules/Plans/views/list/components/PlanStatusVmCount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { useForkliftTranslation } from 'src/utils'; | ||
|
||
import { Flex, FlexItem, Icon, IconComponentProps } from '@patternfly/react-core'; | ||
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; | ||
import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; | ||
import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; | ||
|
||
interface PlanStatusVmCountProps { | ||
count: number; | ||
status: IconComponentProps['status']; | ||
linkPath: string; | ||
} | ||
|
||
export const PlanStatusVmCount: React.FC<PlanStatusVmCountProps> = ({ | ||
count, | ||
status, | ||
linkPath, | ||
}) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
const statusIcon = React.useMemo(() => { | ||
switch (status) { | ||
case 'success': | ||
return <CheckCircleIcon />; | ||
case 'warning': | ||
return <ExclamationTriangleIcon />; | ||
case 'danger': | ||
return <ExclamationCircleIcon />; | ||
} | ||
}, [status]); | ||
|
||
return ( | ||
<Flex alignItems={{ default: 'alignItemsCenter' }} spaceItems={{ default: 'spaceItemsSm' }}> | ||
<Icon status={status}>{statusIcon}</Icon> | ||
|
||
<FlexItem> | ||
<Link to={linkPath}>{t('{{total}} VM', { count, total: count })}</Link> | ||
</FlexItem> | ||
</Flex> | ||
); | ||
}; |
29 changes: 0 additions & 29 deletions
29
packages/forklift-console-plugin/src/modules/Plans/views/list/components/StatusCell.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.