Skip to content

Commit a36c229

Browse files
authored
fix: Fix editing search tiles in dashboard (#820)
Fix the issue with `select` field becoming an empty array for Search tiles.
1 parent 8ecf44b commit a36c229

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

packages/app/src/components/DBEditTimeChartForm.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export default function EditTimeChartForm({
339339

340340
const { fields, append, remove } = useFieldArray({
341341
control: control as Control<SavedChartConfigWithSelectArray>,
342-
name: 'select', // TODO: bug with select = "" - it becomes and empty array
342+
name: 'select',
343343
});
344344

345345
const select = watch('select');
@@ -422,6 +422,17 @@ export default function EditTimeChartForm({
422422
})();
423423
}, [handleSubmit, setChartConfig, setQueriedConfig, tableSource, dateRange]);
424424

425+
const handleSave = useCallback(
426+
(v: SavedChartConfig) => {
427+
// If the chart type is search, we need to ensure the select is a string
428+
if (displayType === DisplayType.Search && typeof v.select !== 'string') {
429+
v.select = '';
430+
}
431+
onSave?.(v);
432+
},
433+
[onSave, displayType],
434+
);
435+
425436
watch((_, { name, type }) => {
426437
// Emulate the granularity picker auto-searching similar to dashboards
427438
if (name === 'granularity' && type === 'change') {
@@ -786,11 +797,7 @@ export default function EditTimeChartForm({
786797
<Button
787798
loading={isSaving}
788799
variant="outline"
789-
onClick={() => {
790-
handleSubmit(v => {
791-
onSave?.(v);
792-
})();
793-
}}
800+
onClick={handleSubmit(handleSave)}
794801
>
795802
Save
796803
</Button>

packages/app/src/components/SQLInlineEditor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,22 @@ export function SQLInlineEditorControlled({
359359
}: Omit<SQLInlineEditorProps, 'value' | 'onChange'> & UseControllerProps<any>) {
360360
const { field } = useController(props);
361361

362+
// Guard against wrongly typed values
363+
const value = field.value || props.defaultValue;
364+
365+
let stringValue = '';
366+
if (typeof value === 'string') {
367+
stringValue = value;
368+
} else {
369+
console.error('SQLInlineEditor: value is not a string', value);
370+
}
371+
362372
return (
363373
<SQLInlineEditor
364374
filterField={filterField}
365375
onChange={field.onChange}
366376
placeholder={placeholder}
367-
value={field.value || props.defaultValue}
377+
value={stringValue}
368378
additionalSuggestions={additionalSuggestions}
369379
queryHistoryType={queryHistoryType}
370380
{...props}

0 commit comments

Comments
 (0)