Skip to content

Commit

Permalink
Merge pull request #1297 from sgratch/vmware-filter-vms-by-available-…
Browse files Browse the repository at this point in the history
…dynamic-enum-host-list

VMware - filter VMs by available dynamic enum list of hosts
  • Loading branch information
yaacov authored Jul 30, 2024
2 parents 1b4532b + 6b590b6 commit 904e596
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 904e596

Please sign in to comment.