You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2026/03/26 17:05:28 UTC
(superset) branch 6.1 updated (97ddc0701e2 -> bd552209e7f)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a change to branch 6.1
in repository https://gitbox.apache.org/repos/asf/superset.git
discard 97ddc0701e2 fix(sqllab): inactive leftbar selector on empty state (#38833)
new bd552209e7f fix(sqllab): inactive leftbar selector on empty state (#38833)
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (97ddc0701e2)
\
N -- N -- N refs/heads/6.1 (bd552209e7f)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../DashboardBuilder/DashboardBuilder.tsx | 51 ++++++++++++----------
1 file changed, 27 insertions(+), 24 deletions(-)
(superset) 01/01: fix(sqllab): inactive leftbar selector on empty state (#38833)
Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 6.1
in repository https://gitbox.apache.org/repos/asf/superset.git
commit bd552209e7fcf770c920f2895642f4cc52fc1809
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Thu Mar 26 08:57:16 2026 -0700
fix(sqllab): inactive leftbar selector on empty state (#38833)
(cherry picked from commit cfa1aba1e0bc23868669bba3583939eafcd4f84c)
---
.../src/SqlLab/actions/sqlLab.test.ts | 39 +++++++++++++++++
superset-frontend/src/SqlLab/actions/sqlLab.ts | 3 +-
.../SqlEditorLeftBar/SqlEditorLeftBar.test.tsx | 15 +++++++
.../SqlLab/components/SqlEditorLeftBar/index.tsx | 6 ++-
.../src/SqlLab/hooks/useQueryEditor/index.ts | 3 ++
superset-frontend/src/SqlLab/reducers/sqlLab.ts | 5 ++-
.../DashboardBuilder/DashboardBuilder.tsx | 51 ++++++++++++----------
7 files changed, 94 insertions(+), 28 deletions(-)
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts
index 0de713eae3a..740d0a6e36e 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.test.ts
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.ts
@@ -33,6 +33,7 @@ import {
} from 'src/SqlLab/fixtures';
import { SupersetClient, isFeatureEnabled } from '@superset-ui/core';
import { ADD_TOAST } from 'src/components/MessageToasts/actions';
+import { EMPTY_STATE_QE_ID } from 'src/SqlLab/hooks/useQueryEditor';
import { ToastType } from '../../components/MessageToasts/types';
const isFeatureEnabledMock = isFeatureEnabled as unknown as jest.Mock;
@@ -882,6 +883,44 @@ describe('async actions', () => {
request(store.dispatch, store.getState, undefined);
expect(store.getActions()).toEqual(expectedActions);
});
+
+ test('creates a new query editor from the saved state in the empty tab', () => {
+ const unsavedEmptyTabState = {
+ id: EMPTY_STATE_QE_ID,
+ dbId: 2,
+ catalog: 'test_catalog',
+ schema: 'test_schema',
+ };
+ const store = mockStore({
+ ...initialState,
+ sqlLab: {
+ ...initialState.sqlLab,
+ tabHistory: [EMPTY_STATE_QE_ID],
+ unsavedQueryEditor: unsavedEmptyTabState,
+ },
+ });
+ const expectedActions = [
+ {
+ type: actions.ADD_QUERY_EDITOR,
+ queryEditor: {
+ id: 'abcd',
+ immutableId: 'abcd',
+ sql: expect.stringContaining('SELECT ...'),
+ name: 'Untitled Query 4',
+ dbId: unsavedEmptyTabState.dbId,
+ catalog: unsavedEmptyTabState.catalog,
+ schema: unsavedEmptyTabState.schema,
+ inLocalStorage: true,
+ autorun: false,
+ queryLimit: initialState.common.conf.DEFAULT_SQLLAB_LIMIT,
+ loaded: true,
+ },
+ },
+ ];
+ const request = actions.addNewQueryEditor();
+ request(store.dispatch, store.getState, undefined);
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
});
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.ts b/superset-frontend/src/SqlLab/actions/sqlLab.ts
index 093d1a497eb..dc5441ecfd0 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.ts
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.ts
@@ -47,6 +47,7 @@ import { newQueryTabName } from '../utils/newQueryTabName';
import getInitialState from '../reducers/getInitialState';
import { rehydratePersistedState } from '../utils/reduxStateToLocalStorageHelper';
import { PREVIEW_QUERY_LIMIT } from '../constants';
+import { EMPTY_STATE_QE_ID } from '../hooks/useQueryEditor';
// Type definitions for SqlLab actions
export interface Query {
@@ -754,7 +755,7 @@ export function addNewQueryEditor(): SqlLabThunkAction<SqlLabAction> {
const defaultDbId = common.conf.SQLLAB_DEFAULT_DBID as number | undefined;
const activeQueryEditor = queryEditors.find(
(qe: QueryEditor) => qe.id === tabHistory[tabHistory.length - 1],
- );
+ ) ?? { id: EMPTY_STATE_QE_ID };
const dbIds = Object.values(databases).map(
(database: { id: number }) => database.id,
);
diff --git a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.tsx b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.tsx
index 673171787ae..ea90b1cb3fa 100644
--- a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.tsx
+++ b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.tsx
@@ -32,6 +32,8 @@ import {
defaultQueryEditor,
extraQueryEditor2,
} from 'src/SqlLab/fixtures';
+import { EMPTY_STATE_QE_ID } from 'src/SqlLab/hooks/useQueryEditor';
+import * as useDatabaseSelectorModule from '../SqlEditorTopBar/useDatabaseSelector';
import type { RootState } from 'src/views/store';
import type { Store } from 'redux';
@@ -235,3 +237,16 @@ test('ignore schema api when current schema is deprecated', async () => {
]),
);
});
+
+test('uses EMPTY_STATE_QE_ID when queryEditorId is empty', async () => {
+ const useDatabaseSelectorSpy = jest.spyOn(
+ useDatabaseSelectorModule,
+ 'default',
+ );
+
+ await renderAndWait({ queryEditorId: '' }, undefined, initialState);
+
+ expect(useDatabaseSelectorSpy).toHaveBeenCalledWith(EMPTY_STATE_QE_ID);
+
+ useDatabaseSelectorSpy.mockRestore();
+});
diff --git a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
index 9ff47fd6223..e4297629271 100644
--- a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
+++ b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
@@ -32,6 +32,7 @@ import { t } from '@apache-superset/core/translation';
import { styled, css } from '@apache-superset/core/theme';
import type { SchemaOption, CatalogOption } from 'src/hooks/apiResources';
import { DatabaseSelector, type DatabaseObject } from 'src/components';
+import { EMPTY_STATE_QE_ID } from 'src/SqlLab/hooks/useQueryEditor';
import useDatabaseSelector from '../SqlEditorTopBar/useDatabaseSelector';
import TableExploreTree from '../TableExploreTree';
@@ -63,7 +64,8 @@ const StyledDivider = styled.div`
`;
const SqlEditorLeftBar = ({ queryEditorId }: SqlEditorLeftBarProps) => {
- const dbSelectorProps = useDatabaseSelector(queryEditorId);
+ const activeQEId = queryEditorId || EMPTY_STATE_QE_ID;
+ const dbSelectorProps = useDatabaseSelector(activeQEId);
const { db, catalog, schema, onDbChange, onCatalogChange, onSchemaChange } =
dbSelectorProps;
@@ -198,7 +200,7 @@ const SqlEditorLeftBar = ({ queryEditorId }: SqlEditorLeftBarProps) => {
/>
</Popover>
<StyledDivider />
- <TableExploreTree queryEditorId={queryEditorId} />
+ <TableExploreTree queryEditorId={activeQEId} />
{shouldShowReset && (
<Button
buttonSize="small"
diff --git a/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts b/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts
index 7a5f3c6874f..2845fe90349 100644
--- a/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts
+++ b/superset-frontend/src/SqlLab/hooks/useQueryEditor/index.ts
@@ -21,6 +21,8 @@ import { useMemo } from 'react';
import { shallowEqual, useSelector } from 'react-redux';
import { SqlLabRootState, QueryEditor } from 'src/SqlLab/types';
+export const EMPTY_STATE_QE_ID = 'tmp_qe_id';
+
export default function useQueryEditor<T extends keyof QueryEditor>(
sqlEditorId: string,
attributes: ReadonlyArray<T>,
@@ -43,6 +45,7 @@ export default function useQueryEditor<T extends keyof QueryEditor>(
{
...queryEditors[queryEditorsById[sqlEditorId]],
...(sqlEditorId === unsavedQueryEditor?.id && unsavedQueryEditor),
+ ...(sqlEditorId === EMPTY_STATE_QE_ID && { id: sqlEditorId }),
},
['id'].concat(attributes),
) as Pick<QueryEditor, T | 'id'>,
diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.ts b/superset-frontend/src/SqlLab/reducers/sqlLab.ts
index 46277bb86b6..34e3af847cc 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.ts
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.ts
@@ -42,7 +42,10 @@ function alterUnsavedQueryEditorState(
id: string,
silent = false,
): Partial<SqlLabState> {
- if (state.tabHistory[state.tabHistory.length - 1] !== id) {
+ if (
+ state.tabHistory.length > 0 &&
+ state.tabHistory[state.tabHistory.length - 1] !== id
+ ) {
const { queryEditors } = alterInArr(
state,
'queryEditors',
diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
index a706f89b7de..a507c65318d 100644
--- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
+++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
@@ -523,30 +523,33 @@ const DashboardBuilder = () => {
({ dropIndicatorProps }: { dropIndicatorProps: JsonObject }) => (
<div>
{dropIndicatorProps && <div {...dropIndicatorProps} />}
- {!isReport && topLevelTabs && !uiConfig.hideTab && !uiConfig.hideNav && (
- <WithPopoverMenu
- shouldFocus={shouldFocusTabs}
- menuItems={[
- <IconButton
- key="collapse-tabs"
- icon={<Icons.FallOutlined iconSize="xl" />}
- label={t('Collapse tab content')}
- onClick={handleDeleteTopLevelTabs}
- />,
- ]}
- editMode={editMode}
- >
- <DashboardComponent
- id={topLevelTabs?.id}
- parentId={DASHBOARD_ROOT_ID}
- depth={DASHBOARD_ROOT_DEPTH + 1}
- index={0}
- renderTabContent={false}
- renderHoverMenu={false}
- onChangeTab={handleChangeTab}
- />
- </WithPopoverMenu>
- )}
+ {!isReport &&
+ topLevelTabs &&
+ !uiConfig.hideTab &&
+ !uiConfig.hideNav && (
+ <WithPopoverMenu
+ shouldFocus={shouldFocusTabs}
+ menuItems={[
+ <IconButton
+ key="collapse-tabs"
+ icon={<Icons.FallOutlined iconSize="xl" />}
+ label={t('Collapse tab content')}
+ onClick={handleDeleteTopLevelTabs}
+ />,
+ ]}
+ editMode={editMode}
+ >
+ <DashboardComponent
+ id={topLevelTabs?.id}
+ parentId={DASHBOARD_ROOT_ID}
+ depth={DASHBOARD_ROOT_DEPTH + 1}
+ index={0}
+ renderTabContent={false}
+ renderHoverMenu={false}
+ onChangeTab={handleChangeTab}
+ />
+ </WithPopoverMenu>
+ )}
</div>
),
[