-
Notifications
You must be signed in to change notification settings - Fork 11.7k
/
OrgDetailsPage.tsx
87 lines (76 loc) · 2.96 KB
/
OrgDetailsPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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 { appEvents, contextSrv } from 'app/core/core';
import { getNavModel } from 'app/core/selectors/navModel';
import { AccessControlAction, Organization, StoreState } from 'app/types';
import { ShowConfirmModalEvent } from 'app/types/events';
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<Props> {
async componentDidMount() {
await this.props.loadOrganization();
}
onUpdateOrganization = (orgName: string) => {
this.props.setOrganizationName(orgName);
this.props.updateOrganization();
};
handleConfirm = () => {
return new Promise<boolean>((resolve) => {
appEvents.publish(
new ShowConfirmModalEvent({
title: 'Confirm preferences update',
text: 'This will update the preferences for the whole organization. Are you sure you want to update the preferences?',
yesText: 'Save',
yesButtonVariant: 'primary',
onConfirm: async () => resolve(true),
onDismiss: async () => resolve(false),
})
);
});
};
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 (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
{!isLoading && (
<VerticalGroup spacing="lg">
{canReadOrg && <OrgProfile onSubmit={this.onUpdateOrganization} orgName={organization.name} />}
{canReadPreferences && (
<SharedPreferences resourceUri="org" disabled={!canWritePreferences} onConfirm={this.handleConfirm} />
)}
</VerticalGroup>
)}
</Page.Contents>
</Page>
);
}
}
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);