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