Skip to content

Commit c4ebee8

Browse files
Have each component in a separate file
1 parent a4c0365 commit c4ebee8

8 files changed

Lines changed: 234 additions & 215 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22

3-
import { Location } from "./locations";
3+
import { Location } from "./locations/Location";
44
import { CellValue } from "../../common/bqrs-cli-types";
55

66
interface Props {

extensions/ql-vscode/src/view/results/alert-table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { parseSarifLocation, isNoLocation } from "../../common/sarif-utils";
2020
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
2121
import { sendTelemetry } from "../common/telemetry";
2222
import { AlertTableHeader } from "./alert-table-header";
23-
import { SarifLocation, SarifMessageWithLocations } from "./locations";
23+
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
24+
import { SarifLocation } from "./locations/SarifLocation";
2425

2526
export type AlertTableProps = ResultTableProps & {
2627
resultSet: InterpretedResultSet<SarifInterpretationData>;

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

Lines changed: 0 additions & 213 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from "react";
2+
import { useCallback } from "react";
3+
import { ResolvableLocationValue } from "../../../common/bqrs-cli-types";
4+
import { jumpToLocation } from "../result-table-utils";
5+
6+
/**
7+
* A clickable location link.
8+
*/
9+
export function ClickableLocation({
10+
loc,
11+
label,
12+
databaseUri,
13+
title,
14+
jumpToLocationCallback,
15+
}: {
16+
loc: ResolvableLocationValue;
17+
label: string;
18+
databaseUri: string;
19+
title?: string;
20+
jumpToLocationCallback?: () => void;
21+
}): JSX.Element {
22+
const jumpToLocationHandler = useCallback(
23+
(e: React.MouseEvent) => {
24+
jumpToLocation(loc, databaseUri);
25+
e.preventDefault();
26+
e.stopPropagation();
27+
if (jumpToLocationCallback) {
28+
jumpToLocationCallback();
29+
}
30+
},
31+
[loc, databaseUri, jumpToLocationCallback],
32+
);
33+
34+
return (
35+
<>
36+
{/*
37+
eslint-disable-next-line
38+
jsx-a11y/anchor-is-valid,
39+
*/}
40+
<a
41+
href="#"
42+
className="vscode-codeql__result-table-location-link"
43+
title={title}
44+
onClick={jumpToLocationHandler}
45+
>
46+
{label}
47+
</a>
48+
</>
49+
);
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as React from "react";
2+
import { useMemo } from "react";
3+
4+
import { UrlValue } from "../../../common/bqrs-cli-types";
5+
import {
6+
isStringLoc,
7+
tryGetResolvableLocation,
8+
} from "../../../common/bqrs-utils";
9+
import { convertNonPrintableChars } from "../../../common/text-utils";
10+
import { NonClickableLocation } from "./NonClickableLocation";
11+
import { ClickableLocation } from "./ClickableLocation";
12+
13+
/**
14+
* A location link. Will be clickable if a location URL and database URI are provided.
15+
*/
16+
export function Location({
17+
loc,
18+
label,
19+
databaseUri,
20+
title,
21+
jumpToLocationCallback,
22+
}: {
23+
loc?: UrlValue;
24+
label?: string;
25+
databaseUri?: string;
26+
title?: string;
27+
jumpToLocationCallback?: () => void;
28+
}): JSX.Element {
29+
const resolvableLoc = useMemo(() => tryGetResolvableLocation(loc), [loc]);
30+
const displayLabel = useMemo(() => convertNonPrintableChars(label!), [label]);
31+
if (loc === undefined) {
32+
return <NonClickableLocation msg={displayLabel} />;
33+
} else if (isStringLoc(loc)) {
34+
return <a href={loc}>{loc}</a>;
35+
} else if (databaseUri === undefined || resolvableLoc === undefined) {
36+
return <NonClickableLocation msg={displayLabel} locationHint={title} />;
37+
} else {
38+
return (
39+
<ClickableLocation
40+
loc={resolvableLoc}
41+
label={displayLabel}
42+
databaseUri={databaseUri}
43+
title={title}
44+
jumpToLocationCallback={jumpToLocationCallback}
45+
/>
46+
);
47+
}
48+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from "react";
2+
3+
/**
4+
* A non-clickable location for when there isn't a valid link.
5+
* Designed to fit in with the other types of location components.
6+
*/
7+
export function NonClickableLocation({
8+
msg,
9+
locationHint,
10+
}: {
11+
msg?: string;
12+
locationHint?: string;
13+
}) {
14+
if (msg === undefined) return null;
15+
return <span title={locationHint}>{msg}</span>;
16+
}

0 commit comments

Comments
 (0)