Skip to content

Commit 0692e9c

Browse files
after rebase
Adjusting to resources approach + adding transition time
1 parent 05a7b50 commit 0692e9c

File tree

6 files changed

+68
-44
lines changed

6 files changed

+68
-44
lines changed

src/components/ControlPlane/ManagedResources.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { timeAgo } from '../../utils/i18n/timeAgo';
66
import IllustratedError from '../Shared/IllustratedError';
77
import '@ui5/webcomponents-icons/dist/sys-enter-2';
88
import '@ui5/webcomponents-icons/dist/sys-cancel-2';
9+
import { resourcesInterval } from '../../lib/shared/constants';
10+
import { StatusCellProps } from '../../lib/shared/interfaces';
911

1012
interface CellData<T> {
1113
cell: {
@@ -30,7 +32,7 @@ export function ManagedResources() {
3032
const { t } = useTranslation();
3133

3234
let {data: managedResources, error, isLoading} = useResource(ManagedResourcesRequest, {
33-
refreshInterval: 30000 // Resources are quite expensive to fetch, so we refresh every 30 seconds
35+
refreshInterval: resourcesInterval // Resources are quite expensive to fetch, so we refresh every 30 seconds
3436
});
3537

3638
const columns: AnalyticalTableColumnDefinition[] = [
@@ -110,13 +112,7 @@ export function ManagedResources() {
110112
)
111113
}
112114

113-
114-
interface ResourceStatusCellProps {
115-
value: boolean;
116-
transitionTime: string;
117-
}
118-
119-
function ResourceStatusCell({ value, transitionTime }: ResourceStatusCellProps) {
115+
function ResourceStatusCell({ value, transitionTime }: StatusCellProps) {
120116
return <Icon
121117
design={value ? 'Positive' : 'Negative'}
122118
name={value ? 'sys-enter-2' : 'sys-cancel-2'}

src/components/ControlPlane/Providers.tsx

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,78 @@ import IllustratedError from '../Shared/IllustratedError';
66
import '@ui5/webcomponents-icons/dist/sys-enter-2';
77
import '@ui5/webcomponents-icons/dist/sys-cancel-2';
88
import { 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

1113
interface 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

1732
export 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+
}

src/components/ControlPlane/ProvidersConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AnalyticalTable, AnalyticalTableColumnDefinition, AnalyticalTableScaleW
44
import '@ui5/webcomponents-icons/dist/sys-enter-2';
55
import '@ui5/webcomponents-icons/dist/sys-cancel-2';
66

7+
//empty table TBD
78
export function ProvidersConfig() {
89
const { t } = useTranslation();
910

src/lib/api/types/crossplane/listProviders.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import { Resource } from "../resource";
22

33
export type ProvidersListResponse = {
44
items: [{
5+
spec: any;
56
kind: string;
67
metadata: {
78
name: string;
89
creationTimestamp: string;
910
};
1011
status: {
1112
conditions: [{
12-
type: "Ready" | "Synced" | unknown;
13+
type: "Healthy" | "Installed" | unknown;
14+
status: "True" | "False";
15+
lastTransitionTime: string;
1316
}]
1417
};
1518
}];

src/lib/shared/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const resourcesInterval = 30000;

src/lib/shared/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface StatusCellProps {
2+
value: boolean;
3+
transitionTime: string;
4+
}

0 commit comments

Comments
 (0)