-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explore): export csv data pivoted for Pivot Table [ID-9] (#17512)
* feat(explore): export csv data pivoted for Pivot Table * Implement dropdown with download csv options * Change label to "Original" * Add tests * Add form data to query context * Add form data to query context generator * Explicitly make form_data optional
- Loading branch information
Showing
12 changed files
with
291 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
superset-frontend/src/explore/components/ExportToCSVDropdown/ExportToCSVDropdown.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { ExportToCSVDropdown } from './index'; | ||
|
||
const exportCSVOriginal = jest.fn(); | ||
const exportCSVPivoted = jest.fn(); | ||
|
||
test('Dropdown button with menu renders', () => { | ||
render( | ||
<ExportToCSVDropdown | ||
exportCSVOriginal={exportCSVOriginal} | ||
exportCSVPivoted={exportCSVPivoted} | ||
> | ||
<div>.CSV</div> | ||
</ExportToCSVDropdown>, | ||
); | ||
|
||
expect(screen.getByText('.CSV')).toBeVisible(); | ||
|
||
userEvent.click(screen.getByText('.CSV')); | ||
expect(screen.getByRole('menu')).toBeInTheDocument(); | ||
expect(screen.getByText('Original')).toBeInTheDocument(); | ||
expect(screen.getByText('Pivoted')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Call export csv original on click', () => { | ||
render( | ||
<ExportToCSVDropdown | ||
exportCSVOriginal={exportCSVOriginal} | ||
exportCSVPivoted={exportCSVPivoted} | ||
> | ||
<div>.CSV</div> | ||
</ExportToCSVDropdown>, | ||
); | ||
|
||
userEvent.click(screen.getByText('.CSV')); | ||
userEvent.click(screen.getByText('Original')); | ||
|
||
expect(exportCSVOriginal).toHaveBeenCalled(); | ||
}); | ||
|
||
test('Call export csv pivoted on click', () => { | ||
render( | ||
<ExportToCSVDropdown | ||
exportCSVOriginal={exportCSVOriginal} | ||
exportCSVPivoted={exportCSVPivoted} | ||
> | ||
<div>.CSV</div> | ||
</ExportToCSVDropdown>, | ||
); | ||
|
||
userEvent.click(screen.getByText('.CSV')); | ||
userEvent.click(screen.getByText('Pivoted')); | ||
|
||
expect(exportCSVPivoted).toHaveBeenCalled(); | ||
}); |
90 changes: 90 additions & 0 deletions
90
superset-frontend/src/explore/components/ExportToCSVDropdown/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { ReactChild, useCallback } from 'react'; | ||
import { t, styled } from '@superset-ui/core'; | ||
import Icons from 'src/components/Icons'; | ||
import { Dropdown, Menu } from 'src/common/components'; | ||
|
||
enum MENU_KEYS { | ||
EXPORT_ORIGINAL = 'export_original', | ||
EXPORT_PIVOTED = 'export_pivoted', | ||
} | ||
|
||
interface ExportToCSVButtonProps { | ||
exportCSVOriginal: () => void; | ||
exportCSVPivoted: () => void; | ||
children: ReactChild; | ||
} | ||
|
||
const MenuItemContent = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
span[role='img'] { | ||
font-size: ${({ theme }) => theme.typography.sizes.l}px; | ||
margin-left: ${({ theme }) => theme.gridUnit * 4}px; | ||
} | ||
`; | ||
|
||
export const ExportToCSVDropdown = ({ | ||
exportCSVOriginal, | ||
exportCSVPivoted, | ||
children, | ||
}: ExportToCSVButtonProps) => { | ||
const handleMenuClick = useCallback( | ||
({ key }: { key: React.Key }) => { | ||
switch (key) { | ||
case MENU_KEYS.EXPORT_ORIGINAL: | ||
exportCSVOriginal(); | ||
break; | ||
case MENU_KEYS.EXPORT_PIVOTED: | ||
exportCSVPivoted(); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, | ||
[exportCSVPivoted, exportCSVOriginal], | ||
); | ||
|
||
return ( | ||
<Dropdown | ||
trigger={['click']} | ||
overlay={ | ||
<Menu onClick={handleMenuClick} selectable={false}> | ||
<Menu.Item key={MENU_KEYS.EXPORT_ORIGINAL}> | ||
<MenuItemContent> | ||
{t('Original')} | ||
<Icons.Download /> | ||
</MenuItemContent> | ||
</Menu.Item> | ||
<Menu.Item key={MENU_KEYS.EXPORT_PIVOTED}> | ||
<MenuItemContent> | ||
{t('Pivoted')} | ||
<Icons.Download /> | ||
</MenuItemContent> | ||
</Menu.Item> | ||
</Menu> | ||
} | ||
> | ||
{children} | ||
</Dropdown> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.