fix(sqllab): invalid empty state on switch tab (#29278)

This commit is contained in:
JUST.in DO IT 2024-06-18 11:45:09 -07:00 committed by GitHub
parent 527f1d20ad
commit 725afc3848
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 19 deletions

View File

@ -303,7 +303,10 @@ const SqlEditor: FC<Props> = ({
); );
const [showCreateAsModal, setShowCreateAsModal] = useState(false); const [showCreateAsModal, setShowCreateAsModal] = useState(false);
const [createAs, setCreateAs] = useState(''); const [createAs, setCreateAs] = useState('');
const [showEmptyState, setShowEmptyState] = useState(false); const showEmptyState = useMemo(
() => !database || isEmpty(database),
[database],
);
const sqlEditorRef = useRef<HTMLDivElement>(null); const sqlEditorRef = useRef<HTMLDivElement>(null);
const northPaneRef = useRef<HTMLDivElement>(null); const northPaneRef = useRef<HTMLDivElement>(null);
@ -562,12 +565,6 @@ const SqlEditor: FC<Props> = ({
// TODO: Remove useEffectEvent deps once https://github.com/facebook/react/pull/25881 is released // TODO: Remove useEffectEvent deps once https://github.com/facebook/react/pull/25881 is released
}, [onBeforeUnload, loadQueryEditor, isActive]); }, [onBeforeUnload, loadQueryEditor, isActive]);
useEffect(() => {
if (!database || isEmpty(database)) {
setShowEmptyState(true);
}
}, [database]);
useEffect(() => { useEffect(() => {
// setup hotkeys // setup hotkeys
const hotkeys = getHotkeyConfig(); const hotkeys = getHotkeyConfig();
@ -911,7 +908,6 @@ const SqlEditor: FC<Props> = ({
<SqlEditorLeftBar <SqlEditorLeftBar
database={database} database={database}
queryEditorId={queryEditor.id} queryEditorId={queryEditor.id}
setEmptyState={bool => setShowEmptyState(bool)}
/> />
</StyledSidebar> </StyledSidebar>
)} )}

View File

@ -16,14 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import { import { useEffect, useCallback, useMemo, useState } from 'react';
useEffect,
useCallback,
useMemo,
useState,
Dispatch,
SetStateAction,
} from 'react';
import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import querystring from 'query-string'; import querystring from 'query-string';
@ -60,7 +53,6 @@ export interface SqlEditorLeftBarProps {
queryEditorId: string; queryEditorId: string;
height?: number; height?: number;
database?: DatabaseObject; database?: DatabaseObject;
setEmptyState?: Dispatch<SetStateAction<boolean>>;
} }
const StyledScrollbarContainer = styled.div` const StyledScrollbarContainer = styled.div`
@ -108,7 +100,6 @@ const SqlEditorLeftBar = ({
database, database,
queryEditorId, queryEditorId,
height = 500, height = 500,
setEmptyState,
}: SqlEditorLeftBarProps) => { }: SqlEditorLeftBarProps) => {
const tables = useSelector<SqlLabRootState, Table[]>( const tables = useSelector<SqlLabRootState, Table[]>(
({ sqlLab }) => ({ sqlLab }) =>
@ -148,7 +139,6 @@ const SqlEditorLeftBar = ({
}, []); }, []);
const onDbChange = ({ id: dbId }: { id: number }) => { const onDbChange = ({ id: dbId }: { id: number }) => {
setEmptyState?.(false);
dispatch(queryEditorSetDb(queryEditor, dbId)); dispatch(queryEditorSetDb(queryEditor, dbId));
}; };

View File

@ -102,6 +102,7 @@ export default function getInitialState({
id: id.toString(), id: id.toString(),
loaded: false, loaded: false,
name: label, name: label,
dbId: undefined,
}; };
} }
queryEditors = { queryEditors = {