Skip to content

Commit fe4ad64

Browse files
authored
fix: Custom Relation badge always taking default color (#28301)
1 parent 2335a5e commit fe4ad64

3 files changed

Lines changed: 57 additions & 10 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/OntologyExplorer/OntologyNodeRelationsContent.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import {
2222
import React, { useCallback, useMemo } from 'react';
2323
import { useTranslation } from 'react-i18next';
2424
import { GlossaryTermRelationType } from '../../rest/settingConfigAPI';
25-
import { RELATION_META } from './OntologyExplorer.constants';
25+
import { COLOR_META_BY_HEX, RELATION_META } from './OntologyExplorer.constants';
2626
import { OntologyEdge, OntologyNode } from './OntologyExplorer.interface';
27+
import { getEffectiveRelationColor } from './utils/graphStyles';
2728

2829
export interface OntologyNodeRelationsContentProps {
2930
readonly node: OntologyNode;
@@ -78,14 +79,16 @@ export const OntologyNodeRelationsContent: React.FC<
7879
const getDisplayName = useCallback(
7980
(relationType: string) => {
8081
const relationMeta = relationTypeMap.get(relationType);
82+
const builtInLabelKey = RELATION_META[relationType]?.labelKey;
8183

8284
return (
83-
relationMeta?.displayName ??
84-
relationLabelOverrides[relationType] ??
85-
relationType
85+
(relationMeta?.displayName ||
86+
relationMeta?.name ||
87+
relationLabelOverrides[relationType]) ??
88+
(builtInLabelKey ? t(builtInLabelKey) : relationType)
8689
);
8790
},
88-
[relationTypeMap, relationLabelOverrides]
91+
[relationTypeMap, relationLabelOverrides, t]
8992
);
9093

9194
const totalRelations =
@@ -134,7 +137,14 @@ export const OntologyNodeRelationsContent: React.FC<
134137
const labelText = relatedDisplayName(rel);
135138
const hasRowBelow = rowIndex < rows.length - 1;
136139

137-
const meta = RELATION_META[rel.relationType];
140+
const customRelation = relationTypeMap.get(rel.relationType);
141+
const effectiveColor = getEffectiveRelationColor(
142+
rel.relationType,
143+
customRelation
144+
);
145+
const meta = effectiveColor
146+
? COLOR_META_BY_HEX[effectiveColor.toLowerCase()]
147+
: undefined;
138148

139149
return (
140150
<li

openmetadata-ui/src/main/resources/ui/src/components/OntologyExplorer/hooks/useGraphData.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
EDGE_STROKE_COLOR,
2626
NODE_BORDER_COLOR,
2727
RELATION_COLORS,
28+
RELATION_META,
2829
} from '../OntologyExplorer.constants';
2930
import {
3031
BuildGraphDataProps,
@@ -191,6 +192,20 @@ export function useGraphDataBuilder({
191192
[inputEdges, relationTypes]
192193
);
193194

195+
const customRelationColorMap = useMemo<Record<string, string>>(() => {
196+
const map: Record<string, string> = {};
197+
relationTypes?.forEach((rt) => {
198+
const effectiveColor = rt.isSystemDefined
199+
? RELATION_META[rt.name]?.color ?? rt.color
200+
: rt.color ?? RELATION_META[rt.name]?.color;
201+
if (effectiveColor) {
202+
map[rt.name] = effectiveColor;
203+
}
204+
});
205+
206+
return map;
207+
}, [relationTypes]);
208+
194209
const neighborSet = useMemo(() => {
195210
const set = new Set<string>();
196211
if (!selectedNodeId || !inputEdges.length) {
@@ -691,7 +706,9 @@ export function useGraphDataBuilder({
691706
const rawEdgeColor =
692707
explorationMode === 'data' && !isTermTermInDataMode
693708
? DATA_MODE_ASSET_EDGE_STROKE_COLOR
694-
: RELATION_COLORS[singleEdge.relationType] ?? EDGE_STROKE_COLOR;
709+
: customRelationColorMap[singleEdge.relationType] ??
710+
RELATION_COLORS[singleEdge.relationType] ??
711+
EDGE_STROKE_COLOR;
695712
const edgeColor = getCanvasColor(
696713
rawEdgeColor,
697714
explorationMode === 'data' && !isTermTermInDataMode
@@ -744,7 +761,8 @@ export function useGraphDataBuilder({
744761
? {
745762
...getEdgeRelationLabelStyle(
746763
labelText,
747-
singleEdge.relationType
764+
singleEdge.relationType,
765+
customRelationColorMap[singleEdge.relationType]
748766
),
749767
labelPosition: 'center',
750768
labelAutoRotate: false,

openmetadata-ui/src/main/resources/ui/src/components/OntologyExplorer/utils/graphStyles.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
register,
2020
} from '@antv/g6';
2121
import {
22+
COLOR_META_BY_HEX,
2223
COMBO_FILL_DEFAULT,
2324
COMBO_HEADER_HEIGHT,
2425
COMBO_INTERIOR_PADDING_SIDES,
@@ -404,14 +405,32 @@ const EDGE_LABEL_BADGE_PADDING: [number, number, number, number] = [4, 8, 4, 8];
404405
const EDGE_LABEL_BADGE_RADIUS = 6;
405406
const EDGE_LABEL_BADGE_FONT_WEIGHT = 700;
406407

408+
export function getEffectiveRelationColor(
409+
relationType: string,
410+
customRelation: { isSystemDefined?: boolean; color?: string } | undefined
411+
): string | undefined {
412+
if (!customRelation) {
413+
return RELATION_META[relationType]?.color;
414+
}
415+
if (customRelation.isSystemDefined) {
416+
return RELATION_META[relationType]?.color ?? customRelation.color;
417+
}
418+
419+
return customRelation.color ?? RELATION_META[relationType]?.color;
420+
}
421+
407422
export function getEdgeRelationLabelStyle(
408423
labelText: string,
409-
relationType?: string
424+
relationType?: string,
425+
effectiveColor?: string
410426
): Record<string, unknown> {
411-
const meta =
427+
const builtInMeta =
412428
relationType != null
413429
? RELATION_META[relationType] ?? RELATION_META.default
414430
: null;
431+
const meta = effectiveColor
432+
? COLOR_META_BY_HEX[effectiveColor.toLowerCase()] ?? builtInMeta
433+
: builtInMeta;
415434

416435
const edgeLabelPadding = EDGE_LABEL_BADGE_PADDING;
417436

0 commit comments

Comments
 (0)