Fix label selection with leading/trailing whitespace
• Fix AsyncSelect value trimming issue • Preserve whitespace in label display • Use safe keys for command items • Add GraphControl dependency fix • Add debug logging for graph labels
This commit is contained in:
parent
3c0ce9e38d
commit
25b5d176cd
4 changed files with 36 additions and 19 deletions
|
|
@ -66,6 +66,11 @@ def create_graph_routes(rag, api_key: Optional[str] = None):
|
||||||
Dict[str, List[str]]: Knowledge graph for label
|
Dict[str, List[str]]: Knowledge graph for label
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Log the label parameter to check for leading spaces
|
||||||
|
logger.debug(
|
||||||
|
f"get_knowledge_graph called with label: '{label}' (length: {len(label)}, repr: {repr(label)})"
|
||||||
|
)
|
||||||
|
|
||||||
return await rag.get_knowledge_graph(
|
return await rag.get_knowledge_graph(
|
||||||
node_label=label,
|
node_label=label,
|
||||||
max_depth=max_depth,
|
max_depth=max_depth,
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ const GraphControl = ({ disableHoverEffect }: { disableHoverEffect?: boolean })
|
||||||
|
|
||||||
// Register the events
|
// Register the events
|
||||||
registerEvents(events)
|
registerEvents(events)
|
||||||
}, [registerEvents, enableEdgeEvents])
|
}, [registerEvents, enableEdgeEvents, sigma])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When edge size settings change, recalculate edge sizes and refresh the sigma instance
|
* When edge size settings change, recalculate edge sizes and refresh the sigma instance
|
||||||
|
|
|
||||||
|
|
@ -140,9 +140,9 @@ const GraphLabels = () => {
|
||||||
searchInputClassName="max-h-8"
|
searchInputClassName="max-h-8"
|
||||||
triggerTooltip={t('graphPanel.graphLabels.selectTooltip')}
|
triggerTooltip={t('graphPanel.graphLabels.selectTooltip')}
|
||||||
fetcher={fetchData}
|
fetcher={fetchData}
|
||||||
renderOption={(item) => <div>{item}</div>}
|
renderOption={(item) => <div style={{ whiteSpace: 'pre' }}>{item}</div>}
|
||||||
getOptionValue={(item) => item}
|
getOptionValue={(item) => item}
|
||||||
getDisplayValue={(item) => <div>{item}</div>}
|
getDisplayValue={(item) => <div style={{ whiteSpace: 'pre' }}>{item}</div>}
|
||||||
notFound={<div className="py-6 text-center text-sm">No labels found</div>}
|
notFound={<div className="py-6 text-center text-sm">No labels found</div>}
|
||||||
label={t('graphPanel.graphLabels.label')}
|
label={t('graphPanel.graphLabels.label')}
|
||||||
placeholder={t('graphPanel.graphLabels.placeholder')}
|
placeholder={t('graphPanel.graphLabels.placeholder')}
|
||||||
|
|
|
||||||
|
|
@ -245,22 +245,34 @@ export function AsyncSelect<T>({
|
||||||
</CommandEmpty>
|
</CommandEmpty>
|
||||||
))}
|
))}
|
||||||
<CommandGroup>
|
<CommandGroup>
|
||||||
{options.map((option) => (
|
{options.map((option, index) => {
|
||||||
<CommandItem
|
const optionValue = getOptionValue(option);
|
||||||
key={getOptionValue(option)}
|
// Use index as a safe value that won't be trimmed by cmdk
|
||||||
value={getOptionValue(option)}
|
const safeValue = `option-${index}-${optionValue.length}`;
|
||||||
onSelect={handleSelect}
|
|
||||||
className="truncate"
|
return (
|
||||||
>
|
<CommandItem
|
||||||
{renderOption(option)}
|
key={optionValue}
|
||||||
<Check
|
value={safeValue}
|
||||||
className={cn(
|
onSelect={(selectedSafeValue) => {
|
||||||
'ml-auto h-3 w-3',
|
// Extract the original value from the safe value
|
||||||
selectedValue === getOptionValue(option) ? 'opacity-100' : 'opacity-0'
|
const selectedIndex = parseInt(selectedSafeValue.split('-')[1]);
|
||||||
)}
|
const originalValue = getOptionValue(options[selectedIndex]);
|
||||||
/>
|
console.log(`CommandItem onSelect: safeValue='${selectedSafeValue}', originalValue='${originalValue}' (length: ${originalValue.length})`);
|
||||||
</CommandItem>
|
handleSelect(originalValue);
|
||||||
))}
|
}}
|
||||||
|
className="truncate"
|
||||||
|
>
|
||||||
|
{renderOption(option)}
|
||||||
|
<Check
|
||||||
|
className={cn(
|
||||||
|
'ml-auto h-3 w-3',
|
||||||
|
selectedValue === optionValue ? 'opacity-100' : 'opacity-0'
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</CommandItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
</CommandList>
|
</CommandList>
|
||||||
</Command>
|
</Command>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue