OrgDetailsPage.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { NavModel } from '@grafana/data';
  4. import { VerticalGroup } from '@grafana/ui';
  5. import Page from 'app/core/components/Page/Page';
  6. import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
  7. import { contextSrv } from 'app/core/core';
  8. import { getNavModel } from 'app/core/selectors/navModel';
  9. import { AccessControlAction, Organization, StoreState } from 'app/types';
  10. import OrgProfile from './OrgProfile';
  11. import { loadOrganization, updateOrganization } from './state/actions';
  12. import { setOrganizationName } from './state/reducers';
  13. export interface Props {
  14. navModel: NavModel;
  15. organization: Organization;
  16. loadOrganization: typeof loadOrganization;
  17. setOrganizationName: typeof setOrganizationName;
  18. updateOrganization: typeof updateOrganization;
  19. }
  20. export class OrgDetailsPage extends PureComponent<Props> {
  21. async componentDidMount() {
  22. await this.props.loadOrganization();
  23. }
  24. onUpdateOrganization = (orgName: string) => {
  25. this.props.setOrganizationName(orgName);
  26. this.props.updateOrganization();
  27. };
  28. render() {
  29. const { navModel, organization } = this.props;
  30. const isLoading = Object.keys(organization).length === 0;
  31. const canReadOrg = contextSrv.hasPermission(AccessControlAction.OrgsRead);
  32. const canReadPreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesRead);
  33. const canWritePreferences = contextSrv.hasPermission(AccessControlAction.OrgsPreferencesWrite);
  34. return (
  35. <Page navModel={navModel}>
  36. <Page.Contents isLoading={isLoading}>
  37. {!isLoading && (
  38. <VerticalGroup spacing="lg">
  39. {canReadOrg && <OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />}
  40. {canReadPreferences && <SharedPreferences resourceUri="org" disabled={!canWritePreferences} />}
  41. </VerticalGroup>
  42. )}
  43. </Page.Contents>
  44. </Page>
  45. );
  46. }
  47. }
  48. function mapStateToProps(state: StoreState) {
  49. return {
  50. navModel: getNavModel(state.navIndex, 'org-settings'),
  51. organization: state.organization.organization,
  52. };
  53. }
  54. const mapDispatchToProps = {
  55. loadOrganization,
  56. setOrganizationName,
  57. updateOrganization,
  58. };
  59. export default connect(mapStateToProps, mapDispatchToProps)(OrgDetailsPage);