chore(sqllab): Relocate user in SqlLab to root (#25010)
This commit is contained in:
parent
5e56871fd9
commit
b339613844
|
|
@ -27,7 +27,7 @@ import {
|
|||
isFeatureEnabled,
|
||||
} from '@superset-ui/core';
|
||||
import { GlobalStyles } from 'src/GlobalStyles';
|
||||
import { setupStore } from 'src/views/store';
|
||||
import { setupStore, userReducer } from 'src/views/store';
|
||||
import setupExtensions from 'src/setup/setupExtensions';
|
||||
import getBootstrapData from 'src/utils/getBootstrapData';
|
||||
import { tableApiUtil } from 'src/hooks/apiResources/tables';
|
||||
|
|
@ -78,12 +78,6 @@ const sqlLabPersistStateConfig = {
|
|||
}
|
||||
});
|
||||
|
||||
if (subset.sqlLab?.user) {
|
||||
// Don't persist the user.
|
||||
// User should really not be stored under the "sqlLab" field. Oh well.
|
||||
delete subset.sqlLab.user;
|
||||
}
|
||||
|
||||
const data = JSON.stringify(subset);
|
||||
// 2 digit precision
|
||||
const currentSize =
|
||||
|
|
@ -105,9 +99,6 @@ const sqlLabPersistStateConfig = {
|
|||
...initialState.sqlLab,
|
||||
},
|
||||
};
|
||||
// Filter out any user data that may have been persisted in an older version.
|
||||
// Get user from bootstrap data instead, every time
|
||||
result.sqlLab.user = initialState.sqlLab.user;
|
||||
return result;
|
||||
},
|
||||
},
|
||||
|
|
@ -115,7 +106,7 @@ const sqlLabPersistStateConfig = {
|
|||
|
||||
export const store = setupStore({
|
||||
initialState,
|
||||
rootReducers: reducers,
|
||||
rootReducers: { ...reducers, user: userReducer },
|
||||
...(!isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE) && {
|
||||
enhancers: [
|
||||
persistState(
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ describe('QueryTable', () => {
|
|||
it('renders a proper table', () => {
|
||||
const mockStore = configureStore([thunk]);
|
||||
const store = mockStore({
|
||||
sqlLab: user,
|
||||
user,
|
||||
});
|
||||
|
||||
const wrapper = mount(
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ const QueryTable = ({
|
|||
[columns],
|
||||
);
|
||||
|
||||
const user = useSelector<SqlLabRootState, User>(state => state.sqlLab.user);
|
||||
const user = useSelector<SqlLabRootState, User>(state => state.user);
|
||||
|
||||
const data = useMemo(() => {
|
||||
const restoreSql = (query: QueryResponse) => {
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ import {
|
|||
DatasetRadioState,
|
||||
EXPLORE_CHART_DEFAULT,
|
||||
DatasetOwner,
|
||||
SqlLabExploreRootState,
|
||||
getInitialState,
|
||||
SqlLabRootState,
|
||||
} from 'src/SqlLab/types';
|
||||
import { mountExploreUrl } from 'src/explore/exploreUtils';
|
||||
|
|
@ -177,9 +175,7 @@ export const SaveDatasetModal = ({
|
|||
>(undefined);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
const user = useSelector<SqlLabExploreRootState, User>(user =>
|
||||
getInitialState(user),
|
||||
);
|
||||
const user = useSelector<SqlLabRootState, User>(state => state.user);
|
||||
const dispatch = useDispatch<(dispatch: any) => Promise<JsonObject>>();
|
||||
|
||||
const createWindow = (url: string) => {
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ const SouthPane = ({
|
|||
const dispatch = useDispatch();
|
||||
|
||||
const { editorQueries, dataPreviewQueries, databases, offline, user } =
|
||||
useSelector(({ sqlLab }: SqlLabRootState) => {
|
||||
const { databases, offline, user, queries, tables } = sqlLab;
|
||||
useSelector(({ user, sqlLab }: SqlLabRootState) => {
|
||||
const { databases, offline, queries, tables } = sqlLab;
|
||||
const dataPreviewQueries = tables
|
||||
.filter(
|
||||
({ dataPreviewQueryId, queryEditorId: qeId }) =>
|
||||
|
|
|
|||
|
|
@ -660,10 +660,10 @@ export const initialState = {
|
|||
workspaceQueries: [],
|
||||
queriesLastUpdate: 0,
|
||||
activeSouthPaneTab: 'Results',
|
||||
user: { user },
|
||||
unsavedQueryEditor: {},
|
||||
},
|
||||
messageToasts: [],
|
||||
user,
|
||||
common: {
|
||||
conf: {
|
||||
DEFAULT_SQLLAB_LIMIT: 1000,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ export default function getInitialState({
|
|||
tab_state_ids: tabStateIds = [],
|
||||
databases,
|
||||
queries: queries_,
|
||||
requested_query: requestedQuery,
|
||||
user,
|
||||
}) {
|
||||
/**
|
||||
|
|
@ -200,11 +199,9 @@ export default function getInitialState({
|
|||
tabHistory: dedupeTabHistory(tabHistory),
|
||||
tables: Object.values(tables),
|
||||
queriesLastUpdate: Date.now(),
|
||||
user,
|
||||
unsavedQueryEditor,
|
||||
queryCostEstimates: {},
|
||||
},
|
||||
requestedQuery,
|
||||
messageToasts: getToastsFromPyFlashMessages(
|
||||
(common || {}).flash_messages || [],
|
||||
),
|
||||
|
|
@ -213,5 +210,6 @@ export default function getInitialState({
|
|||
flash_messages: common.flash_messages,
|
||||
conf: common.conf,
|
||||
},
|
||||
user,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ const apiDataWithTabState = {
|
|||
};
|
||||
describe('getInitialState', () => {
|
||||
it('should output the user that is passed in', () => {
|
||||
expect(getInitialState(apiData).sqlLab.user.userId).toEqual(1);
|
||||
expect(getInitialState(apiData).user.userId).toEqual(1);
|
||||
});
|
||||
it('should return undefined instead of null for templateParams', () => {
|
||||
expect(
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
import { JsonObject, QueryResponse } from '@superset-ui/core';
|
||||
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
|
||||
import { ToastType } from 'src/components/MessageToasts/types';
|
||||
import { RootState } from 'src/dashboard/types';
|
||||
import { DropdownButtonProps } from 'src/components/DropdownButton';
|
||||
import { ButtonProps } from 'src/components/Button';
|
||||
|
||||
|
|
@ -66,33 +65,20 @@ export type SqlLabRootState = {
|
|||
tabHistory: string[]; // default is activeTab ? [activeTab.id.toString()] : []
|
||||
tables: Record<string, any>[];
|
||||
queriesLastUpdate: number;
|
||||
user: UserWithPermissionsAndRoles;
|
||||
errorMessage: string | null;
|
||||
unsavedQueryEditor: Partial<QueryEditor>;
|
||||
queryCostEstimates?: Record<string, QueryCostEstimate>;
|
||||
editorTabLastUpdatedAt?: number;
|
||||
};
|
||||
localStorageUsageInKilobytes: number;
|
||||
messageToasts: toastState[];
|
||||
user: UserWithPermissionsAndRoles;
|
||||
common: {
|
||||
flash_messages: string[];
|
||||
conf: JsonObject;
|
||||
};
|
||||
};
|
||||
|
||||
export type SqlLabExploreRootState = SqlLabRootState | RootState;
|
||||
|
||||
export const getInitialState = (state: SqlLabExploreRootState) => {
|
||||
if (state.hasOwnProperty('sqlLab')) {
|
||||
const {
|
||||
sqlLab: { user },
|
||||
} = state as SqlLabRootState;
|
||||
return user;
|
||||
}
|
||||
|
||||
const { user } = state as RootState;
|
||||
return user as UserWithPermissionsAndRoles;
|
||||
};
|
||||
|
||||
export enum DatasetRadioState {
|
||||
SAVE_NEW = 1,
|
||||
OVERWRITE_DATASET = 2,
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ export type UserLoadedAction = {
|
|||
user: UserWithPermissionsAndRoles;
|
||||
};
|
||||
|
||||
const userReducer = (
|
||||
export const userReducer = (
|
||||
user = bootstrapData.user || {},
|
||||
action: UserLoadedAction,
|
||||
): BootstrapUser | UndefinedUser => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue