Fix: Optimized Input and MultiSelect component functionality and dataSet-chunk page styling #9779 (#9815)

### What problem does this PR solve?

Fix: Optimized Input and MultiSelect component functionality and
dataSet-chunk page styling

- Updated @js-preview/excel to version 1.7.14 #9779
- Optimized the EditTag component
- Updated the Input component to optimize numeric input processing
- Adjusted the MultiSelect component to use lodash's isEmpty method
- Optimized the CheckboxSets component to display action buttons based
on the selected state

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
chanx
2025-08-29 10:57:29 +08:00
committed by GitHub
parent c7f7adf029
commit fe9adbf0a5
8 changed files with 188 additions and 149 deletions

9
web/package-lock.json generated
View File

@ -12,7 +12,7 @@
"@antv/g2": "^5.2.10", "@antv/g2": "^5.2.10",
"@antv/g6": "^5.0.10", "@antv/g6": "^5.0.10",
"@hookform/resolvers": "^3.9.1", "@hookform/resolvers": "^3.9.1",
"@js-preview/excel": "^1.7.8", "@js-preview/excel": "^1.7.14",
"@lexical/react": "^0.23.1", "@lexical/react": "^0.23.1",
"@monaco-editor/react": "^4.6.0", "@monaco-editor/react": "^4.6.0",
"@radix-ui/react-accordion": "^1.2.3", "@radix-ui/react-accordion": "^1.2.3",
@ -4114,9 +4114,10 @@
} }
}, },
"node_modules/@js-preview/excel": { "node_modules/@js-preview/excel": {
"version": "1.7.8", "version": "1.7.14",
"resolved": "https://registry.npmmirror.com/@js-preview/excel/-/excel-1.7.8.tgz", "resolved": "https://registry.npmmirror.com/@js-preview/excel/-/excel-1.7.14.tgz",
"integrity": "sha512-pLJTDIhbzqaiH3kUPnbeWLsBFeCAHjnBwloMvoREdW4YUYTcsHDQ5h41QTyRJWSYRJBCcsy6Kt7KeDHOHDbVEw==" "integrity": "sha512-7QHtuRalWQzWIKARc/IRN8+kj1S5eWV4+cAQipzZngE3mVxMPL1RHXKJt/ONmpcKZ410egYkaBuOOs9+LctBkA==",
"license": "MIT"
}, },
"node_modules/@lexical/clipboard": { "node_modules/@lexical/clipboard": {
"version": "0.23.1", "version": "0.23.1",

View File

@ -23,7 +23,7 @@
"@antv/g2": "^5.2.10", "@antv/g2": "^5.2.10",
"@antv/g6": "^5.0.10", "@antv/g6": "^5.0.10",
"@hookform/resolvers": "^3.9.1", "@hookform/resolvers": "^3.9.1",
"@js-preview/excel": "^1.7.8", "@js-preview/excel": "^1.7.14",
"@lexical/react": "^0.23.1", "@lexical/react": "^0.23.1",
"@monaco-editor/react": "^4.6.0", "@monaco-editor/react": "^4.6.0",
"@radix-ui/react-accordion": "^1.2.3", "@radix-ui/react-accordion": "^1.2.3",

View File

@ -15,7 +15,8 @@ interface EditTagsProps {
onChange?: (tags: string[]) => void; onChange?: (tags: string[]) => void;
} }
const EditTag = ({ value = [], onChange }: EditTagsProps) => { const EditTag = React.forwardRef<HTMLDivElement, EditTagsProps>(
({ value = [], onChange }: EditTagsProps, ref) => {
const [inputVisible, setInputVisible] = useState(false); const [inputVisible, setInputVisible] = useState(false);
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
@ -53,13 +54,10 @@ const EditTag = ({ value = [], onChange }: EditTagsProps) => {
const forMap = (tag: string) => { const forMap = (tag: string) => {
return ( return (
<HoverCard> <HoverCard key={tag}>
<HoverCardContent side="top">{tag}</HoverCardContent> <HoverCardContent side="top">{tag}</HoverCardContent>
<HoverCardTrigger> <HoverCardTrigger asChild>
<div <div className="w-fit flex items-center justify-center gap-2 border-dashed border px-1 rounded-sm bg-bg-card">
key={tag}
className="w-fit flex items-center justify-center gap-2 border-dashed border px-1 rounded-sm bg-bg-card"
>
<div className="flex gap-2 items-center"> <div className="flex gap-2 items-center">
<div className="max-w-80 overflow-hidden text-ellipsis"> <div className="max-w-80 overflow-hidden text-ellipsis">
{tag} {tag}
@ -132,6 +130,7 @@ const EditTag = ({ value = [], onChange }: EditTagsProps) => {
)} )}
</div> </div>
); );
}; },
);
export default EditTag; export default EditTag;

View File

@ -183,13 +183,13 @@ const RaptorFormFields = () => {
render={({ field }) => ( render={({ field }) => (
<FormItem className=" items-center space-y-0 "> <FormItem className=" items-center space-y-0 ">
<div className="flex items-center"> <div className="flex items-center">
<FormLabel className="text-sm text-muted-foreground whitespace-nowrap w-1/4"> <FormLabel className="text-sm text-muted-foreground whitespace-wrap w-1/4">
{t('randomSeed')} {t('randomSeed')}
</FormLabel> </FormLabel>
<div className="w-3/4"> <div className="w-3/4">
<FormControl defaultValue={0}> <FormControl defaultValue={0}>
<div className="flex gap-4"> <div className="flex gap-4 items-center">
<Input {...field} defaultValue={0} /> <Input {...field} defaultValue={0} type="number" />
<Button <Button
size={'sm'} size={'sm'}
onClick={handleGenerate} onClick={handleGenerate}

View File

@ -9,7 +9,24 @@ export interface InputProps
} }
const Input = React.forwardRef<HTMLInputElement, InputProps>( const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, value, ...props }, ref) => { ({ className, type, value, onChange, ...props }, ref) => {
const isControlled = value !== undefined;
const { defaultValue, ...restProps } = props;
const inputValue = isControlled ? value : defaultValue;
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
if (type === 'number') {
const numValue = e.target.value === '' ? '' : Number(e.target.value);
onChange?.({
...e,
target: {
...e.target,
value: numValue,
},
} as React.ChangeEvent<HTMLInputElement>);
} else {
onChange?.(e);
}
};
return ( return (
<input <input
type={type} type={type}
@ -18,8 +35,9 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
className, className,
)} )}
ref={ref} ref={ref}
value={value ?? ''} value={inputValue ?? ''}
{...props} onChange={handleChange}
{...restProps}
/> />
); );
}, },

