Skip to content

Commit

Permalink
chore: Show datasets when search input is empty (apache#12391)
Browse files Browse the repository at this point in the history
  • Loading branch information
geido authored and amitmiran137 committed Jan 14, 2021
1 parent fb9e9d8 commit 503fc2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ describe('ChangeDatasourceModal', () => {
});

it('fetches datasources', async () => {
expect(fetchMock.calls(/api\/v1\/dataset/)).toHaveLength(6);
expect(fetchMock.calls(/api\/v1\/dataset/)).toHaveLength(3);
});

it('renders confirmation message', async () => {
await waitForComponentToPaint(wrapper, 1000);

act(() => {
wrapper.find('[data-test="datasource-link"]').at(0).props().onClick();
});

await waitForComponentToPaint(wrapper);

expect(wrapper.find('.proceed-btn')).toExist();
});

it('changes the datasource', async () => {
await waitForComponentToPaint(wrapper, 1000);

act(() => {
wrapper.find('[data-test="datasource-link"]').at(0).props().onClick();
});
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/common/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ interface ModalProps {
centered?: boolean;
footer?: React.ReactNode;
wrapProps?: object;
height?: string;
}

interface StyledModalProps extends SupersetThemeProps {
maxWidth?: string;
responsive?: boolean;
height?: string;
}

export const StyledModal = styled(BaseModal)<StyledModalProps>`
Expand Down Expand Up @@ -87,6 +89,7 @@ export const StyledModal = styled(BaseModal)<StyledModalProps>`
.ant-modal-body {
padding: ${({ theme }) => theme.gridUnit * 4}px;
overflow: auto;
${({ height }) => height && `height: ${height};`}
}
.ant-modal-footer {
Expand Down
17 changes: 8 additions & 9 deletions superset-frontend/src/datasource/ChangeDatasourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import React, {
} from 'react';
import { Alert, FormControl, FormControlProps } from 'react-bootstrap';
import { SupersetClient, t, styled } from '@superset-ui/core';
import TableView from 'src/components/TableView';
import TableView, { EmptyWrapperType } from 'src/components/TableView';
import StyledModal from 'src/common/components/Modal';
import Button from 'src/components/Button';
import { useListViewResource } from 'src/views/CRUD/hooks';
Expand Down Expand Up @@ -120,18 +120,18 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({

useDebouncedEffect(
() => {
if (filter) {
fetchData({
...emptyRequest,
fetchData({
...emptyRequest,
...(filter && {
filters: [
{
id: 'table_name',
operator: 'ct',
value: filter,
},
],
});
}
}),
});
},
1000,
[filter],
Expand All @@ -142,9 +142,6 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({
if (searchRef && searchRef.current) {
searchRef.current.focus();
}

// Fetch initial datasets for tableview
await fetchData(emptyRequest);
};

if (show) {
Expand Down Expand Up @@ -224,6 +221,7 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({
onHide={onHide}
responsive
title={t('Change Dataset')}
height="350px"
footer={
<>
{confirmChange && (
Expand Down Expand Up @@ -268,6 +266,7 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({
data={renderTableView()}
pageSize={20}
className="table-condensed"
emptyWrapperType={EmptyWrapperType.Small}
/>
)}
</>
Expand Down

0 comments on commit 503fc2b

Please sign in to comment.