Admin: remove Redux from ServerStats (#38581)

* Admin: remove Redux from ServerStats

* Admin: Fix import
This commit is contained in:
Alex Khomenko 2021-08-27 11:09:17 +03:00 committed by GitHub
parent c08d5eeda0
commit a15e33e693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 30 deletions

View File

@ -1,6 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ServerStats, Props } from './ServerStats';
import { ServerStats } from './ServerStats';
import { ServerStat } from './state/apis';
const stats: ServerStat = {
@ -23,21 +23,13 @@ const stats: ServerStat = {
viewers: 2,
};
const getServerStats = () => {
return Promise.resolve(stats);
};
jest.mock('./state/apis', () => ({
getServerStats: async () => stats,
}));
const setup = (propOverrides?: Partial<Props>) => {
const props: Props = {
getServerStats,
};
Object.assign(props, propOverrides);
render(<ServerStats {...props} />);
};
describe('ServerStats', () => {
it('Should render page with stats', async () => {
setup();
render(<ServerStats />);
expect(await screen.findByRole('heading', { name: /instance statistics/i })).toBeInTheDocument();
expect(screen.getByText('Dashboards (starred)')).toBeInTheDocument();
expect(screen.getByText('Tags')).toBeInTheDocument();

View File

@ -1,20 +1,13 @@
import React, { useEffect, useState } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
import { css } from '@emotion/css';
import { CardContainer, LinkButton, useStyles2 } from '@grafana/ui';
import { GrafanaTheme2 } from '@grafana/data';
import { AccessControlAction, StoreState } from 'app/types';
import { getNavModel } from 'app/core/selectors/navModel';
import { AccessControlAction } from 'app/types';
import { getServerStats, ServerStat } from './state/apis';
import { contextSrv } from '../../core/services/context_srv';
import { Loader } from '../plugins/admin/components/Loader';
export interface Props {
getServerStats: () => Promise<ServerStat | null>;
}
export const ServerStats = ({ getServerStats }: Props) => {
export const ServerStats = () => {
const [stats, setStats] = useState<ServerStat | null>(null);
const [isLoading, setIsLoading] = useState(true);
const styles = useStyles2(getStyles);
@ -24,7 +17,7 @@ export const ServerStats = ({ getServerStats }: Props) => {
setStats(stats);
setIsLoading(false);
});
}, [getServerStats]);
}, []);
if (!contextSrv.hasPermission(AccessControlAction.ActionServerStatsRead)) {
return null;
@ -131,11 +124,6 @@ const getStyles = (theme: GrafanaTheme2) => {
};
};
const mapStateToProps = (state: StoreState) => ({
navModel: getNavModel(state.navIndex, 'server-stats'),
getServerStats,
});
type StatCardProps = {
content: Array<Record<string, number | string>>;
footer?: JSX.Element;
@ -184,4 +172,3 @@ const getCardStyles = (theme: GrafanaTheme2) => {
`,
};
};
export default hot(module)(connect(mapStateToProps)(ServerStats));

View File

@ -8,7 +8,7 @@ import Page from '../../core/components/Page/Page';
import { getNavModel } from '../../core/selectors/navModel';
import { LicenseChrome } from './LicenseChrome';
import { StoreState } from '../../types';
import ServerStats from './ServerStats';
import { ServerStats } from './ServerStats';
interface Props {
navModel: NavModel;