View File

@ -29,6 +29,7 @@ import {
} from '@/components/ui/popover'; } from '@/components/ui/popover';
import { Separator } from '@/components/ui/separator'; import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { isEmpty } from 'lodash';
export type MultiSelectOptionType = { export type MultiSelectOptionType = {
label: React.ReactNode; label: React.ReactNode;
@ -209,13 +210,17 @@ export const MultiSelect = React.forwardRef<
const [isAnimating, setIsAnimating] = React.useState(false); const [isAnimating, setIsAnimating] = React.useState(false);
React.useEffect(() => { React.useEffect(() => {
if (!selectedValues?.length && props.value) { if (isEmpty(selectedValues) && !isEmpty(props.value)) {
setSelectedValues(props.value as string[]); setSelectedValues(props.value as string[]);
} }
}, [props.value, selectedValues]); }, [props.value, selectedValues]);
React.useEffect(() => { React.useEffect(() => {
if (!selectedValues?.length && !props.value && defaultValue) { if (
isEmpty(selectedValues) &&
isEmpty(props.value) &&
!isEmpty(defaultValue)
) {
setSelectedValues(defaultValue); setSelectedValues(defaultValue);
} }
}, [defaultValue, props.value, selectedValues]); }, [defaultValue, props.value, selectedValues]);

View File

@ -1,7 +1,7 @@
import { Checkbox } from '@/components/ui/checkbox'; import { Checkbox } from '@/components/ui/checkbox';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { Ban, CircleCheck, Trash2 } from 'lucide-react'; import { Ban, CircleCheck, Trash2 } from 'lucide-react';
import { useCallback } from 'react'; import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
type ICheckboxSetProps = { type ICheckboxSetProps = {
@ -9,9 +9,16 @@ type ICheckboxSetProps = {
removeChunk: (e?: any) => void; removeChunk: (e?: any) => void;
switchChunk: (available: number) => void; switchChunk: (available: number) => void;
checked: boolean; checked: boolean;
selectedChunkIds: string[];
}; };
export default (props: ICheckboxSetProps) => { export default (props: ICheckboxSetProps) => {
const { selectAllChunk, removeChunk, switchChunk, checked } = props; const {
selectAllChunk,
removeChunk,
switchChunk,
checked,
selectedChunkIds,
} = props;
const { t } = useTranslation(); const { t } = useTranslation();
const handleSelectAllCheck = useCallback( const handleSelectAllCheck = useCallback(
(e: any) => { (e: any) => {
@ -33,26 +40,32 @@ export default (props: ICheckboxSetProps) => {
switchChunk(0); switchChunk(0);
}, [switchChunk]); }, [switchChunk]);
const isSelected = useMemo(() => {
return selectedChunkIds?.length > 0;
}, [selectedChunkIds]);
return ( return (
<div className="flex gap-[40px] p-4"> <div className="flex gap-[40px] py-4 px-2">
<div className="flex items-center gap-3 cursor-pointer text-muted-foreground hover:text-white"> <div className="flex items-center gap-3 cursor-pointer text-muted-foreground hover:text-text-primary">
<Checkbox <Checkbox
id="all_chunks_checkbox" id="all_chunks_checkbox"
onCheckedChange={handleSelectAllCheck} onCheckedChange={handleSelectAllCheck}
checked={checked} checked={checked}
className=" data-[state=checked]:bg-white data-[state=checked]:border-white data-[state=checked]:text-black border-muted-foreground text-muted-foreground hover:text-black hover:border-white " className=" data-[state=checked]:bg-text-primary data-[state=checked]:border-text-primary data-[state=checked]:text-bg-base border-muted-foreground text-muted-foreground hover:text-bg-base hover:border-text-primary "
/> />
<Label htmlFor="all_chunks_checkbox">{t('chunk.selectAll')}</Label> <Label htmlFor="all_chunks_checkbox">{t('chunk.selectAll')}</Label>
</div> </div>
{isSelected && (
<>
<div <div
className="flex items-center cursor-pointer text-muted-foreground hover:text-white" className="flex items-center cursor-pointer text-muted-foreground hover:text-text-primary"
onClick={handleEnabledClick} onClick={handleEnabledClick}
> >
<CircleCheck size={16} /> <CircleCheck size={16} />
<span className="block ml-1">{t('chunk.enable')}</span> <span className="block ml-1">{t('chunk.enable')}</span>
</div> </div>
<div <div
className="flex items-center cursor-pointer text-muted-foreground hover:text-white" className="flex items-center cursor-pointer text-muted-foreground hover:text-text-primary"
onClick={handleDisabledClick} onClick={handleDisabledClick}
> >
<Ban size={16} /> <Ban size={16} />
@ -65,6 +78,8 @@ export default (props: ICheckboxSetProps) => {
<Trash2 size={16} /> <Trash2 size={16} />
<span className="block ml-1">{t('chunk.delete')}</span> <span className="block ml-1">{t('chunk.delete')}</span>
</div> </div>
</>
)}
</div> </div>
); );
}; };

View File

@ -197,7 +197,7 @@ const Chunk = () => {
</BreadcrumbItem> </BreadcrumbItem>
<BreadcrumbSeparator /> <BreadcrumbSeparator />
<BreadcrumbItem> <BreadcrumbItem>
<BreadcrumbPage>{documentInfo.name}</BreadcrumbPage> <BreadcrumbPage>{documentInfo?.name}</BreadcrumbPage>
</BreadcrumbItem> </BreadcrumbItem>
</BreadcrumbList> </BreadcrumbList>
</Breadcrumb> </Breadcrumb>
@ -249,6 +249,7 @@ const Chunk = () => {
switchChunk={handleSwitchChunk} switchChunk={handleSwitchChunk}
removeChunk={handleRemoveChunk} removeChunk={handleRemoveChunk}
checked={selectedChunkIds.length === data.length} checked={selectedChunkIds.length === data.length}
selectedChunkIds={selectedChunkIds}
/> />
</div> </div>
<div className={styles.pageContent}> <div className={styles.pageContent}>