@@ -57,8 +57,8 @@ const TagsControl = codeControl<Array<string> | string>(
57
57
{ expectedType: "string | Array<string>", codeType: "JSON" }
58
58
);
59
59
60
- function getTagColor(tagText : any , tagOptions: any []) {
61
- const foundOption = tagOptions.find(( option: { label: any; }) => option.label === tagText);
60
+ function getTagColor(tagText: string , tagOptions: TagOption []): string | undefined {
61
+ const foundOption = tagOptions.find(option => option.label === tagText);
62
62
if (foundOption) {
63
63
if (foundOption.colorType === "preset") {
64
64
return foundOption.presetColor;
@@ -73,10 +73,10 @@ function getTagColor(tagText : any, tagOptions: any[]) {
73
73
return colors[index];
74
74
}
75
75
76
- function getTagStyle(tagText: any , tagOptions: any []) {
77
- const foundOption = tagOptions.find(( option: { label: any; }) => option.label === tagText);
76
+ function getTagStyle(tagText: string , tagOptions: TagOption []): React.CSSProperties {
77
+ const foundOption = tagOptions.find(option => option.label === tagText);
78
78
if (foundOption) {
79
- const style: any = {};
79
+ const style: React.CSSProperties = {};
80
80
81
81
// Handle color styling
82
82
if (foundOption.colorType === "custom") {
@@ -113,11 +113,23 @@ function getTagStyle(tagText: any, tagOptions: any[]) {
113
113
return {};
114
114
}
115
115
116
- function getTagIcon(tagText: any , tagOptions: any []) {
116
+ function getTagIcon(tagText: string , tagOptions: TagOption []): React.ReactNode | undefined {
117
117
const foundOption = tagOptions.find(option => option.label === tagText);
118
118
return foundOption ? foundOption.icon : undefined;
119
119
}
120
120
121
+ // Utility function to process comma-separated tags into individual tags
122
+ function processTagItems(tagItems: string[]): string[] {
123
+ const result: string[] = [];
124
+ tagItems.forEach((item) => {
125
+ if (item.split(",")[1]) {
126
+ item.split(",").forEach((tag) => result.push(tag));
127
+ }
128
+ result.push(item);
129
+ });
130
+ return result;
131
+ }
132
+
121
133
const childrenMap = {
122
134
text: TagsControl,
123
135
tagColors: ColoredTagOptionControl,
@@ -128,11 +140,25 @@ const getBaseValue: ColumnTypeViewFn<typeof childrenMap, string | string[], stri
128
140
props
129
141
) => props.text;
130
142
143
+ interface TagOption {
144
+ label: string;
145
+ colorType?: "preset" | "custom";
146
+ presetColor?: string;
147
+ color?: string;
148
+ textColor?: string;
149
+ border?: string;
150
+ radius?: string;
151
+ margin?: string;
152
+ padding?: string;
153
+ icon?: React.ReactNode;
154
+ onEvent?: (eventType: string) => void;
155
+ }
156
+
131
157
type TagEditPropsType = {
132
158
value: string | string[];
133
159
onChange: (value: string | string[]) => void;
134
160
onChangeEnd: () => void;
135
- tagOptions: any [];
161
+ tagOptions: TagOption [];
136
162
};
137
163
138
164
export const Wrapper = styled.div`
@@ -240,16 +266,7 @@ export const TagStyled = styled(Tag)`
240
266
241
267
const TagEdit = React.memo((props: TagEditPropsType) => {
242
268
const defaultTags = useContext(TagsContext);
243
- const [tags, setTags] = useState(() => {
244
- const result: string[] = [];
245
- defaultTags.forEach((item) => {
246
- if (item.split(",")[1]) {
247
- item.split(",").forEach((tag) => result.push(tag));
248
- }
249
- result.push(item);
250
- });
251
- return result;
252
- });
269
+ const [tags, setTags] = useState(() => processTagItems(defaultTags));
253
270
const [open, setOpen] = useState(false);
254
271
const mountedRef = useRef(true);
255
272
@@ -268,24 +285,16 @@ const TagEdit = React.memo((props: TagEditPropsType) => {
268
285
// Update tags when defaultTags changes
269
286
useEffect(() => {
270
287
if (!mountedRef.current) return;
271
-
272
- const result: string[] = [];
273
- defaultTags.forEach((item) => {
274
- if (item.split(",")[1]) {
275
- item.split(",").forEach((tag) => result.push(tag));
276
- }
277
- result.push(item);
278
- });
279
- setTags(result);
288
+ setTags(processTagItems(defaultTags));
280
289
}, [defaultTags]);
281
290
282
291
const handleSearch = useCallback((value: string) => {
283
292
if (!mountedRef.current) return;
284
293
285
294
if (defaultTags.findIndex((item) => item.includes(value)) < 0) {
286
- setTags([...defaultTags, value]);
295
+ setTags([...processTagItems( defaultTags) , value]);
287
296
} else {
288
- setTags(defaultTags);
297
+ setTags(processTagItems( defaultTags) );
289
298
}
290
299
props.onChange(value);
291
300
}, [defaultTags, props.onChange]);
@@ -426,17 +435,15 @@ export const ColumnTagsComp = (function () {
426
435
const tagStyle = getTagStyle(tagText, tagOptions);
427
436
428
437
return (
429
- <React.Fragment key={`${tag.split(' ').join('_')}-${index}`}>
430
- <TagStyled
431
- color={tagColor}
432
- icon={tagIcon}
433
- key={index}
434
- style={tagStyle}
435
- onClick={(e) => handleTagClick(e, tagText)}
436
- >
437
- {tagText}
438
- </TagStyled>
439
- </React.Fragment>
438
+ <TagStyled
439
+ key={`${tagText.split(' ').join('_')}-${index}`}
440
+ color={tagColor}
441
+ icon={tagIcon}
442
+ style={tagStyle}
443
+ onClick={(e) => handleTagClick(e, tagText)}
444
+ >
445
+ {tagText}
446
+ </TagStyled>
440
447
);
441
448
});
442
449
return (
0 commit comments