Skip to content

Commit

Permalink
Temp: Pass Icon type as a workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
lordrip committed May 2, 2024
1 parent 24f6342 commit 59319d7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/ui/src/components/IconResolver/IconResolver.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionComponent, PropsWithChildren } from 'react';
import { CatalogKind } from '../../models';
import { NodeIconResolver } from '../../utils/node-icon-resolver';
import { NodeIconResolver, NodeIconType } from '../../utils/node-icon-resolver';
import { ITile } from '../Catalog/Catalog.models';

interface IconResolverProps {
Expand All @@ -20,10 +20,12 @@ export const IconResolver: FunctionComponent<PropsWithChildren<IconResolverProps
);
case CatalogKind.Processor:
case CatalogKind.Component:
// eslint-disable-next-line no-case-declarations
const iconType = props.tile.type === CatalogKind.Processor ? NodeIconType.EIP : NodeIconType.Component;
return (
<img
className={props.className}
src={NodeIconResolver.getIcon(props.tile.name)}
src={NodeIconResolver.getIcon(props.tile.name, iconType)}
alt={`${props.tile.type} icon`}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ProcessorDefinition } from '@kaoto/camel-catalog/types';
import { SchemaService } from '../../../components/Form/schema.service';
import { ROOT_PATH, getArrayProperty, getValue, setValue } from '../../../utils';
import { NodeIconResolver } from '../../../utils/node-icon-resolver';
import { NodeIconResolver, NodeIconType } from '../../../utils/node-icon-resolver';
import { DefinedComponent } from '../../camel-catalog-index';
import { EntityType } from '../../camel/entities';
import {
Expand Down Expand Up @@ -217,7 +217,7 @@ export abstract class AbstractCamelVisualEntity<T extends object> implements Bas
path: ROOT_PATH,
entity: this,
isGroup: true,
icon: NodeIconResolver.getIcon(this.type),
icon: NodeIconResolver.getIcon(this.type, NodeIconType.VisualEntity),
});

const fromNode = CamelStepsService.getVizNodeFromProcessor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OnException, ProcessorDefinition } from '@kaoto/camel-catalog/types';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { isDefined } from '../../../utils';
import { NodeIconResolver, NodeIconType, isDefined } from '../../../utils';
import { EntityType } from '../../camel/entities/base-entity';
import {
BaseVisualCamelEntity,
Expand Down Expand Up @@ -88,6 +88,7 @@ export class CamelOnExceptionVisualEntity
);
onExceptionGroupNode.data.entity = this;
onExceptionGroupNode.data.isGroup = true;
onExceptionGroupNode.data.icon = NodeIconResolver.getIcon(this.type, NodeIconType.VisualEntity);

return onExceptionGroupNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Ajv, { ValidateFunction } from 'ajv-draft-04';
import addFormats from 'ajv-formats';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { isDefined, setValue } from '../../../utils';
import { NodeIconResolver, NodeIconType, isDefined, setValue } from '../../../utils';
import { EntityType } from '../../camel/entities/base-entity';
import { CatalogKind } from '../../catalog-kind';
import {
Expand Down Expand Up @@ -125,6 +125,7 @@ export class CamelRestConfigurationVisualEntity implements BaseVisualCamelEntity
);
restConfigurationGroupNode.data.entity = this;
restConfigurationGroupNode.data.isGroup = true;
restConfigurationGroupNode.data.icon = NodeIconResolver.getIcon(this.type, NodeIconType.VisualEntity);

return restConfigurationGroupNode;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-case-declarations */
import { DoCatch, ProcessorDefinition, When1 } from '@kaoto/camel-catalog/types';
import { getValue } from '../../../../utils';
import { NodeIconResolver } from '../../../../utils/node-icon-resolver';
import { NodeIconResolver, NodeIconType } from '../../../../utils/node-icon-resolver';
import { IVisualizationNode } from '../../base-visual-entity';
import { createVisualizationNode } from '../../visualization-node';
import { CamelComponentSchemaService } from './camel-component-schema.service';
Expand All @@ -17,9 +17,10 @@ export class CamelStepsService {
componentLookup: ICamelElementLookupResult,
entityDefinition: unknown,
): IVisualizationNode {
const nodeIconType = componentLookup.componentName ? NodeIconType.Component : NodeIconType.EIP;
const data: CamelRouteVisualEntityData = {
path,
icon: NodeIconResolver.getIcon(CamelComponentSchemaService.getIconName(componentLookup)),
icon: NodeIconResolver.getIcon(CamelComponentSchemaService.getIconName(componentLookup), nodeIconType),
processorName: componentLookup.processorName,
componentName: componentLookup.componentName,
};
Expand Down
20 changes: 19 additions & 1 deletion packages/ui/src/utils/node-icon-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ import { IKameletDefinition } from '../models/kamelets-catalog';
import { CamelCatalogService } from '../models/visualization/flows/camel-catalog.service';
import { EntityType } from '../models/camel/entities';

export const enum NodeIconType {
Component,
EIP,
VisualEntity,
}

export class NodeIconResolver {
static getIcon(elementName: string | undefined): string {
static getIcon(elementName: string | undefined, type?: NodeIconType): string {
if (elementName?.startsWith('kamelet:')) {
const kameletDefinition = CamelCatalogService.getComponent(
CatalogKind.Kamelet,
Expand All @@ -136,6 +142,17 @@ export class NodeIconResolver {
return kameletDefinition?.metadata.annotations['camel.apache.org/kamelet.icon'] ?? this.getUnknownIcon();
}

/**
* Temporary fix for the missing icons
* TODO: Remove this once all usages are validated and the right types are set
*/
switch (type) {
case NodeIconType.Component:
return this.getComponentIcon(elementName) ?? this.getDefaultCamelIcon();
case NodeIconType.EIP:
return this.getEIPIcon(elementName) ?? this.getDefaultCamelIcon();
}

let icon = this.getComponentIcon(elementName);
if (icon !== undefined) {
return icon;
Expand All @@ -154,6 +171,7 @@ export class NodeIconResolver {
if (elementName === '') {
return this.getUnknownIcon();
}

return this.getDefaultCamelIcon();
}

Expand Down

0 comments on commit 59319d7

Please sign in to comment.