Skip to content

Commit

Permalink
Merge pull request #1298 from sgratch/ovirt-filter-vms-by-available-d…
Browse files Browse the repository at this point in the history
…ynamic-enum-host-list

oVirt - filter VMs by available dynamic enum list of hosts
  • Loading branch information
yaacov authored Jul 31, 2024
2 parents bf89fd4 + 092aa5e commit 730f53c
Show file tree
Hide file tree
Showing 5 changed files with 33 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';

const labelToFilterItem = (label: string): EnumValue =>
label !== '' ? { id: label, label } : { id: label, label: 'Undefined' };

/**
* 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(labelToFilterItem),
],
}),
};
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { EnumValue } from '@kubev2v/common';

const labelToFilterItem = (label: string): EnumValue =>
label !== '' ? { id: label, label } : { id: label, label: 'Undefined' };

/**
* 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(labelToFilterItem),
],
}),
};
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 730f53c

Please sign in to comment.