Skip to content

Commit f38eb48

Browse files
authored
Replace "repository search" filter box with VS Code UI Toolkit (#1424)
1 parent f559b59 commit f38eb48

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

extensions/ql-vscode/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@
11471147
"@octokit/plugin-retry": "^3.0.9",
11481148
"@primer/octicons-react": "^16.3.0",
11491149
"@primer/react": "^35.0.0",
1150+
"@vscode/codicons": "^0.0.31",
11501151
"@vscode/webview-ui-toolkit": "^1.0.0",
11511152
"child-process-promise": "^2.2.1",
11521153
"classnames": "~2.2.6",
@@ -1162,8 +1163,8 @@
11621163
"react": "^17.0.2",
11631164
"react-dom": "^17.0.2",
11641165
"semver": "~7.3.2",
1165-
"source-map-support": "^0.5.21",
11661166
"source-map": "^0.7.4",
1167+
"source-map-support": "^0.5.21",
11671168
"stream": "^0.0.2",
11681169
"stream-chain": "~2.2.4",
11691170
"stream-json": "~1.7.3",

extensions/ql-vscode/src/interface-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export function getHtmlForWebview(
137137
? `${webview.cspSource} vscode-file: 'unsafe-inline'`
138138
: `'nonce-${nonce}'`;
139139

140+
const fontSrc = webview.cspSource;
141+
140142
/*
141143
* Content security policy:
142144
* default-src: allow nothing by default.
@@ -149,7 +151,7 @@ export function getHtmlForWebview(
149151
<html>
150152
<head>
151153
<meta http-equiv="Content-Security-Policy"
152-
content="default-src 'none'; script-src 'nonce-${nonce}'; style-src ${styleSrc}; connect-src ${webview.cspSource};">
154+
content="default-src 'none'; script-src 'nonce-${nonce}'; font-src ${fontSrc}; style-src ${styleSrc}; connect-src ${webview.cspSource};">
153155
${stylesheetsHtmlLines.join(` ${os.EOL}`)}
154156
</head>
155157
<body>

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class RemoteQueriesInterfaceManager {
111111
localResourceRoots: [
112112
Uri.file(this.analysesResultsManager.storagePath),
113113
Uri.file(path.join(this.ctx.extensionPath, 'out')),
114+
Uri.file(path.join(this.ctx.extensionPath, 'node_modules/@vscode/codicons/dist')),
114115
],
115116
}
116117
));
@@ -135,10 +136,16 @@ export class RemoteQueriesInterfaceManager {
135136
ctx.asAbsolutePath('out/remote-queries/view/remoteQueries.css')
136137
);
137138

139+
// Allows use of the VS Code "codicons" icon set.
140+
// See https://github.com/microsoft/vscode-codicons
141+
const codiconsPathOnDisk = Uri.file(
142+
ctx.asAbsolutePath('node_modules/@vscode/codicons/dist/codicon.css')
143+
);
144+
138145
panel.webview.html = getHtmlForWebview(
139146
panel.webview,
140147
scriptPathOnDisk,
141-
[baseStylesheetUriOnDisk, stylesheetPathOnDisk],
148+
[baseStylesheetUriOnDisk, stylesheetPathOnDisk, codiconsPathOnDisk],
142149
true
143150
);
144151
ctx.subscriptions.push(

extensions/ql-vscode/src/remote-queries/view/RepositoriesSearch.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as React from 'react';
2-
import { ChangeEvent } from 'react';
3-
import { TextInput } from '@primer/react';
4-
import { SearchIcon } from '@primer/octicons-react';
2+
import { VSCodeTextField } from '@vscode/webview-ui-toolkit/react';
53

64
interface RepositoriesSearchProps {
75
filterValue: string;
@@ -10,20 +8,16 @@ interface RepositoriesSearchProps {
108

119
const RepositoriesSearch = ({ filterValue, setFilterValue }: RepositoriesSearchProps) => {
1210
return <>
13-
<TextInput
14-
block
15-
sx={{
16-
backgroundColor: 'var(--vscode-editor-background);',
17-
color: 'var(--vscode-editor-foreground);',
18-
width: 'calc(100% - 14px)',
19-
}}
20-
leadingVisual={SearchIcon}
21-
aria-label="Repository search"
11+
<VSCodeTextField
12+
style={{ width: '100%' }}
13+
placeholder='Filter by repository owner/name'
14+
ariaLabel="Repository search"
2215
name="repository-search"
23-
placeholder="Filter by repository owner/name"
2416
value={filterValue}
25-
onChange={(e: ChangeEvent) => setFilterValue((e.target as HTMLInputElement).value)}
26-
/>
17+
onInput={(e: InputEvent) => setFilterValue((e.target as HTMLInputElement).value)}
18+
>
19+
<span slot="start" className="codicon codicon-search"></span>
20+
</VSCodeTextField>
2721
</>;
2822
};
2923

0 commit comments

Comments
 (0)