Skip to content

Commit

Permalink
fix: Fixed saved query export (#14086)
Browse files Browse the repository at this point in the history
* Fixed saved query export

* Te
sting implemented
  • Loading branch information
lyndsiWilliams authored Apr 13, 2021
1 parent 4b23d0e commit 6392d41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { render, screen, cleanup } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import { QueryParamProvider } from 'use-query-params';
import { act } from 'react-dom/test-utils';
import { handleBulkSavedQueryExport } from 'src/views/CRUD/utils';
import * as featureFlags from 'src/featureFlags';
import SavedQueryList from 'src/views/CRUD/data/savedquery/SavedQueryList';
import SubMenu from 'src/components/Menu/SubMenu';
Expand Down Expand Up @@ -95,6 +96,9 @@ fetchMock.get(queriesDistinctEndpoint, {
result: [],
});

// Mock utils module
jest.mock('src/views/CRUD/utils');

describe('SavedQueryList', () => {
const wrapper = mount(
<Provider store={store}>
Expand Down Expand Up @@ -245,4 +249,12 @@ describe('RTL', () => {
});
expect(exportTooltip).toBeInTheDocument();
});

it('runs handleBulkSavedQueryExport when export is clicked', () => {
// Grab Export action button and mock mouse clicking it
const exportActionButton = screen.getAllByRole('button')[17];
userEvent.click(exportActionButton);

expect(handleBulkSavedQueryExport).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
createFetchRelated,
createFetchDistinct,
createErrorHandler,
handleBulkDashboardExport,
handleBulkSavedQueryExport,
} from 'src/views/CRUD/utils';
import Popover from 'src/components/Popover';
import withToasts from 'src/messageToasts/enhancers/withToasts';
Expand Down Expand Up @@ -306,7 +306,7 @@ function SavedQueryList({
};
const handleEdit = () => openInSqlLab(original.id);
const handleCopy = () => copyQueryLink(original.id);
const handleExport = () => handleBulkDashboardExport([original]);
const handleExport = () => handleBulkSavedQueryExport([original]);
const handleDelete = () => setQueryCurrentlyDeleting(original);

const actions = [
Expand Down Expand Up @@ -454,7 +454,7 @@ function SavedQueryList({
key: 'export',
name: t('Export'),
type: 'primary',
onSelect: handleBulkDashboardExport,
onSelect: handleBulkSavedQueryExport,
});
}
return (
Expand Down
12 changes: 11 additions & 1 deletion superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Chart from 'src/types/Chart';
import rison from 'rison';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FetchDataConfig } from 'src/components/ListView';
import { Dashboard, Filters } from './types';
import { Dashboard, Filters, SavedQueryObject } from './types';

const createFetchResourceMethod = (method: string) => (
resource: string,
Expand Down Expand Up @@ -218,6 +218,16 @@ export function handleBulkDashboardExport(dashboardsToExport: Dashboard[]) {
);
}

export function handleBulkSavedQueryExport(
savedQueriesToExport: SavedQueryObject[],
) {
return window.location.assign(
`/api/v1/saved_query/export/?q=${rison.encode(
savedQueriesToExport.map(({ id }) => id),
)}`,
);
}

export function handleDashboardDelete(
{ id, dashboard_title: dashboardTitle }: Dashboard,
refreshData: (config?: FetchDataConfig | null) => void,
Expand Down

0 comments on commit 6392d41

Please sign in to comment.