Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only fetch db function when db exists in sql lab #16754

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions superset-frontend/src/SqlLab/components/AceEditorWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
AceCompleterKeyword,
FullSQLEditor as AceEditor,
} from 'src/components/AsyncAceEditor';
import { QueryEditor } from '../types';

type HotKey = {
key: string;
Expand All @@ -51,7 +52,7 @@ interface Props {
tables: any[];
functionNames: string[];
extendedTables: Array<{ name: string; columns: any[] }>;
queryEditor: any;
queryEditor: QueryEditor;
height: string;
hotkeys: HotKey[];
onChange: (sql: string) => void;
Expand Down Expand Up @@ -86,10 +87,12 @@ class AceEditorWrapper extends React.PureComponent<Props, State> {
componentDidMount() {
// Making sure no text is selected from previous mount
this.props.actions.queryEditorSetSelectedText(this.props.queryEditor, null);
this.props.actions.queryEditorSetFunctionNames(
this.props.queryEditor,
this.props.queryEditor.dbId,
);
if (this.props.queryEditor.dbId) {
this.props.actions.queryEditorSetFunctionNames(
this.props.queryEditor,
this.props.queryEditor.dbId,
);
}
this.setAutoCompleter(this.props);
}

Expand Down Expand Up @@ -228,8 +231,8 @@ class AceEditorWrapper extends React.PureComponent<Props, State> {

getAceAnnotations() {
const { validationResult } = this.props.queryEditor;
const resultIsReady = validationResult && validationResult.completed;
if (resultIsReady && validationResult.errors.length > 0) {
const resultIsReady = validationResult?.completed;
if (resultIsReady && validationResult?.errors?.length) {
const errors = validationResult.errors.map((err: any) => ({
type: 'error',
row: err.line_number - 1,
Expand Down
10 changes: 2 additions & 8 deletions superset-frontend/src/SqlLab/components/ShareSqlLabQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ import CopyToClipboard from 'src/components/CopyToClipboard';
import { storeQuery } from 'src/utils/common';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FeatureFlag, isFeatureEnabled } from '../../featureFlags';
import { QueryEditor } from '../types';

interface ShareSqlLabQueryPropTypes {
queryEditor: {
dbId: number;
title: string;
schema: string;
autorun: boolean;
sql: string;
remoteId: number | null;
};
queryEditor: QueryEditor;
addDangerToast: (msg: string) => void;
}

Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/SqlLab/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ export type Query = {
queryLimit: number;
limitingFactor: string;
};

export interface QueryEditor {
dbId?: number;
title: string;
schema: string;
autorun: boolean;
sql: string;
remoteId: number | null;
validationResult?: {
completed: boolean;
errors: SupersetError[];
};
}