Skip to content

Commit 4dcea44

Browse files
committed
3253 - fix input datapill icons
1 parent bb3bdc2 commit 4dcea44

1 file changed

Lines changed: 11 additions & 42 deletions

File tree

client/src/pages/platform/workflow-editor/components/properties/components/property-mentions-input/PropertyMentionsInputEditor.tsx

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,8 @@ import {Editor, EditorContent, Extension, mergeAttributes, useEditor} from '@tip
2828
import {StarterKit} from '@tiptap/starter-kit';
2929
import {decode} from 'html-entities';
3030
import resolvePath from 'object-resolve-path';
31-
import {
32-
ForwardedRef,
33-
MutableRefObject,
34-
ReactElement,
35-
forwardRef,
36-
useCallback,
37-
useEffect,
38-
useMemo,
39-
useState,
40-
} from 'react';
31+
import {ForwardedRef, MutableRefObject, forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
32+
import {renderToStaticMarkup} from 'react-dom/server';
4133
import sanitizeHtml from 'sanitize-html';
4234
import {twMerge} from 'tailwind-merge';
4335
import {useDebouncedCallback} from 'use-debounce';
@@ -46,9 +38,6 @@ import {useShallow} from 'zustand/shallow';
4638
import {FormulaMode} from './FormulaMode.extension';
4739
import {MentionStorage} from './MentionStorage.extension';
4840

49-
const defaultIcon =
50-
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z"/><path d="M15 3v4a2 2 0 0 0 2 2h4"/></svg>';
51-
5241
interface PropertyMentionsInputEditorProps {
5342
className?: string;
5443
componentDefinitions: ComponentDefinitionBasic[];
@@ -91,9 +80,6 @@ const PropertyMentionsInputEditor = forwardRef<Editor, PropertyMentionsInputEdit
9180
const [editorValue, setEditorValue] = useState<string | number | undefined>(value);
9281
const [isLocalUpdate, setIsLocalUpdate] = useState(false);
9382
const [mentionOccurences, setMentionOccurences] = useState(0);
94-
const [renderToStaticMarkup, setRenderToStaticMarkup] = useState<((element: ReactElement) => string) | null>(
95-
null
96-
);
9783

9884
const currentNode = useWorkflowNodeDetailsPanelStore((state) => state.currentNode);
9985

@@ -105,31 +91,21 @@ const PropertyMentionsInputEditor = forwardRef<Editor, PropertyMentionsInputEdit
10591
componentName = workflow.workflowTriggerComponentNames?.[0] || '';
10692
}
10793

108-
const upperCaseComponentName = componentName.toUpperCase();
109-
110-
if (Object.keys(TYPE_ICONS).includes(upperCaseComponentName)) {
111-
const reactIcon = TYPE_ICONS[upperCaseComponentName as keyof typeof TYPE_ICONS];
94+
if (TASK_DISPATCHER_NAMES.includes(componentName)) {
95+
return taskDispatcherDefinitions.find((component) => component.name === componentName)?.icon;
96+
}
11297

113-
const svgString = renderToStaticMarkup ? renderToStaticMarkup(reactIcon) : '';
98+
const componentIcon = componentDefinitions.find((component) => component.name === componentName)?.icon;
11499

115-
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
100+
if (componentIcon) {
101+
return componentIcon;
116102
}
117103

118-
if (TASK_DISPATCHER_NAMES.includes(componentName)) {
119-
return (
120-
taskDispatcherDefinitions.find((component) => component.name === componentName)?.icon ||
121-
defaultIcon
122-
);
123-
}
104+
const svgString = renderToStaticMarkup(TYPE_ICONS.STRING);
124105

125-
return componentDefinitions.find((component) => component.name === componentName)?.icon || defaultIcon;
106+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgString)}`;
126107
},
127-
[
128-
componentDefinitions,
129-
renderToStaticMarkup,
130-
taskDispatcherDefinitions,
131-
workflow.workflowTriggerComponentNames,
132-
]
108+
[componentDefinitions, taskDispatcherDefinitions, workflow.workflowTriggerComponentNames]
133109
);
134110

135111
const {updateClusterElementParameterMutation, updateWorkflowNodeParameterMutation} = useWorkflowEditor();
@@ -430,13 +406,6 @@ const PropertyMentionsInputEditor = forwardRef<Editor, PropertyMentionsInputEdit
430406
(ref as MutableRefObject<Editor | null>).current = editor;
431407
}
432408

433-
// Load the function when component mounts
434-
useEffect(() => {
435-
import('react-dom/server').then(({renderToStaticMarkup}) => {
436-
setRenderToStaticMarkup(() => renderToStaticMarkup);
437-
});
438-
}, []);
439-
440409
useEffect(() => {
441410
if (editor) {
442411
editor.storage.MentionStorage.dataPills = dataPills;

0 commit comments

Comments
 (0)