Skip to content

Commit a7594fb

Browse files
committed
fix
1 parent 1b3f3de commit a7594fb

File tree

2 files changed

+50
-55
lines changed

2 files changed

+50
-55
lines changed

src/components/ComponentsSelection/ComponentsSelectionContainer.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
6666

6767
const newComponentsList = availableManagedComponentsListData.items
6868
.map((item) => {
69-
const versions = sortVersions(item.status.versions);
70-
const template = defaultComponents.find((dc) => dc.name === item.metadata.name);
69+
const versions = sortVersions(item.status?.versions ?? []);
70+
const template = defaultComponents.find((dc) => dc.name === (item.metadata?.name ?? ''));
7171
const templateVersion = template?.version;
7272
let selectedVersion = template
7373
? templateVersion && versions.includes(templateVersion)
@@ -76,14 +76,14 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
7676
: (versions[0] ?? '');
7777
let isSelected = !!template;
7878

79-
const initSel = initialSelection?.[item.metadata.name];
79+
const initSel = initialSelection?.[item.metadata?.name ?? ''];
8080
if (initSel) {
8181
// Override selection and version from initial selection if provided
8282
isSelected = Boolean(initSel.isSelected);
8383
selectedVersion = initSel.version && versions.includes(initSel.version) ? initSel.version : '';
8484
}
8585
return {
86-
name: item.metadata.name,
86+
name: item.metadata?.name ?? '',
8787
versions,
8888
selectedVersion,
8989
isSelected,
@@ -106,12 +106,12 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
106106
const errs: string[] = [];
107107
defaultComponents.forEach((dc: TemplateDefaultComponent) => {
108108
if (!dc?.name) return;
109-
const item = items.find((it) => it.metadata.name === dc.name);
109+
const item = items.find((it) => it.metadata?.name === dc.name);
110110
if (!item) {
111111
errs.push(`Component "${dc.name}" from template is not available.`);
112112
return;
113113
}
114-
const versions: string[] = Array.isArray(item.status?.versions) ? item.status.versions : [];
114+
const versions: string[] = Array.isArray(item.status?.versions) ? (item.status?.versions as string[]) : [];
115115
if (dc.version && !versions.includes(dc.version)) {
116116
errs.push(`Component "${dc.name}" version "${dc.version}" from template is not available.`);
117117
}
@@ -145,15 +145,16 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
145145
if (isLoading) {
146146
return <Loading />;
147147
}
148-
149-
if (error) {
150-
return <IllustratedError compact={true} />;
151-
}
152-
153-
// Defensive: If the API returned no items, show error
154-
if (!componentsList || componentsList.length === 0) {
155-
return <IllustratedError title={t('componentsSelection.cannotLoad')} compact={true} />;
156-
}
148+
console.log(error);
149+
150+
// if (error) {
151+
// return <IllustratedError compact={true} />;
152+
// }
153+
//
154+
// // Defensive: If the API returned no items, show error
155+
// if (!componentsList || componentsList.length === 0) {
156+
// return <IllustratedError title={t('componentsSelection.cannotLoad')} compact={true} />;
157+
// }
157158

158159
return (
159160
<ComponentsSelection

src/lib/api/types/crate/listManagedComponents.ts

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,44 @@
11
import { Resource } from '../resource';
22

3-
interface ManagedComponentList {
4-
apiVersion: string;
5-
kind: string;
6-
items: ManagedComponent[];
7-
metadata: ListMetadata;
8-
}
9-
10-
interface ListMetadata {
11-
continue: string;
12-
resourceVersion: string;
13-
}
14-
15-
interface ManagedComponent {
16-
apiVersion: string;
17-
kind: string;
18-
metadata: ManagedComponentMetadata;
19-
spec: Record<string, unknown>;
20-
status: ManagedComponentStatus;
3+
export interface ManagedComponentList {
4+
apiVersion?: string;
5+
kind?: string;
6+
metadata?: {
7+
continue?: string;
8+
resourceVersion?: string;
9+
[key: string]: unknown;
10+
};
11+
items?: ManagedComponent[];
2112
}
2213

23-
interface ManagedComponentMetadata {
24-
creationTimestamp: string;
25-
generation: number;
26-
managedFields: ManagedField[];
27-
name: string;
28-
resourceVersion: string;
29-
uid: string;
14+
export interface ManagedComponent {
15+
apiVersion?: string;
16+
kind?: string;
17+
metadata?: {
18+
creationTimestamp?: string;
19+
generation?: number;
20+
managedFields?: ManagedField[];
21+
name?: string;
22+
resourceVersion?: string;
23+
uid?: string;
24+
[key: string]: unknown;
25+
};
26+
spec?: Record<string, unknown>;
27+
status?: {
28+
versions?: string[];
29+
[key: string]: unknown;
30+
};
3031
}
3132

32-
interface ManagedField {
33-
apiVersion: string;
34-
fieldsType: string;
35-
fieldsV1: FieldsV1;
36-
manager: string;
37-
operation: string;
38-
time: string;
33+
export interface ManagedField {
34+
apiVersion?: string;
35+
fieldsType?: string;
36+
fieldsV1?: Record<string, unknown>;
37+
manager?: string;
38+
operation?: string;
39+
time?: string;
3940
subresource?: string;
40-
}
41-
42-
interface FieldsV1 {
43-
[key: string]: never;
44-
}
45-
46-
interface ManagedComponentStatus {
47-
versions: string[];
41+
[key: string]: unknown;
4842
}
4943

5044
export const ListManagedComponents = (): Resource<ManagedComponentList> => {

0 commit comments

Comments
 (0)