Feat: Add TagFeatureItem #4368 (#4432)

### What problem does this PR solve?

Feat: Add TagFeatureItem #4368

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-01-09 18:24:27 +08:00
committed by GitHub
parent dac54ded96
commit 300d8ecf51
15 changed files with 259 additions and 123 deletions

View File

@ -7,11 +7,11 @@ import React, { useEffect, useRef, useState } from 'react';
import styles from './index.less';
interface EditTagsProps {
tags?: string[];
setTags?: (tags: string[]) => void;
value?: string[];
onChange?: (tags: string[]) => void;
}
const EditTag = ({ tags, setTags }: EditTagsProps) => {
const EditTag = ({ value = [], onChange }: EditTagsProps) => {
const { token } = theme.useToken();
const [inputVisible, setInputVisible] = useState(false);
const [inputValue, setInputValue] = useState('');
@ -24,8 +24,8 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
}, [inputVisible]);
const handleClose = (removedTag: string) => {
const newTags = tags?.filter((tag) => tag !== removedTag);
setTags?.(newTags ?? []);
const newTags = value?.filter((tag) => tag !== removedTag);
onChange?.(newTags ?? []);
};
const showInput = () => {
@ -37,12 +37,12 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
};
const handleInputConfirm = () => {
if (inputValue && tags) {
if (inputValue && value) {
const newTags = inputValue
.split(';')
.map((tag) => tag.trim())
.filter((tag) => tag && !tags.includes(tag));
setTags?.([...tags, ...newTags]);
.filter((tag) => tag && !value.includes(tag));
onChange?.([...value, ...newTags]);
}
setInputVisible(false);
setInputValue('');
@ -64,7 +64,7 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
);
};
const tagChild = tags?.map(forMap);
const tagChild = value?.map(forMap);
const tagPlusStyle: React.CSSProperties = {
background: token.colorBgContainer,

View File

@ -18,8 +18,6 @@ const EntityTypesItem = () => {
label={t('entityTypes')}
rules={[{ required: true }]}
initialValue={initialEntityTypes}
valuePropName="tags"
trigger="setTags"
>
<EditTag></EditTag>
</Form.Item>