Skip to content

Commit 947084d

Browse files
authored
Merge pull request #2863 from github/koesie10/refactor-raw-results-table
Split out components in variant analysis raw results table
2 parents 6c1cd71 + 452329b commit 947084d

File tree

3 files changed

+87
-73
lines changed

3 files changed

+87
-73
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from "react";
2+
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react";
3+
4+
import { CellValue } from "../../common/bqrs-cli-types";
5+
import { sendTelemetry } from "../common/telemetry";
6+
import { convertNonPrintableChars } from "../../common/text-utils";
7+
import { tryGetRemoteLocation } from "../../common/bqrs-utils";
8+
9+
type CellProps = {
10+
value: CellValue;
11+
fileLinkPrefix: string;
12+
sourceLocationPrefix: string;
13+
};
14+
15+
const sendRawResultsLinkTelemetry = () => sendTelemetry("raw-results-link");
16+
17+
export const RawResultCell = ({
18+
value,
19+
fileLinkPrefix,
20+
sourceLocationPrefix,
21+
}: CellProps) => {
22+
switch (typeof value) {
23+
case "string":
24+
case "number":
25+
case "boolean":
26+
return <span>{convertNonPrintableChars(value.toString())}</span>;
27+
case "object": {
28+
const url = tryGetRemoteLocation(
29+
value.url,
30+
fileLinkPrefix,
31+
sourceLocationPrefix,
32+
);
33+
const safeLabel = convertNonPrintableChars(value.label);
34+
if (url) {
35+
return (
36+
<VSCodeLink onClick={sendRawResultsLinkTelemetry} href={url}>
37+
{safeLabel}
38+
</VSCodeLink>
39+
);
40+
} else {
41+
return <span>{safeLabel}</span>;
42+
}
43+
}
44+
}
45+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from "react";
2+
import { styled } from "styled-components";
3+
4+
import { CellValue } from "../../common/bqrs-cli-types";
5+
import { RawResultCell } from "./RawResultCell";
6+
7+
const StyledRow = styled.div`
8+
border-color: var(--vscode-editor-snippetFinalTabstopHighlightBorder);
9+
border-style: solid;
10+
justify-content: center;
11+
align-items: center;
12+
padding: 0.4rem;
13+
word-break: break-word;
14+
`;
15+
16+
type RowProps = {
17+
row: CellValue[];
18+
fileLinkPrefix: string;
19+
sourceLocationPrefix: string;
20+
};
21+
22+
export const RawResultRow = ({
23+
row,
24+
fileLinkPrefix,
25+
sourceLocationPrefix,
26+
}: RowProps) => (
27+
<>
28+
{row.map((cell, cellIndex) => (
29+
<StyledRow key={cellIndex}>
30+
<RawResultCell
31+
value={cell}
32+
fileLinkPrefix={fileLinkPrefix}
33+
sourceLocationPrefix={sourceLocationPrefix}
34+
/>
35+
</StyledRow>
36+
))}
37+
</>
38+
);

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

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
import * as React from "react";
22
import { useState } from "react";
33
import { styled } from "styled-components";
4-
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react";
5-
import {
6-
CellValue,
7-
RawResultSet,
8-
ResultSetSchema,
9-
} from "../../common/bqrs-cli-types";
10-
import { tryGetRemoteLocation } from "../../common/bqrs-utils";
4+
import { RawResultSet, ResultSetSchema } from "../../common/bqrs-cli-types";
115
import TextButton from "../common/TextButton";
12-
import { convertNonPrintableChars } from "../../common/text-utils";
13-
import { sendTelemetry, useTelemetryOnChange } from "../common/telemetry";
6+
import { useTelemetryOnChange } from "../common/telemetry";
7+
import { RawResultRow } from "./RawResultRow";
148

159
const numOfResultsInContractedMode = 5;
1610

17-
const StyledRow = styled.div`
18-
border-color: var(--vscode-editor-snippetFinalTabstopHighlightBorder);
19-
border-style: solid;
20-
justify-content: center;
21-
align-items: center;
22-
padding: 0.4rem;
23-
word-break: break-word;
24-
`;
25-
2611
type TableContainerProps = {
2712
columnCount: number;
2813
};
@@ -40,60 +25,6 @@ const TableContainer = styled.div<TableContainerProps>`
4025
padding: 0.4rem;
4126
`;
4227

43-
type CellProps = {
44-
value: CellValue;
45-
fileLinkPrefix: string;
46-
sourceLocationPrefix: string;
47-
};
48-
49-
const sendRawResultsLinkTelemetry = () => sendTelemetry("raw-results-link");
50-
51-
const Cell = ({ value, fileLinkPrefix, sourceLocationPrefix }: CellProps) => {
52-
switch (typeof value) {
53-
case "string":
54-
case "number":
55-
case "boolean":
56-
return <span>{convertNonPrintableChars(value.toString())}</span>;
57-
case "object": {
58-
const url = tryGetRemoteLocation(
59-
value.url,
60-
fileLinkPrefix,
61-
sourceLocationPrefix,
62-
);
63-
const safeLabel = convertNonPrintableChars(value.label);
64-
if (url) {
65-
return (
66-
<VSCodeLink onClick={sendRawResultsLinkTelemetry} href={url}>
67-
{safeLabel}
68-
</VSCodeLink>
69-
);
70-
} else {
71-
return <span>{safeLabel}</span>;
72-
}
73-
}
74-
}
75-
};
76-
77-
type RowProps = {
78-
row: CellValue[];
79-
fileLinkPrefix: string;
80-
sourceLocationPrefix: string;
81-
};
82-
83-
const Row = ({ row, fileLinkPrefix, sourceLocationPrefix }: RowProps) => (
84-
<>
85-
{row.map((cell, cellIndex) => (
86-
<StyledRow key={cellIndex}>
87-
<Cell
88-
value={cell}
89-
fileLinkPrefix={fileLinkPrefix}
90-
sourceLocationPrefix={sourceLocationPrefix}
91-
/>
92-
</StyledRow>
93-
))}
94-
</>
95-
);
96-
9728
type RawResultsTableProps = {
9829
schema: ResultSetSchema;
9930
results: RawResultSet;
@@ -122,7 +53,7 @@ const RawResultsTable = ({
12253
<>
12354
<TableContainer columnCount={schema.columns.length}>
12455
{results.rows.slice(0, numOfResultsToShow).map((row, rowIndex) => (
125-
<Row
56+
<RawResultRow
12657
key={rowIndex}
12758
row={row}
12859
fileLinkPrefix={fileLinkPrefix}

0 commit comments

Comments
 (0)