Skip to content

Commit 3dd8583

Browse files
committed
Use button instead of a for clickable location links
1 parent b066366 commit 3dd8583

5 files changed

Lines changed: 52 additions & 31 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from "react";
2+
3+
import { Meta, StoryFn } from "@storybook/react";
4+
5+
import { ClickableLocation as ClickableLocationComponent } from "../../../view/results/locations/ClickableLocation";
6+
7+
import "../../../view/results/resultsView.css";
8+
9+
export default {
10+
title: "Results/Clickable Location",
11+
component: ClickableLocationComponent,
12+
} as Meta<typeof ClickableLocationComponent>;
13+
14+
const Template: StoryFn<typeof ClickableLocationComponent> = (args) => (
15+
<ClickableLocationComponent {...args} />
16+
);
17+
18+
export const ClickableLocation = Template.bind({});
19+
ClickableLocation.args = {
20+
loc: {
21+
uri: "file:/home/runner/work/sql2o-example/sql2o-example/src/main/java/org/example/HelloController.java",
22+
startLine: 22,
23+
startColumn: 27,
24+
endLine: 22,
25+
endColumn: 57,
26+
},
27+
label: "url : String",
28+
};

extensions/ql-vscode/src/view/common/TextButton.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,28 @@ const StyledButton = styled.button<{ size: Size }>`
99
border: none;
1010
cursor: pointer;
1111
font-size: ${(props) => props.size ?? "1em"};
12+
padding: 0;
1213
`;
1314

1415
const TextButton = ({
1516
size,
1617
onClick,
1718
className,
19+
title,
1820
children,
1921
}: {
2022
size?: Size;
2123
onClick: () => void;
2224
className?: string;
25+
title?: string;
2326
children: React.ReactNode;
2427
}) => (
25-
<StyledButton size={size} onClick={onClick} className={className}>
28+
<StyledButton
29+
size={size}
30+
onClick={onClick}
31+
className={className}
32+
title={title}
33+
>
2634
{children}
2735
</StyledButton>
2836
);

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
ParsedResultSets,
99
} from "../../common/interface-types";
1010
import { basename } from "../../common/path";
11+
import { styled } from "styled-components";
12+
import TextButton from "../common/TextButton";
1113

1214
interface Props {
1315
queryName: string;
@@ -16,6 +18,10 @@ interface Props {
1618
selectedTable: string;
1719
}
1820

21+
const OpenQueryLink = styled(TextButton)`
22+
text-decoration: none;
23+
`;
24+
1925
export function ResultTablesHeader(props: Props) {
2026
const { queryPath, queryName, parsedResultSets, selectedTable } = props;
2127

@@ -122,17 +128,9 @@ export function ResultTablesHeader(props: Props) {
122128
</button>
123129
<div className={tableHeaderItemClassName}>{queryName}</div>
124130
<div className={tableHeaderItemClassName}>
125-
{/*
126-
eslint-disable-next-line
127-
jsx-a11y/anchor-is-valid
128-
*/}
129-
<a
130-
href="#"
131-
onClick={openQueryHandler}
132-
className="vscode-codeql__result-table-location-link"
133-
>
131+
<OpenQueryLink onClick={openQueryHandler}>
134132
Open {basename(queryPath)}
135-
</a>
133+
</OpenQueryLink>
136134
</div>
137135
</span>
138136
);

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as React from "react";
22
import { useCallback } from "react";
33
import { ResolvableLocationValue } from "../../../common/bqrs-cli-types";
44
import { jumpToLocation } from "../result-table-utils";
5+
import TextButton from "../../common/TextButton";
6+
import { styled } from "styled-components";
57

68
interface Props {
79
loc: ResolvableLocationValue;
@@ -11,6 +13,10 @@ interface Props {
1113
onClick?: () => void;
1214
}
1315

16+
const Link = styled(TextButton)`
17+
text-decoration: none;
18+
`;
19+
1420
/**
1521
* A clickable location link.
1622
*/
@@ -31,20 +37,5 @@ export function ClickableLocation({
3137
[loc, databaseUri, onClick],
3238
);
3339

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={handleClick}
45-
>
46-
{label}
47-
</a>
48-
</>
49-
);
40+
return <Link onClick={handleClick}>{label}</Link>;
5041
}

extensions/ql-vscode/src/view/results/resultsView.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@
129129
text-align: left;
130130
}
131131

132-
.vscode-codeql__result-table-location-link {
133-
text-decoration: none;
134-
}
135-
136132
select {
137133
background-color: var(--vscode-dropdown-background);
138134
color: var(--vscode-dropdown-foreground);

0 commit comments

Comments
 (0)