Skip to content

Commit

Permalink
Merge pull request #778 from rszwajko/dynamicConcernEnum
Browse files Browse the repository at this point in the history
Filter VMs based on concerns label
  • Loading branch information
yaacov authored Nov 30, 2023
2 parents 34539a8 + 965de1b commit 0bea166
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { ProviderData } from 'src/modules/Providers/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import {
EnumFilter,
loadUserSettings,
ResourceFieldFactory,
RowProps,
SearchableGroupedEnumFilter,
ValueMatcher,
} from '@kubev2v/common';
import { Concern } from '@kubev2v/types';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const ProviderVirtualMachinesList: React.FC<ProviderVirtualMachinesListPr
title={t('Virtual Machines')}
userSettings={userSettings}
extraSupportedFilters={{
concerns: EnumFilter,
concerns: SearchableGroupedEnumFilter,
}}
extraSupportedMatchers={[concernsMatcher]}
/>
Expand All @@ -62,5 +62,6 @@ export const ProviderVirtualMachinesList: React.FC<ProviderVirtualMachinesListPr
const concernsMatcher: ValueMatcher = {
filterType: 'concerns',
matchValue: (concerns: Concern[]) => (filter: string) =>
Array.isArray(concerns) && concerns.some(({ category }) => category === filter),
Array.isArray(concerns) &&
concerns.some(({ category, label }) => category === filter || label === filter),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
.filter((item) => item?.vm?.concerns?.length)
.flatMap((item) => item.vm.concerns)
.map((concern) => concern.label),
),
) // at this point the list contains unique strings that can be used as ID
.map((label: string): EnumValue => ({ groupId: 'label', id: label, label })),
],
}),
});

0 comments on commit 0bea166

Please sign in to comment.