From 6392d41ac9c2a4810c2a2ecd1b34ee430b8aaee2 Mon Sep 17 00:00:00 2001 From: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com> Date: Tue, 13 Apr 2021 10:09:08 -0500 Subject: [PATCH] fix: Fixed saved query export (#14086) * Fixed saved query export * Te sting implemented --- .../CRUD/data/savedquery/SavedQueryList_spec.jsx | 12 ++++++++++++ .../views/CRUD/data/savedquery/SavedQueryList.tsx | 6 +++--- superset-frontend/src/views/CRUD/utils.tsx | 12 +++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/superset-frontend/spec/javascripts/views/CRUD/data/savedquery/SavedQueryList_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/data/savedquery/SavedQueryList_spec.jsx index e1e5f6e10..ec8b80ed8 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/data/savedquery/SavedQueryList_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/data/savedquery/SavedQueryList_spec.jsx @@ -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'; @@ -95,6 +96,9 @@ fetchMock.get(queriesDistinctEndpoint, { result: [], }); +// Mock utils module +jest.mock('src/views/CRUD/utils'); + describe('SavedQueryList', () => { const wrapper = mount( @@ -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(); + }); }); diff --git a/superset-frontend/src/views/CRUD/data/savedquery/SavedQueryList.tsx b/superset-frontend/src/views/CRUD/data/savedquery/SavedQueryList.tsx index 352aa8eec..fe0312eab 100644 --- a/superset-frontend/src/views/CRUD/data/savedquery/SavedQueryList.tsx +++ b/superset-frontend/src/views/CRUD/data/savedquery/SavedQueryList.tsx @@ -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'; @@ -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 = [ @@ -454,7 +454,7 @@ function SavedQueryList({ key: 'export', name: t('Export'), type: 'primary', - onSelect: handleBulkDashboardExport, + onSelect: handleBulkSavedQueryExport, }); } return ( diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index e70416149..4c5638616 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -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, @@ -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,