Skip to content

Commit 1afee02

Browse files
committed
Extract RawResultCell to separate file
1 parent cbb1de4 commit 1afee02

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
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+
};

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

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
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";
54
import {
65
CellValue,
76
RawResultSet,
87
ResultSetSchema,
98
} from "../../common/bqrs-cli-types";
10-
import { tryGetRemoteLocation } from "../../common/bqrs-utils";
119
import TextButton from "../common/TextButton";
12-
import { convertNonPrintableChars } from "../../common/text-utils";
13-
import { sendTelemetry, useTelemetryOnChange } from "../common/telemetry";
10+
import { useTelemetryOnChange } from "../common/telemetry";
11+
import { RawResultCell } from "./RawResultCell";
1412

1513
const numOfResultsInContractedMode = 5;
1614

@@ -40,40 +38,6 @@ const TableContainer = styled.div<TableContainerProps>`
4038
padding: 0.4rem;
4139
`;
4240

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-
7741
type RowProps = {
7842
row: CellValue[];
7943
fileLinkPrefix: string;
@@ -84,7 +48,7 @@ const Row = ({ row, fileLinkPrefix, sourceLocationPrefix }: RowProps) => (
8448
<>
8549
{row.map((cell, cellIndex) => (
8650
<StyledRow key={cellIndex}>
87-
<Cell
51+
<RawResultCell
8852
value={cell}
8953
fileLinkPrefix={fileLinkPrefix}
9054
sourceLocationPrefix={sourceLocationPrefix}

0 commit comments

Comments
 (0)