This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a commit to branch refactorReports
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/refactorReports by this push:
new 88000cd Arash/refactor (#17548)
88000cd is described below
commit 88000cd529cccc4f9a35bf1221efc5f486b8c57e
Author: AAfghahi <[email protected]>
AuthorDate: Mon Nov 29 14:42:12 2021 -0700
Arash/refactor (#17548)
* pexdax refactor (#16333)
* refactor progress (#16339)
* fix: Header Actions test refactor (#16336)
* fixed tests
* Update index.tsx
Co-authored-by: Elizabeth Thompson <[email protected]>
* code dry (#16358)
* Fetch bug fixed (#16376)
* continued refactoring (#16377)
* pexdax refactor (#16333)
* refactor progress (#16339)
* fix: Header Actions test refactor (#16336)
* fixed tests
* Update index.tsx
Co-authored-by: Elizabeth Thompson <[email protected]>
* code dry (#16358)
* Fetch bug fixed (#16376)
* continued refactoring (#16377)
* refactor: Arash/new state report (#16987)
* code dry (#16358)
* pexdax refactor (#16333)
* refactor progress (#16339)
* fix: Header Actions test refactor (#16336)
* fixed tests
* Update index.tsx
Co-authored-by: Elizabeth Thompson <[email protected]>
* Fetch bug fixed (#16376)
* continued refactoring (#16377)
* refactor(reports): Arash/refactor reports (#16855)
* pexdax refactor (#16333)
* refactor progress (#16339)
* fix: Header Actions test refactor (#16336)
* fixed tests
* Update index.tsx
Co-authored-by: Elizabeth Thompson <[email protected]>
* code dry (#16358)
* Fetch bug fixed (#16376)
* continued refactoring (#16377)
* refactor: Reports - ReportModal (#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 (#16872)
* pexdax refactor (#16333)
* refactor progress (#16339)
* fix: Header Actions test refactor (#16336)
* fixed tests
* Update index.tsx
Co-authored-by: Elizabeth Thompson <[email protected]>
* code dry (#16358)
* Fetch bug fixed (#16376)
* continued refactoring (#16377)
* refactor: Reports - ReportModal (#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]>
* refactor: Reports code clean 10-29 (#17424)
* Add delete functionality
* Report schema restructure progress
* Fix lint
* Removed console.log
* added report state
Co-authored-by: Lyndsi Kay Williams
<[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
---
.../HeaderReportActionsDropdown/index.tsx | 28 +++++----
.../src/dashboard/components/Header/index.jsx | 70 +---------------------
superset-frontend/src/reports/reducers/reports.js | 20 ++++---
3 files changed, 30 insertions(+), 88 deletions(-)
diff --git
a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
index 32d4469..b9de984 100644
---
a/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
+++
b/superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
@@ -25,8 +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 { ChartState } from 'src/explore/types';
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';
@@ -46,24 +46,28 @@ export default function HeaderReportActionsDropDown({
chart?: ChartState;
}) {
const dispatch = useDispatch();
- const reports: Record<number, AlertObject> = useSelector<any, AlertObject>(
- state => state.reports,
- );
- const report: AlertObject = Object.values(reports).filter(report => {
+ const report: AlertObject = useSelector<any, AlertObject>(state => {
if (dashboardId) {
- return report.dashboard_id === dashboardId;
+ return state.reports.dashboards?.[dashboardId];
+ }
+ if (chart?.id) {
+ return state.reports.charts?.[chart.id];
}
- return report.chart_id === chart?.id;
- })[0];
+ return {};
+ });
+ // const report: ReportObject = Object.values(reports).filter(report => {
+ // if (dashboardId) {
+ // return report.dashboards?.[dashboardId];
+ // }
+ // // return report.charts?.[chart?.id]
+ // })[0];
const user: UserWithPermissionsAndRoles = useSelector<
any,
UserWithPermissionsAndRoles
>(state => state.user || state.explore?.user);
- const [
- currentReportDeleting,
- setCurrentReportDeleting,
- ] = useState<AlertObject | null>(null);
+ const [currentReportDeleting, setCurrentReportDeleting] =
+ useState<AlertObject | null>(null);
const theme = useTheme();
const [showModal, setShowModal] = useState<boolean>(false);
const toggleActiveKey = async (data: AlertObject, checked: boolean) => {
diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx
b/superset-frontend/src/dashboard/components/Header/index.jsx
index 1ddf4a1..ad7851f 100644
--- a/superset-frontend/src/dashboard/components/Header/index.jsx
+++ b/superset-frontend/src/dashboard/components/Header/index.jsx
@@ -166,21 +166,6 @@ class Header extends React.PureComponent {
componentDidMount() {
const { refreshFrequency } = this.props;
this.startPeriodicRender(refreshFrequency * 1000);
-<<<<<<< HEAD
-<<<<<<< HEAD
-=======
- if (this.canAddReports()) {
- // this is in case there is an anonymous user.
- this.props.fetchUISpecificReport(
- user.userId,
- 'dashboard_id',
- 'dashboards',
- dashboardInfo.id,
- );
- }
->>>>>>> refactor progress (#16339)
-=======
->>>>>>> code dry (#16358)
}
UNSAFE_componentWillReceiveProps(nextProps) {
@@ -197,24 +182,6 @@ class Header extends React.PureComponent {
) {
this.props.setMaxUndoHistoryExceeded();
}
-<<<<<<< HEAD
-<<<<<<< HEAD
-=======
- if (
- this.canAddReports() &&
- nextProps.dashboardInfo.id !== this.props.dashboardInfo.id
- ) {
- // this is in case there is an anonymous user.
- this.props.fetchUISpecificReport(
- user.userId,
- 'dashboard_id',
- 'dashboards',
- nextProps.dashboardInfo.id,
- );
- }
->>>>>>> refactor progress (#16339)
-=======
->>>>>>> code dry (#16358)
}
componentWillUnmount() {
@@ -396,36 +363,6 @@ class Header extends React.PureComponent {
this.setState({ showingPropertiesModal: false });
}
-<<<<<<< HEAD
-<<<<<<< HEAD
- showReportModal() {
- this.setState({ showingReportModal: true });
- }
-
- hideReportModal() {
- this.setState({ showingReportModal: false });
-=======
- canAddReports() {
- if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
- return false;
- }
- const { user } = this.props;
- if (!user) {
- // this is in the case that there is an anonymous user.
- return false;
- }
- const roles = Object.keys(user.roles || []);
- const permissions = roles.map(key =>
- user.roles[key].filter(
- perms => perms[0] === 'menu_access' && perms[1] === 'Manage',
- ),
- );
- return permissions[0].length > 0;
->>>>>>> refactor progress (#16339)
- }
-
-=======
->>>>>>> code dry (#16358)
render() {
const {
dashboardTitle,
@@ -590,7 +527,6 @@ class Header extends React.PureComponent {
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
dashboardId={dashboardInfo.id}
- showReportModal={this.showReportModal}
/>
</>
)}
@@ -602,10 +538,8 @@ 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),
diff --git a/superset-frontend/src/reports/reducers/reports.js
b/superset-frontend/src/reports/reducers/reports.js
index de23f57..a18d72e 100644
--- a/superset-frontend/src/reports/reducers/reports.js
+++ b/superset-frontend/src/reports/reducers/reports.js
@@ -43,14 +43,13 @@ export default function reportsReducer(state = {}, action) {
[SET_REPORT]() {
// Grabs the first report with a dashboard id that
// matches the parameter report's dashboard_id
- const reportWithDashboard = action.report.result.find(
+ 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 reportWithChart = action.report.result?.find(
+ report => !!report.chart?.id,
);
// This organizes report by its type, dashboard or chart
@@ -64,12 +63,17 @@ export default function reportsReducer(state = {}, action) {
},
};
}
+ if (reportWithChart) {
+ return {
+ ...state,
+ charts: {
+ ...state.chart,
+ [reportWithChart.chart.id]: reportWithChart,
+ },
+ };
+ }
return {
...state,
- charts: {
- ...state.chart,
- [reportWithChart.chart.id]: reportWithChart,
- },
};
},