Live: do not show connection warning when on the login page (#33865)

This commit is contained in:
Ryan McKinley 2021-05-10 13:32:45 -07:00 committed by GitHub
parent fe5fc75ded
commit 81b8e6c13a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 16 deletions

View File

@ -13,7 +13,7 @@ import { SideMenu } from './core/components/sidemenu/SideMenu';
import { GrafanaRoute } from './core/navigation/GrafanaRoute';
import { AppNotificationList } from './core/components/AppNotifications/AppNotificationList';
import { SearchWrapper } from 'app/features/search';
import { LiveConnectionCorner } from './features/live/LiveConnectionCorner';
import { LiveConnectionWarning } from './features/live/LiveConnectionWarning';
interface AppWrapperProps {
app: GrafanaApp;
@ -113,7 +113,7 @@ export class AppWrapper extends React.Component<AppWrapperProps, AppWrapperState
</div>
</Router>
</div>
<LiveConnectionCorner />
<LiveConnectionWarning />
<ModalRoot />
</ModalsProvider>
</ThemeProvider>

View File

@ -1,9 +1,10 @@
import { css } from '@emotion/css';
import { GrafanaTheme } from '@grafana/data';
import { GrafanaTheme2 } from '@grafana/data';
import { config, getGrafanaLiveSrv } from '@grafana/runtime';
import { stylesFactory } from '@grafana/ui';
import { Alert, stylesFactory } from '@grafana/ui';
import React, { PureComponent } from 'react';
import { Unsubscribable } from 'rxjs';
import { contextSrv } from 'app/core/services/context_srv';
export interface Props {}
@ -11,9 +12,9 @@ export interface State {
show?: boolean;
}
export class LiveConnectionCorner extends PureComponent<Props, State> {
export class LiveConnectionWarning extends PureComponent<Props, State> {
subscription?: Unsubscribable;
styles = getStyle(config.theme);
styles = getStyle(config.theme2);
state: State = {};
componentDidMount() {
@ -44,24 +45,36 @@ export class LiveConnectionCorner extends PureComponent<Props, State> {
render() {
const { show } = this.state;
if (show) {
return <div className={this.styles.corner} title="The server is disconnected" />;
if (!contextSrv.isSignedIn) {
return null; // do not show the warning for anonomous users (and /login page etc)
}
return (
<div className={this.styles.foot}>
<Alert severity={'warning'} className={this.styles.warn} title="connection to server is lost..." />
</div>
);
}
return null;
}
}
const getStyle = stylesFactory((theme: GrafanaTheme) => {
const getStyle = stylesFactory((theme: GrafanaTheme2) => {
return {
corner: css`
position: fixed;
top: 0px !important;
left: 0px !important;
width: 0;
height: 0;
border-top: 60px solid ${theme.palette.brandWarning};
border-right: 60px solid transparent;
foot: css`
position: absolute;
bottom: 0px;
left: 0px;
right: 0px;
z-index: 10000;
cursor: wait;
margin: 16px;
`,
warn: css`
border: 2px solid ${theme.colors.warning.main};
max-width: 400px;
margin: auto;
height: 3em;
`,
};
});