Skip to content
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

feat: Create/onsave Email Report functionality for Dashboard and Chart #15856

Merged
merged 30 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0e3088a
style: Rough draft of email report modal (#15666)
lyndsiWilliams Jul 16, 2021
03f8ddd
feat: toggle the ReportModal Icon based on user permissions (#15780)
AAfghahi Jul 20, 2021
6a79189
feat: Begin incorporation of email report modal to Charts (#15793)
lyndsiWilliams Jul 22, 2021
900a244
feat: fetch UI specific reports (#15785)
AAfghahi Jul 22, 2021
c8d5dba
fix: Edit physical dataset from the Edit Dataset modal (#15770)
geido Jul 19, 2021
1561372
feat: add show columns to Reports model (#15712)
AAfghahi Jul 19, 2021
74e120d
fix: margin right on warning icon to 8px (#15715)
stellalc7 Jul 19, 2021
961fcf0
feat: adding Progress Bar to Benchmark script (#15719)
AAfghahi Jul 19, 2021
5c44960
fix: migration downgrade references wrong column (#15791)
betodealmeida Jul 20, 2021
abb464a
fix(dashboard): Add resize handles to right and bottom of component (…
kgabryje Jul 20, 2021
1a0803e
chore: Add tags to the new viz gallery (#15734)
zhaoyongjie Jul 20, 2021
67edec6
chore: bump 0.17.70 (#15795)
zhaoyongjie Jul 20, 2021
98e8f06
docs: Adding Sunbird to users list (#15794)
kumarks1122 Jul 20, 2021
f1bac8b
chore: Improves the Select component UI/UX - iteration 4 (#15480)
michael-s-molina Jul 20, 2021
797efdd
Add z-index only on maximize (#15800)
geido Jul 20, 2021
a24fcdb
chore: remove `retry` dependency in favor of `backoff` (#15788)
betodealmeida Jul 20, 2021
425815e
fix: create fk model in benchmark script (#15804)
betodealmeida Jul 20, 2021
1641250
style: Rough draft of email report modal (#15666)
lyndsiWilliams Jul 16, 2021
7d4ffbd
Working on onSave functionality
lyndsiWilliams Jul 20, 2021
82045aa
style: Rough draft of email report modal (#15666)
lyndsiWilliams Jul 16, 2021
1739db1
feat: toggle the ReportModal Icon based on user permissions (#15780)
AAfghahi Jul 20, 2021
dc2482c
feat: fetch UI specific reports (#15785)
AAfghahi Jul 22, 2021
9b43572
Dashboard onSave progress
lyndsiWilliams Jul 23, 2021
d325e8e
More onSave/create progress
lyndsiWilliams Jul 23, 2021
df6acae
Dashboard POST working!
lyndsiWilliams Jul 23, 2021
da51d03
Dashboard POST relocated to redux
lyndsiWilliams Jul 28, 2021
2d0ed0b
POST now also working in Charts
lyndsiWilliams Jul 28, 2021
4a757b4
Merge branch 'selfSubscribeReports' of https://github.com/apache/supe…
lyndsiWilliams Jul 28, 2021
9bc1065
making linter happy
lyndsiWilliams Jul 28, 2021
3892059
linter again
lyndsiWilliams Jul 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
168 changes: 117 additions & 51 deletions superset-frontend/src/components/ReportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,39 @@
*/
import React, {
useState,
// useEffect,
useCallback,
useReducer,
Reducer,
FunctionComponent,
} from 'react';
import { styled, css, t } from '@superset-ui/core';
import { t } from '@superset-ui/core';
// import { useSingleViewResource } from 'src/views/CRUD/hooks';

import { bindActionCreators } from 'redux';
import { connect, useDispatch } from 'react-redux';
import { addReport } from 'src/reports/actions/reportState';

import LabeledErrorBoundInput from 'src/components/Form/LabeledErrorBoundInput';
import Icons from 'src/components/Icons';
import Modal from 'src/components/Modal';
import withToasts from 'src/messageToasts/enhancers/withToasts';
import { CronPicker, CronError } from 'src/components/CronPicker';

interface ReportProps {
onHide: () => {};
show: boolean;
props: any;
}
import {
StyledModal,
StyledTopSection,
StyledBottomSection,
StyledIconWrapper,
StyledScheduleTitle,
StyledCronError,
noBottomMargin,
StyledFooterButton,
} from './styles';

interface ReportObject {
active: boolean;
crontab: string;
dashboard: number;
dashboard?: number;
chart?: number;
description?: string;
log_retention: number;
name: string;
Expand All @@ -50,6 +61,22 @@ interface ReportObject {
validator_config_json: {} | null;
validator_type: string;
working_timeout: number;
creation_method: string;
}

interface ReportProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
addReport: (report?: ReportObject) => {};
onHide: () => {};
onReportAdd: (report?: ReportObject) => {};
show: boolean;
userId: number;
userEmail: string;
dashboardId?: number;
chartId?: number;
creationMethod: string;
props: any;
}

enum ActionType {
Expand Down Expand Up @@ -94,47 +121,12 @@ const reportReducer = (
}
};

const StyledModal = styled(Modal)`
.ant-modal-body {
padding: 0;
}
`;

const StyledTopSection = styled.div`
padding: ${({ theme }) => theme.gridUnit * 4}px;
`;

const StyledBottomSection = styled.div`
border-top: 1px solid ${({ theme }) => theme.colors.grayscale.light2};
padding: ${({ theme }) => theme.gridUnit * 4}px;
`;

const StyledIconWrapper = styled.span`
span {
margin-right: ${({ theme }) => theme.gridUnit * 2}px;
vertical-align: middle;
}
.text {
vertical-align: middle;
}
`;

const StyledScheduleTitle = styled.div`
margin-bottom: ${({ theme }) => theme.gridUnit * 7}px;
`;

const StyledCronError = styled.p`
color: ${({ theme }) => theme.colors.error.base};
`;

const noBottomMargin = css`
margin-bottom: 0;
`;

const ReportModal: FunctionComponent<ReportProps> = ({
show = false,
// addDangerToast,
onReportAdd,
onHide,
props,
show = false,
...props
}) => {
const [currentReport, setCurrentReport] = useReducer<
Reducer<Partial<ReportObject> | null, ReportActionType>
Expand All @@ -143,6 +135,59 @@ const ReportModal: FunctionComponent<ReportProps> = ({
setCurrentReport({ type, payload } as ReportActionType);
}, []);
const [error, setError] = useState<CronError>();
// ---------- comments on lines 21, 28, 125, 139-159 & 182 are being held for edit functionality
// const [hasConnectedReport, setHasConnectedReport] = useState<boolean>(false);
// const [isLoading, setLoading] = useState<boolean>(false);
const dispatch = useDispatch();

// Report fetch logic
// const {
// state: { resource },
// } = useSingleViewResource<ReportObject>(
// 'report',
// t('report'),
// addDangerToast,
// );

// useEffect(() => {
// if (resource?.dashboard) {
// setHasConnectedReport(true);
// }
// }, [resource?.dashboard]);

const onClose = () => {
// setLoading(false);
onHide();
};

const onSave = async () => {
// Create new Report
const newReportValues: Partial<ReportObject> = {
crontab: currentReport?.crontab,
dashboard: props.props.dashboardId,
chart: props.props.chartId,
description: currentReport?.description,
name: currentReport?.name || 'Weekly Report',
owners: [props.props.userId],
recipients: [
{
recipient_config_json: { target: props.props.userEmail },
type: 'Email',
},
],
type: 'Report',
creation_method: props.props.creationMethod,
};

// setLoading(true);
await dispatch(addReport(newReportValues as ReportObject));

if (onReportAdd) {
onReportAdd();
}

onClose();
};

const wrappedTitle = (
<StyledIconWrapper>
Expand All @@ -151,8 +196,26 @@ const ReportModal: FunctionComponent<ReportProps> = ({
</StyledIconWrapper>
);

const renderModalFooter = (
<>
<StyledFooterButton key="back" onClick={onClose}>
Cancel
</StyledFooterButton>
<StyledFooterButton key="submit" buttonStyle="primary" onClick={onSave}>
Add
</StyledFooterButton>
</>
);

return (
<StyledModal show={show} onHide={onHide} title={wrappedTitle}>
<StyledModal
show={show}
onHide={onClose}
title={wrappedTitle}
footer={renderModalFooter}
width="432"
centered
>
<StyledTopSection>
<LabeledErrorBoundInput
id="name"
Expand Down Expand Up @@ -196,7 +259,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({

<StyledBottomSection>
<StyledScheduleTitle>
<h1>Schedule</h1>
<h2>Schedule</h2>
<p>Scheduled reports will be sent to your email as a PNG</p>
</StyledScheduleTitle>

Expand All @@ -217,4 +280,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
);
};

export default ReportModal;
const mapDispatchToProps = (dispatch: any) =>
bindActionCreators({ addReport }, dispatch);

export default connect(null, mapDispatchToProps)(withToasts(ReportModal));
63 changes: 63 additions & 0 deletions superset-frontend/src/components/ReportModal/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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 { styled, css } from '@superset-ui/core';
import Modal from 'src/components/Modal';
import Button from 'src/components/Button';

export const StyledModal = styled(Modal)`
.ant-modal-body {
padding: 0;
}
`;

export const StyledTopSection = styled.div`
padding: ${({ theme }) => theme.gridUnit * 4}px;
`;

export const StyledBottomSection = styled.div`
border-top: 1px solid ${({ theme }) => theme.colors.grayscale.light2};
padding: ${({ theme }) => theme.gridUnit * 4}px;
`;

export const StyledIconWrapper = styled.span`
span {
margin-right: ${({ theme }) => theme.gridUnit * 2}px;
vertical-align: middle;
}
.text {
vertical-align: middle;
}
`;

export const StyledScheduleTitle = styled.div`
margin-bottom: ${({ theme }) => theme.gridUnit * 7}px;
`;

export const StyledCronError = styled.p`
color: ${({ theme }) => theme.colors.error.base};
`;

export const noBottomMargin = css`
margin-bottom: 0;
`;

export const StyledFooterButton = styled(Button)`
width: ${({ theme }) => theme.gridUnit * 40}px;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ class Header extends React.PureComponent {
userId: user.userId,
userEmail: user.email,
dashboardId: dashboardInfo.id,
creationMethod: 'dashboards',
}}
/>
)}
Expand Down
15 changes: 15 additions & 0 deletions superset-frontend/src/explore/components/ExploreChartHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,25 @@ export class ExploreChartHeader extends React.PureComponent {
isRunning={chartStatus === 'loading'}
status={CHART_STATUS_MAP[chartStatus]}
/>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
{this.canAddReports() && this.renderReportModal()}
<ReportModal
show={this.state.showingReportModal}
onHide={this.hideReportModal}
props={{
userId: this.props.userId,
userEmail: this.props.email,
chartId: this.props.chart.id,
creationMethod: 'charts',
}}
/>
<ExploreActionButtons
actions={{
Expand Down
16 changes: 16 additions & 0 deletions superset-frontend/src/reports/actions/reportState.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ export function fetchUISpecificReport(
};
}

export const ADD_REPORT = 'ADD_REPORT';

export const addReport = report => dispatch => {
SupersetClient.post({
endpoint: `/api/v1/report/`,
jsonPayload: report,
})
.then(() => {
dispatch({ type: ADD_REPORT, report });
})
.catch(() =>
dispatch(
addDangerToast(t('An error occurred while creating this report.')),
),
);
};
export const EDIT_REPORT = 'EDIT_REPORT';

export function reportEditor(report) {
Expand Down
13 changes: 12 additions & 1 deletion superset-frontend/src/reports/reducers/reportState.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
*/
/* eslint-disable camelcase */
import { alterInArr } from 'src/reduxUtils';
import { SET_REPORT, EDIT_REPORT, TOGGLE_ACTIVE } from '../actions/reportState';
import {
SET_REPORT,
ADD_REPORT,
EDIT_REPORT,
TOGGLE_ACTIVE,
} from '../actions/reportState';

export default function reportStateReducer(state = {}, action) {
const actionHandlers = {
Expand All @@ -28,6 +33,12 @@ export default function reportStateReducer(state = {}, action) {
report: action.report,
};
},
[ADD_REPORT]() {
return {
...state,
report: action.report,
};
},
[EDIT_REPORT]() {
return {
...state,
Expand Down