-
Notifications
You must be signed in to change notification settings - Fork 16.6k
fix: Explore "Change Dataset" UX Enhancements #12006
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 all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
8bdd2df
working updated list
hughhhh f928411
cleanup
hughhhh ca6b16e
remove console.logs
hughhhh 49ff839
change uid
hughhhh 70d4004
Merge branch 'master' of https://github.com/apache/incubator-superset…
hughhhh 388737a
update
hughhhh c542f94
remove old test
hughhhh f37293a
Merge branch 'master' of https://github.com/apache/incubator-superset…
hughhhh 36d7782
fix linting
hughhhh ef7a8d9
add confirm overwrite modal
hughhhh 85bdbef
fixed the test
hughhhh 76bca6c
Merge branch 'master' of https://github.com/apache/incubator-superset…
hughhhh 5592a91
Merge branch 'master' of https://github.com/apache/incubator-superset…
hughhhh b30a337
refactor component to have search api
hughhhh 6395dbe
pulled refactored PR
hughhhh ef49578
add success toast
hughhhh 7d3507e
fix linting
hughhhh da2c09b
additional step for testing
hughhhh 3f839c7
refactor for hooks
hughhhh 40b82ac
switched out for hooks
hughhhh 9535d57
update search calls
hughhhh 011ada8
cleaning things up
hughhhh 89d9381
updated component
hughhhh e04c792
change messaging
hughhhh 16e37d9
use debouncing on network calls
hughhhh c0f8da0
fix test
hughhhh e296166
fix merge conflicts
hughhhh 0c95807
fix more errors
hughhhh 027b422
add debonuncing effect to utils fils
hughhhh 28f3c47
address comments
hughhhh f71cf92
update message
hughhhh 53cd8e7
Merge branch 'master' of https://github.com/apache/incubator-superset…
hughhhh 76d91f8
fix linting issue
hughhhh ffd5226
fix linting issues
hughhhh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,25 +20,53 @@ import React, { | |
| FunctionComponent, | ||
| useState, | ||
| useRef, | ||
| useMemo, | ||
| useEffect, | ||
| useCallback, | ||
| } from 'react'; | ||
| import { Alert, FormControl, FormControlProps } from 'react-bootstrap'; | ||
| import { SupersetClient, t } from '@superset-ui/core'; | ||
| import { SupersetClient, t, styled } from '@superset-ui/core'; | ||
| import TableView from 'src/components/TableView'; | ||
| import Modal from 'src/common/components/Modal'; | ||
| import StyledModal from 'src/common/components/Modal'; | ||
| import Button from 'src/components/Button'; | ||
| import { useListViewResource } from 'src/views/CRUD/hooks'; | ||
| import Dataset from 'src/types/Dataset'; | ||
| import { useDebouncedEffect } from 'src/explore/exploreUtils'; | ||
| import { getClientErrorObject } from '../utils/getClientErrorObject'; | ||
| import Loading from '../components/Loading'; | ||
| import withToasts from '../messageToasts/enhancers/withToasts'; | ||
|
|
||
| const CONFIRM_WARNING_MESSAGE = t( | ||
| 'Warning! Changing the dataset may break the chart if the metadata (columns/metrics) does not exist in the target dataset', | ||
| ); | ||
|
|
||
| interface Datasource { | ||
| type: string; | ||
| id: number; | ||
| uid: string; | ||
| } | ||
|
|
||
| interface ChangeDatasourceModalProps { | ||
| addDangerToast: (msg: string) => void; | ||
| onChange: (id: number) => void; | ||
| addSuccessToast: (msg: string) => void; | ||
| onChange: (uid: string) => void; | ||
| onDatasourceSave: (datasource: object, errors?: Array<any>) => {}; | ||
| onHide: () => void; | ||
| show: boolean; | ||
| } | ||
|
|
||
| const ConfirmModalStyled = styled.div` | ||
| .btn-container { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| padding: 0px 15px; | ||
| margin: 10px 0 0 0; | ||
| } | ||
|
|
||
| .confirm-modal-container { | ||
| margin: 9px; | ||
| } | ||
| `; | ||
|
|
||
| const TABLE_COLUMNS = [ | ||
| 'name', | ||
| 'type', | ||
|
|
@@ -47,86 +75,78 @@ const TABLE_COLUMNS = [ | |
| 'creator', | ||
| ].map(col => ({ accessor: col, Header: col })); | ||
|
|
||
| const TABLE_FILTERABLE = ['rawName', 'type', 'schema', 'connection', 'creator']; | ||
| const CHANGE_WARNING_MSG = t( | ||
| 'Changing the dataset may break the chart if the chart relies ' + | ||
| 'on columns or metadata that does not exist in the target dataset', | ||
| ); | ||
|
|
||
| const emptyRequest = { | ||
| pageIndex: 0, | ||
| pageSize: 20, | ||
| filters: [], | ||
| sortBy: [{ id: 'changed_on_delta_humanized' }], | ||
| }; | ||
|
|
||
| const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({ | ||
| addDangerToast, | ||
| addSuccessToast, | ||
| onChange, | ||
| onDatasourceSave, | ||
| onHide, | ||
| show, | ||
| }) => { | ||
| const [datasources, setDatasources] = useState<any>(null); | ||
| const [filter, setFilter] = useState<any>(undefined); | ||
| const [loading, setLoading] = useState(true); | ||
| const [confirmChange, setConfirmChange] = useState(false); | ||
| const [confirmedDataset, setConfirmedDataset] = useState<Datasource>(); | ||
| let searchRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| const selectDatasource = (datasource: any) => { | ||
| SupersetClient.get({ | ||
| endpoint: `/datasource/get/${datasource.type}/${datasource.id}`, | ||
| }) | ||
| .then(({ json }) => { | ||
| onDatasourceSave(json); | ||
| onChange(datasource.uid); | ||
| }) | ||
| .catch(response => { | ||
| getClientErrorObject(response).then( | ||
| ({ error, message }: { error: any; message: string }) => { | ||
| const errorMessage = error | ||
| ? error.error || error.statusText || error | ||
| : message; | ||
| addDangerToast(errorMessage); | ||
| }, | ||
| ); | ||
| }); | ||
| onHide(); | ||
| }; | ||
| const { | ||
| state: { loading, resourceCollection }, | ||
| fetchData, | ||
| } = useListViewResource<Dataset>('dataset', t('dataset'), addDangerToast); | ||
|
|
||
| const selectDatasource = useCallback((datasource: Datasource) => { | ||
| setConfirmChange(true); | ||
| setConfirmedDataset(datasource); | ||
| }, []); | ||
|
|
||
| useDebouncedEffect(() => { | ||
| if (filter) { | ||
| fetchData({ | ||
| ...emptyRequest, | ||
| filters: [ | ||
| { | ||
| id: 'table_name', | ||
| operator: 'ct', | ||
| value: filter, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
| }, 1000); | ||
|
|
||
| const onEnterModal = () => { | ||
| useEffect(() => { | ||
| const onEnterModal = async () => { | ||
| if (searchRef && searchRef.current) { | ||
| searchRef.current.focus(); | ||
| } | ||
| if (!datasources) { | ||
| SupersetClient.get({ | ||
| endpoint: '/superset/datasources/', | ||
| }) | ||
| .then(({ json }) => { | ||
| const data = json.map((ds: any) => ({ | ||
| rawName: ds.name, | ||
| connection: ds.connection, | ||
| schema: ds.schema, | ||
| name: ( | ||
| <a | ||
| href="#" | ||
| onClick={() => selectDatasource(ds)} | ||
| className="datasource-link" | ||
| > | ||
| {ds.name} | ||
| </a> | ||
| ), | ||
| type: ds.type, | ||
| })); | ||
| setLoading(false); | ||
| setDatasources(data); | ||
| }) | ||
| .catch(response => { | ||
| setLoading(false); | ||
| getClientErrorObject(response).then(({ error }: any) => { | ||
| addDangerToast(error.error || error.statusText || error); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // Fetch initial datasets for tableview | ||
| await fetchData(emptyRequest); | ||
| }; | ||
|
|
||
| if (show) { | ||
| onEnterModal(); | ||
| } | ||
| }, [addDangerToast, datasources, onChange, onDatasourceSave, onHide, show]); | ||
| }, [ | ||
| addDangerToast, | ||
| fetchData, | ||
| onChange, | ||
| onDatasourceSave, | ||
| onHide, | ||
| selectDatasource, | ||
| show, | ||
| ]); | ||
|
|
||
| const setSearchRef = (ref: any) => { | ||
| searchRef = ref; | ||
|
|
@@ -135,54 +155,112 @@ const ChangeDatasourceModal: FunctionComponent<ChangeDatasourceModalProps> = ({ | |
| const changeSearch = ( | ||
| event: React.FormEvent<FormControl & FormControlProps>, | ||
| ) => { | ||
| setFilter((event.currentTarget?.value as string) ?? ''); | ||
| const searchValue = (event.currentTarget?.value as string) ?? ''; | ||
| setFilter(searchValue); | ||
| }; | ||
|
|
||
| const data = useMemo( | ||
| () => | ||
| filter && datasources | ||
| ? datasources.filter((datasource: any) => | ||
| TABLE_FILTERABLE.some(field => datasource[field]?.includes(filter)), | ||
| ) | ||
| : datasources, | ||
| [datasources, filter], | ||
| ); | ||
| const handleChangeConfirm = () => { | ||
| SupersetClient.get({ | ||
| endpoint: `/datasource/get/${confirmedDataset?.type}/${confirmedDataset?.id}`, | ||
| }) | ||
| .then(({ json }) => { | ||
| onDatasourceSave(json); | ||
| onChange(`${confirmedDataset?.id}__table`); | ||
| }) | ||
| .catch(response => { | ||
| getClientErrorObject(response).then( | ||
| ({ error, message }: { error: any; message: string }) => { | ||
| const errorMessage = error | ||
| ? error.error || error.statusText || error | ||
| : message; | ||
| addDangerToast(errorMessage); | ||
| }, | ||
| ); | ||
| }); | ||
| onHide(); | ||
| addSuccessToast('Successfully changed datasource!'); | ||
| }; | ||
|
|
||
| const handlerCancelConfirm = () => { | ||
| setConfirmChange(false); | ||
| }; | ||
|
|
||
| const renderTableView = () => { | ||
| const data = resourceCollection.map((ds: any) => ({ | ||
| rawName: ds.table_name, | ||
| connection: ds.database.database_name, | ||
| schema: ds.schema, | ||
| name: ( | ||
| <a | ||
| href="#" | ||
| onClick={() => selectDatasource({ type: 'table', ...ds })} | ||
| className="datasource-link" | ||
| > | ||
| {ds.table_name} | ||
| </a> | ||
| ), | ||
| type: ds.kind, | ||
| })); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| <StyledModal | ||
| show={show} | ||
| onHide={onHide} | ||
| responsive | ||
| title={t('Select a dataset')} | ||
| hideFooter | ||
| > | ||
| <> | ||
| <Alert bsStyle="warning"> | ||
| <strong>{t('Warning!')}</strong> {CHANGE_WARNING_MSG} | ||
| </Alert> | ||
| <div> | ||
| <FormControl | ||
| inputRef={ref => { | ||
| setSearchRef(ref); | ||
| }} | ||
| type="text" | ||
| bsSize="sm" | ||
| value={filter} | ||
| placeholder={t('Search / Filter')} | ||
| onChange={changeSearch} | ||
| /> | ||
| </div> | ||
| {loading && <Loading />} | ||
| {datasources && ( | ||
| <TableView | ||
| columns={TABLE_COLUMNS} | ||
| data={data} | ||
| pageSize={20} | ||
| className="table-condensed" | ||
| /> | ||
| {!confirmChange && ( | ||
| <> | ||
| <Alert bsStyle="warning"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the warning message here, I should use it in the overwrite confirmation dialog! |
||
| <strong>{t('Warning!')}</strong> {CHANGE_WARNING_MSG} | ||
| </Alert> | ||
| <div> | ||
| <FormControl | ||
| inputRef={ref => { | ||
| setSearchRef(ref); | ||
| }} | ||
| type="text" | ||
| bsSize="sm" | ||
| value={filter} | ||
| placeholder={t('Search / Filter')} | ||
| onChange={changeSearch} | ||
| /> | ||
| </div> | ||
| {loading && <Loading />} | ||
| {!loading && ( | ||
| <TableView | ||
| columns={TABLE_COLUMNS} | ||
| data={renderTableView()} | ||
| pageSize={20} | ||
| className="table-condensed" | ||
| /> | ||
| )} | ||
| </> | ||
| )} | ||
| {confirmChange && ( | ||
| <ConfirmModalStyled> | ||
| <div className="confirm-modal-container"> | ||
| {CONFIRM_WARNING_MESSAGE} | ||
| <div className="btn-container"> | ||
| <Button onClick={handlerCancelConfirm}>Cancel</Button> | ||
| <Button | ||
| className="proceed-btn" | ||
| buttonStyle="primary" | ||
| onClick={handleChangeConfirm} | ||
| > | ||
| Proceed | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </ConfirmModalStyled> | ||
| )} | ||
| </> | ||
| </Modal> | ||
| </StyledModal> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be able to use some of the theme gridunits here