import React, { PureComponent } from 'react'; import { connect } from 'react-redux'; import { NavModel } from '@grafana/data'; import { VerticalGroup } from '@grafana/ui'; import Page from 'app/core/components/Page/Page'; import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences'; import { contextSrv } from 'app/core/core'; import { getNavModel } from 'app/core/selectors/navModel'; import { AccessControlAction, Organization, StoreState } from 'app/types'; import OrgProfile from './OrgProfile'; import { loadOrganization, updateOrganization } from './state/actions'; import { setOrganizationName } from './state/reducers'; export interface Props { navModel: NavModel; organization: Organization; loadOrganization: typeof loadOrganization; setOrganizationName: typeof setOrganizationName; updateOrganization: typeof updateOrganization; } export class OrgDetailsPage extends PureComponent { async componentDidMount() { await this.props.loadOrganization(); } onUpdateOrganization = (orgName: string) => { this.props.setOrganizationName(orgName); this.props.updateOrganization(); }; render() { const { navModel, organization } = this.props; const isLoading = Object.keys(organization).length === 0; const canReadOrg = contextSrv.hasPermission(AccessControlAction.OrgsRead); const canReadPreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesRead); const canWritePreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesWrite); return ( {!isLoading && ( {canReadOrg && } {canReadPreferences && } )} ); } } function mapStateToProps(state: StoreState) { return { navModel: getNavModel(state.navIndex, 'org-settings'), organization: state.organization.organization, }; } const mapDispatchToProps = { loadOrganization, setOrganizationName, updateOrganization, }; export default connect(mapStateToProps, mapDispatchToProps)(OrgDetailsPage);