Skip to content

Commit

Permalink
Filter by all concerns present in the VM
Browse files Browse the repository at this point in the history
Before only the most severe concern was used for filtering.

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Sep 28, 2023
1 parent 8483bbf commit 30d66d6
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 49 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 { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OVirtVirtualMachinesRow } from './OVirtVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState } from './utils';
Expand All @@ -22,12 +22,12 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
jsonPath: (data: VmData) => (data.vm.providerType === 'ovirt' ? data?.vm?.concerns : []),
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
type: 'concerns',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import React from 'react';
import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';
import { OpenshiftVM } from '@kubev2v/types';

import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { VmData } from './components';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState } from './utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';

import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList';
import { getVmPowerState } from './utils/helpers/getVmPowerState';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OpenStackVirtualMachinesRow } from './OpenStackVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';

Expand All @@ -22,12 +22,12 @@ export const openStackVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
jsonPath: (data: VmData) => (data.vm.providerType === 'openstack' ? data?.vm?.concerns : []),
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
type: 'concerns',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
Expand Down
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 { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { ProviderVirtualMachinesList, VmData } from './components';
import { OvaVirtualMachinesRow } from './OvaVirtualMachinesRow';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';

Expand All @@ -21,12 +21,12 @@ export const ovaVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
jsonPath: (data: VmData) => (data.vm.providerType === 'ova' ? data?.vm?.concerns : []),
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
type: 'concerns',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
Expand Down
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 { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList';
import { ProviderVirtualMachinesList, VmData } from './components';
import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines';
import { getVmPowerState } from './utils';
import { VSphereVirtualMachinesRow } from './VSphereVirtualMachinesRow';
Expand All @@ -22,12 +22,12 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'concerns',
jsonPath: '$.concerns',
jsonPath: (data: VmData) => (data.vm.providerType === 'vsphere' ? data?.vm?.concerns : []),
label: t('Concerns'),
isVisible: true,
sortable: true,
filter: {
type: 'enum',
type: 'concerns',
primary: true,
placeholderLabel: t('Concerns'),
values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import StandardPage from 'src/components/page/StandardPage';
import { ProviderData } from 'src/modules/Providers/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import { loadUserSettings, ResourceFieldFactory, RowProps } from '@kubev2v/common';
import { ProviderVirtualMachine } from '@kubev2v/types';
import {
EnumFilter,
loadUserSettings,
ResourceFieldFactory,
RowProps,
ValueMatcher,
} from '@kubev2v/common';
import { Concern } from '@kubev2v/types';

import { useInventoryVms } from '../utils/useInventoryVms';

export interface VmData {
vm: ProviderVirtualMachine;
name: string;
concerns: string;
}
import { VmData } from './VMCellProps';

export interface ProviderVirtualMachinesListProps extends RouteComponentProps {
obj: ProviderData;
Expand Down Expand Up @@ -49,6 +51,16 @@ export const ProviderVirtualMachinesList: React.FC<ProviderVirtualMachinesListPr
namespace={obj?.provider?.metadata?.namespace}
title={t('Virtual Machines')}
userSettings={userSettings}
extraSupportedFilters={{
concerns: EnumFilter,
}}
extraSupportedMatchers={[concernsMatcher]}
/>
);
};

const concernsMatcher: ValueMatcher = {
filterType: 'concerns',
matchValue: (concerns: Concern[]) => (filter: string) =>
concerns.some(({ category }) => category === filter),
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ProviderVirtualMachine } from '@kubev2v/types';
export interface VmData {
vm: ProviderVirtualMachine;
name: string;
concerns: string;
}

export interface VMCellProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './PowerStateCellRenderer';
export * from './ProviderVirtualMachinesList';
export * from './VMCellProps';
export * from './VMConcernsCellRenderer';
export * from './VMNameCellRenderer';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './getHighestPriorityConcern';
export * from './getVmPowerState';
// @endindex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { ProviderVirtualMachine } from '@kubev2v/types';

import { VmData } from '../components';

import { getHighestPriorityConcern } from './helpers';

/**
* A hook for retrieving VMs from the inventory.
* Adds providerType property to each VM.
Expand Down Expand Up @@ -46,7 +44,6 @@ export const useInventoryVms = (
providerType: provider?.spec?.type,
} as ProviderVirtualMachine,
name: vm.name,
concerns: getHighestPriorityConcern(vm),
}))
: [];

Expand Down

0 comments on commit 30d66d6

Please sign in to comment.