forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult-table-utils.tsx
More file actions
148 lines (133 loc) · 4.69 KB
/
result-table-utils.tsx
File metadata and controls
148 lines (133 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import * as React from 'react';
import { UrlValue, ResolvableLocationValue } from '../pure/bqrs-cli-types';
import { isStringLoc, tryGetResolvableLocation } from '../pure/bqrs-utils';
import { RawResultsSortState, QueryMetadata, SortDirection } from '../pure/interface-types';
import { assertNever } from '../pure/helpers-pure';
import { ResultSet } from '../pure/interface-types';
import { vscode } from './vscode-api';
export interface ResultTableProps {
resultSet: ResultSet;
databaseUri: string;
metadata?: QueryMetadata;
resultsPath: string | undefined;
sortState?: RawResultsSortState;
offset: number;
/**
* Holds if there are any raw results. When that is the case, we
* want to direct users to pay attention to raw results if
* interpreted results are empty.
*/
nonemptyRawResults: boolean;
/**
* Callback to show raw results.
*/
showRawResults: () => void;
}
export const className = 'vscode-codeql__result-table';
export const tableHeaderClassName = 'vscode-codeql__table-selection-header';
export const tableHeaderItemClassName = 'vscode-codeql__table-selection-header-item';
export const alertExtrasClassName = `${className}-alert-extras`;
export const toggleDiagnosticsClassName = `${className}-toggle-diagnostics`;
export const evenRowClassName = 'vscode-codeql__result-table-row--even';
export const oddRowClassName = 'vscode-codeql__result-table-row--odd';
export const pathRowClassName = 'vscode-codeql__result-table-row--path';
export const selectedRowClassName = 'vscode-codeql__result-table-row--selected';
export function jumpToLocationHandler(
loc: ResolvableLocationValue,
databaseUri: string,
callback?: () => void
): (e: React.MouseEvent) => void {
return (e) => {
jumpToLocation(loc, databaseUri);
e.preventDefault();
e.stopPropagation();
if (callback) {
callback();
}
};
}
export function jumpToLocation(loc: ResolvableLocationValue, databaseUri: string): void {
vscode.postMessage({
t: 'viewSourceFile',
loc,
databaseUri
});
}
export function openFile(filePath: string): void {
vscode.postMessage({
t: 'openFile',
filePath
});
}
/**
* Render a location as a link which when clicked displays the original location.
*/
export function renderLocation(
loc: UrlValue | undefined,
label: string | undefined,
databaseUri: string,
title?: string,
callback?: () => void
): JSX.Element {
// If the label was empty, use a placeholder instead, so the link is still clickable.
let displayLabel = label;
if (!label) {
displayLabel = '[empty string]';
} else if (label.match(/^\s+$/)) {
displayLabel = `[whitespace: "${label}"]`;
}
if (loc === undefined) {
return <span>{displayLabel}</span>;
} else if (isStringLoc(loc)) {
return <a href={loc}>{loc}</a>;
}
const resolvableLoc = tryGetResolvableLocation(loc);
if (resolvableLoc !== undefined) {
return (
<a href="#"
className="vscode-codeql__result-table-location-link"
title={title}
onClick={jumpToLocationHandler(resolvableLoc, databaseUri, callback)}>
{displayLabel}
</a>
);
} else {
return <span title={title}>{displayLabel}</span>;
}
}
/**
* Returns the attributes for a zebra-striped table row at position `index`.
*/
export function zebraStripe(index: number, ...otherClasses: string[]): { className: string } {
return { className: [(index % 2) ? oddRowClassName : evenRowClassName, ...otherClasses].join(' ') };
}
/**
* Returns the attributes for a zebra-striped table row at position `index`,
* with highlighting if `isSelected` is true.
*/
export function selectableZebraStripe(isSelected: boolean, index: number, ...otherClasses: string[]): { className: string } {
return isSelected
? { className: [selectedRowClassName, ...otherClasses].join(' ') }
: zebraStripe(index, ...otherClasses);
}
/**
* Returns the next sort direction when cycling through sort directions while clicking.
* if `includeUndefined` is true, include `undefined` in the cycle.
*/
export function nextSortDirection(direction: SortDirection | undefined, includeUndefined?: boolean): SortDirection | undefined {
switch (direction) {
case SortDirection.asc:
return SortDirection.desc;
case SortDirection.desc:
return includeUndefined ? undefined : SortDirection.asc;
case undefined:
return SortDirection.asc;
default:
return assertNever(direction);
}
}
export function emptyQueryResultsMessage(): JSX.Element {
return <span>
This query returned no results. If this isn't what you're expecting, and for effective query-writing tips, check out the <a href="https://codeql.github.com/docs/codeql-language-guides/">CodeQL language guides</a>.
</span>;
}