Skip to content

Commit

Permalink
feat: Add toast for successful table or schema refreshes in Sqllab (#…
Browse files Browse the repository at this point in the history
…18169)

* save

* add use redux to test

* update test for db selector

* add condition for refresh only
  • Loading branch information
hughhhh authored Jan 27, 2022
1 parent ac564ea commit e6bb0fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ beforeEach(() => {

test('Should render', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });
expect(await screen.findByTestId('DatabaseSelector')).toBeInTheDocument();
});

test('Refresh should work', async () => {
const props = createProps();

render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });

const select = screen.getByRole('combobox', {
name: 'Select schema or type schema name',
Expand Down Expand Up @@ -211,7 +211,7 @@ test('Refresh should work', async () => {

test('Should database select display options', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });
const select = screen.getByRole('combobox', {
name: 'Select database or type database name',
});
Expand All @@ -222,7 +222,7 @@ test('Should database select display options', async () => {

test('Should schema select display options', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });
const select = screen.getByRole('combobox', {
name: 'Select schema or type schema name',
});
Expand All @@ -238,7 +238,7 @@ test('Should schema select display options', async () => {

test('Sends the correct db when changing the database', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });
const select = screen.getByRole('combobox', {
name: 'Select database or type database name',
});
Expand All @@ -259,7 +259,7 @@ test('Sends the correct db when changing the database', async () => {

test('Sends the correct schema when changing the schema', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
render(<DatabaseSelector {...props} />, { useRedux: true });
const select = screen.getByRole('combobox', {
name: 'Select schema or type schema name',
});
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/components/DatabaseSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Select } from 'src/components';
import Label from 'src/components/Label';
import { FormLabel } from 'src/components/Form';
import RefreshLabel from 'src/components/RefreshLabel';
import { useToasts } from 'src/components/MessageToasts/withToasts';

const DatabaseSelectorWrapper = styled.div`
${({ theme }) => `
Expand Down Expand Up @@ -144,7 +145,7 @@ export default function DatabaseSelector({
schema ? { label: schema, value: schema } : undefined,
);
const [refresh, setRefresh] = useState(0);

const { addSuccessToast } = useToasts();
const loadDatabases = useMemo(
() =>
async (
Expand Down Expand Up @@ -224,6 +225,7 @@ export default function DatabaseSelector({
}
setSchemaOptions(options);
setLoadingSchemas(false);
if (refresh > 0) addSuccessToast('List refreshed');
})
.catch(() => {
setLoadingSchemas(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ beforeAll(() => {

test('renders with default props', async () => {
const props = createProps();
render(<TableSelector {...props} />);
render(<TableSelector {...props} />, { useRedux: true });
const databaseSelect = screen.getByRole('combobox', {
name: 'Select database or type database name',
});
Expand All @@ -71,7 +71,7 @@ test('renders with default props', async () => {

test('renders table options', async () => {
const props = createProps();
render(<TableSelector {...props} />);
render(<TableSelector {...props} />, { useRedux: true });
const tableSelect = screen.getByRole('combobox', {
name: 'Select table or type table name',
});
Expand All @@ -86,7 +86,7 @@ test('renders table options', async () => {

test('renders disabled without schema', async () => {
const props = createProps();
render(<TableSelector {...props} schema={undefined} />);
render(<TableSelector {...props} schema={undefined} />, { useRedux: true });
const tableSelect = screen.getByRole('combobox', {
name: 'Select table or type table name',
});
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/components/TableSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import DatabaseSelector, {
import RefreshLabel from 'src/components/RefreshLabel';
import CertifiedBadge from 'src/components/CertifiedBadge';
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
import { useToasts } from 'src/components/MessageToasts/withToasts';

const TableSelectorWrapper = styled.div`
${({ theme }) => `
Expand Down Expand Up @@ -167,6 +168,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
const [previousRefresh, setPreviousRefresh] = useState(0);
const [loadingTables, setLoadingTables] = useState(false);
const [tableOptions, setTableOptions] = useState<TableOption[]>([]);
const { addSuccessToast } = useToasts();

useEffect(() => {
// reset selections
Expand Down Expand Up @@ -212,6 +214,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
setTableOptions(options);
setCurrentTable(currentTable);
setLoadingTables(false);
if (forceRefresh) addSuccessToast('List updated');
})
.catch(e => {
setLoadingTables(false);
Expand Down

0 comments on commit e6bb0fc

Please sign in to comment.