mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 14:38:50 +00:00
feat(nui): Query time table
This commit is contained in:
commit
ed03361f61
3 files changed
+232
-1
No files matched your search
@@ -4,17 +4,20 @@
|
|||||||
"homepage": "ui/build",
|
"homepage": "ui/build",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@chakra-ui/icons": "^1.1.1",
|
||||||
"@chakra-ui/react": "^1.7.3",
|
"@chakra-ui/react": "^1.7.3",
|
||||||
"@emotion/react": "^11",
|
"@emotion/react": "^11",
|
||||||
"@emotion/styled": "^11",
|
"@emotion/styled": "^11",
|
||||||
"@types/node": "^16.11.9",
|
"@types/node": "^16.11.9",
|
||||||
"@types/react": "^17.0.35",
|
"@types/react": "^17.0.35",
|
||||||
"@types/react-dom": "^17.0.11",
|
"@types/react-dom": "^17.0.11",
|
||||||
|
"@types/react-table": "^7.7.9",
|
||||||
"framer-motion": "4.1.17",
|
"framer-motion": "4.1.17",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-router-dom": "6",
|
"react-router-dom": "6",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "4.0.3",
|
||||||
|
"react-table": "^7.7.0",
|
||||||
"typescript": "^4.5.2"
|
"typescript": "^4.5.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,9 +1,115 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { useEffect, useState, useMemo } from 'react';
|
||||||
|
import { fetchNui } from '../utils/fetchNui';
|
||||||
|
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||||
|
import { debugData } from '../utils/debugData';
|
||||||
|
import { Table, Thead, Tbody, Tr, Th, Td, chakra } from '@chakra-ui/react';
|
||||||
|
import { TriangleDownIcon, TriangleUpIcon } from '@chakra-ui/icons';
|
||||||
|
import { useTable, useSortBy, Column } from 'react-table';
|
||||||
|
|
||||||
|
interface QueryData {
|
||||||
|
date: number;
|
||||||
|
query: string;
|
||||||
|
executionTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TableData {
|
||||||
|
query: string;
|
||||||
|
executionTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
const Resource: React.FC = () => {
|
const Resource: React.FC = () => {
|
||||||
let { resource } = useParams();
|
let { resource } = useParams();
|
||||||
|
const [resourceData, setResourceData] = useState<QueryData[]>([
|
||||||
|
{
|
||||||
|
date: 0,
|
||||||
|
query: '',
|
||||||
|
executionTime: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return <h2>{resource}</h2>;
|
useEffect(() => {
|
||||||
|
fetchNui('fetchResource', resource);
|
||||||
|
debugData([
|
||||||
|
{
|
||||||
|
action: 'loadResource',
|
||||||
|
data: [
|
||||||
|
{ query: 'SELECT * FROM `users`', executionTime: 5 },
|
||||||
|
{ query: 'SELECT * FROM `owned_vehicles`', executionTime: 2 },
|
||||||
|
{ query: 'SELECT * FROM `properties`', executionTime: 7 },
|
||||||
|
{ query: 'SELECT * FROM `phone_messages`', executionTime: 13 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}, [resource]);
|
||||||
|
|
||||||
|
useNuiEvent<QueryData[]>('loadResource', (data) => {
|
||||||
|
setResourceData(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = useMemo<TableData[]>(() => resourceData, [resourceData]);
|
||||||
|
|
||||||
|
const columns = useMemo<Column<TableData>[]>(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: 'Query',
|
||||||
|
accessor: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Execution time',
|
||||||
|
accessor: 'executionTime',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data }, useSortBy);
|
||||||
|
|
||||||
|
// Todo: pagination
|
||||||
|
return (
|
||||||
|
<Table {...getTableProps} size="sm">
|
||||||
|
<Thead>
|
||||||
|
{headerGroups.map((header): any => (
|
||||||
|
<Tr {...header.getHeaderGroupProps()}>
|
||||||
|
{header.headers.map((column) => (
|
||||||
|
<Th {...column.getHeaderProps(column.getSortByToggleProps())} color="white" fontFamily="Poppins">
|
||||||
|
{column.render('Header')}
|
||||||
|
<chakra.span pl="4">
|
||||||
|
{column.isSorted ? (
|
||||||
|
column.isSortedDesc ? (
|
||||||
|
<TriangleDownIcon aria-label="sorted descending" />
|
||||||
|
) : (
|
||||||
|
<TriangleUpIcon aria-label="sorted ascending" />
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</chakra.span>
|
||||||
|
</Th>
|
||||||
|
))}
|
||||||
|
</Tr>
|
||||||
|
))}
|
||||||
|
</Thead>
|
||||||
|
<Tbody {...getTableBodyProps()}>
|
||||||
|
{rows.map((row) => {
|
||||||
|
prepareRow(row);
|
||||||
|
return (
|
||||||
|
<Tr {...row.getRowProps()}>
|
||||||
|
{row.cells.map((cell) => (
|
||||||
|
<Td
|
||||||
|
{...cell.getCellProps()}
|
||||||
|
fontFamily="Poppins"
|
||||||
|
wordBreak="break-word"
|
||||||
|
textOverflow="ellipsis"
|
||||||
|
overflow="hidden"
|
||||||
|
>
|
||||||
|
{cell.render('Cell')}
|
||||||
|
</Td>
|
||||||
|
))}
|
||||||
|
</Tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Tbody>
|
||||||
|
</Table>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Resource;
|
export default Resource;
|
||||||
Vendored
+122
@@ -0,0 +1,122 @@
|
|||||||
|
import {
|
||||||
|
UseColumnOrderInstanceProps,
|
||||||
|
UseColumnOrderState,
|
||||||
|
UseExpandedHooks,
|
||||||
|
UseExpandedInstanceProps,
|
||||||
|
UseExpandedOptions,
|
||||||
|
UseExpandedRowProps,
|
||||||
|
UseExpandedState,
|
||||||
|
UseFiltersColumnOptions,
|
||||||
|
UseFiltersColumnProps,
|
||||||
|
UseFiltersInstanceProps,
|
||||||
|
UseFiltersOptions,
|
||||||
|
UseFiltersState,
|
||||||
|
UseGlobalFiltersColumnOptions,
|
||||||
|
UseGlobalFiltersInstanceProps,
|
||||||
|
UseGlobalFiltersOptions,
|
||||||
|
UseGlobalFiltersState,
|
||||||
|
UseGroupByCellProps,
|
||||||
|
UseGroupByColumnOptions,
|
||||||
|
UseGroupByColumnProps,
|
||||||
|
UseGroupByHooks,
|
||||||
|
UseGroupByInstanceProps,
|
||||||
|
UseGroupByOptions,
|
||||||
|
UseGroupByRowProps,
|
||||||
|
UseGroupByState,
|
||||||
|
UsePaginationInstanceProps,
|
||||||
|
UsePaginationOptions,
|
||||||
|
UsePaginationState,
|
||||||
|
UseResizeColumnsColumnOptions,
|
||||||
|
UseResizeColumnsColumnProps,
|
||||||
|
UseResizeColumnsOptions,
|
||||||
|
UseResizeColumnsState,
|
||||||
|
UseRowSelectHooks,
|
||||||
|
UseRowSelectInstanceProps,
|
||||||
|
UseRowSelectOptions,
|
||||||
|
UseRowSelectRowProps,
|
||||||
|
UseRowSelectState,
|
||||||
|
UseRowStateCellProps,
|
||||||
|
UseRowStateInstanceProps,
|
||||||
|
UseRowStateOptions,
|
||||||
|
UseRowStateRowProps,
|
||||||
|
UseRowStateState,
|
||||||
|
UseSortByColumnOptions,
|
||||||
|
UseSortByColumnProps,
|
||||||
|
UseSortByHooks,
|
||||||
|
UseSortByInstanceProps,
|
||||||
|
UseSortByOptions,
|
||||||
|
UseSortByState
|
||||||
|
} from 'react-table'
|
||||||
|
|
||||||
|
declare module 'react-table' {
|
||||||
|
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
|
||||||
|
|
||||||
|
export interface TableOptions<D extends Record<string, unknown>>
|
||||||
|
extends UseExpandedOptions<D>,
|
||||||
|
UseFiltersOptions<D>,
|
||||||
|
UseGlobalFiltersOptions<D>,
|
||||||
|
UseGroupByOptions<D>,
|
||||||
|
UsePaginationOptions<D>,
|
||||||
|
UseResizeColumnsOptions<D>,
|
||||||
|
UseRowSelectOptions<D>,
|
||||||
|
UseRowStateOptions<D>,
|
||||||
|
UseSortByOptions<D>,
|
||||||
|
// note that having Record here allows you to add anything to the options, this matches the spirit of the
|
||||||
|
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
|
||||||
|
// feature set, this is a safe default.
|
||||||
|
Record<string, any> {}
|
||||||
|
|
||||||
|
export interface Hooks<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseExpandedHooks<D>,
|
||||||
|
UseGroupByHooks<D>,
|
||||||
|
UseRowSelectHooks<D>,
|
||||||
|
UseSortByHooks<D> {}
|
||||||
|
|
||||||
|
export interface TableInstance<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseColumnOrderInstanceProps<D>,
|
||||||
|
UseExpandedInstanceProps<D>,
|
||||||
|
UseFiltersInstanceProps<D>,
|
||||||
|
UseGlobalFiltersInstanceProps<D>,
|
||||||
|
UseGroupByInstanceProps<D>,
|
||||||
|
UsePaginationInstanceProps<D>,
|
||||||
|
UseRowSelectInstanceProps<D>,
|
||||||
|
UseRowStateInstanceProps<D>,
|
||||||
|
UseSortByInstanceProps<D> {}
|
||||||
|
|
||||||
|
export interface TableState<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseColumnOrderState<D>,
|
||||||
|
UseExpandedState<D>,
|
||||||
|
UseFiltersState<D>,
|
||||||
|
UseGlobalFiltersState<D>,
|
||||||
|
UseGroupByState<D>,
|
||||||
|
UsePaginationState<D>,
|
||||||
|
UseResizeColumnsState<D>,
|
||||||
|
UseRowSelectState<D>,
|
||||||
|
UseRowStateState<D>,
|
||||||
|
UseSortByState<D> {}
|
||||||
|
|
||||||
|
export interface ColumnInterface<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseFiltersColumnOptions<D>,
|
||||||
|
UseGlobalFiltersColumnOptions<D>,
|
||||||
|
UseGroupByColumnOptions<D>,
|
||||||
|
UseResizeColumnsColumnOptions<D>,
|
||||||
|
UseSortByColumnOptions<D> {}
|
||||||
|
|
||||||
|
export interface ColumnInstance<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseFiltersColumnProps<D>,
|
||||||
|
UseGroupByColumnProps<D>,
|
||||||
|
UseResizeColumnsColumnProps<D>,
|
||||||
|
UseSortByColumnProps<D> {
|
||||||
|
getSortByToggleProps: (props?: Partial<TableSortByToggleProps> | undefined) => TableSortByToggleProps
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Cell<D extends Record<string, unknown> = Record<string, unknown>, V = any>
|
||||||
|
extends UseGroupByCellProps<D>,
|
||||||
|
UseRowStateCellProps<D> {}
|
||||||
|
|
||||||
|
export interface Row<D extends Record<string, unknown> = Record<string, unknown>>
|
||||||
|
extends UseExpandedRowProps<D>,
|
||||||
|
UseGroupByRowProps<D>,
|
||||||
|
UseRowSelectRowProps<D>,
|
||||||
|
UseRowStateRowProps<D> {}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user