refactor(web): query tooltip

This commit is contained in:
Luke committed 2023-03-28 22:26:01 +02:00
1 parent abe50d59e7
commit 3d34282305
4 files changed
+91 -6

No files matched your search

+2
View File
@@ -27,6 +27,8 @@
"prettier": "^2.8.4",
"prettier-plugin-svelte": "^2.9.0",
"prettier-plugin-tailwindcss": "^0.2.5",
"svelte-floating-ui": "^1.5.2",
"svelte-portal": "^2.2.0",
"tailwindcss": "^3.2.7",
"tinro": "^0.6.12"
}
+25
View File
@@ -12,6 +12,8 @@ specifiers:
prettier-plugin-tailwindcss: ^0.2.5
svelte: ^3.55.1
svelte-check: ^2.10.3
svelte-floating-ui: ^1.5.2
svelte-portal: ^2.2.0
tailwindcss: ^3.2.7
tinro: ^0.6.12
tslib: ^2.5.0
@@ -26,6 +28,8 @@ dependencies:
prettier: 2.8.4
prettier-plugin-svelte: 2.9.0_k23gl6auqwrxgr3e6o2bajswou
prettier-plugin-tailwindcss: 0.2.5_yjdjpc7im5hvpskij45owfsns4
svelte-floating-ui: 1.5.2
svelte-portal: 2.2.0
tailwindcss: 3.2[email protected]
tinro: 0.6.12
@@ -238,6 +242,16 @@ packages:
dev: true
optional: true
/@floating-ui/core/1.2.5:
resolution: {integrity: sha512-qrcbyfnRVziRlB6IYwjCopYhO7Vud750JlJyuljruIXcPxr22y8zdckcJGsuOdnQ639uVD1tTXddrcH3t3QYIQ==}
dev: false
/@floating-ui/dom/1.2.5:
resolution: {integrity: sha512-+sAUfpQ3Frz+VCbPCqj+cZzvEESy3fjSeT/pDWkYCWOBXYNNKZfuVsHuv8/JO2zze8+Eb/Q7a6hZVgzS81fLbQ==}
dependencies:
'@floating-ui/core': 1.2.5
dev: false
/@jridgewell/resolve-uri/3.1.0:
resolution: {integrity: sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==}
engines: {node: '>=6.0.0'}
@@ -1068,6 +1082,13 @@ packages:
- sugarss
dev: true
/svelte-floating-ui/1.5.2:
resolution: {integrity: sha512-nV50eno74CEsFfFJ6iyN/oNYDEOck1TZjGV3lmJksVRbiiUAVF6bHspyAhR7GZ7c/4qbRWp9UyX24J+UXdEpag==}
dependencies:
'@floating-ui/core': 1.2.5
'@floating-ui/dom': 1.2.5
dev: false
/svelte-hmr/[email protected]:
resolution: {integrity: sha512-BiKB4RZ8YSwRKCNVdNxK/GfY+r4Kjgp9jCLEy0DuqAKfmQtpL38cQK3afdpjw4sqSs4PLi3jIPJIFp259NkZtA==}
engines: {node: ^12.20 || ^14.13.1 || >= 16}
@@ -1077,6 +1098,10 @@ packages:
svelte: 3.57.0
dev: true
/svelte-portal/2.2.0:
resolution: {integrity: sha512-jhtZWtD6cUE2nMw46dJ5VXWYiqnER+JH+V/BmNBQ5fNP/YdsJCpJi+DemUy9msklqGb0f+wLhJPBtKHLWQvzjg==}
dev: false
/svelte-preprocess/4.10.7_ybrbwhhu54cxvzb5hyvixtn33q:
resolution: {integrity: sha512-sNPBnqYD6FnmdBrUmBCaqS00RyCsCpj2BG58A1JBswNF7b0OKviwxqVrOL/CKyJrLSClrSeqQv5BXNg2RUbPOw==}
engines: {node: '>= 9.11.2'}
@@ -13,6 +13,7 @@
import { meta } from 'tinro';
import { fetchNui } from '../../../utils/fetchNui';
import { debouncedTablePage } from '../../../store';
import QueryTooltip from './QueryTooltip.svelte';
const route = meta();
@@ -105,13 +106,24 @@
{#each $table.getRowModel().rows as row}
<tr>
{#each row.getVisibleCells() as cell}
<td
class={`${cell.column.id === 'executionTime' && 'text-center'} p-2 bg-dark-700 ${
row.original.slow && 'text-yellow-500'
}`}
<QueryTooltip
content={cell.getValue()}
let:floatingRef
let:displayTooltip
let:hideTooltip
disabled={cell.column.id !== 'query'}
>
<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
</td>
<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'
}`}
>
<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
</td>
</QueryTooltip>
{/each}
</tr>
{/each}
@@ -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}