Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const createProps = (props = {}) => ({
...props,
});

const getTableMockFunction = () =>
const getTableMockFunction = (count = 4) =>
({
count: 4,
count,
result: [
{ label: 'table_a', value: 'table_a' },
{ label: 'table_b', value: 'table_b' },
Expand Down Expand Up @@ -82,6 +82,35 @@ afterEach(async () => {
await new Promise(resolve => setTimeout(resolve, 0));
});

test('shows a helper message when some tables are not shown', async () => {
fetchMock.get(catalogApiRoute, { result: [] });
fetchMock.get(schemaApiRoute, { result: ['test_schema'] });
fetchMock.get(tablesApiRoute, getTableMockFunction(5));

const props = createProps();
render(<TableSelector {...props} />, { useRedux: true, store });

expect(
await screen.findByText('Some tables are not shown. Refine your search.'),
).toBeInTheDocument();
});

test('does not show the helper message when table search is read-only', async () => {
fetchMock.get(catalogApiRoute, { result: [] });
fetchMock.get(schemaApiRoute, { result: ['test_schema'] });
fetchMock.get(tablesApiRoute, getTableMockFunction(5));

const props = createProps({ readOnly: true });
render(<TableSelector {...props} />, { useRedux: true, store });

await waitFor(() => {
expect(fetchMock.callHistory.called(tablesApiRoute)).toBe(true);
});
expect(
screen.queryByText('Some tables are not shown. Refine your search.'),
).not.toBeInTheDocument();
});

test('renders with default props', async () => {
fetchMock.get(catalogApiRoute, { result: [] });
fetchMock.get(schemaApiRoute, { result: [] });
Expand Down Expand Up @@ -205,10 +234,10 @@ test('table select retain value if not in SQL Lab mode', async () => {
);
}, 15000);

test('renders disabled without schema', async () => {
test('renders disabled without schema or helper message', async () => {
fetchMock.get(catalogApiRoute, { result: [] });
fetchMock.get(schemaApiRoute, { result: [] });
fetchMock.get(tablesApiRoute, getTableMockFunction());
fetchMock.get(tablesApiRoute, getTableMockFunction(5));

const props = createProps();
render(<TableSelector {...props} schema={undefined} />, {
Expand All @@ -221,6 +250,9 @@ test('renders disabled without schema', async () => {
await waitFor(() => {
expect(tableSelect).toBeDisabled();
});
expect(
screen.queryByText('Some tables are not shown. Refine your search.'),
).not.toBeInTheDocument();
});

test('table multi select retain all the values selected', async () => {
Expand Down
6 changes: 6 additions & 0 deletions superset-frontend/src/components/TableSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
: [],
[data, customTableOptionLabelRenderer],
);
const hasMoreTables = data?.hasMore;

useEffect(() => {
// reset selections
Expand Down Expand Up @@ -339,6 +340,11 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
<>
<StyledFormLabel>{label}</StyledFormLabel>
{renderSelectRow(select, refreshLabel)}
{hasMoreTables && !disabled && (
<div className="table-length">
{t('Some tables are not shown. Refine your search.')}
</div>
)}
</>
);
}
Expand Down
Loading