Skip to content

Commit

Permalink
Arash/refactor (#17548)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 29, 2021
1 parent 150cb81 commit 88000cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) => {
Expand Down
70 changes: 2 additions & 68 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -590,7 +527,6 @@ class Header extends React.PureComponent {
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
dashboardId={dashboardInfo.id}
showReportModal={this.showReportModal}
/>
</>
)}
Expand All @@ -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),
Expand Down
20 changes: 12 additions & 8 deletions superset-frontend/src/reports/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
};
},

Expand Down

0 comments on commit 88000cd

Please sign in to comment.