1
+ import * as React from 'react' ;
1
2
import { useCallback } from 'react' ;
2
- import i18next from 'i18next' ;
3
3
import { useTranslation } from 'react-i18next' ;
4
- import { sortable } from '@patternfly/react-table' ;
5
4
import {
6
5
Button ,
7
6
DescriptionList ,
@@ -14,11 +13,21 @@ import {
14
13
import { PencilAltIcon } from '@patternfly/react-icons/dist/esm/icons/pencil-alt-icon' ;
15
14
16
15
import PaneBody from '@console/shared/src/components/layout/PaneBody' ;
17
- import { referenceForModel , K8sResourceKind } from '../module/k8s' ;
18
- import { ListPage , DetailsPage , Table , TableData , RowFunctionArgs } from './factory' ;
16
+ import { referenceForModel , K8sResourceKind , TableColumn } from '../module/k8s' ;
17
+ import { ListPage , DetailsPage } from './factory' ;
18
+ import {
19
+ actionsCellProps ,
20
+ cellIsStickyProps ,
21
+ getNameCellProps ,
22
+ initialFiltersDefault ,
23
+ ResourceDataView ,
24
+ } from '@console/app/src/components/data-view/ResourceDataView' ;
25
+ import { GetDataViewRows } from '@console/app/src/components/data-view/types' ;
19
26
import { SectionHeading , LabelList , navFactory , ResourceLink , Selector , pluralize } from './utils' ;
20
27
import { useConfigureCountModal } from './modals/configure-count-modal' ;
21
28
import { AlertmanagerModel } from '../models' ;
29
+ import { LoadingBox } from './utils/status-box' ;
30
+ import { LazyActionMenu } from '@console/shared' ;
22
31
23
32
const Details : React . FCC < DetailsProps > = ( props ) => {
24
33
const alertManager = props . obj ;
@@ -97,93 +106,143 @@ const Details: React.FCC<DetailsProps> = (props) => {
97
106
} ;
98
107
99
108
const { details, editYaml } = navFactory ;
109
+ const kind = referenceForModel ( AlertmanagerModel ) ;
100
110
101
111
export const AlertManagersDetailsPage = ( props ) => (
102
112
< DetailsPage { ...props } pages = { [ details ( Details ) , editYaml ( ) ] } />
103
113
) ;
104
114
105
- const tableColumnClasses = [
106
- '' ,
107
- '' ,
108
- 'pf-m-hidden pf-m-visible-on-md pf-v6-u-w-25-on-md' ,
109
- 'pf-m-hidden pf-m-visible-on-lg' ,
110
- 'pf-m-hidden pf-m-visible-on-lg pf-v6-u-w-25-on-lg' ,
115
+ const tableColumnInfo = [
116
+ { id : 'name' } ,
117
+ { id : 'namespace' } ,
118
+ { id : 'labels' } ,
119
+ { id : 'version' } ,
120
+ { id : 'nodeSelector' } ,
121
+ { id : 'actions' } ,
111
122
] ;
112
123
113
- const AlertManagerTableRow : React . FC < RowFunctionArgs < K8sResourceKind > > = ( {
114
- obj : alertManager ,
115
- } ) => {
116
- const { metadata, spec } = alertManager ;
117
- return (
118
- < >
119
- < TableData className = { tableColumnClasses [ 0 ] } >
120
- < ResourceLink
121
- kind = { referenceForModel ( AlertmanagerModel ) }
122
- name = { metadata . name }
123
- namespace = { metadata . namespace }
124
- title = { metadata . uid }
125
- />
126
- </ TableData >
127
- < TableData className = { tableColumnClasses [ 1 ] } >
128
- < ResourceLink kind = "Namespace" name = { metadata . namespace } title = { metadata . namespace } />
129
- </ TableData >
130
- < TableData className = { tableColumnClasses [ 2 ] } >
131
- < LabelList kind = { AlertmanagerModel . kind } labels = { metadata . labels } />
132
- </ TableData >
133
- < TableData className = { tableColumnClasses [ 3 ] } > { spec . version } </ TableData >
134
- < TableData className = { tableColumnClasses [ 4 ] } >
135
- < Selector selector = { spec . nodeSelector } kind = "Node" />
136
- </ TableData >
137
- </ >
138
- ) ;
139
- } ;
124
+ const getDataViewRows : GetDataViewRows < K8sResourceKind , undefined > = ( data , columns ) => {
125
+ return data . map ( ( { obj : alertManager } ) => {
126
+ const { metadata, spec } = alertManager ;
127
+ const resourceKind = referenceForModel ( AlertmanagerModel ) ;
128
+ const context = { [ resourceKind ] : alertManager } ;
140
129
141
- const AlertManagerTableHeader = ( ) => {
142
- return [
143
- {
144
- title : i18next . t ( 'public~Name' ) ,
145
- sortField : 'metadata.name' ,
146
- transforms : [ sortable ] ,
147
- props : { className : tableColumnClasses [ 0 ] } ,
148
- } ,
149
- {
150
- title : i18next . t ( 'public~Namespace' ) ,
151
- sortField : 'metadata.namespace' ,
152
- transforms : [ sortable ] ,
153
- props : { className : tableColumnClasses [ 1 ] } ,
154
- } ,
155
- {
156
- title : i18next . t ( 'public~Labels' ) ,
157
- sortField : 'metadata.labels' ,
158
- transforms : [ sortable ] ,
159
- props : { className : tableColumnClasses [ 2 ] } ,
160
- } ,
161
- {
162
- title : i18next . t ( 'public~Version' ) ,
163
- sortField : 'spec.version' ,
164
- transforms : [ sortable ] ,
165
- props : { className : tableColumnClasses [ 3 ] } ,
166
- } ,
167
- {
168
- title : i18next . t ( 'public~Node selector' ) ,
169
- sortField : 'spec.nodeSelector' ,
170
- transforms : [ sortable ] ,
171
- props : { className : tableColumnClasses [ 4 ] } ,
172
- } ,
173
- ] ;
130
+ const rowCells = {
131
+ [ tableColumnInfo [ 0 ] . id ] : {
132
+ cell : (
133
+ < ResourceLink
134
+ kind = { referenceForModel ( AlertmanagerModel ) }
135
+ name = { metadata . name }
136
+ namespace = { metadata . namespace }
137
+ title = { metadata . uid }
138
+ />
139
+ ) ,
140
+ props : getNameCellProps ( metadata . name ) ,
141
+ } ,
142
+ [ tableColumnInfo [ 1 ] . id ] : {
143
+ cell : (
144
+ < ResourceLink kind = "Namespace" name = { metadata . namespace } title = { metadata . namespace } />
145
+ ) ,
146
+ } ,
147
+ [ tableColumnInfo [ 2 ] . id ] : {
148
+ cell : < LabelList kind = { AlertmanagerModel . kind } labels = { metadata . labels } /> ,
149
+ } ,
150
+ [ tableColumnInfo [ 3 ] . id ] : {
151
+ cell : spec . version || '-' ,
152
+ } ,
153
+ [ tableColumnInfo [ 4 ] . id ] : {
154
+ cell : < Selector selector = { spec . nodeSelector } kind = "Node" /> ,
155
+ } ,
156
+ [ tableColumnInfo [ 5 ] . id ] : {
157
+ cell : < LazyActionMenu context = { context } /> ,
158
+ props : actionsCellProps ,
159
+ } ,
160
+ } ;
161
+
162
+ return columns . map ( ( { id } ) => {
163
+ const cell = rowCells [ id ] ?. cell || '-' ;
164
+ return {
165
+ id,
166
+ props : rowCells [ id ] ?. props ,
167
+ cell,
168
+ } ;
169
+ } ) ;
170
+ } ) ;
174
171
} ;
175
- AlertManagerTableHeader . displayName = 'AlertManagerTableHeader' ;
176
172
177
- const AlertManagersList = ( props ) => {
173
+ const useAlertManagerColumns = ( ) : TableColumn < K8sResourceKind > [ ] => {
178
174
const { t } = useTranslation ( ) ;
175
+ const columns = React . useMemo ( ( ) => {
176
+ return [
177
+ {
178
+ title : t ( 'public~Name' ) ,
179
+ id : tableColumnInfo [ 0 ] . id ,
180
+ sort : 'metadata.name' ,
181
+ props : {
182
+ ...cellIsStickyProps ,
183
+ modifier : 'nowrap' ,
184
+ } ,
185
+ } ,
186
+ {
187
+ title : t ( 'public~Namespace' ) ,
188
+ id : tableColumnInfo [ 1 ] . id ,
189
+ sort : 'metadata.namespace' ,
190
+ props : {
191
+ modifier : 'nowrap' ,
192
+ } ,
193
+ } ,
194
+ {
195
+ title : t ( 'public~Labels' ) ,
196
+ id : tableColumnInfo [ 2 ] . id ,
197
+ sort : 'metadata.labels' ,
198
+ props : {
199
+ modifier : 'nowrap' ,
200
+ } ,
201
+ } ,
202
+ {
203
+ title : t ( 'public~Version' ) ,
204
+ id : tableColumnInfo [ 3 ] . id ,
205
+ sort : 'spec.version' ,
206
+ props : {
207
+ modifier : 'nowrap' ,
208
+ } ,
209
+ } ,
210
+ {
211
+ title : t ( 'public~Node selector' ) ,
212
+ id : tableColumnInfo [ 4 ] . id ,
213
+ sort : 'spec.nodeSelector' ,
214
+ props : {
215
+ modifier : 'nowrap' ,
216
+ } ,
217
+ } ,
218
+ {
219
+ title : '' ,
220
+ id : tableColumnInfo [ 5 ] . id ,
221
+ props : {
222
+ ...cellIsStickyProps ,
223
+ } ,
224
+ } ,
225
+ ] ;
226
+ } , [ t ] ) ;
227
+ return columns ;
228
+ } ;
229
+
230
+ const AlertManagersList : React . FCC < AlertManagersListProps > = ( { data, loaded, ...props } ) => {
231
+ const columns = useAlertManagerColumns ( ) ;
232
+
179
233
return (
180
- < Table
181
- { ...props }
182
- aria-label = { t ( 'public~Alertmanagers' ) }
183
- Header = { AlertManagerTableHeader }
184
- Row = { AlertManagerTableRow }
185
- virtualize
186
- />
234
+ < React . Suspense fallback = { < LoadingBox /> } >
235
+ < ResourceDataView
236
+ { ...props }
237
+ label = { AlertmanagerModel . labelPlural }
238
+ data = { data }
239
+ loaded = { loaded }
240
+ columns = { columns }
241
+ initialFilters = { initialFiltersDefault }
242
+ getDataViewRows = { getDataViewRows }
243
+ hideColumnManagement = { true }
244
+ />
245
+ </ React . Suspense >
187
246
) ;
188
247
} ;
189
248
@@ -192,10 +251,17 @@ export const AlertManagersPage = (props) => (
192
251
{ ...props }
193
252
ListComponent = { AlertManagersList }
194
253
canCreate = { false }
195
- kind = { referenceForModel ( AlertmanagerModel ) }
254
+ kind = { kind }
255
+ omitFilterToolbar = { true }
196
256
/>
197
257
) ;
198
258
199
259
type DetailsProps = {
200
260
obj : K8sResourceKind ;
201
261
} ;
262
+
263
+ type AlertManagersListProps = {
264
+ data : K8sResourceKind [ ] ;
265
+ loaded : boolean ;
266
+ [ key : string ] : any ;
267
+ } ;
0 commit comments