-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
93 lines (80 loc) · 2.53 KB
/
Copy pathindex.tsx
File metadata and controls
93 lines (80 loc) · 2.53 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
import './index.scss';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { Typography } from '@mui/material';
import { ColDef, themeMaterial } from 'ag-grid-community';
import { AgGridReact } from 'ag-grid-react';
import React, {
useEffect,
} from 'react';
import { useQuery } from 'react-query';
import { Link } from 'react-router';
import useGrid from '@/components/hooks/useGrid';
import api from '@/services/api';
import schema from '@/services/schema';
import { QueryBody } from '../types';
import { tuple } from '../util';
interface JumpToRecordProps {
data: {
'@rid': string;
}
}
const JumpToRecord = ({ data }: JumpToRecordProps) => (
<Link className="query-results-table__jump-to-record" target="_blank" to={schema.getLink(data)}>
<OpenInNewIcon />
{data['@rid']}
</Link>
);
interface QueryResultsTableProps {
columnDefs: ColDef[];
/** the body of the query request */
queryBody: QueryBody;
/** the title to put above the table */
title: string;
description?: string;
}
/**
* Given some source node, summarizes the related nodes by their relationship class
* and the node they are related to
*/
const QueryResultsTable = ({
columnDefs, queryBody, title, description = '',
}: QueryResultsTableProps) => {
const grid = useGrid();
const { data, isFetching } = useQuery({ queryKey: tuple('/query', queryBody), queryFn: async ({ queryKey: [, body] }) => api.query(body) });
// resize the columns to fit once the data and grid are ready
useEffect(() => {
const gridApi = grid.ref?.current?.api;
if (gridApi) {
gridApi.sizeColumnsToFit();
if (gridApi && data) {
gridApi.setGridOption('rowData', data);
}
}
}, [grid.ref, data]);
return (
<div className="query-results-table">
<Typography className="query-results-table__title" variant="h3">
{title} ({isFetching ? '?' : data && data.length})
</Typography>
{description && (<Typography paragraph variant="caption">{description}</Typography>)}
<div
className="ag-theme-material query-results-table__content"
role="presentation"
>
<AgGridReact
{...grid.props}
columnDefs={columnDefs}
components={{ JumpToRecord }}
enableCellTextSelection
getRowId={(params) => params.data['@rid']}
pagination
paginationAutoPageSize
rowData={data}
suppressHorizontalScroll
theme={themeMaterial}
/>
</div>
</div>
);
};
export default QueryResultsTable;