Skip to content

Commit 81a95ec

Browse files
committed
fix: I love AI sometimes
1 parent 8263c6f commit 81a95ec

File tree

5 files changed

+105
-81
lines changed

5 files changed

+105
-81
lines changed

public/locales/en.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
"EditMembers": {
166166
"addButton": "Add"
167167
},
168+
168169
"ProjectsPage": {
169170
"header": "Your instances of <span>ManagedControlPlane</span>",
170171
"projectHeader": "Project:"
@@ -360,5 +361,38 @@
360361
"selectedComponents": "Selected Components",
361362
"pleaseSelectComponents": "Choose the components you want to add to your Managed Control Plane.",
362363
"cannotLoad": "Cannot load components list"
364+
},
365+
"Hints": {
366+
"CrossplaneHint": {
367+
"title": "Crossplane",
368+
"subtitle": "Managed Resources Readiness",
369+
"activeStatus": "Active v",
370+
"progressAvailable": "% Available",
371+
"noResources": "No Resources",
372+
"inactive": "Inactive",
373+
"activate": "Activate"
374+
},
375+
"GitOpsHint": {
376+
"title": "Flux",
377+
"subtitle": "GitOps Progress",
378+
"activeStatus": "Active v",
379+
"progressAvailable": "% Available",
380+
"noResources": "No Resources",
381+
"inactive": "Inactive",
382+
"activate": "Activate"
383+
},
384+
"VaultHint": {
385+
"title": "Vault",
386+
"subtitle": "Rotating Secrets Progress",
387+
"activeStatus": "Active v",
388+
"progressAvailable": "% Available",
389+
"noResources": "No Resources",
390+
"inactive": "Inactive",
391+
"activate": "Activate"
392+
},
393+
"common": {
394+
"loading": "Loading...",
395+
"errorLoadingResources": "Error loading resources"
396+
}
363397
}
364398
}

src/components/Hints/CrossplaneHint.tsx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Card, CardHeader, ProgressIndicator, Button } from '@ui5/webcomponents-react';
2-
import { ManagedResourcesResponse } from '../../lib/api/types/crossplane/listManagedResources';
32
import { useTranslation } from 'react-i18next';
43
import { APIError } from '../../lib/api/error';
5-
import { Condition, ManagedResourceItem } from '../Graphs/types';
4+
import { getDisabledCardStyle } from './Hints';
5+
import { ManagedResourceItem, Condition } from '../../lib/shared/types';
66

