eschutho commented on a change in pull request #18131:
URL: https://github.com/apache/superset/pull/18131#discussion_r806343673
##########
File path:
superset-frontend/src/components/ReportModal/HeaderReportDropdown/index.tsx
##########
@@ -147,61 +135,61 @@ export default function HeaderReportActionsDropDown({
</Menu.Item>
</Menu>
);
-
return (
- canAddReports() && (
- <>
- <ReportModal
- userId={user.userId}
- showModal={showModal}
- onHide={() => setShowModal(false)}
- userEmail={user.email}
- dashboardId={dashboardId}
- chart={chart}
- />
- {report ? (
- <>
- <NoAnimationDropdown
- // ref={ref}
- overlay={menu()}
- trigger={['click']}
- getPopupContainer={(triggerNode: any) =>
- triggerNode.closest('.action-button')
- }
+ <>
+ {canAddReports() && (
Review comment:
since this is a functional component we can probably make this a prop
instead of a method. We can fix this on the merge to master PR.
##########
File path: superset-frontend/src/components/ReportModal/index.tsx
##########
@@ -307,6 +283,13 @@ const ReportModal: FunctionComponent<ReportProps> = ({
</>
);
+ const renderErrorMessage = () => {
+ if (currentReport?.error) {
+ return errorMapping[currentReport.error] || currentReport?.error;
+ }
+ return currentReport?.error;
Review comment:
if 287 is false, would this also be falsy/null/undefined? Should we just
return nothing?
##########
File path: superset-frontend/src/components/ReportModal/index.tsx
##########
@@ -330,7 +313,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
value: target.value,
}),
}}
- errorMessage={currentReport?.error || ''}
+ errorMessage={renderErrorMessage() || ''}
Review comment:
another example where this could probably be a static property/const
rather than method.
##########
File path: superset-frontend/src/reports/reducers/reports.js
##########
@@ -18,74 +18,33 @@
*/
/* eslint-disable camelcase */
// eslint-disable-next-line import/no-extraneous-dependencies
-import { report } from 'process';
-import {
- SET_REPORT,
- ADD_REPORT,
- EDIT_REPORT,
- DELETE_REPORT,
-} from '../actions/reports';
-
-/* -- Report schema --
-reports: {
- dashboards: {
- [dashboardId]: {...reportObject}
- },
- charts: {
- [chartId]: {...reportObject}
- },
-}
-*/
+import { SET_REPORT, ADD_REPORT, EDIT_REPORT } from '../actions/reports';
export default function reportsReducer(state = {}, action) {
const actionHandlers = {
[SET_REPORT]() {
- // Grabs the first report with a dashboard id that
- // matches the parameter report's dashboard_id
- const reportWithDashboard = action.report.result?.find(
- report => !!report.dashboard_id,
- );
- // Grabs the first report with a chart id that
- // matches the parameter report's chart.id
- const reportWithChart = action.report.result?.find(
- report => !!report.chart?.id,
- );
+ const { report, resourceId, creationMethod } = action;
+
+ const reportObject = report.result?.find(report => !!report[resourceId]);
- // This organizes report by its type, dashboard or chart
- // and indexes it by the dashboard/chart id
- if (reportWithDashboard) {
- return {
- ...state,
- dashboards: {
- ...state.dashboards,
- [reportWithDashboard.dashboard_id]: reportWithDashboard,
- },
- };
- }
- if (reportWithChart) {
- return {
- ...state,
- charts: {
- ...state.chart,
- [reportWithChart.chart.id]: reportWithChart,
- },
- };
- }
return {
...state,
+ [creationMethod]: {
+ ...state[creationMethod],
+ [resourceId]: reportObject,
+ },
Review comment:
this looks much better!
##########
File path: superset-frontend/src/reports/reducers/reports.js
##########
@@ -94,7 +53,7 @@ export default function reportsReducer(state = {}, action) {
...state,
charts: {
...state.chart,
- [report.id]: report,
+ [result.chart]: report,
Review comment:
can we do the same thing with these actions where we dry up some of the
code to look up the chart or dashboard like above? Maybe in the next PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]