Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed saved query export #14086

Merged
merged 2 commits into from
Apr 13, 2021
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 @@ -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