eschutho commented on a change in pull request #15785:
URL: https://github.com/apache/superset/pull/15785#discussion_r672638006
##########
File path: superset-frontend/src/dashboard/components/Header/index.jsx
##########
@@ -52,8 +58,7 @@ const propTypes = {
addSuccessToast: PropTypes.func.isRequired,
addDangerToast: PropTypes.func.isRequired,
addWarningToast: PropTypes.func.isRequired,
- userId: PropTypes.number,
- userEmail: PropTypes.string,
+ user: PropTypes.object,
Review comment:
has a user type been defined yet?
##########
File path: superset-frontend/src/dashboard/components/Header/index.jsx
##########
@@ -365,6 +374,55 @@ class Header extends React.PureComponent {
this.setState({ showingReportModal: false });
}
+ handleReportModalclick() {
+ const attachedReportExists = this.state.attachedReports.count > 0;
+ if (!attachedReportExists) {
+ this.showReportModal();
+ }
+ }
+
+ canAddReportsModal() {
+ if (!this.props.user) {
+ // this is in the case that there is an anonymous user.
+ return false;
+ }
+ const roles = Object.keys(this.props.user?.roles);
+ const permissions = roles.map(key =>
+ this.props.user.roles[key].filter(
+ perms => perms[0] === 'can_add' && perms[1] === 'AlertModelView',
+ ),
+ );
+ return permissions[0].length > 0;
+ }
+
+ fetchDashboardReport = async () => {
Review comment:
I'd suggest making this a redux action.
##########
File path: superset-frontend/src/dashboard/components/Header/index.jsx
##########
@@ -365,6 +374,55 @@ class Header extends React.PureComponent {
this.setState({ showingReportModal: false });
}
+ handleReportModalclick() {
+ const attachedReportExists = this.state.attachedReports.count > 0;
+ if (!attachedReportExists) {
+ this.showReportModal();
+ }
+ }
+
+ canAddReportsModal() {
+ if (!this.props.user) {
+ // this is in the case that there is an anonymous user.
+ return false;
+ }
+ const roles = Object.keys(this.props.user?.roles);
+ const permissions = roles.map(key =>
+ this.props.user.roles[key].filter(
+ perms => perms[0] === 'can_add' && perms[1] === 'AlertModelView',
+ ),
+ );
+ return permissions[0].length > 0;
+ }
+
+ fetchDashboardReport = async () => {
Review comment:
better yet if it's reusable for fetching charts.
##########
File path: superset-frontend/src/dashboard/components/Header/index.jsx
##########
@@ -394,10 +451,10 @@ class Header extends React.PureComponent {
setRefreshFrequency,
lastModifiedTime,
} = this.props;
-
const userCanEdit = dashboardInfo.dash_edit_perm;
const userCanShare = dashboardInfo.dash_share_perm;
const userCanSaveAs = dashboardInfo.dash_save_perm;
+ const canAccesReportsModal = !editMode && this.canAddReportsModal();
Review comment:
I would use something like "shouldShow..." instead of "canAccess".. the
latter has more of a connotation around permissions, which they could have
permissions to see it, just they're in the wrong mode.
##########
File path: superset-frontend/src/dashboard/components/Header/index.jsx
##########
@@ -52,8 +58,7 @@ const propTypes = {
addSuccessToast: PropTypes.func.isRequired,
addDangerToast: PropTypes.func.isRequired,
addWarningToast: PropTypes.func.isRequired,
- userId: PropTypes.number,
- userEmail: PropTypes.string,
+ user: PropTypes.object,
Review comment:
Actually, this isn't tsx, so we can hold off.
--
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]