-
Notifications
You must be signed in to change notification settings - Fork 3
[feature]: Supports file type selection during export #785
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
167 changes: 167 additions & 0 deletions
167
packages/sqle/src/components/ExportFormatModal/__tests__/__snapshots__/index.test.tsx.snap
This file contains hidden or 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,167 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`ExportFormatModal should render modal with correct title and options 1`] = ` | ||
| <body> | ||
| <div /> | ||
| <div> | ||
| <div | ||
| class="ant-modal-root" | ||
| > | ||
| <div | ||
| class="ant-modal-mask" | ||
| /> | ||
| <div | ||
| class="ant-modal-wrap" | ||
| tabindex="-1" | ||
| > | ||
| <div | ||
| aria-labelledby="test-id" | ||
| aria-modal="true" | ||
| class="ant-modal basic-modal-wrapper css-vvpsbb ant-zoom-appear ant-zoom-appear-prepare ant-zoom" | ||
| role="dialog" | ||
| style="width: 480px;" | ||
| > | ||
| <div | ||
| aria-hidden="true" | ||
| style="width: 0px; height: 0px; overflow: hidden; outline: none;" | ||
| tabindex="0" | ||
| /> | ||
| <div | ||
| class="ant-modal-content" | ||
| > | ||
| <button | ||
| aria-label="Close" | ||
| class="ant-modal-close" | ||
| type="button" | ||
| > | ||
| <span | ||
| class="ant-modal-close-x" | ||
| > | ||
| <svg | ||
| fill="currentColor" | ||
| height="16" | ||
| viewBox="0 0 14 14" | ||
| width="16" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="m7 6.175 2.887-2.887.825.825L7.825 7l2.887 2.888-.825.824L7 7.825l-2.888 2.887-.824-.824L6.175 7 3.288 4.113l.824-.825z" | ||
| /> | ||
| </svg> | ||
| </span> | ||
| </button> | ||
| <div | ||
| class="ant-modal-header" | ||
| > | ||
| <div | ||
| class="ant-modal-title" | ||
| id="test-id" | ||
| > | ||
| 选择导出文件格式 | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="ant-modal-body" | ||
| > | ||
| <div | ||
| class="ant-radio-group ant-radio-group-outline" | ||
| > | ||
| <div | ||
| class="ant-space ant-space-vertical" | ||
| > | ||
| <div | ||
| class="ant-space-item" | ||
| style="margin-bottom: 8px;" | ||
| > | ||
| <label | ||
| class="ant-radio-wrapper ant-radio-wrapper-checked" | ||
| > | ||
| <span | ||
| class="ant-radio ant-radio-checked" | ||
| > | ||
| <input | ||
| checked="" | ||
| class="ant-radio-input" | ||
| type="radio" | ||
| value="csv" | ||
| /> | ||
| <span | ||
| class="ant-radio-inner" | ||
| /> | ||
| </span> | ||
| <span> | ||
| CSV | ||
| </span> | ||
| </label> | ||
| </div> | ||
| <div | ||
| class="ant-space-item" | ||
| > | ||
| <label | ||
| class="ant-radio-wrapper" | ||
| > | ||
| <span | ||
| class="ant-radio" | ||
| > | ||
| <input | ||
| class="ant-radio-input" | ||
| type="radio" | ||
| value="excel" | ||
| /> | ||
| <span | ||
| class="ant-radio-inner" | ||
| /> | ||
| </span> | ||
| <span> | ||
| Excel | ||
| </span> | ||
| </label> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="ant-modal-footer" | ||
| > | ||
| <div | ||
| class="ant-space ant-space-horizontal ant-space-align-center" | ||
| > | ||
| <div | ||
| class="ant-space-item" | ||
| style="margin-right: 8px;" | ||
| > | ||
| <button | ||
| class="ant-btn ant-btn-default basic-button-wrapper css-lfzis8" | ||
| type="button" | ||
| > | ||
| <span> | ||
| 取 消 | ||
| </span> | ||
| </button> | ||
| </div> | ||
| <div | ||
| class="ant-space-item" | ||
| > | ||
| <button | ||
| class="ant-btn ant-btn-primary basic-button-wrapper css-lfzis8" | ||
| type="button" | ||
| > | ||
| <span> | ||
| 确 认 | ||
| </span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div | ||
| aria-hidden="true" | ||
| style="width: 0px; height: 0px; overflow: hidden; outline: none;" | ||
| tabindex="0" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| `; |
65 changes: 65 additions & 0 deletions
65
packages/sqle/src/components/ExportFormatModal/__tests__/index.test.tsx
This file contains hidden or 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,65 @@ | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
| import ExportFormatModal from '../index'; | ||
| import { sqleSuperRender } from '../../../testUtils/superRender'; | ||
|
|
||
| describe('ExportFormatModal', () => { | ||
| const mockOnFormatChange = jest.fn(); | ||
| const mockOnConfirm = jest.fn(); | ||
| const mockOnCancel = jest.fn(); | ||
|
|
||
| const defaultProps = { | ||
| open: true, | ||
| selectedFormat: 'csv' as const, | ||
| onFormatChange: mockOnFormatChange, | ||
| onConfirm: mockOnConfirm, | ||
| onCancel: mockOnCancel | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should render modal with correct title and options', () => { | ||
| const { baseElement } = sqleSuperRender( | ||
| <ExportFormatModal {...defaultProps} /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('选择导出文件格式')).toBeInTheDocument(); | ||
| expect(screen.getByText('CSV')).toBeInTheDocument(); | ||
| expect(screen.getByText('Excel')).toBeInTheDocument(); | ||
| expect(baseElement).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should not render modal when open is false', () => { | ||
| sqleSuperRender(<ExportFormatModal {...defaultProps} open={false} />); | ||
|
|
||
| expect(screen.queryByText('选择导出文件格式')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should call onFormatChange when format is changed', () => { | ||
| sqleSuperRender(<ExportFormatModal {...defaultProps} />); | ||
|
|
||
| const excelRadio = screen.getByText('Excel'); | ||
| fireEvent.click(excelRadio); | ||
|
|
||
| expect(mockOnFormatChange).toHaveBeenCalledWith('excel'); | ||
| }); | ||
|
|
||
| it('should call onConfirm when confirm button is clicked', () => { | ||
| sqleSuperRender(<ExportFormatModal {...defaultProps} />); | ||
|
|
||
| const confirmButton = screen.getByText('确 认'); | ||
| fireEvent.click(confirmButton); | ||
|
|
||
| expect(mockOnConfirm).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should call onCancel when cancel button is clicked', () => { | ||
| sqleSuperRender(<ExportFormatModal {...defaultProps} />); | ||
|
|
||
| const cancelButton = screen.getByText('取 消'); | ||
| fireEvent.click(cancelButton); | ||
|
|
||
| expect(mockOnCancel).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or 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,50 @@ | ||
| import { BasicButton, BasicModal } from '@actiontech/dms-kit'; | ||
| import { Radio, Space } from 'antd'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| export interface ExportFormatModalProps<T extends string = string> { | ||
| open: boolean; | ||
| selectedFormat: T; | ||
| onFormatChange: (format: T) => void; | ||
| onConfirm: () => void; | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| const ExportFormatModal = <T extends string = string>({ | ||
| open, | ||
| selectedFormat, | ||
| onFormatChange, | ||
| onConfirm, | ||
| onCancel | ||
| }: ExportFormatModalProps<T>) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <BasicModal | ||
| title={t('sqlManagement.pageHeader.action.exportFormatModal.title')} | ||
| open={open} | ||
| onCancel={onCancel} | ||
| size="small" | ||
| footer={ | ||
| <Space> | ||
| <BasicButton onClick={onCancel}>{t('common.cancel')}</BasicButton> | ||
| <BasicButton onClick={onConfirm} type="primary"> | ||
| {t('common.ok')} | ||
| </BasicButton> | ||
| </Space> | ||
| } | ||
| > | ||
| <Radio.Group | ||
| value={selectedFormat} | ||
| onChange={(e) => onFormatChange(e.target.value)} | ||
| > | ||
| <Space direction="vertical"> | ||
| <Radio value="csv">CSV</Radio> | ||
LZS911 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Radio value="excel">Excel</Radio> | ||
| </Space> | ||
| </Radio.Group> | ||
| </BasicModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default ExportFormatModal; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.