Chore: convert settings page to function component (#43731)

This commit is contained in:
Ryan McKinley 2022-01-07 08:59:14 -08:00 committed by GitHub
parent a30ca86084
commit 8cf63a9d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 60 deletions

View File

@ -1,4 +1,4 @@
import React, { FC, useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import Page from 'app/core/components/Page/Page'; import Page from 'app/core/components/Page/Page';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { StoreState, OrgUser, AccessControlAction } from 'app/types'; import { StoreState, OrgUser, AccessControlAction } from 'app/types';
@ -37,7 +37,7 @@ const removeOrgUser = async (orgUser: OrgUser, orgId: UrlQueryValue) => {
interface Props extends GrafanaRouteComponentProps<{ id: string }> {} interface Props extends GrafanaRouteComponentProps<{ id: string }> {}
export const AdminEditOrgPage: FC<Props> = ({ match }) => { export default function AdminEditOrgPage({ match }: Props) {
const navIndex = useSelector((state: StoreState) => state.navIndex); const navIndex = useSelector((state: StoreState) => state.navIndex);
const navModel = getNavModel(navIndex, 'global-orgs'); const navModel = getNavModel(navIndex, 'global-orgs');
const orgId = parseInt(match.params.id, 10); const orgId = parseInt(match.params.id, 10);
@ -123,6 +123,4 @@ export const AdminEditOrgPage: FC<Props> = ({ match }) => {
</Page.Contents> </Page.Contents>
</Page> </Page>
); );
}; }
export default AdminEditOrgPage;

View File

@ -1,4 +1,4 @@
import React, { FC, useEffect } from 'react'; import React, { useEffect } from 'react';
import { getNavModel } from 'app/core/selectors/navModel'; import { getNavModel } from 'app/core/selectors/navModel';
import Page from 'app/core/components/Page/Page'; import Page from 'app/core/components/Page/Page';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
@ -22,7 +22,7 @@ const getErrorMessage = (error: any) => {
return error?.data?.message || 'An unexpected error happened.'; return error?.data?.message || 'An unexpected error happened.';
}; };
export const AdminListOrgsPages: FC = () => { export default function AdminListOrgsPages() {
const navIndex = useSelector((state: StoreState) => state.navIndex); const navIndex = useSelector((state: StoreState) => state.navIndex);
const navModel = getNavModel(navIndex, 'global-orgs'); const navModel = getNavModel(navIndex, 'global-orgs');
const [state, fetchOrgs] = useAsyncFn(async () => await getOrgs(), []); const [state, fetchOrgs] = useAsyncFn(async () => await getOrgs(), []);
@ -56,6 +56,4 @@ export const AdminListOrgsPages: FC = () => {
</Page.Contents> </Page.Contents>
</Page> </Page>
); );
}; }
export default AdminListOrgsPages;

View File

