Skip to content

Commit fae17f5

Browse files
Fix cell diagram filtering for dynamic component types
Update CellDiagramInfoService to use ComponentTypeUtils instead of hardcoded type checks ('Service', 'WebApplication'). Now properly handles new dynamic component type format (e.g., 'deployment/http-service'). - Add openchoreo-common dependency to openchoreo-backend - Pass config to CellDiagramInfoService constructor - Replace hardcoded type filters with page variant-based filtering - Support all service and website component types via pattern matching Fixes cell diagram returning empty components after component type system changes.
1 parent 1b3acea commit fae17f5

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

plugins/openchoreo-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@backstage/plugin-kubernetes-backend": "^0.20.2",
4242
"@backstage/plugin-kubernetes-node": "^0.3.4",
4343
"@backstage/plugin-permission-common": "^0.9.1",
44+
"@openchoreo/backstage-plugin-common": "workspace:^",
4445
"@openchoreo/openchoreo-client-node": "workspace:^",
4546
"@wso2/cell-diagram": "0.2.0",
4647
"express": "^4.17.1",

plugins/openchoreo-backend/src/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const choreoPlugin = createBackendPlugin({
5252
const cellDiagramInfoService = new CellDiagramInfoService(
5353
logger,
5454
openchoreoConfig.get('baseUrl'),
55+
config,
5556
);
5657

5758
const buildTemplateInfoService = new BuildTemplateInfoService(

plugins/openchoreo-backend/src/services/CellDiagramService/CellDiagramInfoService.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LoggerService } from '@backstage/backend-plugin-api';
2+
import { Config } from '@backstage/config';
23

34
import {
45
Project,
@@ -10,6 +11,7 @@ import {
1011
createOpenChoreoApiClient,
1112
type OpenChoreoComponents,
1213
} from '@openchoreo/openchoreo-client-node';
14+
import { ComponentTypeUtils } from '@openchoreo/backstage-plugin-common';
1315

1416
// Use generated type from OpenAPI spec
1517
type ModelsCompleteComponent =
@@ -44,17 +46,20 @@ enum ConnectionType {
4446
export class CellDiagramInfoService implements CellDiagramService {
4547
private readonly logger: LoggerService;
4648
private readonly baseUrl: string;
49+
private readonly componentTypeUtils: ComponentTypeUtils;
4750

4851
/**
4952
* Private constructor for CellDiagramInfoService.
5053
* Use the static create method to instantiate.
5154
* @param {LoggerService} logger - Logger service instance
5255
* @param {string} baseUrl - Base url of openchoreo api
56+
* @param {Config} config - Backstage config for component type mappings
5357
* @private
5458
*/
55-
public constructor(logger: LoggerService, baseUrl: string) {
59+
public constructor(logger: LoggerService, baseUrl: string, config: Config) {
5660
this.baseUrl = baseUrl;
5761
this.logger = logger;
62+
this.componentTypeUtils = ComponentTypeUtils.fromConfig(config);
5863
}
5964

6065
/**
@@ -143,10 +148,17 @@ export class CellDiagramInfoService implements CellDiagramService {
143148

144149
const components: Component[] = completeComponents
145150
.filter(component => {
146-
this.logger.info(JSON.stringify(component, null, 2));
147-
return (
148-
component.type === 'Service' || component.type === 'WebApplication'
151+
if (!component.type) return false;
152+
153+
const pageVariant = this.componentTypeUtils.getPageVariant(
154+
component.type,
155+
);
156+
this.logger.debug(
157+
`Component ${component.name} has type ${component.type} mapped to variant ${pageVariant}`,
149158
);
159+
160+
// Include service and website components in cell diagram
161+
return pageVariant === 'service' || pageVariant === 'website';
150162
})
151163
.map(component => {
152164
// Get connections from workload data included in component response
@@ -159,7 +171,12 @@ export class CellDiagramInfoService implements CellDiagramService {
159171
completeComponents,
160172
);
161173

162-
if (component.type === 'Service') {
174+
const pageVariant = this.componentTypeUtils.getPageVariant(
175+
component.type!,
176+
);
177+
178+
// Map based on page variant instead of hardcoded type names
179+
if (pageVariant === 'service') {
163180
// Extract API information from the Service.apis object
164181
const apis = component.service?.apis || {};
165182
const services: { [key: string]: any } = {};
@@ -196,7 +213,7 @@ export class CellDiagramInfoService implements CellDiagramService {
196213
connections: connections,
197214
} as Component;
198215
}
199-
if (component.type === 'WebApplication') {
216+
if (pageVariant === 'website') {
200217
return {
201218
id: component.name || '',
202219
label: component.name || '',

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9191,6 +9191,7 @@ __metadata:
91919191
"@backstage/plugin-kubernetes-backend": "npm:^0.20.2"
91929192
"@backstage/plugin-kubernetes-node": "npm:^0.3.4"
91939193
"@backstage/plugin-permission-common": "npm:^0.9.1"
9194+
"@openchoreo/backstage-plugin-common": "workspace:^"
91949195
"@openchoreo/openchoreo-client-node": "workspace:^"
91959196
"@types/express": "npm:^4.17.6"
91969197
"@types/supertest": "npm:^2.0.12"

0 commit comments

Comments
 (0)