You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2021/07/30 19:31:26 UTC
[superset] 09/14: feat: Delete Report Modal for charts and
Dashboards (#15934)
This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a commit to branch selfSubscribeReports
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d82dafc5ca520d66b9a6406220087daa8917dc30
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Wed Jul 28 19:44:51 2021 -0400
feat: Delete Report Modal for charts and Dashboards (#15934)
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
* feat: toggle the ReportModal Icon based on user permissions (#15780)
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* fix: avoid fetching favorite status for anonymous user (#15590)
* avoid fetching favorite status for anonymous user
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* first draft
* added testing props
* cleaned up rebase
* changed name and type
Co-authored-by: Lyndsi Kay Williams <55...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* feat: fetch UI specific reports (#15785)
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* fix: avoid fetching favorite status for anonymous user (#15590)
* avoid fetching favorite status for anonymous user
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* first draft
* created Api call
* added click logic
* made the fetch report into a action/reducer
* abstracted report action
* revision
* added reportState to reducer
* reports conditions
* revisions
* revisions
Co-authored-by: Lyndsi Kay Williams <55...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* initial draft
* started implementation into charts
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* fix: avoid fetching favorite status for anonymous user (#15590)
* avoid fetching favorite status for anonymous user
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
* feat: fetch UI specific reports (#15785)
* style: Rough draft of email report modal (#15666)
* clears errors when closing out of modal (#15623)
* fix: avoid fetching favorite status for anonymous user (#15590)
* avoid fetching favorite status for anonymous user
* add test + fix types
* fix lint errors
* Building ReportModal component
* Continued ReportModal creation
* Visual details updated
* CronError style
* Very basic testing added
Co-authored-by: AAfghahi <48...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* first draft
* created Api call
* added click logic
* made the fetch report into a action/reducer
* abstracted report action
* revision
* added reportState to reducer
* reports conditions
* revisions
* revisions
Co-authored-by: Lyndsi Kay Williams <55...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
* started implementation into charts
* revisions
* fixed tests
* delete modal for charts and dashboards
Co-authored-by: Lyndsi Kay Williams <55...@users.noreply.github.com>
Co-authored-by: aspedrosa <as...@ua.pt>
---
.../HeaderReportActionsDropdown/index.tsx | 74 ++++++++++++++++------
.../src/dashboard/components/Header/index.jsx | 1 +
.../src/dashboard/containers/DashboardHeader.jsx | 2 +
.../src/explore/components/ExploreChartHeader.jsx | 9 +--
.../src/reports/actions/reportState.js | 38 ++++++++++-
5 files changed, 101 insertions(+), 23 deletions(-)
diff --git a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index b00f6f8..2fad319 100644
--- a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++ b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -16,29 +16,39 @@
* specific language governing permissions and limitations
* under the License.
*/
-import React from 'react';
+import React, { useState } from 'react';
import { useSelector } from 'react-redux';
-import { t } from '@superset-ui/core';
+import { t, SupersetTheme, css } from '@superset-ui/core';
import Icons from 'src/components/Icons';
import { Switch } from 'src/components/Switch';
import { AlertObject } from 'src/views/CRUD/alert/types';
import { Menu, NoAnimationDropdown } from 'src/common/components';
+import DeleteModal from 'src/components/DeleteModal';
+
+const deleteColor = (theme: SupersetTheme) => css`
+ color: ${theme.colors.error.base};
+`;
+
export default function HeaderReportActionsDropDown({
// showReportModal,
// hideReportModal,
// addDangerToast,
toggleActive,
+ deleteActiveReport,
}: {
showReportModal: () => void;
hideReportModal: () => void;
- // addDangerToast: () => void;
toggleActive: (data: AlertObject, checked: boolean) => void;
+ deleteActiveReport: (data: AlertObject) => void;
}) {
- // const ref: any = useRef();
const report = useSelector<any, AlertObject>(
state => state.reportState.report.result[0],
);
+ const [
+ currentReportDeleting,
+ setCurrentReportDeleting,
+ ] = useState<AlertObject | null>(null);
const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
if (data?.id) {
@@ -46,13 +56,18 @@ export default function HeaderReportActionsDropDown({
}
};
+ const handleReportDelete = (report: AlertObject) => {
+ deleteActiveReport(report);
+ setCurrentReportDeleting(null);
+ };
+
const menu = () => (
<Menu selectable={false}>
<Menu.Item>
{t('Email reports active')}
<Switch
data-test="toggle-active"
- checked={report.active}
+ checked={report?.active}
onClick={(checked: boolean) => toggleActiveKey(report, checked)}
size="small"
/>
@@ -63,22 +78,45 @@ export default function HeaderReportActionsDropDown({
{t('Edit email report')}
</div>
</Menu.Item>
- <Menu.Item>{t('Delete email report')}</Menu.Item>
+ <Menu.Item
+ onClick={() => setCurrentReportDeleting(report)}
+ css={deleteColor}
+ >
+ {t('Delete email report')}
+ </Menu.Item>
</Menu>
);
return (
- <NoAnimationDropdown
- // ref={ref}
- overlay={menu()}
- trigger={['click']}
- getPopupContainer={(triggerNode: any) =>
- triggerNode.closest('.action-button')
- }
- >
- <span role="button" className="action-button" tabIndex={0}>
- <Icons.Calendar />
- </span>
- </NoAnimationDropdown>
+ <>
+ <NoAnimationDropdown
+ // ref={ref}
+ overlay={menu()}
+ trigger={['click']}
+ getPopupContainer={(triggerNode: any) =>
+ triggerNode.closest('.action-button')
+ }
+ >
+ <span role="button" className="action-button" tabIndex={0}>
+ <Icons.Calendar />
+ </span>
+ </NoAnimationDropdown>
+ {currentReportDeleting && (
+ <DeleteModal
+ description={t(
+ 'This action will permanently delete %s.',
+ currentReportDeleting.name,
+ )}
+ onConfirm={() => {
+ if (currentReportDeleting) {
+ handleReportDelete(currentReportDeleting);
+ }
+ }}
+ onHide={() => setCurrentReportDeleting(null)}
+ open
+ title={t('Delete Report?')}
+ />
+ )}
+ </>
);
}
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx
index 1a3b814..c4d3fa9 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -387,6 +387,7 @@ class Header extends React.PureComponent {
showReportModal={this.showReportModal}
hideReportModal={this.hideReportModal}
toggleActive={this.props.toggleActive}
+ deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
diff --git a/superset-frontend/src/dashboard/containers/DashboardHeader.jsx b/superset-frontend/src/dashboard/containers/DashboardHeader.jsx
index 5e9126e..42c2065 100644
--- a/superset-frontend/src/dashboard/containers/DashboardHeader.jsx
+++ b/superset-frontend/src/dashboard/containers/DashboardHeader.jsx
@@ -60,6 +60,7 @@ import { DASHBOARD_HEADER_ID } from '../util/constants';
import {
fetchUISpecificReport,
toggleActive,
+ deleteActiveReport,
} from '../../reports/actions/reportState';
function mapStateToProps({
@@ -133,6 +134,7 @@ function mapDispatchToProps(dispatch) {
updateDataMask,
fetchUISpecificReport,
toggleActive,
+ deleteActiveReport,
},
dispatch,
);
diff --git a/superset-frontend/src/explore/components/ExploreChartHeader.jsx b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
index aeca9cd..33342b8 100644
--- a/superset-frontend/src/explore/components/ExploreChartHeader.jsx
+++ b/superset-frontend/src/explore/components/ExploreChartHeader.jsx
@@ -27,6 +27,7 @@ import ReportModal from 'src/components/ReportModal';
import {
fetchUISpecificReport,
toggleActive,
+ deleteActiveReport,
} from 'src/reports/actions/reportState';
import HeaderReportActionsDropdown from 'src/components/ReportModal/HeaderReportActionsDropdown';
import { chartPropShape } from '../../dashboard/util/propShapes';
@@ -115,7 +116,7 @@ export class ExploreChartHeader extends React.PureComponent {
componentDidMount() {
const { user, chart } = this.props;
if (user) {
- // handles anonymous user.
+ // this is in the case that there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
'chart_id',
@@ -166,6 +167,7 @@ export class ExploreChartHeader extends React.PureComponent {
showReportModal={this.showReportModal}
hideReportModal={this.hideReportModal}
toggleActive={this.props.toggleActive}
+ deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
@@ -198,8 +200,7 @@ export class ExploreChartHeader extends React.PureComponent {
}
render() {
- const formData = this.props.form_data;
- const { user } = this.props;
+ const { user, form_data: formData } = this.props;
const {
chartStatus,
chartUpdateEndTime,
@@ -321,7 +322,7 @@ ExploreChartHeader.propTypes = propTypes;
function mapDispatchToProps(dispatch) {
return bindActionCreators(
- { sliceUpdated, fetchUISpecificReport, toggleActive },
+ { sliceUpdated, fetchUISpecificReport, toggleActive, deleteActiveReport },
dispatch,
);
}
diff --git a/superset-frontend/src/reports/actions/reportState.js b/superset-frontend/src/reports/actions/reportState.js
index f0c5b6a..64f32bf 100644
--- a/superset-frontend/src/reports/actions/reportState.js
+++ b/superset-frontend/src/reports/actions/reportState.js
@@ -19,7 +19,7 @@
/* eslint camelcase: 0 */
import { t, SupersetClient } from '@superset-ui/core';
import rison from 'rison';
-import { addDangerToast } from '../../messageToasts/actions';
+import { addDangerToast, addSuccessToast } from '../../messageToasts/actions';
export const SET_REPORT = 'SET_REPORT';
export function setReport(report) {
@@ -128,3 +128,39 @@ export function toggleActive(report, isActive) {
});
};
}
+
+export function deleteActiveReport(report) {
+ return function deleteActiveReportThunk(dispatch, getState) {
+ return SupersetClient.delete({
+ endpoint: encodeURI(`/api/v1/report/${report.id}`),
+ })
+ .catch(() => {
+ dispatch(addDangerToast(t('Your report could not be deleted')));
+ })
+ .finally(() => {
+ const state = getState();
+ const { user, dashboardInfo, charts, explore } = state;
+ if (dashboardInfo) {
+ dispatch(
+ fetchUISpecificReport(
+ user.userId,
+ 'dashboard_id',
+ 'dashboards',
+ dashboardInfo.id,
+ ),
+ );
+ } else {
+ const [chartArr] = Object.keys(charts);
+ dispatch(
+ fetchUISpecificReport(
+ explore.user.userId,
+ 'chart_id',
+ 'charts',
+ charts[chartArr].id,
+ ),
+ );
+ }
+ dispatch(addSuccessToast(t('Deleted: %s', report.name)));
+ });
+ };
+}