Skip to content

Commit

Permalink
Merge #45638
Browse files Browse the repository at this point in the history
45638: ui: Network latency tooltip r=dhartunian a=elkmaster

Updated tooltip styles.

Resolves: #45228

Release note (ui): none

Co-authored-by: Vlad Los <[email protected]>
Co-authored-by: Vlad <[email protected]>
  • Loading branch information
craig[bot] and vladlos committed May 26, 2020
2 parents 0857bf6 + e317cea commit e6c15ca
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 75 deletions.
1 change: 1 addition & 0 deletions pkg/ui/src/components/core/colors.styl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $colors--primary-blue-3 = #0788ff
$colors--primary-blue-4 = #005fb3
$colors--primary-blue-5 = #00294d

$colors--primary-green-0 = #daf8d4
$colors--primary-green-1 = #b4f1aa
$colors--primary-green-2 = #76de49
$colors--primary-green-3 = #37a806
Expand Down
35 changes: 35 additions & 0 deletions pkg/ui/src/util/decorators.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

import React from "react";
import { RenderFunction } from "storybook__react";
import { Provider } from "react-redux";
import { combineReducers, createStore } from "redux";
import { ConnectedRouter, connectRouter } from "connected-react-router";
import { createMemoryHistory } from "history";

const history = createMemoryHistory();
const routerReducer = connectRouter(history);

const store = createStore(
combineReducers({
router: routerReducer,
}),
);

export const styledWrapper = (styles: React.CSSProperties) => (
storyFn: RenderFunction,
) => <div style={styles}>{storyFn()}</div>;

export const withRouterDecorator = (storyFn: RenderFunction) => (
<Provider store={store}>
<ConnectedRouter history={history}>{storyFn()}</ConnectedRouter>
</Provider>
);
5 changes: 4 additions & 1 deletion pkg/ui/src/views/reports/containers/network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface NetworkOwnProps {
export interface Identity {
nodeID: number;
address: string;
locality: string;
locality?: string;
updatedAt: moment.Moment;
}

Expand Down Expand Up @@ -76,6 +76,9 @@ function contentAvailable(nodesSummary: NodesSummary) {
}

export function getValueFromString(key: string, params: string, fullString?: boolean) {
if (!params) {
return;
}
const result = params.match(new RegExp(key + "=([^,#]*)"));
if (!result) {
return;
Expand Down
48 changes: 23 additions & 25 deletions pkg/ui/src/views/reports/containers/network/latency/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface StdDev {
stddevPlus2: number;
}

interface ILegendProps {
export interface ILatencyProps {
displayIdentities: Identity[];
staleIDs: Set<number>;
multipleHeader: boolean;
Expand Down Expand Up @@ -159,20 +159,6 @@ const getLatencyCell = ({ latency, identityB, identityA }: { latency: number; id
/>
);
}
if (latency === -2) {
return (
<td
className={generateClassName(["latency-table__cell", "latency-table__cell--no-connection"])}
>
<Tooltip placement="bottom" title="Disconnected">
<Chip
title="--"
type="yellow"
/>
</Tooltip>
</td>
);
}
if (latency === -1) {
return (
<td
Expand Down Expand Up @@ -201,17 +187,29 @@ const getLatencyCell = ({ latency, identityB, identityA }: { latency: number; id
std.stddev > 0 && latency > std.stddevPlus2,
});
const type: any = classNames({
"yellow":
latency === -2,
"green":
std.stddev > 0 && latency < std.stddevMinus2,
latency > 0 && std.stddev > 0 && latency < std.stddevMinus2,
"lightgreen":
std.stddev > 0 && latency < std.stddevMinus1 && latency >= std.stddevMinus2,
latency > 0 && std.stddev > 0 && latency < std.stddevMinus1 && latency >= std.stddevMinus2,
"grey":
std.stddev > 0 && latency >= std.stddevMinus1 && latency <= std.stddevPlus1,
latency > 0 && std.stddev > 0 && latency >= std.stddevMinus1 && latency <= std.stddevPlus1,
"lightblue":
std.stddev > 0 && latency > std.stddevPlus1 && latency <= std.stddevPlus2,
latency > 0 && std.stddev > 0 && latency > std.stddevPlus1 && latency <= std.stddevPlus2,
"blue":
std.stddev > 0 && latency > std.stddevPlus2,
latency > 0 && std.stddev > 0 && latency > std.stddevPlus2,
});
const renderDescription = (data: string) => {
if (!data) {
return;
}
return _.map(data.split(","), (identity, index) => (
<p key={index} className="Chip--tooltip__nodes--item-description">
{`${identity},`}
</p>
));
};
return (
<td className={className}>
{collapsed ? (
Expand All @@ -225,20 +223,20 @@ const getLatencyCell = ({ latency, identityB, identityA }: { latency: number; id
<div className="Chip--tooltip__nodes">
<div className="Chip--tooltip__nodes--item">
<p className="Chip--tooltip__nodes--item-title">{`Node ${identityB.nodeID}`}</p>
<p className="Chip--tooltip__nodes--item-description">{identityB.locality}</p>
{renderDescription(identityB.locality)}
</div>
<Divider type="vertical" />
<div className="Chip--tooltip__nodes--item">
<p className="Chip--tooltip__nodes--item-title">{`Node ${identityA.nodeID}`}</p>
<p className="Chip--tooltip__nodes--item-description">{identityA.locality}</p>
{renderDescription(identityA.locality)}
</div>
</div>
<p className={`color--${type}`}>{`${latency.toFixed(2)}ms roundtrip`}</p>
{latency > 0 && <p className={`color--${type} Chip--tooltip__latency`}>{`${latency.toFixed(2)}ms roundtrip`}</p>}
</div>
)}>
<div>
<Chip
title={`${latency.toFixed(2)}ms`}
title={latency > 0 ? latency.toFixed(2) + "ms" : "--"}
type={type}
/>
</div>
Expand All @@ -249,7 +247,7 @@ const getLatencyCell = ({ latency, identityB, identityA }: { latency: number; id
};

// tslint:disable-next-line: variable-name
export const Latency: React.SFC <ILegendProps> = ({
export const Latency: React.SFC <ILatencyProps> = ({
displayIdentities,
staleIDs,
multipleHeader,
Expand Down
Loading

0 comments on commit e6c15ca

Please sign in to comment.