From bd67ccfbcf66b919453ca6c0bfd71e16772b3d8e Mon Sep 17 00:00:00 2001 From: Guy Ben-Aharon Date: Tue, 11 Mar 2025 18:49:10 +0200 Subject: [PATCH] feat(chart max length): enable edit length from data type select box (#616) * feat(chart max length): enable edit length from data type select box * fix --- src/components/select-box/select-box.tsx | 94 ++++++++++++++----- .../canvas/table-node/table-node-field.tsx | 2 +- .../table-field-modal/table-field-modal.tsx | 8 +- .../table-field/table-field.tsx | 94 +++++++++++++++---- 4 files changed, 157 insertions(+), 41 deletions(-) diff --git a/src/components/select-box/select-box.tsx b/src/components/select-box/select-box.tsx index a3ba0f98..d9eeb96d 100644 --- a/src/components/select-box/select-box.tsx +++ b/src/components/select-box/select-box.tsx @@ -24,12 +24,19 @@ export interface SelectBoxOption { value: string; label: string; description?: string; + regex?: string; + extractRegex?: RegExp; } export interface SelectBoxProps { options: SelectBoxOption[]; value?: string[] | string; - onChange?: (values: string[] | string) => void; + valueSuffix?: string; + optionSuffix?: (option: SelectBoxOption) => string; + onChange?: ( + values: string[] | string, + regexMatches?: string[] | string + ) => void; placeholder?: string; inputPlaceholder?: string; emptyPlaceholder?: string; @@ -55,10 +62,12 @@ export const SelectBox = React.forwardRef( className, options, value, + valueSuffix, onChange, multiple, oneLine, selectAll, + optionSuffix, deselectAll, clearText, showClear, @@ -86,7 +95,7 @@ export const SelectBox = React.forwardRef( ); const handleSelect = React.useCallback( - (selectedValue: string) => { + (selectedValue: string, regexMatches?: string[]) => { if (multiple) { const newValue = value?.includes(selectedValue) && Array.isArray(value) @@ -94,7 +103,7 @@ export const SelectBox = React.forwardRef( : [...(value ?? []), selectedValue]; onChange?.(newValue); } else { - onChange?.(selectedValue); + onChange?.(selectedValue, regexMatches); setIsOpen(false); } }, @@ -199,6 +208,7 @@ export const SelectBox = React.forwardRef( (opt) => opt.value === value )?.label } + {valueSuffix ? valueSuffix : ''} ) ) : ( @@ -239,11 +249,22 @@ export const SelectBox = React.forwardRef( align="center" > - value.toLowerCase().includes(search.toLowerCase()) + filter={(value, search, keywords) => { + if ( + keywords?.length && + keywords.some((keyword) => + new RegExp(keyword).test(search) + ) + ) { + return 1; + } + + return value + .toLowerCase() + .includes(search.toLowerCase()) ? 1 - : 0 - } + : 0; + }} >
( const isSelected = Array.isArray(value) && value.includes(option.value); + + const isRegexMatch = + option.regex && + new RegExp(option.regex)?.test( + searchTerm + ); + + const matches = option.extractRegex + ? searchTerm.match( + option.extractRegex + ) + : undefined; + return ( handleSelect( - option.value + option.value, + matches?.map( + (match) => + match.toString() + ) ) } > @@ -327,7 +370,15 @@ export const SelectBox = React.forwardRef( )}
- {option.label} + {isRegexMatch + ? searchTerm + : option.label} + {!isRegexMatch && + optionSuffix + ? optionSuffix( + option + ) + : ''} {option.description && ( @@ -337,19 +388,20 @@ export const SelectBox = React.forwardRef( )}
- {!multiple && + {((!multiple && option.value === - value && ( - - )} + value) || + isRegexMatch) && ( + + )}
); })} diff --git a/src/pages/editor-page/canvas/table-node/table-node-field.tsx b/src/pages/editor-page/canvas/table-node/table-node-field.tsx index eb56a55e..b79f90fc 100644 --- a/src/pages/editor-page/canvas/table-node/table-node-field.tsx +++ b/src/pages/editor-page/canvas/table-node/table-node-field.tsx @@ -227,7 +227,7 @@ export const TableNodeField: React.FC = React.memo( !readonly ? 'group-hover:hidden' : '' )} > - {field.type.name} + {field.type.name.split(' ')[0]} {field.nullable ? '?' : ''}
{readonly ? null : ( diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx index 07da2671..5b3eb185 100644 --- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx +++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx @@ -55,7 +55,13 @@ export const TableFieldPopover: React.FC = ({ }, [localField]); return ( - !isOpen && setLocalField(field)}> + { + if (isOpen) { + setLocalField(field); + } + }} + >