Skip to content

Commit

Permalink
Merge pull request #1180 from yaacov/filter-migration-vms-by-status
Browse files Browse the repository at this point in the history
Filter migration vms by status
  • Loading branch information
yaacov authored May 29, 2024
2 parents ef4218f + 2f7f72d commit 5ac4a50
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@ import { PlanData, VMData } from '../types';
import { MigrationVirtualMachinesRow } from './MigrationVirtualMachinesRow';
import { MigrationVirtualMachinesRowExtended } from './MigrationVirtualMachinesRowExtended';

const vmStatuses = [
{ id: 'Failed', label: 'Failed' },
{ id: 'Running', label: 'Running' },
{ id: 'Succeeded', label: 'Succeeded' },
{ id: 'Unknown', label: 'Unknown' },
];

const getVMMigrationStatus = (obj: VMData) => {
const isError = obj.statusVM?.conditions?.find((c) => c.type === 'Failed' && c.status === 'True');
const isSuccess = obj.statusVM?.conditions?.find(
(c) => c.type === 'Succeeded' && c.status === 'True',
);
const isRunning = obj.statusVM?.completed === undefined;

if (isError) {
return 'Failed';
}

if (isSuccess) {
return 'Succeeded';
}

if (isRunning) {
return 'Running';
}

return 'Unknown';
};

const fieldsMetadataFactory: ResourceFieldFactory = (t) => [
{
resourceFieldId: 'name',
Expand Down Expand Up @@ -89,14 +118,16 @@ const fieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'status',
jsonPath: (obj: VMData) => {
const completed = obj.statusVM?.pipeline.filter((p) => p?.phase === 'Completed');

return (completed || []).length;
},
jsonPath: getVMMigrationStatus,
label: t('Status'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
primary: true,
placeholderLabel: t('Status'),
values: vmStatuses,
},
},
];

Expand Down

0 comments on commit 5ac4a50

Please sign in to comment.