short cuts need to track by id

This commit is contained in:
Nate Kelley 2025-10-01 10:58:34 -06:00
parent 743d0d71c9
commit e66e344f1c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 11 additions and 4 deletions

View File

@ -100,6 +100,7 @@ export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
console.warn('Input is disabled or value is not defined');
return;
}
onSubmit({ ...value, mode });
};

View File

@ -73,7 +73,7 @@ export const useCreateShortcutsMentionsSuggestions = (
popoverContent: ShortcutPopoverContent,
popoverClassName: '',
onChangeTransform: (v) => {
const foundShortcut = shortcuts.find((shortcut) => shortcut.name === v.label);
const foundShortcut = shortcuts.find((shortcut) => shortcut.id === v.value);
if (foundShortcut) {
return foundShortcut.instructions;
}
@ -91,9 +91,9 @@ export const useCreateShortcutForMention = () => {
shortcut: Shortcut,
_editor?: Editor
): MentionTriggerItem<string> => {
console.log('shortcut', shortcut);
return {
value: shortcut.id,
labelMatches: [shortcut.name, shortcut.instructions],
label: (
<div className="flex flex-col space-y-1.5 py-1.5">
<Text>{`${SHORTCUT_MENTION_TRIGGER}${shortcut.name}`}</Text>

View File

@ -427,7 +427,7 @@ export const DynamicItems: Story = {
placeholder="Type ! to see dynamic mentions..."
mentions={[dynamicSuggestions]}
onChange={(value) => {
console.log('Input changed:', value);
console.info('Input changed:', value);
}}
/>

View File

@ -60,7 +60,7 @@ const PopoverWrapper = <T extends string>({
return (
<Popover
trigger="hover"
trigger="click"
align="start"
side="bottom"
sideOffset={8}

View File

@ -26,6 +26,12 @@ const itemMatchesQuery = (item: MentionTriggerItem, query: string): boolean => {
return results.length > 0;
}
if (typeof item.pillLabel === 'string') {
const pillLabelFuse = new Fuse([item.pillLabel], fuseConfig);
const results = pillLabelFuse.search(query);
return results.length > 0;
}
// No match if label is not a string and no labelMatches provided
return false;
};