mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 14:38:50 +00:00
feat(nui): copy query on left click
This commit is contained in:
1 parent
98b4f108e8
commit
82006d251d
2 files changed
+39
-2
No files matched your search
@@ -1,8 +1,22 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useEffect, useState, useMemo } from 'react';
|
import React, { useEffect, useState, useMemo } from 'react';
|
||||||
import { fetchNui } from '../utils/fetchNui';
|
import { fetchNui } from '../utils/fetchNui';
|
||||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||||
import { Table, Thead, Tbody, Tr, Th, Td, chakra, Flex, IconButton, Text, Spinner, Tooltip } from '@chakra-ui/react';
|
import {
|
||||||
|
Table,
|
||||||
|
Thead,
|
||||||
|
Tbody,
|
||||||
|
Tr,
|
||||||
|
Th,
|
||||||
|
Td,
|
||||||
|
chakra,
|
||||||
|
Flex,
|
||||||
|
IconButton,
|
||||||
|
Text,
|
||||||
|
Spinner,
|
||||||
|
Tooltip,
|
||||||
|
useToast,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
import {
|
import {
|
||||||
TriangleDownIcon,
|
TriangleDownIcon,
|
||||||
TriangleUpIcon,
|
TriangleUpIcon,
|
||||||
@@ -13,6 +27,7 @@ import {
|
|||||||
} from '@chakra-ui/icons';
|
} from '@chakra-ui/icons';
|
||||||
import { useTable, useSortBy, Column, usePagination, useFlexLayout } from 'react-table';
|
import { useTable, useSortBy, Column, usePagination, useFlexLayout } from 'react-table';
|
||||||
import { debugData } from '../utils/debugData';
|
import { debugData } from '../utils/debugData';
|
||||||
|
import { setClipboard } from '../utils/setClipboard';
|
||||||
|
|
||||||
interface QueryData {
|
interface QueryData {
|
||||||
date: number;
|
date: number;
|
||||||
@@ -34,6 +49,7 @@ interface NuiData {
|
|||||||
|
|
||||||
const Resource: React.FC = () => {
|
const Resource: React.FC = () => {
|
||||||
const { resource } = useParams();
|
const { resource } = useParams();
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
const [isLoaded, setIsLoaded] = useState(false);
|
const [isLoaded, setIsLoaded] = useState(false);
|
||||||
const [resourceData, setResourceData] = useState<QueryData[]>([
|
const [resourceData, setResourceData] = useState<QueryData[]>([
|
||||||
@@ -118,6 +134,15 @@ const Resource: React.FC = () => {
|
|||||||
setIsLoaded(true);
|
setIsLoaded(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleClick = (value: string) => {
|
||||||
|
setClipboard(value);
|
||||||
|
toast({
|
||||||
|
title: 'Query copied to clipboard',
|
||||||
|
duration: 2500,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction="column" justifyContent="space-between" alignItems="center" h="full">
|
<Flex direction="column" justifyContent="space-between" alignItems="center" h="full">
|
||||||
<Table {...getTableProps()} size="sm">
|
<Table {...getTableProps()} size="sm">
|
||||||
@@ -155,6 +180,7 @@ const Resource: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<Tr {...row.getRowProps()} key={`row-${index}`}>
|
<Tr {...row.getRowProps()} key={`row-${index}`}>
|
||||||
{row.cells.map((cell, index) => (
|
{row.cells.map((cell, index) => (
|
||||||
|
<React.Fragment key={`row-${index}`}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
isDisabled={cell.column.id === 'executionTime'}
|
isDisabled={cell.column.id === 'executionTime'}
|
||||||
label={cell.value}
|
label={cell.value}
|
||||||
@@ -168,10 +194,12 @@ const Resource: React.FC = () => {
|
|||||||
color={row.values.slow && '#f3eca1'}
|
color={row.values.slow && '#f3eca1'}
|
||||||
isTruncated={cell.column.id === 'query'}
|
isTruncated={cell.column.id === 'query'}
|
||||||
textAlign={cell.column.id === 'executionTime' ? 'center' : 'left'}
|
textAlign={cell.column.id === 'executionTime' ? 'center' : 'left'}
|
||||||
|
onClick={(e) => cell.column.id === 'query' && handleClick(cell.value)}
|
||||||
>
|
>
|
||||||
{cell.render('Cell')}
|
{cell.render('Cell')}
|
||||||
</Td>
|
</Td>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// yoinked from https://github.com/project-error/npwd/blob/d8dc5b7f47faf5fc581ffee30f31ff61d184cfe7/phone/src/os/phone/hooks/useClipboard.ts#L1
|
||||||
|
export const setClipboard = (value: string) => {
|
||||||
|
const clipElem = document.createElement('input');
|
||||||
|
clipElem.value = value;
|
||||||
|
document.body.appendChild(clipElem);
|
||||||
|
clipElem.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(clipElem);
|
||||||
|
};
|
||||||
Reference in new issue
Block a user