betodealmeida commented on a change in pull request #15898:
URL: https://github.com/apache/superset/pull/15898#discussion_r678480145
##########
File path: superset-frontend/src/explore/components/ExploreChartHeader.jsx
##########
@@ -141,8 +159,47 @@ export class ExploreChartHeader extends
React.PureComponent {
this.setState({ showingReportModal: false });
}
+ renderReportModal() {
+ const attachedReportExists = this.props.report?.count > 0;
+ return attachedReportExists ? (
+ <HeaderReportActionsDropdown
+ showReportModal={this.showReportModal}
+ hideReportModal={this.hideReportModal}
+ toggleActive={this.props.toggleActive}
+ />
+ ) : (
+ <>
+ <span
+ role="button"
+ title={t('Schedule email report')}
+ tabIndex={0}
+ className="action-button"
+ onClick={this.showReportModal}
+ >
+ <Icons.Calendar />
+ </span>
+ </>
+ );
+ }
+
+ canAddReports() {
+ 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] === 'can_add' && perms[1] === 'AlertModelView',
+ ),
+ );
+ return this.props.report && permissions[0].length > 0;
+ }
+
render() {
const formData = this.props.form_data;
+ const { user } = this.props;
Review comment:
```suggestion
const { user, form_data: formData } = this.props;
```
##########
File path: superset-frontend/src/explore/components/ExploreChartHeader.jsx
##########
@@ -107,6 +112,19 @@ export class ExploreChartHeader extends
React.PureComponent {
this.hideReportModal = this.hideReportModal.bind(this);
}
+ componentDidMount() {
+ const { user, chart } = this.props;
+ if (user) {
+ // handles anonymous user.
Review comment:
```suggestion
```
This comment is incorrect, right? The code handles an existing user.
--
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]