-
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(dashboard): Add Drill to Detail modal w/ chart menu + right-clic…
…k support (#20728) * Add drill-to-detail modal. * Include additional filters from dashboard context in request. * Set page cache size to be approximately equal to memory usage of Samples pane. * Update getDatasourceSamples signature. * One-line import/export. * Fix incorrect argument order in getDatasourceSamples invocation. * Fix height of modal. * Disable option in chart menu unless feature flag is set. * Open modal on right-click. * Fix double requests on modal open, controls disappearing on filter update. * Show formattedVal in clearable filter tag. * Set force=false for all requests. * Rearrange/refactor DrillDetailPane. * Reset page index on reload. * Fix endless re-requests on request failure. * Fix modal layout issues.
- Loading branch information
Showing
9 changed files
with
755 additions
and
45 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
117 changes: 117 additions & 0 deletions
117
superset-frontend/src/components/Chart/DrillDetailModal.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,117 @@ | ||
/** | ||
* 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, { | ||
useCallback, | ||
useContext, | ||
useEffect, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { | ||
BinaryQueryObjectFilterClause, | ||
css, | ||
QueryFormData, | ||
t, | ||
useTheme, | ||
} from '@superset-ui/core'; | ||
import DrillDetailPane from 'src/dashboard/components/DrillDetailPane'; | ||
import { DashboardPageIdContext } from 'src/dashboard/containers/DashboardPage'; | ||
import { Slice } from 'src/types/Chart'; | ||
import Modal from '../Modal'; | ||
import Button from '../Button'; | ||
|
||
const DrillDetailModal: React.FC<{ | ||
chartId: number; | ||
initialFilters?: BinaryQueryObjectFilterClause[]; | ||
formData: QueryFormData; | ||
}> = ({ chartId, initialFilters, formData }) => { | ||
const [showModal, setShowModal] = useState(false); | ||
const openModal = useCallback(() => setShowModal(true), []); | ||
const closeModal = useCallback(() => setShowModal(false), []); | ||
const history = useHistory(); | ||
const theme = useTheme(); | ||
const dashboardPageId = useContext(DashboardPageIdContext); | ||
const { slice_name: chartName } = useSelector( | ||
(state: { sliceEntities: { slices: Record<number, Slice> } }) => | ||
state.sliceEntities.slices[chartId], | ||
); | ||
|
||
const exploreUrl = useMemo( | ||
() => `/explore/?dashboard_page_id=${dashboardPageId}&slice_id=${chartId}`, | ||
[chartId, dashboardPageId], | ||
); | ||
|
||
const exploreChart = useCallback(() => { | ||
history.push(exploreUrl); | ||
}, [exploreUrl, history]); | ||
|
||
// Trigger modal open when initial filters change | ||
useEffect(() => { | ||
if (initialFilters) { | ||
openModal(); | ||
} | ||
}, [initialFilters, openModal]); | ||
|
||
return ( | ||
<Modal | ||
css={css` | ||
.ant-modal-body { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
`} | ||
show={showModal} | ||
onHide={closeModal} | ||
title={t('Drill to detail: %s', chartName)} | ||
footer={ | ||
<> | ||
<Button | ||
buttonStyle="secondary" | ||
buttonSize="small" | ||
onClick={exploreChart} | ||
> | ||
{t('Edit chart')} | ||
</Button> | ||
<Button buttonStyle="primary" buttonSize="small" onClick={closeModal}> | ||
{t('Close')} | ||
</Button> | ||
</> | ||
} | ||
responsive | ||
resizable | ||
resizableConfig={{ | ||
minHeight: theme.gridUnit * 128, | ||
minWidth: theme.gridUnit * 128, | ||
defaultSize: { | ||
width: 'auto', | ||
height: '75vh', | ||
}, | ||
}} | ||
draggable | ||
destroyOnClose | ||
> | ||
<DrillDetailPane formData={formData} initialFilters={initialFilters} /> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DrillDetailModal; |
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.