grafana/public/app/features/org/OrgDetailsPage.tsx

66 lines
2.0 KiB
TypeScript
Raw Normal View History

2018-10-25 00:45:22 -05:00
import React, { PureComponent } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
import { NavModel } from '@grafana/data';
import Page from 'app/core/components/Page/Page';
2018-10-25 09:56:49 -05:00
import OrgProfile from './OrgProfile';
import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
import { loadOrganization, updateOrganization } from './state/actions';
import { Organization, StoreState } from 'app/types';
import { getNavModel } from 'app/core/selectors/navModel';
import { setOrganizationName } from './state/reducers';
import { VerticalGroup } from '@grafana/ui';
2018-10-25 00:45:22 -05:00
export interface Props {
navModel: NavModel;
2018-10-25 09:56:49 -05:00
organization: Organization;
loadOrganization: typeof loadOrganization;
2018-10-26 07:15:37 -05:00
setOrganizationName: typeof setOrganizationName;
updateOrganization: typeof updateOrganization;
2018-10-25 00:45:22 -05:00
}
2018-10-26 07:15:37 -05:00
export class OrgDetailsPage extends PureComponent<Props> {
2018-10-25 00:45:22 -05:00
async componentDidMount() {
2018-10-26 07:15:37 -05:00
await this.props.loadOrganization();
2018-10-25 00:45:22 -05:00
}
onUpdateOrganization = (orgName: string) => {
this.props.setOrganizationName(orgName);
this.props.updateOrganization();
};
2018-10-25 00:45:22 -05:00
2018-10-25 09:56:49 -05:00
render() {
const { navModel, organization } = this.props;
const isLoading = Object.keys(organization).length === 0;
2018-10-25 00:45:22 -05:00
return (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
{!isLoading && (
<VerticalGroup>
<OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />
<SharedPreferences resourceUri="org" />
</VerticalGroup>
)}
</Page.Contents>
</Page>
2018-10-25 00:45:22 -05:00
);
}
}
function mapStateToProps(state: StoreState) {
return {
navModel: getNavModel(state.navIndex, 'org-settings'),
2018-10-26 07:15:37 -05:00
organization: state.organization.organization,
2018-10-25 00:45:22 -05:00
};
}
const mapDispatchToProps = {
2018-10-25 09:56:49 -05:00
loadOrganization,
2018-10-26 07:15:37 -05:00
setOrganizationName,
updateOrganization,
2018-10-25 00:45:22 -05:00
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(OrgDetailsPage));