-
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
[MTV-1686] Simplify/update migration plan status cell #1411
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice refactor of the component name, status cell was too general |
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess we will remove this in a followup ...
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.
Right, at least for now, I think the design plan is to move this button to a "Migration type" column as seen here:
(can be seen in figma here)