Skip to content

Commit

Permalink
code dry (#16358)
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi authored and eschutho committed Nov 24, 2021
1 parent 7ee4117 commit 8169789
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { t, SupersetTheme, css, useTheme } from '@superset-ui/core';
import Icons from 'src/components/Icons';
Expand All @@ -28,6 +28,7 @@ import DeleteModal from 'src/components/DeleteModal';
import { ChartState } from 'src/explore/types';
import ReportModal from 'src/components/ReportModal';
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 @@ -37,11 +38,14 @@ export default function HeaderReportActionsDropDown({
toggleActive,
deleteActiveReport,
dashboardId,
chart,
}: {
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,
);
Expand Down Expand Up @@ -85,6 +89,19 @@ 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,
}),
);
}
}, []);

const menu = () => (
<Menu selectable={false} css={{ width: '200px' }}>
<Menu.Item>
Expand Down Expand Up @@ -118,6 +135,7 @@ export default function HeaderReportActionsDropDown({
userId={user.userId}
userEmail={user.email}
dashboardId={dashboardId}
chart={chart}
/>
{report ? (
<>
Expand Down
3 changes: 1 addition & 2 deletions superset-frontend/src/components/ReportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface ReportProps {
userId: number;
userEmail: string;
dashboardId?: number;
chart?: ChartObject;
chart?: ChartState;
props: any;
}

Expand Down Expand Up @@ -159,7 +159,6 @@ const ReportModal: FunctionComponent<ReportProps> = ({
chart,
userId,
userEmail,
...props
}) => {
const vizType = chart?.sliceFormData?.viz_type;
const isChart = !!chart;
Expand Down
9 changes: 9 additions & 0 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Header extends React.PureComponent {
const { refreshFrequency } = this.props;
this.startPeriodicRender(refreshFrequency * 1000);
<<<<<<< HEAD
<<<<<<< HEAD
=======
if (this.canAddReports()) {
// this is in case there is an anonymous user.
Expand All @@ -178,6 +179,8 @@ class Header extends React.PureComponent {
);
}
>>>>>>> refactor progress (#16339)
=======
>>>>>>> code dry (#16358)
}

componentDidUpdate(prevProps) {
Expand All @@ -202,6 +205,7 @@ class Header extends React.PureComponent {
this.props.setMaxUndoHistoryExceeded();
}
<<<<<<< HEAD
<<<<<<< HEAD
=======
if (
this.canAddReports() &&
Expand All @@ -216,6 +220,8 @@ class Header extends React.PureComponent {
);
}
>>>>>>> refactor progress (#16339)
=======
>>>>>>> code dry (#16358)
}

componentWillUnmount() {
Expand Down Expand Up @@ -397,6 +403,7 @@ class Header extends React.PureComponent {
this.setState({ showingPropertiesModal: false });
}

<<<<<<< HEAD
<<<<<<< HEAD
showReportModal() {
this.setState({ showingReportModal: true });
Expand Down Expand Up @@ -424,6 +431,8 @@ class Header extends React.PureComponent {
>>>>>>> refactor progress (#16339)
}

=======
>>>>>>> code dry (#16358)
render() {
const {
dashboardTitle,
Expand Down

0 comments on commit 8169789

Please sign in to comment.