From 0cd877323e108a0006cb962c4c40e8dede8ed6d2 Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Wed, 8 Nov 2023 20:23:04 +0100 Subject: [PATCH] Filter VMs based on concerns label Signed-off-by: Radoslaw Szwajkowski --- .../en/plugin__forklift-console-plugin.json | 2 ++ .../OVirtVirtualMachinesList.tsx | 8 ++----- .../OpenStackVirtualMachinesList.tsx | 8 ++----- .../OvaVirtualMachinesList.tsx | 10 +++----- .../VSphereVirtualMachinesList.tsx | 8 ++----- .../ProviderVirtualMachinesList.tsx | 7 +++--- .../VirtualMachines/utils/concernFilter.ts | 23 +++++++++++++++++++ 7 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/concernFilter.ts diff --git a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json index dfc3c4e66..68bd72653 100644 --- a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json +++ b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json @@ -36,11 +36,13 @@ "Cannot delete migration plan": "Cannot delete migration plan", "Cannot delete network mapping": "Cannot delete network mapping", "Cannot delete storage mapping": "Cannot delete storage mapping", + "Category": "Category", "Clear all filters": "Clear all filters", "Click the update credentials button to save your changes, button is disabled until a change is detected.": "Click the update credentials button to save your changes, button is disabled until a change is detected.", "Close": "Close", "Cluster": "Cluster", "Clusters": "Clusters", + "Concern": "Concern", "Concerns": "Concerns", "Conditions": "Conditions", "Connection Failed": "Connection Failed", diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx index a001d110f..00edf8c18 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; +import { concernFilter } from './utils/concernFilter'; import { ProviderVirtualMachinesList, VmData } from './components'; import { OVirtVirtualMachinesRow } from './OVirtVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -26,12 +27,7 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ label: t('Concerns'), isVisible: true, sortable: true, - filter: { - type: 'concerns', - primary: true, - placeholderLabel: t('Concerns'), - values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), - }, + filter: concernFilter(t), }, { resourceFieldId: 'cluster', diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx index ff392e83c..9751935d0 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; +import { concernFilter } from './utils/concernFilter'; import { getVmPowerState } from './utils/helpers/getVmPowerState'; import { ProviderVirtualMachinesList, VmData } from './components'; import { OpenStackVirtualMachinesRow } from './OpenStackVirtualMachinesRow'; @@ -26,12 +27,7 @@ export const openStackVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ label: t('Concerns'), isVisible: true, sortable: true, - filter: { - type: 'concerns', - primary: true, - placeholderLabel: t('Concerns'), - values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), - }, + filter: concernFilter(t), }, { resourceFieldId: 'hostID', diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx index 8597a3008..744b8e933 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OvaVirtualMachinesList.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; +import { ResourceFieldFactory } from '@kubev2v/common'; +import { concernFilter } from './utils/concernFilter'; import { ProviderVirtualMachinesList } from './components'; import { OvaVirtualMachinesRow } from './OvaVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -25,12 +26,7 @@ export const ovaVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ label: t('Concerns'), isVisible: true, sortable: true, - filter: { - type: 'concerns', - primary: true, - placeholderLabel: t('Concerns'), - values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), - }, + filter: concernFilter(t), }, { resourceFieldId: 'ovaPath', diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx index 3da749ffe..473d72c9f 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; +import { concernFilter } from './utils/concernFilter'; import { ProviderVirtualMachinesList, VmData } from './components'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; import { getVmPowerState } from './utils'; @@ -26,12 +27,7 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ label: t('Concerns'), isVisible: true, sortable: true, - filter: { - type: 'concerns', - primary: true, - placeholderLabel: t('Concerns'), - values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), - }, + filter: concernFilter(t), }, { resourceFieldId: 'isTemplate', diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx index 964041aac..372a2fbef 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/ProviderVirtualMachinesList.tsx @@ -5,7 +5,7 @@ import { ProviderData } from 'src/modules/Providers/utils'; import { useForkliftTranslation } from 'src/utils/i18n'; import { - EnumFilter, + GroupedEnumFilter, loadUserSettings, ResourceFieldFactory, RowProps, @@ -52,7 +52,7 @@ export const ProviderVirtualMachinesList: React.FC @@ -62,5 +62,6 @@ export const ProviderVirtualMachinesList: React.FC (filter: string) => - Array.isArray(concerns) && concerns.some(({ category }) => category === filter), + Array.isArray(concerns) && + concerns.some(({ category, label }) => category === filter || label === filter), }; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/concernFilter.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/concernFilter.ts new file mode 100644 index 000000000..d0f4c92f6 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/concernFilter.ts @@ -0,0 +1,23 @@ +import { EnumToTuple, EnumValue } from '@kubev2v/common'; + +export const concernFilter = (t: (string) => string) => ({ + type: 'concerns', + primary: true, + placeholderLabel: t('Concerns'), + groups: [ + { groupId: 'category', label: t('Category') }, + { groupId: 'label', label: t('Concern') }, + ], + dynamicFilter: (items: { vm: { concerns: { label: string }[] } }[]) => ({ + values: [ + ...EnumToTuple({ + Critical: 'Critical', + Warning: 'Warning', + Information: 'Information', + }).map(({ id, label }: EnumValue): EnumValue => ({ id, label, groupId: 'category' })), + ...Array.from( + new Set(items.flatMap((item) => item.vm.concerns).map((concern) => concern.label)), + ).map((label: string): EnumValue => ({ groupId: 'label', id: label, label })), + ], + }), +});