Skip to content

Commit

Permalink
refactor: Arash/new state report (apache#16987)
Browse files Browse the repository at this point in the history
* code dry (apache#16358)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor(reports): Arash/refactor reports (apache#16855)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* report pickup

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* refactor(reports):  Arash/again refactor reports (apache#16872)

* pexdax refactor (apache#16333)

* refactor progress (apache#16339)

* fix: Header Actions test refactor (apache#16336)

* fixed tests

* Update index.tsx

Co-authored-by: Elizabeth Thompson <[email protected]>

* code dry (apache#16358)

* Fetch bug fixed (apache#16376)

* continued refactoring (apache#16377)

* refactor: Reports - ReportModal (apache#16622)

* refactoring progress

* removed consoles

* Working, but with 2 fetches

* it is still not working

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>

* next changes

Co-authored-by: Lyndsi Kay Williams <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
  • Loading branch information
3 people committed May 9, 2022
1 parent e8ec94d commit 3904e6b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 47 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 Down Expand Up @@ -50,19 +50,23 @@ export default function HeaderReportActionsDropDown({
const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
state => state.reports,
);
const report: AlertObject = Object.values(reports).filter(report => {
if (dashboardId) {
return report.dashboard_id === dashboardId;
}
return report.chart_id === chart?.id;
})[0];

const user: UserWithPermissionsAndRoles = useSelector<
any,
UserWithPermissionsAndRoles
>(state => state.user || state.explore?.user);
const reportsIds = Object.keys(reports || []);
const report: AlertObject = reports?.[reportsIds[0]];
const [
currentReportDeleting,
setCurrentReportDeleting,
] = useState<AlertObject | null>(null);
const theme = useTheme();
const [showModal, setShowModal] = useState(false);
const dashboardIdRef = useRef(dashboardId);
const [showModal, setShowModal] = useState<boolean>(false);
const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
if (data?.id) {
toggleActive(data, checked);
Expand Down Expand Up @@ -105,17 +109,13 @@ export default function HeaderReportActionsDropDown({
}, []);

useEffect(() => {
if (
canAddReports() &&
dashboardId &&
dashboardId !== dashboardIdRef.current
) {
if (canAddReports()) {
dispatch(
fetchUISpecificReport({
userId: user.userId,
filterField: 'dashboard_id',
creationMethod: 'dashboards',
resourceId: dashboardId,
filterField: dashboardId ? 'dashboard_id' : 'chart_id',
creationMethod: dashboardId ? 'dashboards' : 'charts',
resourceId: dashboardId || chart?.id,
}),
);
}
Expand Down Expand Up @@ -149,14 +149,14 @@ export default function HeaderReportActionsDropDown({
canAddReports() && (
<>
<ReportModal
show={showModal}
onHide={() => setShowModal(false)}
userId={user.userId}
showModal={showModal}
onHide={() => setShowModal(false)}
userEmail={user.email}
dashboardId={dashboardId}
chart={chart}
/>
{report ? (
{reports ? (
<>
<NoAnimationDropdown
// ref={ref}
Expand Down
24 changes: 0 additions & 24 deletions superset-frontend/src/components/ReportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ import withToasts from 'src/components/MessageToasts/withToasts';
import { CronError } from 'src/components/CronPicker';
import { RadioChangeEvent } from 'src/components';
import { ChartState } from 'src/explore/types';
<<<<<<< HEAD
import {
ReportCreationMethod,
ReportRecipientType,
ReportScheduleType,
} from 'src/reports/types';
=======
>>>>>>> code dry (#16358)
import {
antDErrorAlertStyles,
StyledModal,
Expand Down Expand Up @@ -134,7 +131,6 @@ const ReportModal: FunctionComponent<ReportProps> = ({
chart,
userId,
userEmail,
<<<<<<< HEAD
creationMethod,
...props
}) => {
Expand Down Expand Up @@ -173,22 +169,6 @@ const ReportModal: FunctionComponent<ReportProps> = ({
reportReducer,
initialState,
);
=======
props,
}) => {
const vizType = chart?.sliceFormData?.viz_type;
const isChart = !!chart;
const defaultNotificationFormat =
vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType)
? NOTIFICATION_FORMATS.TEXT
: NOTIFICATION_FORMATS.PNG;
const [currentReport, setCurrentReport] = useReducer<
Reducer<Partial<ReportObject> | null, ReportActionType>
>(reportReducer, null);
const onReducerChange = useCallback((type: any, payload: any) => {
setCurrentReport({ type, payload });
}, []);
>>>>>>> code dry (#16358)
const [cronError, setCronError] = useState<CronError>();

const dispatch = useDispatch();
Expand Down Expand Up @@ -285,11 +265,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
}}
value={currentReport.report_format || defaultNotificationFormat}
>
<<<<<<< HEAD
{isTextBasedChart && (
=======
{vizType && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) && (
>>>>>>> code dry (#16358)
<StyledRadio value={NOTIFICATION_FORMATS.TEXT}>
{t('Text embedded in email')}
</StyledRadio>
Expand Down
8 changes: 1 addition & 7 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ class Header extends React.PureComponent {
this.startPeriodicRender(refreshFrequency * 1000);
}

componentDidUpdate(prevProps) {
if (this.props.refreshFrequency !== prevProps.refreshFrequency) {
const { refreshFrequency } = this.props;
this.startPeriodicRender(refreshFrequency * 1000);
}
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (
UNDO_LIMIT - nextProps.undoLength <= 0 &&
Expand Down Expand Up @@ -554,6 +547,7 @@ class Header extends React.PureComponent {
</span>
)}
<HeaderReportActionsDropdown
key={dashboardInfo.id}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
dashboardId={dashboardInfo.id}
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/reports/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
/* eslint-disable camelcase */
import { SET_REPORT, ADD_REPORT, EDIT_REPORT } from '../actions/reports';

// Talk about the delete

export default function reportsReducer(state = {}, action) {
const actionHandlers = {
[SET_REPORT]() {
return {
...state,
...action.report.result.reduce(
(obj, report) => ({ ...obj, [report.id]: report }),
{},
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/views/CRUD/alert/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export type AlertObject = {
chart?: MetaObject;
changed_by?: user;
changed_on_delta_humanized?: string;
chart_id: number;
created_by?: user;
created_on?: string;
crontab?: string;
dashboard?: MetaObject;
dashboard_id?: number;
database?: MetaObject;
description?: string;
force_screenshot: boolean;
Expand Down
2 changes: 2 additions & 0 deletions superset/reports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ def ensure_alert_reports_enabled(self) -> Optional[Response]:
"changed_by.last_name",
"changed_on",
"changed_on_delta_humanized",
"chart_id",
"created_by.first_name",
"created_by.last_name",
"created_on",
"creation_method",
"crontab",
"crontab_humanized",
"dashboard_id",
"description",
"id",
"last_eval_dttm",
Expand Down

0 comments on commit 3904e6b

Please sign in to comment.