feat(sqllab): save query parameters in database (#21682)

This commit is contained in:
Mayur
2022-10-07 12:49:14 +05:30
committed by GitHub
parent 882bfb67ae
commit 61319fd759
11 changed files with 132 additions and 61 deletions

View File

@@ -36,8 +36,8 @@ import { QueryEditor } from 'src/SqlLab/types';
interface SaveQueryProps {
queryEditorId: string;
columns: ISaveableDatasource['columns'];
onSave: (arg0: QueryPayload) => void;
onUpdate: (arg0: QueryPayload) => void;
onSave: (arg0: QueryPayload, id: string) => void;
onUpdate: (arg0: QueryPayload, id: string) => void;
saveQueryWarning: string | null;
database: Record<string, any>;
}
@@ -46,19 +46,8 @@ type QueryPayload = {
name: string;
description?: string;
id?: string;
} & Pick<
QueryEditor,
| 'autorun'
| 'dbId'
| 'schema'
| 'sql'
| 'selectedText'
| 'remoteId'
| 'latestQueryId'
| 'queryLimit'
| 'tableOptions'
| 'schemaOptions'
>;
remoteId?: number;
} & Pick<QueryEditor, 'dbId' | 'schema' | 'sql'>;
const Styles = styled.span`
span[role='img'] {
@@ -93,11 +82,11 @@ export default function SaveQuery({
'selectedText',
'sql',
'tableOptions',
'templateParams',
]);
const query = useMemo(
() => ({
...queryEditor,
columns,
}),
[queryEditor, columns],
);
@@ -120,10 +109,13 @@ export default function SaveQuery({
);
const queryPayload = () => ({
...query,
name: label,
description,
dbId: query.dbId ?? 0,
sql: query.sql,
schema: query.schema,
templateParams: query.templateParams,
remoteId: query?.remoteId || undefined,
});
useEffect(() => {
@@ -133,12 +125,12 @@ export default function SaveQuery({
const close = () => setShowSave(false);
const onSaveWrapper = () => {
onSave(queryPayload());
onSave(queryPayload(), query.id);
close();
};
const onUpdateWrapper = () => {
onUpdate(queryPayload());
onUpdate(queryPayload(), query.id);
close();
};