fix(sqllab): prev shema/table options remained on fail (#29638)
This commit is contained in:
parent
85b66946ed
commit
5539f87912
|
|
@ -77,7 +77,7 @@ export function useKeywords(
|
|||
// skipFetch is used to prevent re-evaluating memoized keywords
|
||||
// due to updated api results by skip flag
|
||||
const skipFetch = hasFetchedKeywords && skip;
|
||||
const { data: schemaOptions } = useSchemasQueryState(
|
||||
const { currentData: schemaOptions } = useSchemasQueryState(
|
||||
{
|
||||
dbId,
|
||||
catalog: catalog || undefined,
|
||||
|
|
@ -85,7 +85,7 @@ export function useKeywords(
|
|||
},
|
||||
{ skip: skipFetch || !dbId },
|
||||
);
|
||||
const { data: tableData } = useTablesQueryState(
|
||||
const { currentData: tableData } = useTablesQueryState(
|
||||
{
|
||||
dbId,
|
||||
catalog,
|
||||
|
|
@ -95,7 +95,7 @@ export function useKeywords(
|
|||
{ skip: skipFetch || !dbId || !schema },
|
||||
);
|
||||
|
||||
const { data: functionNames, isError } = useDatabaseFunctionsQuery(
|
||||
const { currentData: functionNames, isError } = useDatabaseFunctionsQuery(
|
||||
{ dbId },
|
||||
{ skip: skipFetch || !dbId },
|
||||
);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,11 @@ const QueryHistory = ({
|
|||
({ sqlLab: { queries } }: SqlLabRootState) => queries,
|
||||
shallowEqual,
|
||||
);
|
||||
const { data, isLoading, isFetching } = useEditorQueriesQuery(
|
||||
const {
|
||||
currentData: data,
|
||||
isLoading,
|
||||
isFetching,
|
||||
} = useEditorQueriesQuery(
|
||||
{ editorId: `${queryEditorId}`, pageIndex },
|
||||
{
|
||||
skip: !isFeatureEnabled(FeatureFlag.SqllabBackendPersistence),
|
||||
|
|
|
|||
|
|
@ -47,7 +47,14 @@ beforeEach(() => {
|
|||
count: 0,
|
||||
result: [],
|
||||
});
|
||||
fetchMock.get('glob:*/api/v1/database/*/schemas/?*', {
|
||||
fetchMock.get('glob:*/api/v1/database/3/schemas/?*', {
|
||||
error: 'Unauthorized',
|
||||
});
|
||||
fetchMock.get('glob:*/api/v1/database/1/schemas/?*', {
|
||||
count: 2,
|
||||
result: ['main', 'db1_schema', 'db1_schema2'],
|
||||
});
|
||||
fetchMock.get('glob:*/api/v1/database/2/schemas/?*', {
|
||||
count: 2,
|
||||
result: ['main', 'new_schema'],
|
||||
});
|
||||
|
|
@ -198,7 +205,7 @@ test('should toggle the table when the header is clicked', async () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('When changing database the table list must be updated', async () => {
|
||||
test('When changing database the schema and table list must be updated', async () => {
|
||||
const { rerender } = await renderAndWait(mockedProps, undefined, {
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
|
|
@ -245,6 +252,32 @@ test('When changing database the table list must be updated', async () => {
|
|||
expect(updatedDbSelector[0]).toBeInTheDocument();
|
||||
const updatedTableSelector = await screen.findAllByText(/new_table/i);
|
||||
expect(updatedTableSelector[0]).toBeInTheDocument();
|
||||
|
||||
const select = screen.getByRole('combobox', {
|
||||
name: 'Select schema or type to search schemas',
|
||||
});
|
||||
userEvent.click(select);
|
||||
expect(
|
||||
await screen.findByRole('option', { name: 'main' }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
await screen.findByRole('option', { name: 'new_schema' }),
|
||||
).toBeInTheDocument();
|
||||
rerender(
|
||||
<SqlEditorLeftBar
|
||||
{...mockedProps}
|
||||
database={{
|
||||
id: 3,
|
||||
database_name: 'unauth_db',
|
||||
backend: 'minervasql',
|
||||
}}
|
||||
queryEditorId={extraQueryEditor1.id}
|
||||
/>,
|
||||
);
|
||||
userEvent.click(select);
|
||||
expect(
|
||||
await screen.findByText('No compatible schema found'),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('ignore schema api when current schema is deprecated', async () => {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ const TableElement = ({ table, ...props }: TableElementProps) => {
|
|||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
data: tableMetadata,
|
||||
currentData: tableMetadata,
|
||||
isSuccess: isMetadataSuccess,
|
||||
isLoading: isMetadataLoading,
|
||||
isError: hasMetadataError,
|
||||
|
|
@ -119,7 +119,7 @@ const TableElement = ({ table, ...props }: TableElementProps) => {
|
|||
{ skip: !expanded },
|
||||
);
|
||||
const {
|
||||
data: tableExtendedMetadata,
|
||||
currentData: tableExtendedMetadata,
|
||||
isSuccess: isExtraMetadataSuccess,
|
||||
isLoading: isExtraMetadataLoading,
|
||||
isError: hasExtendedMetadataError,
|
||||
|
|
|
|||
|
|
@ -272,7 +272,6 @@ test('should display options in order of the api response', async () => {
|
|||
});
|
||||
|
||||
test('Should fetch the search keyword when total count exceeds initial options', async () => {
|
||||
fetchMock.reset();
|
||||
fetchMock.get(
|
||||
databaseApiRoute,
|
||||
{
|
||||
|
|
@ -365,7 +364,7 @@ test('Sends the correct schema when changing the schema', async () => {
|
|||
});
|
||||
await waitFor(() => expect(fetchMock.calls(databaseApiRoute).length).toBe(1));
|
||||
rerender(<DatabaseSelector {...props} />);
|
||||
expect(props.onSchemaChange).toBeCalledTimes(0);
|
||||
expect(props.onSchemaChange).toHaveBeenCalledTimes(0);
|
||||
const select = screen.getByRole('combobox', {
|
||||
name: 'Select schema or type to search schemas',
|
||||
});
|
||||
|
|
@ -376,5 +375,5 @@ test('Sends the correct schema when changing the schema', async () => {
|
|||
await waitFor(() =>
|
||||
expect(props.onSchemaChange).toHaveBeenCalledWith('information_schema'),
|
||||
);
|
||||
expect(props.onSchemaChange).toBeCalledTimes(1);
|
||||
expect(props.onSchemaChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ export default function DatabaseSelector({
|
|||
}
|
||||
|
||||
const {
|
||||
data: schemaData,
|
||||
currentData: schemaData,
|
||||
isFetching: loadingSchemas,
|
||||
refetch: refetchSchemas,
|
||||
} = useSchemas({
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
|||
SelectValue | undefined
|
||||
>(undefined);
|
||||
const {
|
||||
data,
|
||||
currentData: data,
|
||||
isFetching: loadingTables,
|
||||
refetch,
|
||||
} = useTables({
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ export type InitialState = {
|
|||
}[];
|
||||
};
|
||||
|
||||
const queryValidationApi = api.injectEndpoints({
|
||||
const initialStateApi = api.injectEndpoints({
|
||||
endpoints: builder => ({
|
||||
sqlLabInitialState: builder.query<InitialState, void>({
|
||||
providesTags: ['SqlLabInitialState'],
|
||||
|
|
@ -83,4 +83,4 @@ const queryValidationApi = api.injectEndpoints({
|
|||
});
|
||||
|
||||
export const { useSqlLabInitialStateQuery: useSqlLabInitialState } =
|
||||
queryValidationApi;
|
||||
initialStateApi;
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ export const {
|
|||
export function useTables(options: Params) {
|
||||
const { dbId, catalog, schema, onSuccess, onError } = options || {};
|
||||
const isMountedRef = useRef(false);
|
||||
const { data: schemaOptions, isFetching } = useSchemas({
|
||||
const { currentData: schemaOptions, isFetching } = useSchemas({
|
||||
dbId,
|
||||
catalog: catalog || undefined,
|
||||
});
|
||||
|
|
@ -203,13 +203,13 @@ export function useTables(options: Params) {
|
|||
isSuccess,
|
||||
isError,
|
||||
isFetching,
|
||||
data,
|
||||
currentData,
|
||||
error,
|
||||
originalArgs,
|
||||
} = result;
|
||||
if (!originalArgs?.forceRefresh && requestId && !isFetching) {
|
||||
if (isSuccess && data) {
|
||||
handleOnSuccess(data, false);
|
||||
if (isSuccess && currentData) {
|
||||
handleOnSuccess(currentData, false);
|
||||
}
|
||||
if (isError) {
|
||||
handleOnError(error as Response);
|
||||
|
|
|
|||
Loading…
Reference in New Issue