-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathRawResultsTable.tsx
More file actions
76 lines (68 loc) · 2.15 KB
/
RawResultsTable.tsx
File metadata and controls
76 lines (68 loc) · 2.15 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
import * as React from "react";
import { useState } from "react";
import { styled } from "styled-components";
import { RawResultSet, ResultSetSchema } from "../../common/bqrs-cli-types";
import TextButton from "../common/TextButton";
import { useTelemetryOnChange } from "../common/telemetry";
import { RawResultRow } from "./RawResultRow";
const numOfResultsInContractedMode = 5;
type TableContainerProps = {
$columnCount: number;
};
const TableContainer = styled.div<TableContainerProps>`
display: grid;
// Create n equal size columns. We use minmax(0, 1fr) because the
// minimum width of 1fr is auto, not 0.
// https://css-tricks.com/equal-width-columns-in-css-grid-are-kinda-weird/
grid-template-columns: repeat(
${(props) => props.$columnCount},
minmax(0, 1fr)
);
max-width: 45rem;
padding: 0.4rem;
`;
type RawResultsTableProps = {
schema: ResultSetSchema;
results: RawResultSet;
fileLinkPrefix: string;
sourceLocationPrefix: string;
};
const filterTableExpandedTelemetry = (v: boolean) => v;
const RawResultsTable = ({
schema,
results,
fileLinkPrefix,
sourceLocationPrefix,
}: RawResultsTableProps) => {
const [tableExpanded, setTableExpanded] = useState(false);
useTelemetryOnChange(tableExpanded, "raw-results-table-expanded", {
filterTelemetryOnValue: filterTableExpandedTelemetry,
});
const numOfResultsToShow = tableExpanded
? results.rows.length
: numOfResultsInContractedMode;
const showButton = results.rows.length > numOfResultsInContractedMode;
return (
<>
<TableContainer $columnCount={schema.columns.length}>
{results.rows.slice(0, numOfResultsToShow).map((row, rowIndex) => (
<RawResultRow
key={rowIndex}
row={row}
fileLinkPrefix={fileLinkPrefix}
sourceLocationPrefix={sourceLocationPrefix}
/>
))}
</TableContainer>
{showButton && (
<TextButton
size="x-small"
onClick={() => setTableExpanded(!tableExpanded)}
>
{tableExpanded ? <span>View less</span> : <span>View all</span>}
</TextButton>
)}
</>
);
};
export default RawResultsTable;