Skip to content

Commit

Permalink
pexdax refactor (#16333)
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi authored and eschutho committed Nov 24, 2021
1 parent c5bae17 commit 6650425
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import { AlertObject } from 'src/views/CRUD/alert/types';
import { Menu, NoAnimationDropdown } from 'src/common/components';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
import DeleteModal from 'src/components/DeleteModal';
import ReportModal from 'src/components/ReportModal';
import { ChartState } from 'src/explore/types';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import { fetchUISpecificReport } from 'src/reports/actions/reports';

const deleteColor = (theme: SupersetTheme) => css`
color: ${theme.colors.error.base};
Expand All @@ -38,23 +36,23 @@ export default function HeaderReportActionsDropDown({
toggleActive,
deleteActiveReport,
dashboardId,
chart,
showReportModal,
}: {
showReportModal: () => void;
toggleActive: (data: AlertObject, checked: boolean) => void;
deleteActiveReport: (data: AlertObject) => void;
dashboardId?: number;
chart?: ChartState;
}) {
const dispatch = useDispatch();
const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
state => state.reports,
);
const user: UserWithPermissionsAndRoles = useSelector<
any,
UserWithPermissionsAndRoles
>(state => state.user || state.explore?.user);
const reportsIds = Object.keys(reports || []);
const report: AlertObject = reports?.[reportsIds[0]];
const reportsIds = Object.keys(reports);
const report: AlertObject = reports[reportsIds[0]];
const [
currentReportDeleting,
setCurrentReportDeleting,
Expand Down Expand Up @@ -90,36 +88,6 @@ export default function HeaderReportActionsDropDown({
return permissions[0].length > 0;
};

useEffect(() => {
if (canAddReports()) {
dispatch(
fetchUISpecificReport({
userId: user.userId,
filterField: dashboardId ? 'dashboard_id' : 'chart_id',
creationMethod: dashboardId ? 'dashboards' : 'charts',
resourceId: dashboardId || chart?.id,
}),
);
}
}, []);

useEffect(() => {
if (
canAddReports() &&
dashboardId &&
dashboardId !== dashboardIdRef.current
) {
dispatch(
fetchUISpecificReport({
userId: user.userId,
filterField: 'dashboard_id',
creationMethod: 'dashboards',
resourceId: dashboardId,
}),
);
}
}, [dashboardId]);

const menu = () => (
<Menu selectable={false} css={{ width: '200px' }}>
<Menu.Item>
Expand All @@ -144,60 +112,48 @@ export default function HeaderReportActionsDropDown({
</Menu>
);

return (
canAddReports() && (
return canAddReports() ? (
report ? (
<>
<ReportModal
show={showModal}
onHide={() => setShowModal(false)}
userId={user.userId}
userEmail={user.email}
dashboardId={dashboardId}
chart={chart}
/>
{report ? (
<>
<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?')}
/>
)}
</>
) : (
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={() => setShowModal(true)}
>
<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?')}
/>
)}
</>
) : (
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={showReportModal}
>
<Icons.Calendar />
</span>
)
);
) : null;
}
17 changes: 15 additions & 2 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class Header extends React.PureComponent {
this.overwriteDashboard = this.overwriteDashboard.bind(this);
this.showPropertiesModal = this.showPropertiesModal.bind(this);
this.hidePropertiesModal = this.hidePropertiesModal.bind(this);
this.showReportModal = this.showReportModal.bind(this);
this.hideReportModal = this.hideReportModal.bind(this);
}

componentDidMount() {
Expand Down Expand Up @@ -370,6 +372,14 @@ class Header extends React.PureComponent {
this.setState({ showingPropertiesModal: false });
}

showReportModal() {
this.setState({ showingReportModal: true });
}

hideReportModal() {
this.setState({ showingReportModal: false });
}

render() {
const {
dashboardTitle,
Expand Down Expand Up @@ -533,6 +543,7 @@ class Header extends React.PureComponent {
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
dashboardId={dashboardInfo.id}
showReportModal={this.showReportModal}
/>
</>
)}
Expand All @@ -544,8 +555,10 @@ class Header extends React.PureComponent {
onHide={this.hidePropertiesModal}
colorScheme={this.props.colorScheme}
onSubmit={updates => {
const { dashboardInfoChanged, dashboardTitleChanged } =
this.props;
const {
dashboardInfoChanged,
dashboardTitleChanged
} = this.props;
dashboardInfoChanged({
slug: updates.slug,
metadata: JSON.parse(updates.jsonMetadata),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import PropTypes from 'prop-types';
import Icons from 'src/components/Icons';
import {
CategoricalColorNamespace,
SupersetClient,
Expand Down

0 comments on commit 6650425

Please sign in to comment.