Skip to content

Commit

Permalink
oVirt - filter VMs by available dynamic enum list of hosts
Browse files Browse the repository at this point in the history
Reference: kubev2v#1275

This includes the following changes for the oVirt provider VMs list only:

 1. Set the 'Host' filter to be a primary filter.
 2. Display a dynamic list of hosts that the VMs run on as an enum filter to select.
 3. All VMs that are not assigned to any host, will be filtered out by
    the "Undefined" option.
 4. Enable selecting any number of hosts from the enum filter list. If none, all VMs are filtered.
 5. Enable to type-ahead input for displaying a subset of the enum filter list of hosts.

Signed-off-by: Sharon Gratch <[email protected]>
  • Loading branch information
sgratch committed Jul 30, 2024
1 parent 904e596 commit 025fac6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';

import { concernFilter } from './utils/filters/concernFilter';
import { concernFilter, OvirtHostFiler } from './utils/filters';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OVirtVirtualMachinesCells } from './OVirtVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
Expand Down Expand Up @@ -47,11 +47,8 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
label: t('Host'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by host'),
},
sortable: true,
filter: OvirtHostFiler(t),
},
{
resourceFieldId: 'path',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';
import { VSphereVM } from '@kubev2v/types';

import { concernFilter, hostFilter } from './utils/filters';
import { concernFilter, VsphereHostFilter } from './utils/filters';
import { ProviderVirtualMachinesList, VmData } from './components';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState, useVSphereInventoryVms } from './utils';
Expand Down Expand Up @@ -45,7 +45,7 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
isVisible: true,
isIdentity: false,
sortable: true,
filter: hostFilter(t),
filter: VsphereHostFilter(t),
},
{
resourceFieldId: 'folder',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { EnumValue } from '@kubev2v/common';

/**
* This component enables filtering the oVirt virtual machines
* by the hostname that they are running on.
*/
export const OvirtHostFiler = (t: (string) => string) => {
return {
type: 'host',
primary: true,
placeholderLabel: t('Host'),
dynamicFilter: (items: { vm: { host: string } }[]) => ({
values: [
...Array.from(new Set(items.map((item) => item.vm.host))) // at this point the list contains unique strings that can be used as ID
.map(
(label: string): EnumValue =>
label !== '' ? { id: label, label } : { id: label, label: 'Undefined' },
),
],
}),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { EnumValue } from '@kubev2v/common';
* This component enables filtering the VMware's virtual machines
* by the hostname that they are running on.
*/
export const hostFilter = (t: (string) => string) => {
export const VsphereHostFilter = (t: (string) => string) => {
return {
type: 'host',
primary: true,
placeholderLabel: t('Host'),
dynamicFilter: (items: { hostName: string }[]) => ({
values: [
...Array.from(new Set(items.map((item) => item.hostName))) // at this point the list contains unique strings that can be used as ID
.map((label: string): EnumValue => ({ id: label, label })),
//.map((label: string): EnumValue => ({ id: label, label })),
.map(
(label: string): EnumValue =>
label !== '' ? { id: label, label } : { id: label, label: 'Undefined' },
),
],
}),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './concernFilter';
export * from './hostFilter';
export * from './OvirtHostFilter';
export * from './VsphereHostFilter';
// @endindex

0 comments on commit 025fac6

Please sign in to comment.