-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db-console: statement details component extraction
This change extracts Statements details page and its dependent components and styles. - most of the components moved without any changes, only import paths were adjusted - styles converted from Styl to SCSS - modified route paths to ensure they start with "/" root path (it ensures that routes behave the same way regardless to current path). - `util` directory now contain `network` and `nodes` subdirectories with logic specific to particular entities. It allows avoid extra logic in redux layer and keep it independently.
- Loading branch information
Showing
52 changed files
with
3,919 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/admin-ui-components/src/barCharts/genericBarChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from "react"; | ||
import classNames from "classnames/bind"; | ||
import { scaleLinear } from "d3-scale"; | ||
import { format as d3Format } from "d3-format"; | ||
|
||
import { stdDevLong } from "src/util/appStats"; | ||
import { Tooltip } from "src/tooltip"; | ||
import { NumericStat } from "../util"; | ||
import { clamp, longToInt, normalizeClosedDomain } from "./utils"; | ||
import styles from "./barCharts.module.scss"; | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
function renderNumericStatLegend( | ||
count: number | Long, | ||
stat: number, | ||
sd: number, | ||
formatter: (d: number) => string, | ||
) { | ||
return ( | ||
<table className={cx("numeric-stat-legend")}> | ||
<tbody> | ||
<tr> | ||
<th> | ||
<div | ||
className={cx( | ||
"numeric-stat-legend__bar", | ||
"numeric-stat-legend__bar--mean", | ||
)} | ||
/> | ||
Mean | ||
</th> | ||
<td>{formatter(stat)}</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<div | ||
className={cx( | ||
"numeric-stat-legend__bar", | ||
"numeric-stat-legend__bar--dev", | ||
)} | ||
/> | ||
Standard Deviation | ||
</th> | ||
<td>{longToInt(count) < 2 ? "-" : sd ? formatter(sd) : "0"}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
|
||
export function genericBarChart( | ||
s: NumericStat, | ||
count: number | Long, | ||
format?: (v: number) => string, | ||
) { | ||
if (!s) { | ||
return () => <div />; | ||
} | ||
const mean = s.mean; | ||
const sd = stdDevLong(s, count); | ||
|
||
const max = mean + sd; | ||
const scale = scaleLinear() | ||
.domain(normalizeClosedDomain([0, max])) | ||
.range([0, 100]); | ||
if (!format) { | ||
format = d3Format(".2f"); | ||
} | ||
return function MakeGenericBarChart() { | ||
const width = scale(clamp(mean - sd)); | ||
const right = scale(mean); | ||
const spread = scale(sd + (sd > mean ? mean : sd)); | ||
const title = renderNumericStatLegend(count, mean, sd, format); | ||
return ( | ||
<Tooltip text={title} short> | ||
<div className={cx("bar-chart", "bar-chart--breakdown")}> | ||
<div className={cx("bar-chart__label")}>{format(mean)}</div> | ||
<div className={cx("bar-chart__multiplebars")}> | ||
<div | ||
className={cx("bar-chart__parse", "bar-chart__bar")} | ||
style={{ width: right + "%", position: "absolute", left: 0 }} | ||
/> | ||
<div | ||
className={cx( | ||
"bar-chart__parse-dev", | ||
"bar-chart__bar", | ||
"bar-chart__bar--dev", | ||
)} | ||
style={{ | ||
width: spread + "%", | ||
position: "absolute", | ||
left: width + "%", | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</Tooltip> | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from "./barCharts"; | ||
export * from "./rowsBrealdown"; | ||
export * from "./utils"; | ||
export * from "./latencyBreakdown"; | ||
export * from "./genericBarChart"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/admin-ui-components/src/downloadFile/downloadFile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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, { | ||
useRef, | ||
useEffect, | ||
forwardRef, | ||
useImperativeHandle, | ||
} from "react"; | ||
|
||
type FileTypes = "text/plain" | "application/json"; | ||
|
||
export interface DownloadAsFileProps { | ||
fileName?: string; | ||
fileType?: FileTypes; | ||
content?: string; | ||
} | ||
|
||
export interface DownloadFileRef { | ||
download: (name: string, type: FileTypes, body: string) => void; | ||
} | ||
|
||
/* | ||
* DownloadFile can download file in two modes `default` and `imperative`. | ||
* `Default` mode - when DownloadFile wraps component which should trigger | ||
* downloading and can work only if content of file is already available. | ||
* | ||
* For example: | ||
* ``` | ||
* <DownloadFile fileName="example.txt" fileType="text/plain" content="Some text"> | ||
* <button>Download</download> | ||
* </DownloadFile> | ||
* ``` | ||
* | ||
* `Imperative` mode allows initiate file download in async way, and trigger | ||
* download manually. | ||
* | ||
* For example: | ||
* ``` | ||
* downloadRef = React.createRef<DownloadFileRef>(); | ||
* | ||
* fetchData = () => { | ||
* Promise.resolve().then((someText) => | ||
* this.downloadRef.current.download("example.txt", "text/plain", someText)) | ||
* } | ||
* | ||
* <DownloadFile ref={downloadRef} /> | ||
* <button onClick={fetchData}>Download</button> | ||
* ``` | ||
* */ | ||
// tslint:disable-next-line:variable-name | ||
export const DownloadFile = forwardRef<DownloadFileRef, DownloadAsFileProps>( | ||
(props, ref) => { | ||
const { children, fileName, fileType, content } = props; | ||
const anchorRef = useRef<HTMLAnchorElement>(); | ||
|
||
const bootstrapFile = (name: string, type: FileTypes, body: string) => { | ||
const anchorElement = anchorRef.current; | ||
const file = new Blob([body], { type }); | ||
anchorElement.href = URL.createObjectURL(file); | ||
anchorElement.download = name; | ||
}; | ||
|
||
useEffect(() => { | ||
if (content === undefined) { | ||
return; | ||
} | ||
bootstrapFile(fileName, fileType, content); | ||
}, [fileName, fileType, content]); | ||
|
||
useImperativeHandle(ref, () => ({ | ||
download: (name: string, type: FileTypes, body: string) => { | ||
bootstrapFile(name, type, body); | ||
anchorRef.current.click(); | ||
}, | ||
})); | ||
|
||
return <a ref={anchorRef}>{children}</a>; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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. | ||
|
||
export * from "./downloadFile"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/admin-ui-components/src/statementDetails/diagnostics/diagnosticsUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { isUndefined } from "lodash"; | ||
import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; | ||
import { DiagnosticStatuses } from "src/statementsDiagnostics"; | ||
|
||
type IStatementDiagnosticsReport = cockroach.server.serverpb.IStatementDiagnosticsReport; | ||
|
||
export function getDiagnosticsStatus( | ||
diagnosticsRequest: IStatementDiagnosticsReport, | ||
): DiagnosticStatuses { | ||
if (diagnosticsRequest.completed) { | ||
return "READY"; | ||
} | ||
|
||
return "WAITING"; | ||
} | ||
|
||
export function sortByRequestedAtField( | ||
a: IStatementDiagnosticsReport, | ||
b: IStatementDiagnosticsReport, | ||
) { | ||
const activatedOnA = a.requested_at?.seconds?.toNumber(); | ||
const activatedOnB = b.requested_at?.seconds?.toNumber(); | ||
if (isUndefined(activatedOnA) && isUndefined(activatedOnB)) { | ||
return 0; | ||
} | ||
if (activatedOnA < activatedOnB) { | ||
return -1; | ||
} | ||
if (activatedOnA > activatedOnB) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
export function sortByCompletedField( | ||
a: IStatementDiagnosticsReport, | ||
b: IStatementDiagnosticsReport, | ||
) { | ||
const completedA = a.completed ? 1 : -1; | ||
const completedB = b.completed ? 1 : -1; | ||
if (completedA < completedB) { | ||
return -1; | ||
} | ||
if (completedA > completedB) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
export function sortByStatementFingerprintField( | ||
a: IStatementDiagnosticsReport, | ||
b: IStatementDiagnosticsReport, | ||
) { | ||
const statementFingerprintA = a.statement_fingerprint; | ||
const statementFingerprintB = b.statement_fingerprint; | ||
if ( | ||
isUndefined(statementFingerprintA) && | ||
isUndefined(statementFingerprintB) | ||
) { | ||
return 0; | ||
} | ||
if (statementFingerprintA < statementFingerprintB) { | ||
return -1; | ||
} | ||
if (statementFingerprintA > statementFingerprintB) { | ||
return 1; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.