1-
21import { useTranslation } from 'react-i18next' ;
3- import { AnalyticalTable , AnalyticalTableColumnDefinition , AnalyticalTableScaleWidthMode , Icon , Title } from '@ui5/webcomponents-react' ;
2+ import {
3+ AnalyticalTable ,
4+ AnalyticalTableColumnDefinition ,
5+ AnalyticalTableScaleWidthMode ,
6+ Title ,
7+ } from '@ui5/webcomponents-react' ;
48import useResource from '../../lib/api/useApiResource' ;
59import IllustratedError from '../Shared/IllustratedError' ;
610import '@ui5/webcomponents-icons/dist/sys-enter-2' ;
711import '@ui5/webcomponents-icons/dist/sys-cancel-2' ;
812import { ProvidersListRequest } from '../../lib/api/types/crossplane/listProviders' ;
913import { resourcesInterval } from '../../lib/shared/constants' ;
1014import { timeAgo } from '../../utils/i18n/timeAgo' ;
11- import { StatusCellProps } from '../../lib/shared/interfaces ' ;
15+ import { ResourceStatusCell } from '../Shared/ResourceStatusCell ' ;
1216
1317interface CellData < T > {
1418 cell : {
1519 value : T | null ; // null for grouping rows
1620 row : {
1721 original ?: ProvidersRow ; // missing for grouping rows
18- }
22+ } ;
1923 } ;
2024}
2125
2226type ProvidersRow = {
23- name : string
27+ name : string ;
2428 version : string ;
2529 healthy : boolean ;
2630 healthyTransitionTime : string ;
2731 installed : boolean ;
2832 installedTransitionTime : string ;
2933 created : string ;
30- }
34+ } ;
3135
3236export function Providers ( ) {
3337 const { t } = useTranslation ( ) ;
3438
35- let { data : providers , error, isLoading} = useResource ( ProvidersListRequest , {
36- refreshInterval : resourcesInterval
39+ const {
40+ data : providers ,
41+ error,
42+ isLoading,
43+ } = useResource ( ProvidersListRequest , {
44+ refreshInterval : resourcesInterval ,
3745 } ) ;
3846
3947 const columns : AnalyticalTableColumnDefinition [ ] = [
@@ -48,12 +56,24 @@ export function Providers() {
4856 {
4957 Header : t ( 'Providers.tableHeaderInstalled' ) ,
5058 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
59+ Cell : ( cellData : CellData < ProvidersRow [ 'installed' ] > ) =>
60+ cellData . cell . row . original ?. installed != null ? (
61+ < ResourceStatusCell
62+ value = { cellData . cell . row . original ?. installed }
63+ transitionTime = { cellData . cell . row . original ?. installedTransitionTime }
64+ />
65+ ) : null ,
5266 } ,
5367 {
5468 Header : t ( 'Providers.tableHeaderHealthy' ) ,
5569 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
70+ Cell : ( cellData : CellData < ProvidersRow [ 'healthy' ] > ) =>
71+ cellData . cell . row . original ?. installed != null ? (
72+ < ResourceStatusCell
73+ value = { cellData . cell . row . original ?. healthy }
74+ transitionTime = { cellData . cell . row . original ?. healthyTransitionTime }
75+ />
76+ ) : null ,
5777 } ,
5878 {
5979 Header : t ( 'Providers.tableHeaderCreated' ) ,
@@ -63,28 +83,31 @@ export function Providers() {
6383
6484 const rows : ProvidersRow [ ] =
6585 providers ?. items ?. map ( ( item ) => {
66- const installed = item . status . conditions ?. find ( ( condition ) => condition . type === 'Installed' ) ;
67- const healthy = item . status . conditions ?. find ( ( condition ) => condition . type === 'Healthy' ) ;
86+ const installed = item . status . conditions ?. find (
87+ ( condition ) => condition . type === 'Installed' ,
88+ ) ;
89+ const healthy = item . status . conditions ?. find (
90+ ( condition ) => condition . type === 'Healthy' ,
91+ ) ;
6892
6993 return {
7094 name : item . metadata . name ,
7195 created : timeAgo . format ( new Date ( item . metadata . creationTimestamp ) ) ,
72- installed : installed ?. status === "True" ,
73- installedTransitionTime : installed ?. lastTransitionTime ?? "" ,
74- healthy : healthy ?. status === "True" ,
75- healthyTransitionTime : healthy ?. lastTransitionTime ?? "" ,
76- version : item . spec . package . match ( / \d + ( \. \d + ) + / g) ?. toString ( ) ?? "" ,
77- }
78- } )
79- ?? [ ] ;
96+ installed : installed ?. status === 'True' ,
97+ installedTransitionTime : installed ?. lastTransitionTime ?? '' ,
98+ healthy : healthy ?. status === 'True' ,
99+ healthyTransitionTime : healthy ?. lastTransitionTime ?? '' ,
100+ version : item . spec . package . match ( / \d + ( \. \d + ) + / g) ?. toString ( ) ?? '' ,
101+ } ;
102+ } ) ?? [ ] ;
80103
81104 return (
82105 < >
83- < Title level = 'H4' > { t ( 'Providers.headerProviders' ) } </ Title >
106+ < Title level = "H4" > { t ( 'Providers.headerProviders' ) } </ Title >
84107
85- { error && < IllustratedError error = { error } /> }
108+ { error && < IllustratedError error = { error } /> }
86109
87- { ! error &&
110+ { ! error && (
88111 < AnalyticalTable
89112 columns = { columns }
90113 data = { rows }
@@ -103,19 +126,10 @@ export function Providers() {
103126 autoResetSortBy : false ,
104127 autoResetFilters : false ,
105128 autoResetRowState : false ,
106- autoResetResize : false
129+ autoResetResize : false ,
107130 } }
108131 />
109- }
132+ ) }
110133 </ >
111- )
112- }
113-
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- />
134+ ) ;
121135}
0 commit comments