fix: Address regression introduced in #21284 (#21470)

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
John Bodley 2022-09-16 14:18:03 -07:00 committed by GitHub
parent b739e27f6d
commit 8c16806f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 41 deletions

View File

@ -196,7 +196,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
? data.options.map(table => ({
value: table.value,
label: <TableOption table={table} />,
text: table.label,
text: table.value,
}))
: [],
[data],

View File

@ -103,7 +103,7 @@ describe('useTables hook', () => {
});
expect(SupersetClient.get).toHaveBeenCalledTimes(1);
expect(SupersetClient.get).toHaveBeenCalledWith({
endpoint: `/superset/tables/${expectDbId}/${expectedSchema}/undefined/${forceRefresh}/`,
endpoint: `/superset/tables/${expectDbId}/${expectedSchema}/${forceRefresh}/`,
});
expect(result.current.data).toEqual(expectedData);
await act(async () => {
@ -111,38 +111,11 @@ describe('useTables hook', () => {
});
expect(SupersetClient.get).toHaveBeenCalledTimes(2);
expect(SupersetClient.get).toHaveBeenCalledWith({
endpoint: `/superset/tables/${expectDbId}/${expectedSchema}/undefined/true/`,
endpoint: `/superset/tables/${expectDbId}/${expectedSchema}/true/`,
});
expect(result.current.data).toEqual(expectedData);
});
it('returns api response for search keyword', async () => {
const expectDbId = 'db1';
const expectedSchema = 'schemaA';
const expectedKeyword = 'my work';
const forceRefresh = false;
renderHook(
() =>
useTables({
dbId: expectDbId,
schema: expectedSchema,
keyword: expectedKeyword,
}),
{
wrapper: QueryProvider,
},
);
await act(async () => {
jest.runAllTimers();
});
expect(SupersetClient.get).toHaveBeenCalledTimes(1);
expect(SupersetClient.get).toHaveBeenCalledWith({
endpoint: `/superset/tables/${expectDbId}/${expectedSchema}/${encodeURIComponent(
expectedKeyword,
)}/${forceRefresh}/`,
});
});
it('returns hasMore when total is larger than result size', async () => {
(SupersetClient.get as jest.Mock).mockResolvedValueOnce(
fakeHasMoreApiResult,

View File

@ -24,7 +24,6 @@ export type FetchTablesQueryParams = {
dbId?: string | number;
schema?: string;
forceRefresh?: boolean;
keyword?: string;
};
export interface Table {
label: string;
@ -52,14 +51,12 @@ export function fetchTables({
dbId,
schema,
forceRefresh,
keyword,
}: FetchTablesQueryParams) {
const encodedSchema = schema ? encodeURIComponent(schema) : '';
const encodedKeyword = keyword ? encodeURIComponent(keyword) : 'undefined';
// TODO: Would be nice to add pagination in a follow-up. Needs endpoint changes.
const endpoint = `/superset/tables/${
dbId ?? 'undefined'
}/${encodedSchema}/${encodedKeyword}/${forceRefresh}/`;
}/${encodedSchema}/${forceRefresh}/`;
return SupersetClient.get({ endpoint }) as Promise<QueryData>;
}
@ -67,11 +64,11 @@ type Params = FetchTablesQueryParams &
Pick<UseQueryOptions, 'onSuccess' | 'onError'>;
export function useTables(options: Params) {
const { dbId, schema, keyword, onSuccess, onError } = options || {};
const { dbId, schema, onSuccess, onError } = options || {};
const forceRefreshRef = useRef(false);
const params = { dbId, schema, keyword };
const params = { dbId, schema };
const result = useQuery<QueryData, Error, Data>(
['tables', { dbId, schema, keyword }],
['tables', { dbId, schema }],
() => fetchTables({ ...params, forceRefresh: forceRefreshRef.current }),
{
select: ({ json }) => ({

View File

@ -172,7 +172,7 @@ export default function LeftPanel({
useEffect(() => {
if (loadTables) {
const endpoint = encodeURI(
`/superset/tables/${dbId}/${encodedSchema}/undefined/${refresh}/`,
`/superset/tables/${dbId}/${encodedSchema}/${refresh}/`,
);
getTablesList(endpoint);
}
@ -188,10 +188,8 @@ export default function LeftPanel({
const search = useMemo(
() =>
debounce((value: string) => {
const encodeTableName =
value === '' ? undefined : encodeURIComponent(value);
const endpoint = encodeURI(
`/superset/tables/${dbId}/${encodedSchema}/${encodeTableName}/`,
`/superset/tables/${dbId}/${encodedSchema}/`,
);
getTablesList(endpoint);
}, FAST_DEBOUNCE),