Skip to content

Commit d4cb53e

Browse files
committed
refactor(iconUrl): move icon fetching from the canvas layer to the mapping layer
1 parent 9b12db9 commit d4cb53e

151 files changed

Lines changed: 5653 additions & 3619 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/ui/src/camel-utils/camel-to-tile.adapter.test.ts

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from './camel-to-tile.adapter';
1515

1616
describe('camelComponentToTile', () => {
17-
it('should return a tile with the correct type', () => {
17+
it('should return a tile with the correct type', async () => {
1818
const componentDef = {
1919
component: {
2020
name: 'my-component',
@@ -23,80 +23,79 @@ describe('camelComponentToTile', () => {
2323
},
2424
} as ICamelComponentDefinition;
2525

26-
const tile = camelComponentToTile(componentDef);
26+
const tile = await camelComponentToTile(componentDef);
2727

28-
expect(tile.type).toEqual(CatalogKind.Component);
2928
expect(tile.name).toEqual('my-component');
3029
expect(tile.description).toEqual('My Component Description');
3130
});
3231

33-
it('should populate the headerTags', () => {
32+
it('should populate the headerTags', async () => {
3433
const componentDef = {
3534
component: {
3635
supportLevel: 'Preview',
3736
},
3837
} as ICamelComponentDefinition;
3938

40-
const tile = camelComponentToTile(componentDef);
39+
const tile = await camelComponentToTile(componentDef);
4140

4241
expect(tile.headerTags).toEqual(['Component', 'Preview']);
4342
});
4443

45-
it('should populate the tags and version', () => {
44+
it('should populate the tags and version', async () => {
4645
const componentDef = {
4746
component: {
4847
label: 'label1,label2',
4948
version: '4.0.0',
5049
},
5150
} as ICamelComponentDefinition;
5251

53-
const tile = camelComponentToTile(componentDef);
52+
const tile = await camelComponentToTile(componentDef);
5453

5554
expect(tile.tags).toEqual(['label1', 'label2']);
5655
expect(tile.version).toEqual('4.0.0');
5756
});
5857

59-
it('should populate the provider', () => {
58+
it('should populate the provider', async () => {
6059
const componentDef = {
6160
component: {
6261
provider: 'my-provider',
6362
},
6463
} as ICamelComponentDefinition;
6564

66-
const tile = camelComponentToTile(componentDef);
65+
const tile = await camelComponentToTile(componentDef);
6766

6867
expect(tile.provider).toEqual('my-provider');
6968
});
7069

71-
it('should populate tags with `consumerOnly` and `producerOnly` when applicable', () => {
70+
it('should populate tags with `consumerOnly` and `producerOnly` when applicable', async () => {
7271
const componentDef = {
7372
component: {
7473
consumerOnly: true,
7574
producerOnly: true,
7675
},
7776
} as ICamelComponentDefinition;
7877

79-
const tile = camelComponentToTile(componentDef);
78+
const tile = await camelComponentToTile(componentDef);
8079

8180
expect(tile.tags).toEqual(['consumerOnly', 'producerOnly']);
8281
});
8382

84-
it('should replace the supportLevel header tag if the component is deprecated', () => {
83+
it('should replace the supportLevel header tag if the component is deprecated', async () => {
8584
const componentDef = {
8685
component: {
8786
supportLevel: 'Stable',
8887
deprecated: true,
8988
},
9089
} as ICamelComponentDefinition;
9190

92-
const tile = camelComponentToTile(componentDef);
91+
const tile = await camelComponentToTile(componentDef);
9392

9493
expect(tile.headerTags).toEqual(['Component', 'Deprecated']);
9594
});
9695
});
9796

9897
describe('camelProcessorToTile', () => {
99-
it('should return a tile with the correct type', () => {
98+
it('should return a tile with the correct type', async () => {
10099
const processorDef = {
101100
model: {
102101
name: 'my-processor',
@@ -106,39 +105,38 @@ describe('camelProcessorToTile', () => {
106105
},
107106
} as ICamelProcessorDefinition;
108107

109-
const tile = camelProcessorToTile(processorDef);
108+
const tile = await camelProcessorToTile(processorDef);
110109

111-
expect(tile.type).toEqual(CatalogKind.Processor);
112110
expect(tile.name).toEqual('my-processor');
113111
expect(tile.description).toEqual('My Processor Description');
114112
});
115113

116-
it('should populate the headerTags', () => {
114+
it('should populate the headerTags', async () => {
117115
const processorDef = {
118116
model: {
119117
supportLevel: 'Preview',
120118
label: 'label1,label2',
121119
},
122120
} as ICamelProcessorDefinition;
123121

124-
const tile = camelProcessorToTile(processorDef);
122+
const tile = await camelProcessorToTile(processorDef);
125123

126124
expect(tile.headerTags).toEqual(['Processor', 'Preview']);
127125
});
128126

129-
it('should populate the tags', () => {
127+
it('should populate the tags', async () => {
130128
const processorDef = {
131129
model: {
132130
label: 'label1,label2',
133131
},
134132
} as ICamelProcessorDefinition;
135133

136-
const tile = camelProcessorToTile(processorDef);
134+
const tile = await camelProcessorToTile(processorDef);
137135

138136
expect(tile.tags).toEqual(['label1', 'label2']);
139137
});
140138

141-
it('should populate the provider', () => {
139+
it('should populate the provider', async () => {
142140
const processorDef = {
143141
model: {
144142
name: 'my-processor',
@@ -149,14 +147,14 @@ describe('camelProcessorToTile', () => {
149147
},
150148
} as ICamelProcessorDefinition;
151149

152-
const tile = camelProcessorToTile(processorDef);
150+
const tile = await camelProcessorToTile(processorDef);
153151

154152
expect(tile.provider).toEqual('my-provider');
155153
});
156154
});
157155

158156
describe('camelEntityToTile', () => {
159-
it('should return a tile with the correct type', () => {
157+
it('should return a tile with the correct type', async () => {
160158
const processorDef = {
161159
model: {
162160
name: 'my-entity',
@@ -166,16 +164,15 @@ describe('camelEntityToTile', () => {
166164
},
167165
} as ICamelProcessorDefinition;
168166

169-
const tile = camelEntityToTile(processorDef);
167+
const tile = await camelEntityToTile(processorDef);
170168

171-
expect(tile.type).toEqual(CatalogKind.Entity);
172169
expect(tile.name).toEqual('my-entity');
173170
expect(tile.description).toEqual('My Entity Description');
174171
});
175172
});
176173

177174
describe('citrusComponentToTile', () => {
178-
it('should return a tile with the correct type', () => {
175+
it('should return a tile with the correct type', async () => {
179176
const componentDef = {
180177
kind: CatalogKind.TestAction,
181178
name: 'my-action',
@@ -184,31 +181,29 @@ describe('citrusComponentToTile', () => {
184181
description: 'This is the description',
185182
} as ICitrusComponentDefinition;
186183

187-
const tile = citrusComponentToTile(componentDef);
184+
const tile = await citrusComponentToTile(componentDef);
188185

189-
expect(tile.type).toEqual(CatalogKind.TestAction);
190186
expect(tile.name).toEqual('my-action');
191187
expect(tile.title).toEqual('My Action');
192188
expect(tile.description).toEqual('This is the description');
193189
});
194190

195-
it('should return a tile with defaults', () => {
191+
it('should return a tile with defaults', async () => {
196192
const componentDef = {
197193
kind: CatalogKind.TestContainer,
198194
name: 'my-container',
199195
} as ICitrusComponentDefinition;
200196

201-
const tile = citrusComponentToTile(componentDef);
197+
const tile = await citrusComponentToTile(componentDef);
202198

203-
expect(tile.type).toEqual(CatalogKind.TestContainer);
204199
expect(tile.name).toEqual('my-container');
205200
expect(tile.title).toEqual('my-container');
206201
expect(tile.description).toBeUndefined();
207202
});
208203
});
209204

210205
describe('kameletToTile', () => {
211-
it('should return a tile with the correct type', () => {
206+
it('should return a tile with the correct type', async () => {
212207
const kameletDef = {
213208
metadata: {
214209
name: 'my-kamelet',
@@ -227,14 +222,13 @@ describe('kameletToTile', () => {
227222
},
228223
} as IKameletDefinition;
229224

230-
const tile = kameletToTile(kameletDef);
225+
const tile = await kameletToTile(kameletDef);
231226

232-
expect(tile.type).toEqual(CatalogKind.Kamelet);
233227
expect(tile.name).toEqual('my-kamelet');
234228
expect(tile.description).toEqual('My Kamelet Description');
235229
});
236230

237-
it('should populate the tags for type', () => {
231+
it('should populate the tags for type', async () => {
238232
const kameletDef = {
239233
metadata: {
240234
labels: {
@@ -250,12 +244,12 @@ describe('kameletToTile', () => {
250244
},
251245
} as IKameletDefinition;
252246

253-
const tile = kameletToTile(kameletDef);
247+
const tile = await kameletToTile(kameletDef);
254248

255249
expect(tile.tags).toEqual(['source']);
256250
});
257251

258-
it('should use the selected CatalogKind.Kamelet by default', () => {
252+
it('should use the selected CatalogKind.Kamelet by default', async () => {
259253
const kameletDef = {
260254
metadata: {
261255
labels: {
@@ -271,12 +265,12 @@ describe('kameletToTile', () => {
271265
},
272266
} as IKameletDefinition;
273267

274-
const tile = kameletToTile(kameletDef);
268+
const tile = await kameletToTile(kameletDef);
275269

276270
expect(tile.type).toEqual(CatalogKind.Kamelet);
277271
});
278272

279-
it('should populate the version for annotations', () => {
273+
it('should populate the version for annotations', async () => {
280274
const kameletDef = {
281275
metadata: {
282276
labels: {},
@@ -292,12 +286,12 @@ describe('kameletToTile', () => {
292286
},
293287
} as IKameletDefinition;
294288

295-
const tile = kameletToTile(kameletDef);
289+
const tile = await kameletToTile(kameletDef);
296290

297291
expect(tile.version).toEqual('1.0.0');
298292
});
299293

300-
it('should populate the headerTags', () => {
294+
it('should populate the headerTags', async () => {
301295
const kameletDef = {
302296
metadata: {
303297
annotations: {
@@ -313,7 +307,7 @@ describe('kameletToTile', () => {
313307
},
314308
} as IKameletDefinition;
315309

316-
const tile = kameletToTile(kameletDef);
310+
const tile = await kameletToTile(kameletDef);
317311

318312
expect(tile.headerTags).toEqual(['Kamelet', 'Preview']);
319313
});

packages/ui/src/camel-utils/camel-to-tile.adapter.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ITile } from '../components/Catalog/Catalog.models';
2+
import { getIconRequest } from '../components/IconResolver/getIconRequest';
23
import {
34
CatalogKind,
45
ICamelComponentDefinition,
@@ -7,7 +8,7 @@ import {
78
IKameletDefinition,
89
} from '../models';
910

10-
export const camelComponentToTile = (componentDef: ICamelComponentDefinition): ITile => {
11+
export const camelComponentToTile = async (componentDef: ICamelComponentDefinition): Promise<ITile> => {
1112
const { name, title, description, supportLevel, label, provider, version } = componentDef.component;
1213
const headerTags: string[] = ['Component'];
1314
const tags: string[] = [];
@@ -27,6 +28,8 @@ export const camelComponentToTile = (componentDef: ICamelComponentDefinition): I
2728
tags.push('producerOnly');
2829
}
2930

31+
const { icon: iconUrl } = await getIconRequest(CatalogKind.Component, name);
32+
3033
return {
3134
type: CatalogKind.Component,
3235
name,
@@ -36,10 +39,11 @@ export const camelComponentToTile = (componentDef: ICamelComponentDefinition): I
3639
tags,
3740
provider,
3841
version,
42+
iconUrl,
3943
};
4044
};
4145

42-
export const camelProcessorToTile = (processorDef: ICamelProcessorDefinition): ITile => {
46+
export const camelProcessorToTile = async (processorDef: ICamelProcessorDefinition): Promise<ITile> => {
4347
const { name, title, description, supportLevel, label, provider } = processorDef.model;
4448
const headerTags: string[] = ['Processor'];
4549
const tags = label.split(',');
@@ -48,6 +52,8 @@ export const camelProcessorToTile = (processorDef: ICamelProcessorDefinition): I
4852
headerTags.push(supportLevel);
4953
}
5054

55+
const { icon: iconUrl } = await getIconRequest(CatalogKind.Processor, name);
56+
5157
return {
5258
type: CatalogKind.Processor,
5359
name,
@@ -56,18 +62,22 @@ export const camelProcessorToTile = (processorDef: ICamelProcessorDefinition): I
5662
headerTags,
5763
tags,
5864
provider,
65+
iconUrl,
5966
};
6067
};
6168

62-
export const camelEntityToTile = (processorDef: ICamelProcessorDefinition): ITile => {
63-
const entityTile = camelProcessorToTile(processorDef);
69+
export const camelEntityToTile = async (processorDef: ICamelProcessorDefinition): Promise<ITile> => {
70+
const entityTile = await camelProcessorToTile(processorDef);
6471
entityTile.type = CatalogKind.Entity;
6572
entityTile.headerTags = ['Entity'];
6673

74+
const { icon: iconUrl } = await getIconRequest(CatalogKind.Entity, entityTile.name);
75+
entityTile.iconUrl = iconUrl;
76+
6777
return entityTile;
6878
};
6979

70-
export const kameletToTile = (kameletDef: IKameletDefinition): ITile => {
80+
export const kameletToTile = async (kameletDef: IKameletDefinition): Promise<ITile> => {
7181
const headerTags: string[] = ['Kamelet'];
7282
if (kameletDef.metadata.annotations['camel.apache.org/kamelet.support.level']) {
7383
headerTags.push(kameletDef.metadata.annotations['camel.apache.org/kamelet.support.level']);
@@ -83,6 +93,8 @@ export const kameletToTile = (kameletDef: IKameletDefinition): ITile => {
8393
version = kameletDef.metadata.annotations['camel.apache.org/catalog.version'];
8494
}
8595

96+
const { icon: iconUrl } = await getIconRequest(CatalogKind.Kamelet, kameletDef.metadata.name);
97+
8698
return {
8799
type: CatalogKind.Kamelet,
88100
name: kameletDef.metadata.name,
@@ -91,15 +103,18 @@ export const kameletToTile = (kameletDef: IKameletDefinition): ITile => {
91103
headerTags,
92104
tags,
93105
version,
106+
iconUrl,
94107
};
95108
};
96109

97-
export const citrusComponentToTile = (componentDefinition: ICitrusComponentDefinition): ITile => {
110+
export const citrusComponentToTile = async (componentDefinition: ICitrusComponentDefinition): Promise<ITile> => {
98111
const { kind, version, name, title, description } = componentDefinition;
99112

100113
const headerTags: string[] = [kind];
101114
const tags: string[] = [];
102115

116+
const { icon: iconUrl } = await getIconRequest(CatalogKind.TestAction, name);
117+
103118
return {
104119
type: kind,
105120
name: name,
@@ -108,5 +123,6 @@ export const citrusComponentToTile = (componentDefinition: ICitrusComponentDefin
108123
headerTags,
109124
tags,
110125
version,
126+
iconUrl,
111127
};
112128
};

0 commit comments

Comments
 (0)