-
Notifications
You must be signed in to change notification settings - Fork 593
/
table-filters.ts
51 lines (49 loc) · 1.56 KB
/
table-filters.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { TFunction } from 'i18next';
import * as _ from 'lodash';
import { RowFilter } from '@console/dynamic-plugin-sdk';
import {
getVmStatusLabelFromPrintable,
VM_STATUS_SIMPLE_LABELS,
} from '../../constants/vm/vm-status';
import { VMStatusBundle } from '../../statuses/vm/types';
export const vmStatusFilter = (t: TFunction): RowFilter => {
return {
filterGroupName: t('kubevirt-plugin~Status'),
type: 'vm-status',
reducer: (obj) => {
return ((obj?.metadata as any)?.vmStatusBundle as VMStatusBundle)?.status?.getSimpleLabel();
},
items: VM_STATUS_SIMPLE_LABELS.map((status) => ({
id: status,
title: status,
})),
filter: (statuses, obj) => {
const status = ((obj?.metadata as any)
?.vmStatusBundle as VMStatusBundle)?.status.getSimpleLabel();
return (
statuses.selected?.length === 0 ||
statuses.selected?.includes(status) ||
!_.includes(statuses.all, status)
);
},
};
};
export const vmStatusFilterNew = (t: TFunction): RowFilter => {
return {
filterGroupName: t('kubevirt-plugin~Status'),
type: 'vm-status',
reducer: (obj) => getVmStatusLabelFromPrintable(obj?.metadata?.status),
items: VM_STATUS_SIMPLE_LABELS.map((status) => ({
id: status,
title: status,
})),
filter: (statuses, obj) => {
const status = getVmStatusLabelFromPrintable(obj?.metadata?.status);
return (
statuses.selected?.length === 0 ||
statuses.selected?.includes(status) ||
!_.includes(statuses?.all, status)
);
},
};
};