chore(dataset): add context menu

This commit is contained in:
Yann Amsellem
2024-12-03 17:08:40 +01:00
parent 1b0822b461
commit 048e0db7f8
7 changed files with 205 additions and 4 deletions

9
package-lock.json generated
View File

@@ -19,6 +19,7 @@
"@tauri-apps/api": "^1",
"d3": "^7.9.0",
"normalize.css": "^8.0.1",
"tauri-plugin-context-menu": "^0.8.0",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1"
},
"devDependencies": {
@@ -2432,6 +2433,14 @@
"typescript": ">=5.0.0"
}
},
"node_modules/tauri-plugin-context-menu": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/tauri-plugin-context-menu/-/tauri-plugin-context-menu-0.8.0.tgz",
"integrity": "sha512-7+JAFbNpEKqSlnfU3PwQRB9ZGmWPDExgxkuiEv+athavFkAvLMYXlynme0ZW2rQO5ciz8lX/OsgGth7qT0JeNA==",
"dependencies": {
"@tauri-apps/api": "^1.5.0"
}
},
"node_modules/tauri-plugin-store-api": {
"version": "0.0.0",
"resolved": "git+ssh://git@github.com/tauri-apps/tauri-plugin-store.git#a599aee9b0ec92c68ac992ca25084c205ef468eb",

View File

@@ -24,6 +24,7 @@
"@tauri-apps/api": "^1",
"d3": "^7.9.0",
"normalize.css": "^8.0.1",
"tauri-plugin-context-menu": "^0.8.0",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1"
},
"devDependencies": {

145
src-tauri/Cargo.lock generated
View File

@@ -30,6 +30,7 @@ dependencies = [
"bindgen",
"tauri",
"tauri-build",
"tauri-plugin-context-menu",
"tauri-plugin-store",
"thiserror",
]
@@ -162,6 +163,12 @@ dependencies = [
"syn 2.0.77",
]
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -506,6 +513,12 @@ version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -720,6 +733,21 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "exr"
version = "1.73.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83197f59927b46c04a183a619b7c29df34e63e63c7869320862268c0ef687e0"
dependencies = [
"bit_field",
"half",
"lebe",
"miniz_oxide 0.8.0",
"rayon-core",
"smallvec",
"zune-inflate",
]
[[package]]
name = "fastrand"
version = "2.1.1"
@@ -1019,6 +1047,16 @@ dependencies = [
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "gif"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2"
dependencies = [
"color_quant",
"weezl",
]
[[package]]
name = "gimli"
version = "0.31.0"
@@ -1185,6 +1223,16 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "half"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888"
dependencies = [
"cfg-if",
"crunchy",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@@ -1329,7 +1377,13 @@ dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"exr",
"gif",
"jpeg-decoder",
"num-traits",
"png",
"qoi",
"tiff",
]
[[package]]
@@ -1436,6 +1490,15 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jpeg-decoder"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
dependencies = [
"rayon",
]
[[package]]
name = "js-sys"
version = "0.3.70"
@@ -1487,6 +1550,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "lebe"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]]
name = "libc"
version = "0.2.159"
@@ -2119,6 +2188,15 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "qoi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
dependencies = [
"bytemuck",
]
[[package]]
name = "quick-xml"
version = "0.32.0"
@@ -2224,6 +2302,26 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "redox_syscall"
version = "0.5.5"
@@ -2885,6 +2983,27 @@ dependencies = [
"tauri-utils",
]
[[package]]
name = "tauri-plugin-context-menu"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4acbb7935b3773a9615315eeebab32d16c4fec95cae6aa410488c41a1d306b77"
dependencies = [
"cocoa",
"dispatch",
"gdk",
"glib",
"gtk",
"image",
"lazy_static",
"libc",
"objc",
"serde",
"tauri",
"time",
"winapi",
]
[[package]]
name = "tauri-plugin-store"
version = "0.0.0"
@@ -3038,6 +3157,17 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tiff"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]]
name = "time"
version = "0.3.36"
@@ -3512,6 +3642,12 @@ dependencies = [
"windows-metadata",
]
[[package]]
name = "weezl"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "winapi"
version = "0.3.9"
@@ -4012,3 +4148,12 @@ dependencies = [
"quote",
"syn 2.0.77",
]
[[package]]
name = "zune-inflate"
version = "0.2.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
dependencies = [
"simd-adler32",
]

View File

@@ -12,6 +12,7 @@ bindgen = "0.70.1"
[dependencies]
tauri = { version = "1", features = [ "dialog-open", "window-unmaximize", "window-start-dragging", "window-maximize", "shell-open"] }
tauri-plugin-context-menu = "0.8.2"
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
thiserror = "1"

View File

@@ -15,6 +15,7 @@ struct AppState {
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.plugin(tauri_plugin_context_menu::init())
.setup(|app| {
let working_dir = app.path_resolver().app_local_data_dir().unwrap();
let clickhouse_dir = working_dir.join("ch");

View File

@@ -4,10 +4,13 @@
import Database from '$lib/icons/Database.svelte';
import Plus from '$lib/icons/Plus.svelte';
import Table from '$lib/icons/Table.svelte';
import { listen } from '@tauri-apps/api/event';
import { showMenu } from 'tauri-plugin-context-menu';
import AddDataset from './AddDataset.svelte';
import {
DATASOURCE_TYPE_COLOR_MAP,
DATASOURCE_TYPE_SHORT_NAME_MAP,
DEFAULT_SOURCE,
filter,
remove_nullable
} from './utils';
@@ -24,7 +27,41 @@
<article>
{#each filtered as source, i (source.slug)}
<details open={i === 0}>
<summary>
<summary
oncontextmenu={async (e) => {
e.preventDefault();
const element = e.currentTarget;
element.classList.add('Selected');
await showMenu({
theme: 'dark',
items: [
{
label: 'Reload',
event: () => datasets.refresh(source)
},
{
label: 'Copy path',
event: () => navigator.clipboard.writeText(source.path)
},
{
label: 'Copy slug',
event: () => navigator.clipboard.writeText(source.slug)
},
{ is_separator: true },
{
label: 'Remove',
event: () => datasets.remove(source),
disabled: source.slug === DEFAULT_SOURCE.slug
}
]
});
const unlistenMenuClose = await listen('menu-did-close', () => {
element.classList.remove('Selected');
unlistenMenuClose();
});
}}
>
{#if source.type === 'MergeTree'}
<Database size="15" />
{:else}
@@ -80,9 +117,16 @@
align-items: center;
gap: 5px;
padding: 3px 5px;
border-radius: 3px;
&::-webkit-details-marker {
display: none;
}
&:global(.Selected) {
background-color: hsl(210deg 100% 52%);
}
}
h3 {

View File

@@ -63,17 +63,17 @@ export class Datasets {
}
remove(source: Dataset) {
const index = this.#sources.indexOf(source);
const index = this.#sources.findIndex((s) => s.slug === source.slug);
if (index === -1)
throw new Error('Tried to remove a source that is not registered in the datasets');
this.#sources = this.#sources.filter((s) => s !== source);
this.#sources = this.#sources.filter((s) => s.slug !== source.slug);
this.#onreset(this.#sources);
}
async refresh(source: Dataset) {
const index = this.#sources.indexOf(source);
const index = this.#sources.findIndex((s) => s.slug === source.slug);
if (index === -1)
throw new Error('Tried to refresh a source that is not registered in the datasets');