77
interface CrossplaneHintProps {
88
enabled?: boolean;
99
version?: string;
1010
onActivate?: () => void;
11-
managedResources?: ManagedResourcesResponse | undefined;
11+
allItems?: ManagedResourceItem[];
1212
isLoading?: boolean;
1313
error?: APIError;
1414
}
@@ -17,26 +17,13 @@ export const CrossplaneHint: React.FC<CrossplaneHintProps> = ({
1717
enabled = false,
1818
version,
1919
onActivate,
20-
managedResources,
20+
allItems = [],
2121
isLoading,
2222
error,
2323
}) => {
2424
const { t } = useTranslation();
2525

26-
const cardStyle = enabled
27-
? {}
28-
: {
29-
background: '#f3f3f3',
30-
filter: 'grayscale(0.7)',
31-
opacity: 0.7,
32-
};
33-
34-
// Flatten all items from all managedResources entries
35-
const allItems = managedResources
36-
? managedResources
37-
.filter((managedResource) => managedResource.items)
38-
.flatMap((managedResource) => managedResource.items)
39-
: [];
26+
const cardStyle = enabled ? {} : getDisabledCardStyle();
4027

4128
// Health state counts for slider segments
4229
const healthyCount = allItems.filter((item: ManagedResourceItem) => {
@@ -52,13 +39,13 @@ export const CrossplaneHint: React.FC<CrossplaneHintProps> = ({
5239
const progressValue = totalCount > 0 ? Math.round((healthyCount / totalCount) * 100) : 0;
5340
// Display value: show ratio
5441
const progressDisplay = enabled
55-
? managedResources
56-
? `${Math.round((healthyCount / totalCount) * 100)}% Available`
57-
: 'No Resources'
58-
: 'Inactive';
42+
? allItems.length > 0
43+
? `${Math.round((healthyCount / totalCount) * 100)}${t('Hints.CrossplaneHint.progressAvailable')}`
44+
: t('Hints.CrossplaneHint.noResources')
45+
: t('Hints.CrossplaneHint.inactive');
5946
// Value state: positive if half are ready & synced
6047
const progressValueState = enabled
61-
? managedResources
48+
? allItems.length > 0
6249
? healthyCount >= totalCount / 2 && totalCount > 0
6350
? 'Positive'
6451
: 'Critical'
@@ -70,16 +57,16 @@ export const CrossplaneHint: React.FC<CrossplaneHintProps> = ({
7057
<Card
7158
header={
7259
<CardHeader
73-
additionalText={enabled ? `Active v${version ?? ''}` : undefined}
60+
additionalText={enabled ? `${t('Hints.CrossplaneHint.activeStatus')}${version ?? ''}` : undefined}
7461
avatar={
7562
<img
7663
src="/crossplane-icon.png"
7764
alt="Crossplane"
7865
style={{ width: 50, height: 50, borderRadius: '50%', background: 'transparent', objectFit: 'cover' }}
7966
/>
8067
}
81-
titleText="Crossplane"
82-
subtitleText="Managed Resources Readiness"
68+
titleText={t('Hints.CrossplaneHint.title')}
69+
subtitleText={t('Hints.CrossplaneHint.subtitle')}
8370
interactive={true}
8471
/>
8572
}
@@ -95,14 +82,14 @@ export const CrossplaneHint: React.FC<CrossplaneHintProps> = ({
9582
{isLoading ? (
9683
<ProgressIndicator
9784
value={0}
98-
displayValue={t('Loading...')}
85+
displayValue={t('Hints.common.loading')}
9986
valueState="None"
10087
style={{ width: '80%', maxWidth: 500, minWidth: 120 }}
10188
/>
10289
) : error ? (
10390
<ProgressIndicator
10491
value={0}
105-
displayValue={t('Error loading resources')}
92+
displayValue={t('Hints.common.errorLoadingResources')}
10693
valueState="Negative"
10794
style={{ width: '80%', maxWidth: 500, minWidth: 120 }}
10895
/>
@@ -126,7 +113,7 @@ export const CrossplaneHint: React.FC<CrossplaneHintProps> = ({
126113
}}
127114
>
128115
<Button design="Emphasized" onClick={onActivate}>
129-
{t('Activate')}
116+
{t('Hints.CrossplaneHint.activate')}
130117
</Button>
131118
</div>
132119
)}

src/components/Hints/GitOpsHint.tsx

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Card, CardHeader, ProgressIndicator, Button } from '@ui5/webcomponents-react';
2-
import { ManagedResourcesResponse } from '../../lib/api/types/crossplane/listManagedResources';
32
import { useTranslation } from 'react-i18next';
43
import { APIError } from '../../lib/api/error';
4+
import { getDisabledCardStyle } from './Hints';
5+
import { ManagedResourceItem } from '../../lib/shared/types';
56

67
interface GitOpsHintProps {
78
enabled?: boolean;
89
version?: string;
910
onActivate?: () => void;
10-
managedResources?: ManagedResourcesResponse | undefined;
11+
allItems?: ManagedResourceItem[];
1112
isLoading?: boolean;
1213
error?: APIError;
1314
}
@@ -16,67 +17,54 @@ export const GitOpsHint: React.FC<GitOpsHintProps> = ({
1617
enabled = false,
1718
version,
1819
onActivate,
19-
managedResources,
20+
allItems = [],
2021
isLoading,
2122
error,
2223
}) => {
2324
const { t } = useTranslation();
2425

25-
// Flatten all items from all managedResources entries
26-
const allItems = managedResources
27-
? managedResources
28-
.filter((managedResource) => managedResource.items)
29-
.flatMap((managedResource) => managedResource.items)
30-
: [];
31-
3226
const totalCount = allItems.length;
3327

3428
// Count the number of items with the flux label
3529
const fluxLabelCount = allItems.filter(
36-
(item) =>
30+
(item: ManagedResourceItem) =>
3731
item?.metadata?.labels &&
3832
Object.prototype.hasOwnProperty.call(item.metadata.labels, 'kustomize.toolkit.fluxcd.io/name'),
3933
).length;
4034

4135
const progressValue = totalCount > 0 ? Math.round((fluxLabelCount / totalCount) * 100) : 0;
4236
// Display value: show ratio
4337
const progressDisplay = enabled
44-
? managedResources
45-
? `${Math.round((fluxLabelCount / totalCount) * 100)}% Available`
46-
: 'No Resources'
47-
: 'Inactive';
38+
? allItems.length > 0
39+
? `${Math.round((fluxLabelCount / totalCount) * 100)}${t('Hints.GitOpsHint.progressAvailable')}`
40+
: t('Hints.GitOpsHint.noResources')
41+
: t('Hints.GitOpsHint.inactive');
4842
// Value state: positive if half are ready & synced
4943
const progressValueState = enabled
50-
? managedResources
44+
? allItems.length > 0
5145
? fluxLabelCount >= totalCount / 2 && totalCount > 0
5246
? 'Positive'
5347
: 'Critical'
5448
: 'None'
5549
: 'None';
5650

57-
const cardStyle = enabled
58-
? {}
59-
: {
60-
background: '#f3f3f3',
61-
filter: 'grayscale(0.7)',
62-
opacity: 0.7,
63-
};
51+
const cardStyle = enabled ? {} : getDisabledCardStyle();
6452

6553
return (
6654
<div style={{ position: 'relative', width: '100%' }}>
6755
<Card
6856
header={
6957
<CardHeader
70-
additionalText={enabled ? `Active v${version ?? ''}` : undefined}
58+
additionalText={enabled ? `${t('Hints.GitOpsHint.activeStatus')}${version ?? ''}` : undefined}
7159
avatar={
7260
<img
7361
src="/flux.png"
7462
alt="Flux"
7563
style={{ width: 50, height: 50, borderRadius: '50%', background: 'transparent', objectFit: 'cover' }}
7664
/>
7765
}
78-
titleText="Flux"
79-
subtitleText="GitOps Progress"
66+
titleText={t('Hints.GitOpsHint.title')}
67+
subtitleText={t('Hints.GitOpsHint.subtitle')}
8068
interactive={true}
8169
/>
8270
}
@@ -92,14 +80,14 @@ export const GitOpsHint: React.FC<GitOpsHintProps> = ({
9280
{isLoading ? (
9381
<ProgressIndicator
9482
value={0}
95-
displayValue={t('Loading...')}
83+
displayValue={t('Hints.common.loading')}
9684
valueState="None"
9785
style={{ width: '80%', maxWidth: 500, minWidth: 120 }}
9886
/>
9987
) : error ? (
10088
<ProgressIndicator
10189
value={0}
102-
displayValue={t('Error loading resources')}
90+
displayValue={t('Hints.common.errorLoadingResources')}
10391
valueState="Negative"
10492
style={{ width: '80%', maxWidth: 500, minWidth: 120 }}
10593
/>
@@ -123,7 +111,7 @@ export const GitOpsHint: React.FC<GitOpsHintProps> = ({
123111
}}
124112
>
125113
<Button design="Emphasized" onClick={onActivate}>
126-
{t('Activate')}
114+
{t('Hints.GitOpsHint.activate')}
127115
</Button>
128116
</div>
129117
)}

src/components/Hints/Hints.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@ import { ControlPlaneType } from '../../lib/api/types/crate/controlPlanes';
77
import { ManagedResourcesRequest } from '../../lib/api/types/crossplane/listManagedResources';
88
import { resourcesInterval } from '../../lib/shared/constants';
99
import { useApiResource } from '../../lib/api/useApiResource';
10-
import React from 'react';
10+
import { ManagedResourceItem } from '../../lib/shared/types';
11+
import React, { useMemo } from 'react';
1112

1213
interface HintsProps {
1314
mcp: ControlPlaneType;
1415
}
1516

17+
// Utility function to create disabled card style
18+
export const getDisabledCardStyle = () => ({
19+
background: '#f3f3f3',
20+
filter: 'grayscale(0.7)',
21+
opacity: 0.7,
22+
});
23+
24+
// Utility function to flatten managed resources
25+
export const flattenManagedResources = (managedResources: any): ManagedResourceItem[] => {
26+
if (!managedResources || !Array.isArray(managedResources)) return [];
27+
28+
return managedResources
29+
.filter((managedResource) => managedResource?.items)
30+
.flatMap((managedResource) => managedResource.items || []);
31+
};
32+
1633
const Hints: React.FC<HintsProps> = ({ mcp }) => {
1734
const {
1835
data: managedResources,
@@ -22,6 +39,9 @@ const Hints: React.FC<HintsProps> = ({ mcp }) => {
2239
refreshInterval: resourcesInterval,
2340
});
2441

42+
// Flatten all managed resources once and pass to components
43+
const allItems = useMemo(() => flattenManagedResources(managedResources), [managedResources]);
44+
2545
return (
2646
<FlexBox
2747
direction={FlexBoxDirection.Row}
@@ -35,21 +55,21 @@ const Hints: React.FC<HintsProps> = ({ mcp }) => {
3555
<CrossplaneHint
3656
enabled={!!mcp?.spec?.components?.crossplane}
3757
version={mcp?.spec?.components?.crossplane?.version}
38-
managedResources={managedResources}
58+
allItems={allItems}
3959
isLoading={managedResourcesLoading}
4060
error={managedResourcesError}
4161
/>
4262
<GitOpsHint
4363
enabled={!!mcp?.spec?.components?.flux}
4464
version={mcp?.spec?.components?.flux?.version}
45-
managedResources={managedResources}
65+
allItems={allItems}
4666
isLoading={managedResourcesLoading}
4767
error={managedResourcesError}
4868
/>
4969
<VaultHint
5070
enabled={!!mcp?.spec?.components?.externalSecretsOperator}
5171
version={mcp?.spec?.components?.externalSecretsOperator?.version}
52-
managedResources={managedResources}
72+
allItems={allItems}
5373
isLoading={managedResourcesLoading}
5474
error={managedResourcesError}
5575
/>

0 commit comments

Comments
 (0)