Skip to content

Commit e475036

Browse files
committed
Right align and format raw result numbers
This changes the formatting for both the local raw results table and the variant analysis raw results table to right align and format numbers.
1 parent 42192fa commit e475036

File tree

4 files changed

+66
-21
lines changed

4 files changed

+66
-21
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from "react";
2+
import { styled } from "styled-components";
3+
import { formatDecimal } from "../../common/number";
4+
5+
const RightAlignedSpan = styled.span`
6+
display: inline-block;
7+
text-align: right;
8+
width: 100%;
9+
`;
10+
11+
type Props = {
12+
value: number;
13+
};
14+
15+
export const RawNumberValue = ({ value }: Props) => {
16+
return <RightAlignedSpan>{formatDecimal(value)}</RightAlignedSpan>;
17+
};

extensions/ql-vscode/src/view/results/RawTableValue.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,34 @@ import * as React from "react";
22

33
import { Location } from "./locations/Location";
44
import { CellValue } from "../../common/bqrs-cli-types";
5+
import { RawNumberValue } from "../common/RawNumberValue";
56

67
interface Props {
78
value: CellValue;
89
databaseUri: string;
910
onSelected?: () => void;
1011
}
1112

12-
export default function RawTableValue(props: Props): JSX.Element {
13-
const rawValue = props.value;
14-
if (
15-
typeof rawValue === "string" ||
16-
typeof rawValue === "number" ||
17-
typeof rawValue === "boolean"
18-
) {
19-
return <Location label={rawValue.toString()} />;
13+
export default function RawTableValue({
14+
value,
15+
databaseUri,
16+
onSelected,
17+
}: Props): JSX.Element {
18+
switch (typeof value) {
19+
case "boolean":
20+
return <span>{value.toString()}</span>;
21+
case "number":
22+
return <RawNumberValue value={value} />;
23+
case "string":
24+
return <Location label={value.toString()} />;
25+
default:
26+
return (
27+
<Location
28+
loc={value.url}
29+
label={value.label}
30+
databaseUri={databaseUri}
31+
onClick={onSelected}
32+
/>
33+
);
2034
}
21-
22-
return (
23-
<Location
24-
loc={rawValue.url}
25-
label={rawValue.label}
26-
databaseUri={props.databaseUri}
27-
onClick={props.onSelected}
28-
/>
29-
);
3035
}

extensions/ql-vscode/src/view/variant-analysis/RawResultCell.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CellValue } from "../../common/bqrs-cli-types";
55
import { sendTelemetry } from "../common/telemetry";
66
import { convertNonPrintableChars } from "../../common/text-utils";
77
import { tryGetRemoteLocation } from "../../common/bqrs-utils";
8+
import { RawNumberValue } from "../common/RawNumberValue";
89

910
type CellProps = {
1011
value: CellValue;
@@ -20,9 +21,11 @@ export const RawResultCell = ({
2021
sourceLocationPrefix,
2122
}: CellProps) => {
2223
switch (typeof value) {
23-
case "string":
24-
case "number":
2524
case "boolean":
25+
return <span>{value.toString()}</span>;
26+
case "number":
27+
return <RawNumberValue value={value} />;
28+
case "string":
2629
return <span>{convertNonPrintableChars(value.toString())}</span>;
2730
case "object": {
2831
const url = tryGetRemoteLocation(

extensions/ql-vscode/src/view/variant-analysis/__tests__/AnalyzedRepoItemContent.spec.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ describe(AnalyzedRepoItemContent.name, () => {
7171
{
7272
kind: "i",
7373
},
74+
{
75+
kind: "s",
76+
},
77+
{
78+
kind: "b",
79+
},
7480
],
7581
},
7682
resultSet: {
@@ -81,9 +87,18 @@ describe(AnalyzedRepoItemContent.name, () => {
8187
{
8288
kind: "i",
8389
},
90+
{
91+
kind: "s",
92+
},
93+
{
94+
kind: "b",
95+
},
8496
],
8597
},
86-
rows: [[60688]],
98+
rows: [
99+
[60688, "foo", true],
100+
[5, "bar", false],
101+
],
87102
},
88103
fileLinkPrefix:
89104
"https://github.com/octodemo/hello-world-1/blob/59a2a6c7d9dde7a6ecb77c2f7e8197d6925c143b",
@@ -92,7 +107,12 @@ describe(AnalyzedRepoItemContent.name, () => {
92107
},
93108
});
94109

95-
expect(screen.getByText("60688")).toBeInTheDocument();
110+
expect(screen.getByText("60,688")).toBeInTheDocument();
111+
expect(screen.getByText("foo")).toBeInTheDocument();
112+
expect(screen.getByText("true")).toBeInTheDocument();
113+
expect(screen.getByText("5")).toBeInTheDocument();
114+
expect(screen.getByText("bar")).toBeInTheDocument();
115+
expect(screen.getByText("false")).toBeInTheDocument();
96116
});
97117

98118
it("renders the failed state", () => {

0 commit comments

Comments
 (0)