|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { useTranslation } from 'react-i18next'; |
3 | | -import { useActiveColumns } from '@console/internal/components/factory/Table/active-columns-hook'; |
4 | | -import VirtualizedTable from '@console/internal/components/factory/Table/VirtualizedTable'; |
5 | | -import { getPDBTableColumns } from './pdb-table-columns'; |
6 | | -import PodDisruptionBudgetTableRow from './PDBTableRow'; |
| 3 | +import { |
| 4 | + actionsCellProps, |
| 5 | + cellIsStickyProps, |
| 6 | + getNameCellProps, |
| 7 | + initialFiltersDefault, |
| 8 | + ConsoleDataView, |
| 9 | +} from '@console/app/src/components/data-view/ConsoleDataView'; |
| 10 | +import { GetDataViewRows } from '@console/app/src/components/data-view/types'; |
| 11 | +import { TableColumn } from '@console/dynamic-plugin-sdk/src/extensions/console-types'; |
| 12 | +import { ResourceLink, Selector } from '@console/internal/components/utils'; |
| 13 | +import { LoadingBox } from '@console/internal/components/utils/status-box'; |
| 14 | +import { referenceForModel } from '@console/internal/module/k8s'; |
| 15 | +import { LazyActionMenu, DASH } from '@console/shared'; |
| 16 | +import { Timestamp } from '@console/shared/src/components/datetime/Timestamp'; |
| 17 | +import { PodDisruptionBudgetModel } from '../../models'; |
| 18 | +import AvailabilityDisplay from './AvailabilityDisplay'; |
| 19 | +import DisruptionsAllowed from './DisruptionsAllowed'; |
7 | 20 | import { PodDisruptionBudgetKind } from './types'; |
8 | 21 |
|
9 | | -const PodDisruptionBudgetList: React.FC<PodDisruptionBudgetsListProps> = (props) => { |
| 22 | +export const tableColumnInfo = [ |
| 23 | + { id: 'name' }, |
| 24 | + { id: 'namespace' }, |
| 25 | + { id: 'selector' }, |
| 26 | + { id: 'minAvailable' }, |
| 27 | + { id: 'disruptionsAllowed' }, |
| 28 | + { id: 'creationTimestamp' }, |
| 29 | + { id: '' }, |
| 30 | +]; |
| 31 | + |
| 32 | +const getDataViewRows: GetDataViewRows<PodDisruptionBudgetKind, undefined> = (data, columns) => { |
| 33 | + return data.map(({ obj: pdb }) => { |
| 34 | + const { name, namespace } = pdb.metadata; |
| 35 | + const resourceKind = referenceForModel(PodDisruptionBudgetModel); |
| 36 | + const context = { [resourceKind]: pdb }; |
| 37 | + |
| 38 | + const rowCells = { |
| 39 | + [tableColumnInfo[0].id]: { |
| 40 | + cell: <ResourceLink kind={resourceKind} name={name} namespace={namespace} />, |
| 41 | + props: getNameCellProps(name), |
| 42 | + }, |
| 43 | + [tableColumnInfo[1].id]: { |
| 44 | + cell: <ResourceLink kind="Namespace" name={namespace} />, |
| 45 | + }, |
| 46 | + [tableColumnInfo[2].id]: { |
| 47 | + cell: <Selector selector={pdb.spec.selector} namespace={namespace} />, |
| 48 | + }, |
| 49 | + [tableColumnInfo[3].id]: { |
| 50 | + cell: <AvailabilityDisplay pdb={pdb} />, |
| 51 | + }, |
| 52 | + [tableColumnInfo[4].id]: { |
| 53 | + cell: <DisruptionsAllowed pdb={pdb} />, |
| 54 | + }, |
| 55 | + [tableColumnInfo[5].id]: { |
| 56 | + cell: <Timestamp timestamp={pdb.metadata.creationTimestamp} />, |
| 57 | + }, |
| 58 | + [tableColumnInfo[6].id]: { |
| 59 | + cell: <LazyActionMenu context={context} />, |
| 60 | + props: actionsCellProps, |
| 61 | + }, |
| 62 | + }; |
| 63 | + |
| 64 | + return columns.map(({ id }) => { |
| 65 | + const cell = rowCells[id]?.cell || DASH; |
| 66 | + return { |
| 67 | + id, |
| 68 | + props: rowCells[id]?.props, |
| 69 | + cell, |
| 70 | + }; |
| 71 | + }); |
| 72 | + }); |
| 73 | +}; |
| 74 | + |
| 75 | +const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => { |
10 | 76 | const { t } = useTranslation(); |
11 | | - const [columns] = useActiveColumns({ columns: getPDBTableColumns() }); |
| 77 | + const columns = React.useMemo(() => { |
| 78 | + return [ |
| 79 | + { |
| 80 | + title: t('console-app~Name'), |
| 81 | + id: tableColumnInfo[0].id, |
| 82 | + sort: 'metadata.name', |
| 83 | + props: { |
| 84 | + ...cellIsStickyProps, |
| 85 | + modifier: 'nowrap', |
| 86 | + }, |
| 87 | + }, |
| 88 | + { |
| 89 | + title: t('console-app~Namespace'), |
| 90 | + id: tableColumnInfo[1].id, |
| 91 | + sort: 'metadata.namespace', |
| 92 | + props: { |
| 93 | + modifier: 'nowrap', |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + title: t('console-app~Selector'), |
| 98 | + id: tableColumnInfo[2].id, |
| 99 | + sort: 'spec.selector', |
| 100 | + props: { |
| 101 | + modifier: 'nowrap', |
| 102 | + width: 20, |
| 103 | + }, |
| 104 | + }, |
| 105 | + { |
| 106 | + title: t('console-app~Availability'), |
| 107 | + id: tableColumnInfo[3].id, |
| 108 | + sort: 'spec.minAvailable', |
| 109 | + props: { |
| 110 | + modifier: 'nowrap', |
| 111 | + }, |
| 112 | + }, |
| 113 | + { |
| 114 | + title: t('console-app~Allowed disruptions'), |
| 115 | + id: tableColumnInfo[4].id, |
| 116 | + sort: 'status.disruptionsAllowed', |
| 117 | + props: { |
| 118 | + modifier: 'nowrap', |
| 119 | + }, |
| 120 | + }, |
| 121 | + { |
| 122 | + title: t('console-app~Created'), |
| 123 | + id: tableColumnInfo[5].id, |
| 124 | + sort: 'metadata.creationTimestamp', |
| 125 | + props: { |
| 126 | + modifier: 'nowrap', |
| 127 | + }, |
| 128 | + }, |
| 129 | + { |
| 130 | + title: '', |
| 131 | + id: tableColumnInfo[6].id, |
| 132 | + props: { |
| 133 | + ...cellIsStickyProps, |
| 134 | + }, |
| 135 | + }, |
| 136 | + ]; |
| 137 | + }, [t]); |
| 138 | + return columns; |
| 139 | +}; |
| 140 | + |
| 141 | +const PodDisruptionBudgetList: React.FCC<PodDisruptionBudgetsListProps> = ({ |
| 142 | + data, |
| 143 | + loaded, |
| 144 | + ...props |
| 145 | +}) => { |
| 146 | + const columns = usePDBColumns(); |
12 | 147 |
|
13 | 148 | return ( |
14 | | - <VirtualizedTable<PodDisruptionBudgetKind> |
15 | | - {...props} |
16 | | - aria-label={t('console-app~PodDisruptionBudgets')} |
17 | | - label={t('console-app~PodDisruptionBudgets')} |
18 | | - columns={columns} |
19 | | - Row={PodDisruptionBudgetTableRow} |
20 | | - /> |
| 149 | + <React.Suspense fallback={<LoadingBox />}> |
| 150 | + <ConsoleDataView<PodDisruptionBudgetKind> |
| 151 | + {...props} |
| 152 | + label={PodDisruptionBudgetModel.labelPlural} |
| 153 | + data={data} |
| 154 | + loaded={loaded} |
| 155 | + columns={columns} |
| 156 | + initialFilters={initialFiltersDefault} |
| 157 | + getDataViewRows={getDataViewRows} |
| 158 | + hideColumnManagement |
| 159 | + /> |
| 160 | + </React.Suspense> |
21 | 161 | ); |
22 | 162 | }; |
23 | 163 |
|
24 | 164 | export default PodDisruptionBudgetList; |
25 | 165 |
|
26 | 166 | type PodDisruptionBudgetsListProps = { |
27 | 167 | data: PodDisruptionBudgetKind[]; |
28 | | - unfilteredData: PodDisruptionBudgetKind[]; |
29 | 168 | loaded: boolean; |
30 | | - loadError: any; |
| 169 | + loadError?: any; |
| 170 | + [key: string]: any; |
31 | 171 | }; |
0 commit comments