Skip to content

Commit

Permalink
fix(sqllab): invalid empty state on switch tab
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Jun 17, 2024
1 parent ae7c409 commit d151886
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
12 changes: 4 additions & 8 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ const SqlEditor: FC<Props> = ({
);
const [showCreateAsModal, setShowCreateAsModal] = useState(false);
const [createAs, setCreateAs] = useState('');
const [showEmptyState, setShowEmptyState] = useState(false);
const showEmptyState = useMemo(
() => !database || isEmpty(database),
[database],
);

const sqlEditorRef = useRef<HTMLDivElement>(null);
const northPaneRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -562,12 +565,6 @@ const SqlEditor: FC<Props> = ({
// TODO: Remove useEffectEvent deps once https://github.com/facebook/react/pull/25881 is released
}, [onBeforeUnload, loadQueryEditor, isActive]);

useEffect(() => {
if (!database || isEmpty(database)) {
setShowEmptyState(true);
}
}, [database]);

useEffect(() => {
// setup hotkeys
const hotkeys = getHotkeyConfig();
Expand Down Expand Up @@ -911,7 +908,6 @@ const SqlEditor: FC<Props> = ({
<SqlEditorLeftBar
database={database}
queryEditorId={queryEditor.id}
setEmptyState={bool => setShowEmptyState(bool)}
/>
</StyledSidebar>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export interface SqlEditorLeftBarProps {
queryEditorId: string;
height?: number;
database?: DatabaseObject;
setEmptyState?: Dispatch<SetStateAction<boolean>>;
}

const StyledScrollbarContainer = styled.div`
Expand Down Expand Up @@ -108,7 +107,6 @@ const SqlEditorLeftBar = ({
database,
queryEditorId,
height = 500,
setEmptyState,
}: SqlEditorLeftBarProps) => {
const tables = useSelector<SqlLabRootState, Table[]>(
({ sqlLab }) =>
Expand Down Expand Up @@ -148,7 +146,6 @@ const SqlEditorLeftBar = ({
}, []);

const onDbChange = ({ id: dbId }: { id: number }) => {
setEmptyState?.(false);
dispatch(queryEditorSetDb(queryEditor, dbId));
};

Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/SqlLab/reducers/getInitialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default function getInitialState({
id: id.toString(),
loaded: false,
name: label,
dbId: undefined,
};
}
queryEditors = {
Expand Down

0 comments on commit d151886

Please sign in to comment.