mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 14:38:50 +00:00
Merge pull request #173 from overextended/svelte-rewrite
Svelte rewrite
This commit is contained in:
58 files changed
+2161
-12198
No files matched your search
@@ -31,12 +31,12 @@ jobs:
|
|||||||
- name: Bundle files
|
- name: Bundle files
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ./temp/oxmysql
|
mkdir -p ./temp/oxmysql
|
||||||
mkdir -p ./temp/oxmysql/ui/
|
mkdir -p ./temp/oxmysql/web/
|
||||||
mkdir -p ./temp/oxmysql/lib/
|
mkdir -p ./temp/oxmysql/lib/
|
||||||
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
|
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
|
||||||
cp ./lib/{MySQL.lua,define.lua} ./temp/oxmysql/lib
|
cp ./lib/{MySQL.lua,define.lua} ./temp/oxmysql/lib
|
||||||
cp -r ./dist ./temp/oxmysql
|
cp -r ./dist ./temp/oxmysql
|
||||||
cp -r ./ui/build ./temp/oxmysql/ui/
|
cp -r ./web/build ./temp/oxmysql/web/
|
||||||
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
|
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ jobs:
|
|||||||
- name: Bundle files
|
- name: Bundle files
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ./temp/oxmysql
|
mkdir -p ./temp/oxmysql
|
||||||
mkdir -p ./temp/oxmysql/ui/
|
mkdir -p ./temp/oxmysql/web/
|
||||||
mkdir -p ./temp/oxmysql/lib/
|
mkdir -p ./temp/oxmysql/lib/
|
||||||
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
|
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
|
||||||
cp ./lib/{MySQL.lua,define.lua} ./temp/oxmysql/lib
|
cp ./lib/{MySQL.lua,define.lua} ./temp/oxmysql/lib
|
||||||
cp -r ./dist ./temp/oxmysql
|
cp -r ./dist ./temp/oxmysql
|
||||||
cp -r ./ui/build ./temp/oxmysql/ui/
|
cp -r ./web/build ./temp/oxmysql/web/
|
||||||
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
|
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ dist
|
|||||||
# Stores VSCode versions used for testing VSCode extensions
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
.vscode-test
|
.vscode-test
|
||||||
|
|
||||||
|
# JetBrains
|
||||||
|
.idea
|
||||||
|
|
||||||
# yarn v2
|
# yarn v2
|
||||||
.yarn/cache
|
.yarn/cache
|
||||||
.yarn/unplugged
|
.yarn/unplugged
|
||||||
|
|||||||
+3
-3
@@ -15,11 +15,11 @@ client_script 'ui.lua'
|
|||||||
server_script 'dist/build.js'
|
server_script 'dist/build.js'
|
||||||
|
|
||||||
files {
|
files {
|
||||||
'ui/build/index.html',
|
'web/build/index.html',
|
||||||
'ui/build/**/*'
|
'web/build/**/*'
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_page 'ui/build/index.html'
|
ui_page 'web/build/index.html'
|
||||||
|
|
||||||
provide 'mysql-async'
|
provide 'mysql-async'
|
||||||
provide 'ghmattimysql'
|
provide 'ghmattimysql'
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"packages": ["ui"],
|
"packages": ["web"],
|
||||||
"npmClient": "pnpm",
|
"npmClient": "pnpm",
|
||||||
"version": "0.0.0"
|
"version": "0.0.0"
|
||||||
}
|
}
|
||||||
+26
-19
@@ -51,19 +51,7 @@ RegisterCommand(
|
|||||||
let totalQueries: number = 0;
|
let totalQueries: number = 0;
|
||||||
let totalTime = 0;
|
let totalTime = 0;
|
||||||
let slowQueries = 0;
|
let slowQueries = 0;
|
||||||
let chartData: [
|
let chartData: { labels: string[]; data: { queries: number; time: number }[] } = { labels: [], data: [] };
|
||||||
{
|
|
||||||
x: number; // Number of queries
|
|
||||||
y: number; // Execution time
|
|
||||||
z: string; // Resource name
|
|
||||||
}
|
|
||||||
] = [
|
|
||||||
{
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
z: '',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const resource in logStorage) {
|
for (const resource in logStorage) {
|
||||||
const queries = logStorage[resource];
|
const queries = logStorage[resource];
|
||||||
@@ -73,7 +61,8 @@ RegisterCommand(
|
|||||||
totalTime += queries.reduce((totalTime, query) => (totalTime += query.executionTime), 0);
|
totalTime += queries.reduce((totalTime, query) => (totalTime += query.executionTime), 0);
|
||||||
slowQueries += queries.reduce((slowQueries, query) => (slowQueries += query.slow ? 1 : 0), 0);
|
slowQueries += queries.reduce((slowQueries, query) => (slowQueries += query.slow ? 1 : 0), 0);
|
||||||
totalResourceTime += queries.reduce((totalResourceTime, query) => (totalResourceTime += query.executionTime), 0);
|
totalResourceTime += queries.reduce((totalResourceTime, query) => (totalResourceTime += query.executionTime), 0);
|
||||||
chartData.push({ x: queries.length, y: totalResourceTime, z: resource });
|
chartData.labels.push(resource);
|
||||||
|
chartData.data.push({ queries: queries.length, time: totalResourceTime });
|
||||||
}
|
}
|
||||||
|
|
||||||
emitNet(`oxmysql:openUi`, source, {
|
emitNet(`oxmysql:openUi`, source, {
|
||||||
@@ -106,18 +95,36 @@ onNet(
|
|||||||
`oxmysql:fetchResource`,
|
`oxmysql:fetchResource`,
|
||||||
(data: { resource: string; pageIndex: number; sortBy?: { id: 'query' | 'executionTime'; desc: boolean }[] }) => {
|
(data: { resource: string; pageIndex: number; sortBy?: { id: 'query' | 'executionTime'; desc: boolean }[] }) => {
|
||||||
if (typeof data.resource !== 'string') return;
|
if (typeof data.resource !== 'string') return;
|
||||||
|
const resourceLog = logStorage[data.resource];
|
||||||
|
|
||||||
const sort = data.sortBy ? data.sortBy[0] : false;
|
const sort = data.sortBy && data.sortBy.length > 0 ? data.sortBy[0] : false;
|
||||||
|
|
||||||
const startRow = data.pageIndex * 12;
|
const startRow = data.pageIndex * 10;
|
||||||
const endRow = startRow + 12;
|
const endRow = startRow + 10;
|
||||||
const queries = sort
|
const queries = sort
|
||||||
? sortQueries(logStorage[data.resource], sort).slice(startRow, endRow)
|
? sortQueries(logStorage[data.resource], sort).slice(startRow, endRow)
|
||||||
: logStorage[data.resource].slice(startRow, endRow);
|
: logStorage[data.resource].slice(startRow, endRow);
|
||||||
const pageCount = Math.ceil(logStorage[data.resource].length / 12);
|
const pageCount = Math.ceil(resourceLog.length / 10);
|
||||||
|
|
||||||
if (!queries) return;
|
if (!queries) return;
|
||||||
|
|
||||||
emitNet(`oxmysql:loadResource`, source, { queries, pageCount });
|
let resourceTime = 0;
|
||||||
|
let resourceSlowQueries = 0;
|
||||||
|
const resourceQueriesCount = resourceLog.length;
|
||||||
|
|
||||||
|
for (let i = 0; i < resourceQueriesCount; i++) {
|
||||||
|
const query = resourceLog[i];
|
||||||
|
|
||||||
|
resourceTime += query.executionTime;
|
||||||
|
if (query.slow) resourceSlowQueries += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
emitNet(`oxmysql:loadResource`, source, {
|
||||||
|
queries,
|
||||||
|
pageCount,
|
||||||
|
resourceQueriesCount,
|
||||||
|
resourceSlowQueries,
|
||||||
|
resourceTime,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
||||||
|
|
||||||
# dependencies
|
|
||||||
/node_modules
|
|
||||||
/.pnp
|
|
||||||
.pnp.js
|
|
||||||
|
|
||||||
# testing
|
|
||||||
/coverage
|
|
||||||
|
|
||||||
# production
|
|
||||||
/build
|
|
||||||
|
|
||||||
# misc
|
|
||||||
.DS_Store
|
|
||||||
.env.local
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
module.exports = {
|
|
||||||
webpack: {
|
|
||||||
configure: (webpackConfig) => {
|
|
||||||
// Because CEF has issues with loading source maps properly atm,
|
|
||||||
// lets use the best we can get in line with `eval-source-map`
|
|
||||||
if (webpackConfig.mode === 'development' && process.env.IN_GAME_DEV) {
|
|
||||||
webpackConfig.devtool = 'eval-source-map';
|
|
||||||
webpackConfig.output.path = path.join(__dirname, 'build');
|
|
||||||
}
|
|
||||||
|
|
||||||
return webpackConfig;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
devServer: (devServerConfig) => {
|
|
||||||
if (process.env.IN_GAME_DEV) {
|
|
||||||
// Used for in-game dev mode
|
|
||||||
devServerConfig.devMiddleware.writeToDisk = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return devServerConfig;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ui",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"homepage": "ui/build",
|
|
||||||
"private": true,
|
|
||||||
"dependencies": {
|
|
||||||
"@chakra-ui/icons": "^1.1.1",
|
|
||||||
"@chakra-ui/react": "^1.7.3",
|
|
||||||
"@emotion/react": "^11",
|
|
||||||
"@emotion/styled": "^11",
|
|
||||||
"@types/jest": "^26.0.24",
|
|
||||||
"@types/node": "^16.11.18",
|
|
||||||
"@types/react": "^17.0.38",
|
|
||||||
"@types/react-dom": "^17.0.11",
|
|
||||||
"@types/react-table": "^7.7.9",
|
|
||||||
"framer-motion": "4.1.17",
|
|
||||||
"react": "^17.0.2",
|
|
||||||
"react-dom": "^17.0.2",
|
|
||||||
"react-router-dom": "6",
|
|
||||||
"react-scripts": "5.0.0",
|
|
||||||
"react-table": "^7.7.0",
|
|
||||||
"typescript": "^4.5.4",
|
|
||||||
"victory": "^36.2.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "cross-env PUBLIC_URL=/ craco start",
|
|
||||||
"start:game": "cross-env IN_GAME_DEV=1 craco start",
|
|
||||||
"build": "rimraf build && craco build",
|
|
||||||
"test": "craco test",
|
|
||||||
"eject": "react-scripts eject"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
|
||||||
"extends": [
|
|
||||||
"react-app",
|
|
||||||
"react-app/jest"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"browserslist": {
|
|
||||||
"production": [
|
|
||||||
">0.2%",
|
|
||||||
"not dead",
|
|
||||||
"not op_mini all"
|
|
||||||
],
|
|
||||||
"development": [
|
|
||||||
"last 1 chrome version",
|
|
||||||
"last 1 firefox version",
|
|
||||||
"last 1 safari version"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@babel/core": ">=7.0.0 <8.0.0",
|
|
||||||
"@babel/plugin-syntax-flow": "^7.14.5",
|
|
||||||
"@babel/plugin-transform-react-jsx": "^7.14.9",
|
|
||||||
"@chakra-ui/system": "^1.11.2",
|
|
||||||
"@craco/craco": "^6.4.3",
|
|
||||||
"autoprefixer": "^10.0.2",
|
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"postcss": "^8.1.0",
|
|
||||||
"rimraf": "^3.0.2"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@babel/core": ">=7.0.0 <8.0.0",
|
|
||||||
"@babel/plugin-syntax-flow": "^7.14.5",
|
|
||||||
"@babel/plugin-transform-react-jsx": "^7.14.9",
|
|
||||||
"@chakra-ui/system": "^1.11.2",
|
|
||||||
"autoprefixer": "^10.0.2",
|
|
||||||
"postcss": "^8.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
-11261
File diff suppressed because it is too large.
Load diff
@@ -1,23 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<meta name="theme-color" content="#000000" />
|
|
||||||
<title>NUI React Boilerplate</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
||||||
<div id="root"></div>
|
|
||||||
<!--
|
|
||||||
This HTML file is a template.
|
|
||||||
If you open it directly in the browser, you will see an empty page.
|
|
||||||
|
|
||||||
You can add webfonts, meta tags, or analytics to this file.
|
|
||||||
The build step will place the bundled scripts into the <body> tag.
|
|
||||||
|
|
||||||
To begin the development, run `npm start` or `yarn start`.
|
|
||||||
To create a production bundle, use `npm run build` or `yarn build`.
|
|
||||||
-->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { Flex, Box } from '@chakra-ui/react';
|
|
||||||
import { debugData } from '../utils/debugData';
|
|
||||||
import TopBar from './NavBars/TopBar';
|
|
||||||
import LeftBar from './NavBars/LeftBar';
|
|
||||||
import { Routes, Route, useNavigate } from 'react-router-dom';
|
|
||||||
import Resource from './Resource';
|
|
||||||
import RightBar from './NavBars/RightBar';
|
|
||||||
import MainContent from './MainContent';
|
|
||||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
|
||||||
|
|
||||||
debugData([
|
|
||||||
{
|
|
||||||
action: 'openUI',
|
|
||||||
data: {
|
|
||||||
resources: ['ox_inventory', 'luke_garages', 'es_extended'],
|
|
||||||
totalQueries: 732,
|
|
||||||
totalTime: 258,
|
|
||||||
slowQueries: 6,
|
|
||||||
chartData: [
|
|
||||||
{ x: 13, y: 350, z: 'ox_inventory' },
|
|
||||||
{ x: 27, y: 752, z: 'es_extended' },
|
|
||||||
{ x: 41, y: 52, z: 'luke_garages' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const App: React.FC = () => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
useNuiEvent('openUI', () => navigate('/'));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex w="100%" h="100%" alignItems="center" justifyContent="center">
|
|
||||||
<Box
|
|
||||||
width="6xl"
|
|
||||||
height="lg"
|
|
||||||
backgroundColor="#191E26"
|
|
||||||
borderRadius="lg"
|
|
||||||
color="white"
|
|
||||||
fontFamily="Poppins"
|
|
||||||
userSelect="none"
|
|
||||||
>
|
|
||||||
<TopBar />
|
|
||||||
<LeftBar />
|
|
||||||
<RightBar />
|
|
||||||
<MainContent>
|
|
||||||
<Routes>
|
|
||||||
<Route path="/:resource" element={<Resource />} />
|
|
||||||
<Route path="/" element={<></>} />
|
|
||||||
</Routes>
|
|
||||||
</MainContent>
|
|
||||||
</Box>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Box, Center } from '@chakra-ui/react';
|
|
||||||
|
|
||||||
const MainContent: React.FC = ({ children }) => {
|
|
||||||
return (
|
|
||||||
<Center>
|
|
||||||
<Box h="30.3rem" w="50%" backgroundColor="#1B2129" flex="1">
|
|
||||||
{children}
|
|
||||||
</Box>
|
|
||||||
</Center>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MainContent;
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { Box, VStack } from '@chakra-ui/react';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { NavLink } from 'react-router-dom';
|
|
||||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
|
||||||
import type { InitData } from '../../types';
|
|
||||||
|
|
||||||
const LeftBar: React.FC = () => {
|
|
||||||
const [initData, setInitData] = useState<InitData>({
|
|
||||||
resources: [''],
|
|
||||||
totalQueries: 0,
|
|
||||||
totalTime: 0,
|
|
||||||
slowQueries: 0,
|
|
||||||
chartData: [{ x: 0, y: 0, z: '' }],
|
|
||||||
});
|
|
||||||
|
|
||||||
useNuiEvent<InitData>('openUI', (data) => {
|
|
||||||
setInitData(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box pl={3} pr={3} pb={3} pt={2} fontSize="md" float="left" w={150} height="90%" overflowY="scroll">
|
|
||||||
<VStack align="left">
|
|
||||||
{initData.resources.map((resource, index) => (
|
|
||||||
<Box isTruncated key={`${resource}-${index}`}>
|
|
||||||
<NavLink
|
|
||||||
to={resource}
|
|
||||||
style={(state) => ({
|
|
||||||
color: state.isActive ? 'white' : 'grey',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<Box _hover={{ color: 'white' }} isTruncated>
|
|
||||||
{resource}
|
|
||||||
</Box>
|
|
||||||
</NavLink>
|
|
||||||
</Box>
|
|
||||||
))}
|
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LeftBar;
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { Box, VStack, Center, Spacer, Flex, Text } from '@chakra-ui/react';
|
|
||||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
|
||||||
import { VictoryPie, VictoryTooltip } from 'victory';
|
|
||||||
import type { InitData } from '../../types';
|
|
||||||
|
|
||||||
const RightBar: React.FC = () => {
|
|
||||||
const [initData, setInitData] = useState<InitData>({
|
|
||||||
totalQueries: 0,
|
|
||||||
totalTime: 0,
|
|
||||||
slowQueries: 0,
|
|
||||||
resources: [''],
|
|
||||||
chartData: [{ x: 0, y: 0, z: '' }],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Debug data defined in LeftBar.tsx
|
|
||||||
|
|
||||||
useNuiEvent<InitData>('openUI', (data) => {
|
|
||||||
setInitData(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box float="right" w="3xs" h="100%" p={3}>
|
|
||||||
<Center h="100%">
|
|
||||||
<Flex direction="column" h="100%">
|
|
||||||
<Box>
|
|
||||||
<VStack align="left">
|
|
||||||
<Text>Number of queries: {initData.totalQueries.toLocaleString('en-US')}</Text>
|
|
||||||
<Text>Time querying: {Math.trunc(initData.totalTime).toLocaleString('en-US')} ms</Text>
|
|
||||||
<Text color="#f3eca1">Slow queries: {initData.slowQueries.toLocaleString('en-US')}</Text>
|
|
||||||
</VStack>
|
|
||||||
</Box>
|
|
||||||
<Spacer />
|
|
||||||
<Box>
|
|
||||||
<VictoryPie
|
|
||||||
colorScale="qualitative"
|
|
||||||
data={initData.chartData}
|
|
||||||
labelComponent={<VictoryTooltip flyoutPadding={18} style={{ fontSize: 24 }} cornerRadius={15} />}
|
|
||||||
style={{
|
|
||||||
labels: {
|
|
||||||
fill: 'black',
|
|
||||||
fontFamily: 'Poppins',
|
|
||||||
fontSize: 28,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
labels={({ datum }) => `${datum.z}: ${datum.x} (${Math.trunc(datum.y)}ms)`}
|
|
||||||
labelPlacement="parallel"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Flex>
|
|
||||||
</Center>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RightBar;
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { Box, Text } from '@chakra-ui/react';
|
|
||||||
|
|
||||||
const TopBar: React.FC = () => {
|
|
||||||
return (
|
|
||||||
<Box w="full" h="4xs">
|
|
||||||
<Text paddingLeft={3} fontSize="lg">
|
|
||||||
Resources
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TopBar;
|
|
||||||
@@ -1,257 +0,0 @@
|
|||||||
import { useParams } from 'react-router-dom';
|
|
||||||
import React, { useEffect, useState, useMemo } from 'react';
|
|
||||||
import { fetchNui } from '../utils/fetchNui';
|
|
||||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
Thead,
|
|
||||||
Tbody,
|
|
||||||
Tr,
|
|
||||||
Th,
|
|
||||||
Td,
|
|
||||||
chakra,
|
|
||||||
Flex,
|
|
||||||
IconButton,
|
|
||||||
Text,
|
|
||||||
Spinner,
|
|
||||||
Tooltip,
|
|
||||||
useToast,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import {
|
|
||||||
TriangleDownIcon,
|
|
||||||
TriangleUpIcon,
|
|
||||||
ArrowLeftIcon,
|
|
||||||
ChevronLeftIcon,
|
|
||||||
ArrowRightIcon,
|
|
||||||
ChevronRightIcon,
|
|
||||||
} from '@chakra-ui/icons';
|
|
||||||
import { useTable, useSortBy, Column, usePagination, useFlexLayout } from 'react-table';
|
|
||||||
import { debugData } from '../utils/debugData';
|
|
||||||
import { setClipboard } from '../utils/setClipboard';
|
|
||||||
|
|
||||||
interface QueryData {
|
|
||||||
date: number;
|
|
||||||
query: string;
|
|
||||||
executionTime: number;
|
|
||||||
slow?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TableData {
|
|
||||||
query: string;
|
|
||||||
executionTime: number;
|
|
||||||
slow?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NuiData {
|
|
||||||
queries: QueryData[];
|
|
||||||
pageCount: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Resource: React.FC = () => {
|
|
||||||
const { resource } = useParams();
|
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
const [isLoaded, setIsLoaded] = useState(false);
|
|
||||||
const [resourceData, setResourceData] = useState<QueryData[]>([
|
|
||||||
{
|
|
||||||
date: 0,
|
|
||||||
query: '',
|
|
||||||
executionTime: 0,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const [totalPages, setTotalPages] = useState(1);
|
|
||||||
|
|
||||||
const data = useMemo<TableData[]>(() => resourceData, [resourceData]);
|
|
||||||
|
|
||||||
const columns = useMemo<Column<TableData>[]>(
|
|
||||||
() => [
|
|
||||||
{
|
|
||||||
Header: 'Query',
|
|
||||||
accessor: 'query',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: 'Execution time (ms)',
|
|
||||||
accessor: 'executionTime',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: 'Slow',
|
|
||||||
accessor: 'slow',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
|
||||||
getTableProps,
|
|
||||||
getTableBodyProps,
|
|
||||||
headerGroups,
|
|
||||||
page,
|
|
||||||
canPreviousPage,
|
|
||||||
canNextPage,
|
|
||||||
pageOptions,
|
|
||||||
pageCount,
|
|
||||||
gotoPage,
|
|
||||||
nextPage,
|
|
||||||
previousPage,
|
|
||||||
state: { pageIndex, sortBy },
|
|
||||||
prepareRow,
|
|
||||||
} = useTable(
|
|
||||||
{
|
|
||||||
columns,
|
|
||||||
data,
|
|
||||||
initialState: { pageSize: 12, hiddenColumns: ['slow'] },
|
|
||||||
manualPagination: true,
|
|
||||||
manualSortBy: true,
|
|
||||||
pageCount: totalPages,
|
|
||||||
autoResetPage: false,
|
|
||||||
},
|
|
||||||
useSortBy,
|
|
||||||
usePagination,
|
|
||||||
useFlexLayout
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchNui('fetchResource', { resource, pageIndex, sortBy });
|
|
||||||
setIsLoaded(false);
|
|
||||||
debugData<NuiData>([
|
|
||||||
{
|
|
||||||
action: 'loadResource',
|
|
||||||
data: {
|
|
||||||
queries: [
|
|
||||||
{ query: 'SELECT * FROM `owned_vehicles`', date: 0, executionTime: 3.5 },
|
|
||||||
{ query: 'SELECT * FROM `users`', date: 0, executionTime: 7.3 },
|
|
||||||
{ query: 'SELECT * FROM `properties`', date: 0, executionTime: 25.7 },
|
|
||||||
],
|
|
||||||
pageCount: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}, [resource, pageIndex, sortBy]);
|
|
||||||
|
|
||||||
useNuiEvent<NuiData>('loadResource', (data) => {
|
|
||||||
setResourceData(data.queries);
|
|
||||||
setTotalPages(data.pageCount);
|
|
||||||
setIsLoaded(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleClick = (value: string) => {
|
|
||||||
setClipboard(value);
|
|
||||||
toast({
|
|
||||||
title: 'Query copied to clipboard',
|
|
||||||
duration: 2500,
|
|
||||||
status: 'success',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex direction="column" justifyContent="space-between" alignItems="center" h="full">
|
|
||||||
<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"
|
|
||||||
borderBottomColor="#313C4A"
|
|
||||||
textAlign="center"
|
|
||||||
>
|
|
||||||
{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()}>
|
|
||||||
{isLoaded && (
|
|
||||||
<>
|
|
||||||
{page.map((row, index) => {
|
|
||||||
prepareRow(row);
|
|
||||||
return (
|
|
||||||
<Tr {...row.getRowProps()} key={`row-${index}`}>
|
|
||||||
{row.cells.map((cell, index) => (
|
|
||||||
<React.Fragment key={`row-${index}`}>
|
|
||||||
<Tooltip
|
|
||||||
isDisabled={cell.column.id === 'executionTime'}
|
|
||||||
label={cell.value}
|
|
||||||
openDelay={500}
|
|
||||||
key={`cell-${index}`}
|
|
||||||
>
|
|
||||||
<Td
|
|
||||||
{...cell.getCellProps()}
|
|
||||||
fontFamily="Poppins"
|
|
||||||
borderBottomColor="#313C4A"
|
|
||||||
color={row.values.slow && '#f3eca1'}
|
|
||||||
isTruncated={cell.column.id === 'query'}
|
|
||||||
textAlign={cell.column.id === 'executionTime' ? 'center' : 'left'}
|
|
||||||
onClick={(e) => cell.column.id === 'query' && handleClick(cell.value)}
|
|
||||||
>
|
|
||||||
{cell.render('Cell')}
|
|
||||||
</Td>
|
|
||||||
</Tooltip>
|
|
||||||
</React.Fragment>
|
|
||||||
))}
|
|
||||||
</Tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Tbody>
|
|
||||||
</Table>
|
|
||||||
|
|
||||||
{!isLoaded && <Spinner />}
|
|
||||||
|
|
||||||
<Flex justifyContent="center" alignItems="center" p={3}>
|
|
||||||
<Flex>
|
|
||||||
<IconButton
|
|
||||||
icon={<ArrowLeftIcon h={3} w={3} color="black" />}
|
|
||||||
aria-label="Last page"
|
|
||||||
onClick={() => gotoPage(0)}
|
|
||||||
size="sm"
|
|
||||||
isDisabled={!canPreviousPage}
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
aria-label="Previous page"
|
|
||||||
onClick={previousPage}
|
|
||||||
isDisabled={!canPreviousPage}
|
|
||||||
icon={<ChevronLeftIcon h={6} w={6} color="black" />}
|
|
||||||
size="sm"
|
|
||||||
ml={4}
|
|
||||||
/>
|
|
||||||
</Flex>
|
|
||||||
<Text align="center" pl={4} pr={4}>
|
|
||||||
Page {pageIndex + 1} of {pageOptions.length}
|
|
||||||
</Text>
|
|
||||||
<Flex>
|
|
||||||
<IconButton
|
|
||||||
aria-label="Next page"
|
|
||||||
onClick={nextPage}
|
|
||||||
size="sm"
|
|
||||||
isDisabled={!canNextPage}
|
|
||||||
icon={<ChevronRightIcon h={6} w={6} color="black" />}
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
aria-label="Last page"
|
|
||||||
onClick={() => gotoPage(pageCount - 1)}
|
|
||||||
isDisabled={!canNextPage}
|
|
||||||
icon={<ArrowRightIcon h={3} w={3} color="black" />}
|
|
||||||
size="sm"
|
|
||||||
ml={4}
|
|
||||||
/>
|
|
||||||
</Flex>
|
|
||||||
</Flex>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Resource;
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import { MutableRefObject, useEffect, useRef } from 'react';
|
|
||||||
import { noop } from '../utils/misc';
|
|
||||||
|
|
||||||
interface NuiMessageData<T = unknown> {
|
|
||||||
action: string;
|
|
||||||
data: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
type NuiHandlerSignature<T> = (data: T) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A hook that manage events listeners for receiving data from the client scripts
|
|
||||||
* @param action The specific `action` that should be listened for.
|
|
||||||
* @param handler The callback function that will handle data relayed by this hook
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* useNuiEvent<{visibility: true, wasVisible: 'something'}>('setVisible', (data) => {
|
|
||||||
* // whatever logic you want
|
|
||||||
* })
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
|
|
||||||
export const useNuiEvent = <T = any>(action: string, handler: (data: T) => void) => {
|
|
||||||
const savedHandler: MutableRefObject<NuiHandlerSignature<T>> = useRef(noop);
|
|
||||||
|
|
||||||
// Make sure we handle for a reactive handler
|
|
||||||
useEffect(() => {
|
|
||||||
savedHandler.current = handler;
|
|
||||||
}, [handler]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const eventListener = (event: MessageEvent<NuiMessageData<T>>) => {
|
|
||||||
const { action: eventAction, data } = event.data;
|
|
||||||
|
|
||||||
if (savedHandler.current) {
|
|
||||||
if (eventAction === action) {
|
|
||||||
savedHandler.current(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('message', eventListener);
|
|
||||||
// Remove Event Listener on component cleanup
|
|
||||||
return () => window.removeEventListener('message', eventListener);
|
|
||||||
}, [action]);
|
|
||||||
};
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
|
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
|
|
||||||
'Droid Sans', 'Helvetica Neue', sans-serif;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
height: 100vh;
|
|
||||||
background: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
#root {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar {
|
|
||||||
width: 2px;
|
|
||||||
border-radius: 1vh;
|
|
||||||
background-color: transparent;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar-thumb {
|
|
||||||
background: grey;
|
|
||||||
border-radius: 1vh;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
|
||||||
import './index.css';
|
|
||||||
import App from './components/App';
|
|
||||||
import { VisibilityProvider } from './providers/VisibilityProvider';
|
|
||||||
import { ChakraProvider } from '@chakra-ui/react';
|
|
||||||
|
|
||||||
ReactDOM.render(
|
|
||||||
<React.StrictMode>
|
|
||||||
<VisibilityProvider>
|
|
||||||
<ChakraProvider>
|
|
||||||
<BrowserRouter>
|
|
||||||
<App />
|
|
||||||
</BrowserRouter>
|
|
||||||
</ChakraProvider>
|
|
||||||
</VisibilityProvider>
|
|
||||||
</React.StrictMode>,
|
|
||||||
document.getElementById('root')
|
|
||||||
);
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import React, { Context, createContext, useContext, useEffect, useState } from 'react';
|
|
||||||
import { useNuiEvent } from '../hooks/useNuiEvent';
|
|
||||||
import { fetchNui } from '../utils/fetchNui';
|
|
||||||
|
|
||||||
const VisibilityCtx = createContext<VisibilityProviderValue | null>(null);
|
|
||||||
|
|
||||||
interface VisibilityProviderValue {
|
|
||||||
setVisible: (visible: boolean) => void;
|
|
||||||
visible: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should be mounted at the top level of your application, it is currently set to
|
|
||||||
// apply a CSS visibility value. If this is non-performant, this should be customized.
|
|
||||||
export const VisibilityProvider: React.FC = ({ children }) => {
|
|
||||||
const [visible, setVisible] = useState(false);
|
|
||||||
|
|
||||||
useNuiEvent<boolean>('openUI', setVisible);
|
|
||||||
|
|
||||||
// Handle pressing escape/backspace
|
|
||||||
useEffect(() => {
|
|
||||||
// Only attach listener when we are visible
|
|
||||||
if (!visible) return;
|
|
||||||
|
|
||||||
const keyHandler = (e: KeyboardEvent) => {
|
|
||||||
if (['Escape'].includes(e.code)) {
|
|
||||||
fetchNui('exit');
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('keydown', keyHandler);
|
|
||||||
|
|
||||||
return () => window.removeEventListener('keydown', keyHandler);
|
|
||||||
}, [visible]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<VisibilityCtx.Provider
|
|
||||||
value={{
|
|
||||||
visible,
|
|
||||||
setVisible,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ visibility: visible ? 'visible' : 'hidden', height: '100%' }}>{children}</div>
|
|
||||||
</VisibilityCtx.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useVisibility = () =>
|
|
||||||
useContext<VisibilityProviderValue>(VisibilityCtx as Context<VisibilityProviderValue>);
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
/// <reference types="react-scripts" />
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
interface ChartData {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
z: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type InitData = {
|
|
||||||
resources: string[];
|
|
||||||
totalQueries: number;
|
|
||||||
totalTime: number;
|
|
||||||
slowQueries: number;
|
|
||||||
chartData: ChartData[];
|
|
||||||
};
|
|
||||||
Vendored
-122
@@ -1,122 +0,0 @@
|
|||||||
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> {}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// Will return whether the current environment is in a regular browser
|
|
||||||
// and not CEF
|
|
||||||
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
|
||||||
|
|
||||||
// Basic no operation function
|
|
||||||
export const noop = () => {};
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// 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);
|
|
||||||
};
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es5",
|
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
|
||||||
"allowJs": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"strict": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"noFallthroughCasesInSwitch": true,
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"isolatedModules": true,
|
|
||||||
"noEmit": true,
|
|
||||||
"jsx": "react-jsx"
|
|
||||||
},
|
|
||||||
"include": ["src"]
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 120,
|
||||||
|
"singleQuote": true,
|
||||||
|
"useTabs": false,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"semi": true,
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
|
||||||
|
"pluginSearchDirs": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Vite + Svelte + TS</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "oxmysql",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "vite",
|
||||||
|
"start:game": "vite build --watch",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^2.0.3",
|
||||||
|
"@tsconfig/svelte": "^3.0.0",
|
||||||
|
"svelte": "^3.55.1",
|
||||||
|
"svelte-check": "^2.10.3",
|
||||||
|
"tslib": "^2.5.0",
|
||||||
|
"typescript": "^4.9.3",
|
||||||
|
"vite": "^4.2.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tabler/icons-svelte": "^2.10.0",
|
||||||
|
"@tanstack/svelte-table": "^8.8.0",
|
||||||
|
"autoprefixer": "^10.4.14",
|
||||||
|
"chart.js": "^4.2.1",
|
||||||
|
"postcss": "^8.4.21",
|
||||||
|
"prettier": "^2.8.4",
|
||||||
|
"prettier-plugin-svelte": "^2.9.0",
|
||||||
|
"prettier-plugin-tailwindcss": "^0.2.5",
|
||||||
|
"svelte-chartjs": "^3.1.2",
|
||||||
|
"svelte-floating-ui": "^1.5.2",
|
||||||
|
"svelte-portal": "^2.2.0",
|
||||||
|
"tailwindcss": "^3.2.7",
|
||||||
|
"tinro": "^0.6.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+1311
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,85 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Route, router } from 'tinro';
|
||||||
|
import Resource from './pages/resource/Resource.svelte';
|
||||||
|
import Root from './pages/root/Root.svelte';
|
||||||
|
import { useNuiEvent } from './utils/useNuiEvent';
|
||||||
|
import { resources, generalData, chartData } from './store';
|
||||||
|
import { debugData } from './utils/debugData';
|
||||||
|
import { visible } from './store';
|
||||||
|
import { scale } from 'svelte/transition';
|
||||||
|
import { fetchNui } from './utils/fetchNui';
|
||||||
|
|
||||||
|
interface OpenData {
|
||||||
|
resources: string[];
|
||||||
|
totalQueries: number;
|
||||||
|
slowQueries: number;
|
||||||
|
totalTime: number;
|
||||||
|
chartData: {
|
||||||
|
labels: string[];
|
||||||
|
data: { queries: number; time: number }[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
router.mode.hash();
|
||||||
|
router.goto('/');
|
||||||
|
|
||||||
|
useNuiEvent('openUI', (data: OpenData) => {
|
||||||
|
$visible = true;
|
||||||
|
$resources = data.resources;
|
||||||
|
$generalData = {
|
||||||
|
queries: data.totalQueries,
|
||||||
|
slowQueries: data.slowQueries,
|
||||||
|
timeQuerying: data.totalTime,
|
||||||
|
};
|
||||||
|
$chartData = {
|
||||||
|
labels: data.chartData.labels,
|
||||||
|
data: data.chartData.data,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
debugData<OpenData>([
|
||||||
|
{
|
||||||
|
action: 'openUI',
|
||||||
|
data: {
|
||||||
|
resources: ['ox_core', 'oxmysql', 'ox_inventory', 'ox_doorlock', 'ox_lib', 'ox_vehicleshop', 'ox_target'],
|
||||||
|
slowQueries: 13,
|
||||||
|
totalQueries: 332,
|
||||||
|
totalTime: 230123,
|
||||||
|
chartData: {
|
||||||
|
labels: ['oxmysql', 'ox_core', 'ox_inventory', 'ox_doorlock'],
|
||||||
|
data: [
|
||||||
|
{ queries: 25, time: 133 },
|
||||||
|
{ queries: 5, time: 12 },
|
||||||
|
{ queries: 3, time: 2 },
|
||||||
|
{ queries: 72, time: 133 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handleESC = (e: KeyboardEvent) => {
|
||||||
|
if (e.key !== 'Escape') return;
|
||||||
|
|
||||||
|
$visible = false;
|
||||||
|
fetchNui('exit');
|
||||||
|
};
|
||||||
|
|
||||||
|
$: $visible ? window.addEventListener('keydown', handleESC) : window.removeEventListener('keydown', handleESC);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if $visible}
|
||||||
|
<main
|
||||||
|
transition:scale={{ start: 0.95, duration: 150 }}
|
||||||
|
class="w-full h-full flex justify-center items-center font-main"
|
||||||
|
>
|
||||||
|
<div class="bg-dark-800 text-white w-[1000px] h-[600px] flex rounded-md">
|
||||||
|
<Route path="/">
|
||||||
|
<Root />
|
||||||
|
</Route>
|
||||||
|
<Route path="/:resource">
|
||||||
|
<Resource />
|
||||||
|
</Route>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
@import url(https://use.typekit.net/wxh5ury.css);
|
||||||
|
|
||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: #25262b;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: #909296;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: #a6a7ab;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import './index.css';
|
||||||
|
import App from './App.svelte';
|
||||||
|
import { isEnvBrowser } from './utils/misc';
|
||||||
|
|
||||||
|
const app = new App({
|
||||||
|
target: document.getElementById('app'),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
const root = document.getElementById('app');
|
||||||
|
|
||||||
|
// https://i.imgur.com/iPTAdYV.png - Night time img
|
||||||
|
root!.style.backgroundImage = 'url("https://i.imgur.com/3pzRj9n.png")';
|
||||||
|
root!.style.backgroundSize = 'cover';
|
||||||
|
root!.style.backgroundRepeat = 'no-repeat';
|
||||||
|
root!.style.backgroundPosition = 'center';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default app;
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { fetchNui } from '../../utils/fetchNui';
|
||||||
|
import Pagination from './components/Pagination.svelte';
|
||||||
|
import QueryTable from './components/QueryTable.svelte';
|
||||||
|
import ResourceHeader from './components/ResourceHeader.svelte';
|
||||||
|
import { meta } from 'tinro';
|
||||||
|
import { useNuiEvent } from '../../utils/useNuiEvent';
|
||||||
|
import { queries, resourceData, type QueryData } from '../../store';
|
||||||
|
import { debugData } from '../../utils/debugData';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import { tablePage } from '../../store';
|
||||||
|
|
||||||
|
let maxPage = 0;
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
$queries = [];
|
||||||
|
$tablePage = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
interface ResourceData {
|
||||||
|
queries: QueryData[];
|
||||||
|
pageCount: number;
|
||||||
|
resourceQueriesCount: number;
|
||||||
|
resourceSlowQueries: number;
|
||||||
|
resourceTime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugData<ResourceData>([
|
||||||
|
{
|
||||||
|
action: 'loadResource',
|
||||||
|
data: {
|
||||||
|
queries: [
|
||||||
|
{ query: 'SELECT * FROM users WHERE ID = 1', executionTime: 3, slow: false, date: Date.now() },
|
||||||
|
{ query: 'SELECT * FROM users WHERE ID = 1', executionTime: 23, slow: true, date: Date.now() },
|
||||||
|
{ query: 'SELECT * FROM users WHERE ID = 1', executionTime: 15, slow: false, date: Date.now() },
|
||||||
|
{ query: 'SELECT * FROM users WHERE ID = 1', executionTime: 122, slow: true, date: Date.now() },
|
||||||
|
],
|
||||||
|
resourceQueriesCount: 3,
|
||||||
|
resourceSlowQueries: 2,
|
||||||
|
resourceTime: 1342,
|
||||||
|
pageCount: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
// I miss callbacks :(
|
||||||
|
useNuiEvent('loadResource', (data: ResourceData) => {
|
||||||
|
maxPage = data.pageCount;
|
||||||
|
$queries = data.queries;
|
||||||
|
$resourceData = {
|
||||||
|
resourceQueriesCount: data.resourceQueriesCount,
|
||||||
|
resourceSlowQueries: data.resourceSlowQueries,
|
||||||
|
resourceTime: data.resourceTime,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-col w-full justify-between">
|
||||||
|
<div>
|
||||||
|
<ResourceHeader />
|
||||||
|
<QueryTable />
|
||||||
|
</div>
|
||||||
|
<Pagination {maxPage} />
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import IconChevronLeft from '@tabler/icons-svelte/dist/svelte/icons/IconChevronLeft.svelte';
|
||||||
|
import IconChevronRight from '@tabler/icons-svelte/dist/svelte/icons/IconChevronRight.svelte';
|
||||||
|
import IconChevronsLeft from '@tabler/icons-svelte/dist/svelte/icons/IconChevronsLeft.svelte';
|
||||||
|
import IconChevronsRight from '@tabler/icons-svelte/dist/svelte/icons/IconChevronsRight.svelte';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
import { tablePage } from '../../../store';
|
||||||
|
|
||||||
|
export let maxPage: number;
|
||||||
|
|
||||||
|
onDestroy(() => (maxPage = 0));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex justify-center items-center gap-6 pb-5">
|
||||||
|
<button
|
||||||
|
disabled={$tablePage === 0}
|
||||||
|
on:click={() => ($tablePage = 0)}
|
||||||
|
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||||
|
>
|
||||||
|
<IconChevronsLeft />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
disabled={$tablePage === 0}
|
||||||
|
on:click={() => $tablePage--}
|
||||||
|
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</button>
|
||||||
|
<p>Page {$tablePage + 1} of {maxPage}</p>
|
||||||
|
<button
|
||||||
|
disabled={$tablePage >= maxPage - 1}
|
||||||
|
on:click={() => $tablePage++}
|
||||||
|
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||||
|
>
|
||||||
|
<IconChevronRight />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
disabled={$tablePage === maxPage - 1}
|
||||||
|
on:click={() => ($tablePage = maxPage - 1)}
|
||||||
|
class="bg-dark-600 disabled:bg-dark-300 disabled:text-dark-400 disabled:cursor-not-allowed text-dark-100 hover:text-white focus-visible:text-white rounded-md hover:bg-dark-500 p-2 active:translate-y-[3px] outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||||
|
>
|
||||||
|
<IconChevronsRight />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import IconChevronDown from '@tabler/icons-svelte/dist/svelte/icons/IconChevronDown.svelte';
|
||||||
|
import IconChevronUp from '@tabler/icons-svelte/dist/svelte/icons/IconChevronUp.svelte';
|
||||||
|
|
||||||
|
import { queries, type QueryData } from '../../../store';
|
||||||
|
import {
|
||||||
|
createSvelteTable,
|
||||||
|
getCoreRowModel,
|
||||||
|
type TableOptions,
|
||||||
|
type ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
type SortingState,
|
||||||
|
} from '@tanstack/svelte-table';
|
||||||
|
import { writable } from 'svelte/store';
|
||||||
|
import { meta } from 'tinro';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { debouncedTablePage } from '../../../store';
|
||||||
|
import QueryTooltip from './QueryTooltip.svelte';
|
||||||
|
|
||||||
|
const route = meta();
|
||||||
|
|
||||||
|
const columns: ColumnDef<QueryData, number>[] = [
|
||||||
|
{
|
||||||
|
accessorKey: 'query',
|
||||||
|
header: 'Query',
|
||||||
|
cell: (info) => info.getValue(),
|
||||||
|
enableSorting: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'executionTime',
|
||||||
|
header: 'Time (ms)',
|
||||||
|
cell: (info) => info.getValue().toFixed(2),
|
||||||
|
enableSorting: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let sorting: SortingState = [];
|
||||||
|
|
||||||
|
const setSorting = (updater) => {
|
||||||
|
if (updater instanceof Function) {
|
||||||
|
sorting = updater(sorting);
|
||||||
|
} else {
|
||||||
|
sorting = updater;
|
||||||
|
}
|
||||||
|
options.update((old) => ({
|
||||||
|
...old,
|
||||||
|
state: {
|
||||||
|
...old.state,
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const options = writable<TableOptions<QueryData>>({
|
||||||
|
data: $queries,
|
||||||
|
columns,
|
||||||
|
manualPagination: true,
|
||||||
|
manualSorting: true,
|
||||||
|
pageCount: -1,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
onSortingChange: setSorting,
|
||||||
|
state: {
|
||||||
|
sorting,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
$: options.update((prev) => ({ ...prev, data: $queries }));
|
||||||
|
|
||||||
|
const table = createSvelteTable(options);
|
||||||
|
|
||||||
|
$: {
|
||||||
|
fetchNui('fetchResource', {
|
||||||
|
resource: route.params.resource,
|
||||||
|
pageIndex: $debouncedTablePage,
|
||||||
|
sortBy: sorting,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="px-4">
|
||||||
|
<table class="w-full">
|
||||||
|
<thead class="bg-dark-600">
|
||||||
|
{#each $table.getHeaderGroups() as headerGroup}
|
||||||
|
<tr>
|
||||||
|
{#each headerGroup.headers as header}
|
||||||
|
<th class={`p-1 bg-dark-600 select-none ${header.id === 'executionTime' ? 'w-1/4' : 'w-3/4'}`}>
|
||||||
|
{#if !header.isPlaceholder}
|
||||||
|
<button
|
||||||
|
class:cursor-pointer={header.column.getCanSort()}
|
||||||
|
class:select-none={header.column.getCanSort()}
|
||||||
|
class="flex items-center justify-center w-full gap-1"
|
||||||
|
on:click={header.column.getToggleSortingHandler()}
|
||||||
|
>
|
||||||
|
<svelte:component this={flexRender(header.column.columnDef.header, header.getContext())} />
|
||||||
|
{#if header.column.getIsSorted() === 'asc'}
|
||||||
|
<IconChevronUp />
|
||||||
|
{:else if header.column.getIsSorted() === 'desc'}
|
||||||
|
<IconChevronDown />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</th>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each $table.getRowModel().rows as row}
|
||||||
|
<tr>
|
||||||
|
{#each row.getVisibleCells() as cell}
|
||||||
|
<QueryTooltip
|
||||||
|
content={cell.getValue()}
|
||||||
|
let:floatingRef
|
||||||
|
let:displayTooltip
|
||||||
|
let:hideTooltip
|
||||||
|
disabled={cell.column.id !== 'query'}
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
use:floatingRef
|
||||||
|
on:mouseenter={displayTooltip}
|
||||||
|
on:mouseleave={hideTooltip}
|
||||||
|
class={`${cell.column.id === 'executionTime' && 'text-center'} p-2 bg-dark-700 ${
|
||||||
|
row.original.slow && 'text-yellow-500'
|
||||||
|
} truncate max-w-[200px]`}
|
||||||
|
>
|
||||||
|
<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
|
||||||
|
</td>
|
||||||
|
</QueryTooltip>
|
||||||
|
{/each}
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { offset, flip, shift } from 'svelte-floating-ui/dom';
|
||||||
|
import { createFloatingActions } from 'svelte-floating-ui';
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
|
import Portal from 'svelte-portal';
|
||||||
|
|
||||||
|
export let content: unknown;
|
||||||
|
export let disabled: boolean;
|
||||||
|
|
||||||
|
const [floatingRef, floatingContent] = createFloatingActions({
|
||||||
|
strategy: 'absolute',
|
||||||
|
placement: 'top',
|
||||||
|
middleware: [offset(6), flip(), shift()],
|
||||||
|
});
|
||||||
|
|
||||||
|
let display = false;
|
||||||
|
|
||||||
|
let timer: NodeJS.Timer;
|
||||||
|
|
||||||
|
const displayTooltip = () => {
|
||||||
|
if (disabled) return;
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
display = true;
|
||||||
|
}, 300);
|
||||||
|
};
|
||||||
|
|
||||||
|
const hideTooltip = () => {
|
||||||
|
if (disabled) return;
|
||||||
|
clearTimeout(timer);
|
||||||
|
display = false;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<slot {floatingRef} {displayTooltip} {hideTooltip} />
|
||||||
|
{#if display && !disabled}
|
||||||
|
<Portal target="body">
|
||||||
|
<div
|
||||||
|
transition:fade={{ duration: 150 }}
|
||||||
|
use:floatingContent
|
||||||
|
class="absolute p-2 text-sm bg-dark-50 text-dark-400 rounded-md max-w-xl font-main"
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</div>
|
||||||
|
</Portal>
|
||||||
|
{/if}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import IconChevronLeft from '@tabler/icons-svelte/dist/svelte/icons/IconChevronLeft.svelte';
|
||||||
|
|
||||||
|
import { meta, router } from 'tinro';
|
||||||
|
import { resourceData } from '../../../store';
|
||||||
|
|
||||||
|
const route = meta();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="p-4 grid grid-flow-col grid-cols-3 items-center ">
|
||||||
|
<button
|
||||||
|
on:click={() => router.goto('/')}
|
||||||
|
class="flex p-2 w-12 bg-dark-600 text-dark-100 hover:text-white rounded-md justify-center items-center hover:bg-dark-500 outline-none border-[1px] border-transparent focus-visible:border-cyan-600"
|
||||||
|
>
|
||||||
|
<IconChevronLeft />
|
||||||
|
</button>
|
||||||
|
<p class="text-center text-lg">{route.params.resource}</p>
|
||||||
|
<div class="text-end text-dark-100 flex flex-col text-xs">
|
||||||
|
<p>Queries: {$resourceData.resourceQueriesCount}</p>
|
||||||
|
<p>Time: {$resourceData.resourceTime.toFixed(2)} ms</p>
|
||||||
|
<p class="text-yellow-500">Slow queries: {$resourceData.resourceSlowQueries}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Search from './components/Search.svelte';
|
||||||
|
import IconFileAnalytics from '@tabler/icons-svelte/dist/svelte/icons/IconFileAnalytics.svelte';
|
||||||
|
import IconSearch from '@tabler/icons-svelte/dist/svelte/icons/IconSearch.svelte';
|
||||||
|
import IconSourceCode from '@tabler/icons-svelte/dist/svelte/icons/IconSourceCode.svelte';
|
||||||
|
import { router } from 'tinro';
|
||||||
|
import { search, filteredResources, generalData } from '../../store';
|
||||||
|
import Chart from './components/Chart.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="p-2 w-full h-full flex justify-between gap-2">
|
||||||
|
<div class="bg-dark-700 p-4 pr-0 flex flex-col w-2/3 rounded-md">
|
||||||
|
<div class="pr-4 flex justify-between items-center">
|
||||||
|
<div class="flex gap-3 items-center ">
|
||||||
|
<p class="text-2xl">Resources</p>
|
||||||
|
<IconSourceCode />
|
||||||
|
</div>
|
||||||
|
<Search icon={IconSearch} bind:value={$search} />
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-3 mt-6 overflow-y-auto pr-4">
|
||||||
|
{#each $filteredResources as resource}
|
||||||
|
<button
|
||||||
|
on:click={() => router.goto(`/${resource}`)}
|
||||||
|
class="bg-dark-600 p-3 border-[1px] outline-none border-transparent focus-visible:border-cyan-600 text-left hover:bg-dark-400 rounded-md"
|
||||||
|
>
|
||||||
|
{resource}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-dark-700 p-4 flex flex-col justify-between w-1/3 rounded-md">
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<div class="flex gap-3 items-center mb-4">
|
||||||
|
<p class="text-2xl">General data</p>
|
||||||
|
<IconFileAnalytics />
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col text-dark-50">
|
||||||
|
<p>Queries: {$generalData.queries}</p>
|
||||||
|
<p>Time querying: {$generalData.timeQuerying.toFixed(2)} ms</p>
|
||||||
|
<p class="text-yellow-500">Slow queries: {$generalData.slowQueries}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Chart />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Pie } from 'svelte-chartjs';
|
||||||
|
import { Chart as ChartJS, Title, Tooltip, ArcElement, CategoryScale, Colors, type TooltipItem } from 'chart.js';
|
||||||
|
import { chartData } from '../../../store';
|
||||||
|
|
||||||
|
ChartJS.register(Title, Tooltip, ArcElement, CategoryScale, Colors);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Pie
|
||||||
|
class="self-center"
|
||||||
|
width={256}
|
||||||
|
height={256}
|
||||||
|
data={{
|
||||||
|
labels: $chartData.labels,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
// @ts-ignore
|
||||||
|
data: $chartData.data,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
options={{
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
responsive: false,
|
||||||
|
parsing: {
|
||||||
|
key: 'time',
|
||||||
|
},
|
||||||
|
animation: false,
|
||||||
|
plugins: {
|
||||||
|
tooltip: {
|
||||||
|
callbacks: {
|
||||||
|
label: (context) => {
|
||||||
|
// @ts-ignore
|
||||||
|
return `Queries: ${context.raw.queries}, Time: ${context.raw.time.toFixed(2)} ms`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let icon: ConstructorOfATypedSvelteComponent;
|
||||||
|
export let value: string;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="p-2 flex items-center outline-none border-[1px] border-transparent transition-all duration-100 focus-within:border-cyan-600 rounded-md bg-dark-600"
|
||||||
|
>
|
||||||
|
<div class="pr-2">
|
||||||
|
<svelte:component this={icon} class="text-dark-300" />
|
||||||
|
</div>
|
||||||
|
<input type="text" bind:value class="bg-transparent outline-none w-full" placeholder="Search resources..." />
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { derived, writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export const visible = writable(false);
|
||||||
|
|
||||||
|
export const search = writable('');
|
||||||
|
let timeout: NodeJS.Timeout;
|
||||||
|
export const debouncedSearch = derived(search, (value, set: (value: string) => void) => {
|
||||||
|
timeout = setTimeout(() => set(value), 500);
|
||||||
|
return () => clearTimeout(timeout);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const resources = writable<string[]>([]);
|
||||||
|
|
||||||
|
export const filteredResources = derived(
|
||||||
|
[resources, debouncedSearch],
|
||||||
|
([$resources, $debouncedSearch], set: (value: string[]) => void) => {
|
||||||
|
if ($debouncedSearch === '' || !$debouncedSearch) return set($resources);
|
||||||
|
|
||||||
|
const query = $debouncedSearch.toLowerCase();
|
||||||
|
|
||||||
|
return set($resources.filter((resource) => resource.toLowerCase().includes(query)));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const generalData = writable({
|
||||||
|
queries: 0,
|
||||||
|
timeQuerying: 0,
|
||||||
|
slowQueries: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const chartData = writable<{ labels: string[]; data: { queries: number; time: number }[] }>({
|
||||||
|
labels: [],
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './general';
|
||||||
|
export * from './resource';
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { derived, writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export interface QueryData {
|
||||||
|
date: number;
|
||||||
|
query: string;
|
||||||
|
executionTime: number;
|
||||||
|
slow?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const queries = writable<QueryData[]>([]);
|
||||||
|
|
||||||
|
export const resourceData = writable<{
|
||||||
|
resourceQueriesCount: number;
|
||||||
|
resourceSlowQueries: number;
|
||||||
|
resourceTime: number;
|
||||||
|
}>({
|
||||||
|
resourceQueriesCount: 0,
|
||||||
|
resourceSlowQueries: 0,
|
||||||
|
resourceTime: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const tablePage = writable(0);
|
||||||
|
|
||||||
|
let timer: NodeJS.Timer;
|
||||||
|
export const debouncedTablePage = derived(tablePage, ($tablePage, set) => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
set($tablePage);
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
@@ -13,7 +13,7 @@ interface DebugEvent<T = any> {
|
|||||||
* @param timer - How long until it should trigger (ms)
|
* @param timer - How long until it should trigger (ms)
|
||||||
*/
|
*/
|
||||||
export const debugData = <P>(events: DebugEvent<P>[], timer = 1000): void => {
|
export const debugData = <P>(events: DebugEvent<P>[], timer = 1000): void => {
|
||||||
if (process.env.NODE_ENV === 'development' && isEnvBrowser()) {
|
if (isEnvBrowser()) {
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
@@ -1,17 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* Simple wrapper around fetch API tailored for CEF/NUI use. This abstraction
|
|
||||||
* can be extended to include AbortController if needed or if the response isn't
|
|
||||||
* JSON. Tailor it to your needs.
|
|
||||||
*
|
|
||||||
* @param eventName - The endpoint eventname to target
|
* @param eventName - The endpoint eventname to target
|
||||||
* @param data - Data you wish to send in the NUI Callback
|
* @param data - Data you wish to send in the NUI Callback
|
||||||
*
|
*
|
||||||
* @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
|
* @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { isEnvBrowser } from './misc';
|
export async function fetchNui<T = any>(eventName: string, data: unknown = {}): Promise<T> {
|
||||||
|
|
||||||
export async function fetchNui<T = any>(eventName: string, data?: any): Promise<T> {
|
|
||||||
const options = {
|
const options = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -20,15 +14,11 @@ export async function fetchNui<T = any>(eventName: string, data?: any): Promise<
|
|||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isEnvBrowser()) return undefined as any;
|
|
||||||
|
|
||||||
const resourceName = (window as any).GetParentResourceName
|
const resourceName = (window as any).GetParentResourceName
|
||||||
? (window as any).GetParentResourceName()
|
? (window as any).GetParentResourceName()
|
||||||
: 'nui-frame-app';
|
: 'nui-frame-app';
|
||||||
|
|
||||||
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
||||||
|
|
||||||
const respFormatted = await resp.json();
|
return await resp.json();
|
||||||
|
|
||||||
return respFormatted;
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { onMount, onDestroy } from 'svelte';
|
||||||
|
|
||||||
|
interface NuiMessage<T = unknown> {
|
||||||
|
action: string;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that manage events listeners for receiving data from the client scripts
|
||||||
|
* @param action The specific `action` that should be listened for.
|
||||||
|
* @param handler The callback function that will handle data relayed by this function
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* useNuiEvent<{visibility: true, wasVisible: 'something'}>('setVisible', (data) => {
|
||||||
|
* // whatever logic you want
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
export function useNuiEvent<T = unknown>(action: string, handler: (data: T) => void) {
|
||||||
|
const eventListener = (event: MessageEvent<NuiMessage<T>>) => {
|
||||||
|
const { action: eventAction, data } = event.data;
|
||||||
|
|
||||||
|
eventAction === action && handler(data);
|
||||||
|
};
|
||||||
|
onMount(() => window.addEventListener('message', eventListener));
|
||||||
|
onDestroy(() => window.removeEventListener('message', eventListener));
|
||||||
|
}
|
||||||
Vendored
+2
@@ -0,0 +1,2 @@
|
|||||||
|
/// <reference types="svelte" />
|
||||||
|
/// <reference types="vite/client" />
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||||
|
// for more information about preprocessors
|
||||||
|
preprocess: vitePreprocess(),
|
||||||
|
};
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: ['./index.html', './src/**/*.{js,ts,svelte}'],
|
||||||
|
theme: {
|
||||||
|
extend: {
|
||||||
|
fontFamily: {
|
||||||
|
main: 'Roboto',
|
||||||
|
},
|
||||||
|
colors: {
|
||||||
|
// Mantine dark colours
|
||||||
|
dark: {
|
||||||
|
50: '#C1C2C5',
|
||||||
|
100: '#A6A7AB',
|
||||||
|
200: '#909296',
|
||||||
|
300: '#5C5F66',
|
||||||
|
400: '#373A40',
|
||||||
|
500: '#2C2E33',
|
||||||
|
600: '#25262B',
|
||||||
|
700: '#1A1B1E',
|
||||||
|
800: '#141517',
|
||||||
|
900: '#101113',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
};
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
/**
|
||||||
|
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||||
|
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||||
|
* Note that setting allowJs false does not prevent the use
|
||||||
|
* of JS in `.svelte` files.
|
||||||
|
*/
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
||||||
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Node"
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [svelte()],
|
||||||
|
base: './',
|
||||||
|
server: {
|
||||||
|
port: 3000,
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
outDir: 'build',
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in new issue
Block a user