Skip to content

Commit

Permalink
VMware - filter VMs by available dynamiclly enum list of hosts
Browse files Browse the repository at this point in the history
Reference: #1274

This includes the following changes for the VMware provider VMs list:
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. Enable selecting any number of hosts from the enum filter list. If none, all
   VMs are filtered.
3. Enable to type-ahead input for displaying a subset of the enum filter list of
   hosts.

Signed-off-by: Sharon Gratch <sgratch@redhat.com>
  • Loading branch information
sgratch committed Jul 30, 2024
1 parent 1b4532b commit 6b590b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
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 } from './utils/filters/concernFilter';
import { concernFilter, hostFilter } from './utils/filters';
import { ProviderVirtualMachinesList, VmData } from './components';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState, useVSphereInventoryVms } from './utils';
Expand Down Expand Up @@ -44,11 +44,8 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
label: t('Host'),
isVisible: true,
isIdentity: false,
filter: {
type: 'freetext',
placeholderLabel: t('Filter by host'),
},
sortable: true,
filter: hostFilter(t),
},
{
resourceFieldId: 'folder',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
loadUserSettings,
ResourceFieldFactory,
RowProps,
SearchableEnumFilter,
SearchableGroupedEnumFilter,
ValueMatcher,
} from '@kubev2v/common';
Expand Down Expand Up @@ -86,9 +87,10 @@ export const ProviderVirtualMachinesList: FC<ProviderVirtualMachinesListProps> =
userSettings={userSettings}
extraSupportedFilters={{
concerns: SearchableGroupedEnumFilter,
host: SearchableEnumFilter,
features: EnumFilter,
}}
extraSupportedMatchers={[concernsMatcher, featuresMatcher]}
extraSupportedMatchers={[concernsMatcher, hostMatcher, featuresMatcher]}
GlobalActionToolbarItems={showActions ? actions : undefined}
toId={toId}
onSelect={onSelectedIds}
Expand All @@ -111,3 +113,8 @@ export const featuresMatcher: ValueMatcher = {
filterType: 'features',
matchValue: (features: { [key: string]: boolean }) => (filter: string) => !!features?.[filter],
};

export const hostMatcher: ValueMatcher = {
filterType: 'host',
matchValue: (value: string) => (filter: string) => value == filter,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,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) => {
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 })),
],
}),
};
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './concernFilter';
export * from './hostFilter';
// @endindex

0 comments on commit 6b590b6

Please sign in to comment.