@ -1,4 +1,4 @@
import React, { FC, useState } from 'react'; import React, { useState } from 'react';
import { AccessControlAction, Organization } from 'app/types'; import { AccessControlAction, Organization } from 'app/types';
import { Button, ConfirmModal } from '@grafana/ui'; import { Button, ConfirmModal } from '@grafana/ui';
import { contextSrv } from 'app/core/core'; import { contextSrv } from 'app/core/core';
@ -8,7 +8,7 @@ interface Props {
onDelete: (orgId: number) => void; onDelete: (orgId: number) => void;
} }
export const AdminOrgsTable: FC<Props> = ({ orgs, onDelete }) => { export function AdminOrgsTable({ orgs, onDelete }: Props) {
const canDeleteOrgs = contextSrv.hasPermission(AccessControlAction.OrgsDelete); const canDeleteOrgs = contextSrv.hasPermission(AccessControlAction.OrgsDelete);
const [deleteOrg, setDeleteOrg] = useState<Organization>(); const [deleteOrg, setDeleteOrg] = useState<Organization>();
@ -64,4 +64,4 @@ export const AdminOrgsTable: FC<Props> = ({ orgs, onDelete }) => {
)} )}
</table> </table>
); );
}; }

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { useAsync } from 'react-use';
import { getBackendSrv } from '@grafana/runtime'; import { getBackendSrv } from '@grafana/runtime';
import { NavModel } from '@grafana/data'; import { NavModel } from '@grafana/data';
@ -13,37 +14,21 @@ interface Props {
navModel: NavModel; navModel: NavModel;
} }
interface State { function AdminSettings({ navModel }: Props) {
settings: Settings; const { loading, value: settings } = useAsync(
isLoading: boolean; () => getBackendSrv().get('/api/admin/settings') as Promise<Settings>,
} []
);
export class AdminSettings extends React.PureComponent<Props, State> { return (
state: State = { <Page navModel={navModel}>
settings: {}, <Page.Contents isLoading={loading}>
isLoading: true, <div className="grafana-info-box span8" style={{ margin: '20px 0 25px 0' }}>
}; These system settings are defined in grafana.ini or custom.ini (or overridden in ENV variables). To change
these you currently need to restart Grafana.
async componentDidMount() { </div>
const settings: Settings = await getBackendSrv().get('/api/admin/settings');
this.setState({
settings,
isLoading: false,
});
}
render() {
const { settings, isLoading } = this.state;
const { navModel } = this.props;
return (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
<div className="grafana-info-box span8" style={{ margin: '20px 0 25px 0' }}>
These system settings are defined in grafana.ini or custom.ini (or overridden in ENV variables). To change
these you currently need to restart Grafana.
</div>
{settings && (
<table className="filter-table"> <table className="filter-table">
<tbody> <tbody>
{Object.entries(settings).map(([sectionName, sectionSettings], i) => ( {Object.entries(settings).map(([sectionName, sectionSettings], i) => (
@ -62,10 +47,10 @@ export class AdminSettings extends React.PureComponent<Props, State> {
))} ))}
</tbody> </tbody>
</table> </table>
</Page.Contents> )}
</Page> </Page.Contents>
); </Page>
} );
} }
const mapStateToProps = (state: StoreState) => ({ const mapStateToProps = (state: StoreState) => ({

View File

@ -32,9 +32,10 @@ interface Props {
header: string; header: string;
subheader?: string; subheader?: string;
editionNotice?: string; editionNotice?: string;
children?: React.ReactNode;
} }
export const LicenseChrome: React.FC<Props> = ({ header, editionNotice, subheader, children }) => { export function LicenseChrome({ header, editionNotice, subheader, children }: Props) {
const theme = useTheme(); const theme = useTheme();
const styles = getStyles(theme); const styles = getStyles(theme);
@ -68,7 +69,7 @@ export const LicenseChrome: React.FC<Props> = ({ header, editionNotice, subheade
{editionNotice && <div className={styles.footer}>{editionNotice}</div>} {editionNotice && <div className={styles.footer}>{editionNotice}</div>}
</> </>
); );
}; }
interface CircleProps { interface CircleProps {
size: string; size: string;

View File

@ -1,4 +1,4 @@
import React, { FC } from 'react'; import React from 'react';
import { OrgRole } from '@grafana/data'; import { OrgRole } from '@grafana/data';
import { Select } from '@grafana/ui'; import { Select } from '@grafana/ui';
@ -13,14 +13,7 @@ interface Props {
const options = Object.keys(OrgRole).map((key) => ({ label: key, value: key })); const options = Object.keys(OrgRole).map((key) => ({ label: key, value: key }));
export const OrgRolePicker: FC<Props> = ({ export function OrgRolePicker({ value, onChange, 'aria-label': ariaLabel, inputId, autoFocus, ...restProps }: Props) {
value,
onChange,
'aria-label': ariaLabel,
inputId,
autoFocus,
...restProps
}) => {
return ( return (
<Select <Select
menuShouldPortal menuShouldPortal
@ -34,4 +27,4 @@ export const OrgRolePicker: FC<Props> = ({
{...restProps} {...restProps}
/> />
); );
}; }

View File

@ -13,7 +13,7 @@ interface Props {
navModel: NavModel; navModel: NavModel;
} }
export const UpgradePage: React.FC<Props> = ({ navModel }) => { export function UpgradePage({ navModel }: Props) {
return ( return (
<Page navModel={navModel}> <Page navModel={navModel}>
<Page.Contents> <Page.Contents>
@ -25,7 +25,7 @@ export const UpgradePage: React.FC<Props> = ({ navModel }) => {
</Page.Contents> </Page.Contents>
</Page> </Page>
); );
}; }
const titleStyles = { fontWeight: 500, fontSize: '26px', lineHeight: '123%' }; const titleStyles = { fontWeight: 500, fontSize: '26px', lineHeight: '123%' };