@@ -6,49 +6,78 @@ import IllustratedError from '../Shared/IllustratedError';
66import '@ui5/webcomponents-icons/dist/sys-enter-2' ;
77import '@ui5/webcomponents-icons/dist/sys-cancel-2' ;
88import { ProvidersListRequest } from '../../lib/api/types/crossplane/listProviders' ;
9- import ReactTimeAgo from 'react-time-ago' ;
9+ import { resourcesInterval } from '../../lib/shared/constants' ;
10+ import { timeAgo } from '../../utils/i18n/timeAgo' ;
11+ import { StatusCellProps } from '../../lib/shared/interfaces' ;
1012
1113interface CellData < T > {
12- cell : {
13- value : T | null ;
14- } ;
15- }
14+ cell : {
15+ value : T | null ; // null for grouping rows
16+ row : {
17+ original ?: providersRow ; // missing for grouping rows
18+ }
19+ } ;
20+ }
21+
22+ type providersRow = {
23+ name : string
24+ version : string ;
25+ healthy : boolean ;
26+ healthyTransitionTime : string ;
27+ installed : boolean ;
28+ installedTransitionTime : string ;
29+ created : string ;
30+ }
1631
1732export function Providers ( ) {
1833 const { t } = useTranslation ( ) ;
1934
2035 let { data : providers , error, isLoading} = useResource ( ProvidersListRequest , {
21- refreshInterval : 300000
36+ refreshInterval : resourcesInterval
2237 } ) ;
2338
2439 const columns : AnalyticalTableColumnDefinition [ ] = [
2540 {
2641 Header : t ( 'Providers.tableHeaderName' ) ,
27- accessor : 'metadata. name' ,
42+ accessor : 'name' ,
2843 } ,
2944 {
3045 Header : t ( 'Providers.tableHeaderVersion' ) ,
31- accessor : 'spec.package' ,
32- Cell : ( cellData : CellData < string > ) => cellData . cell . value ?. match ( / \d + ( \. \d + ) + / )
46+ accessor : 'version' ,
3347 } ,
3448 {
3549 Header : t ( 'Providers.tableHeaderInstalled' ) ,
36- accessor : 'status.conditions[1].status ' ,
37- Cell : ( cellData : CellData < boolean > ) => < ResourceStatusCell cellData = { cellData } />
50+ accessor : 'installed ' ,
51+ Cell : ( cellData : CellData < providersRow [ 'installed' ] > ) => cellData . cell . row . original ?. installed != null ? < ResourceStatusCell value = { cellData . cell . row . original ?. installed } transitionTime = { cellData . cell . row . original ?. installedTransitionTime } /> : null
3852 } ,
39- //last.transitiontime on hover
4053 {
4154 Header : t ( 'Providers.tableHeaderHealthy' ) ,
42- accessor : 'status.conditions[0].status ' ,
43- Cell : ( cellData : CellData < boolean > ) => < ResourceStatusCell cellData = { cellData } />
55+ accessor : 'healthy ' ,
56+ Cell : ( cellData : CellData < providersRow [ 'healthy' ] > ) => cellData . cell . row . original ?. installed != null ? < ResourceStatusCell value = { cellData . cell . row . original ?. healthy } transitionTime = { cellData . cell . row . original ?. healthyTransitionTime } /> : null
4457 } ,
4558 {
4659 Header : t ( 'Providers.tableHeaderCreated' ) ,
47- accessor : 'metadata.creationTimestamp' ,
48- Cell : ( props : any ) => < ReactTimeAgo date = { new Date ( props . cell . value ) } /> ,
60+ accessor : 'created' ,
4961 } ,
5062 ] ;
5163
64+ const rows : providersRow [ ] =
65+ providers ?. items ?. map ( ( item ) => {
66+ const installed = item . status . conditions ?. find ( ( condition ) => condition . type === 'Installed' ) ;
67+ const healhty = item . status . conditions ?. find ( ( condition ) => condition . type === 'Healthy' ) ;
68+
69+ return {
70+ name : item . metadata . name ,
71+ created : timeAgo . format ( new Date ( item . metadata . creationTimestamp ) ) ,
72+ installed : installed ?. status === "True" ,
73+ installedTransitionTime : installed ?. lastTransitionTime ?? "" ,
74+ healthy : healhty ?. status === "True" ,
75+ healthyTransitionTime : healhty ?. lastTransitionTime ?? "" ,
76+ version : item . spec . package . match ( / \d + ( \. \d + ) + / ) ,
77+ }
78+ } )
79+ ?? [ ] ;
80+
5281 return (
5382 < >
5483 < Title level = 'H4' > { t ( 'Providers.headerProviders' ) } </ Title >
@@ -58,9 +87,8 @@ export function Providers() {
5887 { ! error &&
5988 < AnalyticalTable
6089 columns = { columns }
61- data = { providers ?. items ?? [ ] }
90+ data = { rows }
6291 minRows = { 1 }
63- groupBy = { [ 'name' ] }
6492 scaleWidthMode = { AnalyticalTableScaleWidthMode . Smart }
6593 loading = { isLoading }
6694 filterable
@@ -83,20 +111,11 @@ export function Providers() {
83111 )
84112}
85113
86- interface ResourceStatusCellProps {
87- cellData : CellData < boolean > ;
88- }
89-
90- function ResourceStatusCell ( { cellData } : ResourceStatusCellProps ) {
91- const { t } = useTranslation ( ) ;
92-
93- if ( cellData . cell . value === null ) {
94- return null ;
95- }
96-
97- return < Icon
98- design = { cellData . cell . value ? 'Positive' : 'Negative' }
99- accessibleName = { cellData . cell . value ? t ( 'ManagedResources.iconAriaYes' ) : t ( 'ManagedResources.iconAriaNo' ) }
100- name = { cellData . cell . value ? 'sys-enter-2' : 'sys-cancel-2' }
101- />
102- }
114+ function ResourceStatusCell ( { value, transitionTime } : StatusCellProps ) {
115+ return < Icon
116+ design = { value ? 'Positive' : 'Negative' }
117+ name = { value ? 'sys-enter-2' : 'sys-cancel-2' }
118+ showTooltip = { true }
119+ accessibleName = { timeAgo . format ( new Date ( transitionTime ) ) }
120+ />
121+ }
0 commit comments