diff --git a/src/containers/Editor/components/views/GraphView/CustomNode/TextRenderer.tsx b/src/containers/Editor/components/views/GraphView/CustomNode/TextRenderer.tsx index 8ecb58e031c..0a9b69b5f12 100644 --- a/src/containers/Editor/components/views/GraphView/CustomNode/TextRenderer.tsx +++ b/src/containers/Editor/components/views/GraphView/CustomNode/TextRenderer.tsx @@ -32,9 +32,10 @@ const Linkify = (text: string) => { interface TextRendererProps { children: string; + fieldColors?: Record; } -export const TextRenderer = ({ children }: TextRendererProps) => { +export const TextRenderer = ({ children, fieldColors = {} }: TextRendererProps) => { const text = children?.replaceAll('"', ""); if (isURL(text)) return Linkify(text); @@ -47,7 +48,9 @@ export const TextRenderer = ({ children }: TextRendererProps) => { ); } - return <>{children}; + + const color = fieldColors[text]; + return {children}; }; function isColorFormat(colorString: string) { diff --git a/src/containers/Editor/components/views/GraphView/CustomNode/index.tsx b/src/containers/Editor/components/views/GraphView/CustomNode/index.tsx index 05196d7e050..cabff19128a 100644 --- a/src/containers/Editor/components/views/GraphView/CustomNode/index.tsx +++ b/src/containers/Editor/components/views/GraphView/CustomNode/index.tsx @@ -12,6 +12,7 @@ export interface CustomNodeProps { x: number; y: number; hasCollapse?: boolean; + fieldColors?: Record; } const rootProps = { @@ -46,7 +47,15 @@ const CustomNodeWrapper = (nodeProps: NodeProps) => { return ; } - return ; + return ( + + ); }} ); diff --git a/src/containers/Editor/components/views/GraphView/CustomNode/styles.tsx b/src/containers/Editor/components/views/GraphView/CustomNode/styles.tsx index 2e8bfcc37c3..df4488fa5f1 100644 --- a/src/containers/Editor/components/views/GraphView/CustomNode/styles.tsx +++ b/src/containers/Editor/components/views/GraphView/CustomNode/styles.tsx @@ -26,6 +26,10 @@ function getTextColor({ $value, $type, $parent, theme }: TextColorFn) { return theme.NODE_COLORS.NODE_VALUE; } +function getDynamicTextColor(fieldColors: Record, key: string): string | undefined { + return fieldColors[key]; +} + export const StyledLinkItUrl = styled(LinkItUrl)` text-decoration: underline; pointer-events: all; diff --git a/src/containers/Editor/components/views/GraphView/index.tsx b/src/containers/Editor/components/views/GraphView/index.tsx index 78097037424..2871faa6145 100644 --- a/src/containers/Editor/components/views/GraphView/index.tsx +++ b/src/containers/Editor/components/views/GraphView/index.tsx @@ -86,6 +86,21 @@ const GraphCanvas = ({ isWidget }: GraphProps) => { const edges = useGraph(state => state.edges); const [paneWidth, setPaneWidth] = React.useState(2000); const [paneHeight, setPaneHeight] = React.useState(2000); + const [fieldColors, setFieldColors] = React.useState>({}); + + React.useEffect(() => { + const fetchFieldColors = async () => { + try { + const response = await fetch("/api/fieldColors"); + const data = await response.json(); + setFieldColors(data); + } catch (error) { + console.error("Failed to fetch field colors:", error); + } + }; + + fetchFieldColors(); + }, []); const onLayoutChange = React.useCallback( (layout: ElkRoot) => { @@ -112,7 +127,7 @@ const GraphCanvas = ({ isWidget }: GraphProps) => { } + node={p => } edge={p => } nodes={nodes} edges={edges} diff --git a/src/pages/api/fieldColors.ts b/src/pages/api/fieldColors.ts new file mode 100644 index 00000000000..b87d1dc6fce --- /dev/null +++ b/src/pages/api/fieldColors.ts @@ -0,0 +1,19 @@ +import { NextApiRequest, NextApiResponse } from 'next'; + +let fieldColors: Record = {}; + +export default function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method === 'GET') { + res.status(200).json(fieldColors); + } else if (req.method === 'POST') { + const { key, color } = req.body; + if (key && color) { + fieldColors[key] = color; + res.status(200).json({ message: 'Color set successfully' }); + } else { + res.status(400).json({ message: 'Invalid request' }); + } + } else { + res.status(405).json({ message: 'Method not allowed' }); + } +}