feat(mongodb): improve GridFS manager filtering and sorting
* docs: add GridFS manager filter and sort design * feat: improve GridFS manager filtering and sorting
This commit is contained in:
14 files changed
+1294
-40
No files matched your search
@@ -1,13 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { FolderOpen, Plus, RefreshCcw, Trash2 } from "@lucide/vue";
|
||||
import { ArrowDown, ArrowUp, ArrowUpDown, Filter, FolderOpen, Plus, RefreshCcw, Trash2, X } from "@lucide/vue";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { currentGridFsBucketFilter, currentGridFsBucketSort, currentGridFsBucketSortDirection, gridFsBucketSortInputForColumn } from "@/lib/document/gridFsBrowser";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
|
||||
@@ -30,6 +32,9 @@ const selectedBucketName = ref("");
|
||||
const showCreateDialog = ref(false);
|
||||
const showDeleteConfirm = ref(false);
|
||||
const newBucketName = ref("");
|
||||
const filterInput = ref("");
|
||||
const sortInput = ref("");
|
||||
const filterBuilderOpen = ref(false);
|
||||
|
||||
const selectedBucket = computed(() => buckets.value.find((bucket) => bucket.name === selectedBucketName.value) || null);
|
||||
const totalFiles = computed(() => buckets.value.reduce((sum, bucket) => sum + bucket.fileCount, 0));
|
||||
@@ -47,7 +52,7 @@ async function loadBuckets() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const nextBuckets = await api.documentListGridFsBuckets(props.connectionId, props.database);
|
||||
const nextBuckets = await api.documentListGridFsBuckets(props.connectionId, props.database, currentGridFsBucketFilter(filterInput.value), currentGridFsBucketSort(sortInput.value));
|
||||
buckets.value = nextBuckets;
|
||||
if (selectedBucketName.value && !nextBuckets.some((bucket) => bucket.name === selectedBucketName.value)) {
|
||||
selectedBucketName.value = "";
|
||||
@@ -59,6 +64,48 @@ async function loadBuckets() {
|
||||
}
|
||||
}
|
||||
|
||||
function applyQuery() {
|
||||
void loadBuckets();
|
||||
}
|
||||
|
||||
type SortDirection = "asc" | "desc" | null;
|
||||
|
||||
function currentSortDirection(column: "name" | "fileCount" | "totalBytes"): SortDirection {
|
||||
const direction = currentGridFsBucketSortDirection(sortInput.value, column);
|
||||
return direction === "none" ? null : direction;
|
||||
}
|
||||
|
||||
function toggleSortForColumn(column: "name" | "fileCount" | "totalBytes") {
|
||||
const current = currentSortDirection(column);
|
||||
const nextDirection: SortDirection = current === "asc" ? "desc" : current === "desc" ? null : "asc";
|
||||
sortInput.value = gridFsBucketSortInputForColumn(column, nextDirection);
|
||||
void loadBuckets();
|
||||
}
|
||||
|
||||
function sortIconForColumn(column: "name" | "fileCount" | "totalBytes") {
|
||||
const direction = currentSortDirection(column);
|
||||
return direction === "asc" ? ArrowUp : direction === "desc" ? ArrowDown : ArrowUpDown;
|
||||
}
|
||||
|
||||
function sortIconClass(column: "name" | "fileCount" | "totalBytes"): string {
|
||||
return currentSortDirection(column) ? "text-foreground" : "text-muted-foreground/60";
|
||||
}
|
||||
|
||||
function applyBucketNameFilter() {
|
||||
filterBuilderOpen.value = false;
|
||||
void loadBuckets();
|
||||
}
|
||||
|
||||
function resetBucketNameFilter() {
|
||||
filterInput.value = "";
|
||||
}
|
||||
|
||||
function clearBucketNameFilter() {
|
||||
filterInput.value = "";
|
||||
filterBuilderOpen.value = false;
|
||||
void loadBuckets();
|
||||
}
|
||||
|
||||
function openBucket(bucketName = selectedBucketName.value) {
|
||||
if (!bucketName) return;
|
||||
queryStore.openMongoBucket(props.connectionId, props.database, bucketName);
|
||||
@@ -131,6 +178,77 @@ onMounted(() => {
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 overflow-hidden rounded-xl border border-border/70 bg-background/80 shadow-xs">
|
||||
<div class="flex flex-col md:flex-row">
|
||||
<div class="flex min-w-0 flex-1 items-center gap-1 px-2 py-1.5">
|
||||
<Popover v-model:open="filterBuilderOpen">
|
||||
<PopoverTrigger as-child>
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-md border text-[11px] transition-colors"
|
||||
:class="filterInput.trim() ? 'border-primary/40 bg-primary/10 text-primary hover:bg-primary/15' : 'border-border/70 text-muted-foreground hover:bg-accent hover:text-foreground'"
|
||||
>
|
||||
<Filter class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" class="w-[420px] max-w-[calc(100vw-24px)] gap-3 p-3" @click.stop @keydown.stop>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="text-xs font-medium text-foreground">{{ t("grid.filter") }}</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-[minmax(0,1fr)_minmax(0,0.95fr)_minmax(0,1fr)] items-center gap-1.5">
|
||||
<div class="flex h-8 min-w-0 items-center overflow-hidden rounded-md border px-2 text-xs font-medium text-foreground">
|
||||
<span class="truncate">{{ t("gridfsBrowser.name") }}</span>
|
||||
</div>
|
||||
<div class="flex h-8 min-w-0 items-center overflow-hidden rounded-md border px-2 text-xs text-muted-foreground">
|
||||
<span class="truncate">{{ t("grid.filterBuilderContains") }}</span>
|
||||
</div>
|
||||
<Input v-model="filterInput" class="h-8 min-w-0 text-xs" :placeholder="t('gridfsBrowser.bucketNamePlaceholder')" @keydown.enter.prevent="applyBucketNameFilter" />
|
||||
</div>
|
||||
<div class="flex items-center justify-between gap-2 pt-1">
|
||||
<Button variant="ghost" size="sm" class="h-8 px-2 text-xs" @click="clearBucketNameFilter">
|
||||
{{ t("grid.clearFilter") }}
|
||||
</Button>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button variant="ghost" size="sm" class="h-8 px-2 text-xs" @click="resetBucketNameFilter">
|
||||
{{ t("grid.resetFilterBuilder") }}
|
||||
</Button>
|
||||
<Button size="sm" class="h-8 px-3 text-xs" @click="applyBucketNameFilter">
|
||||
{{ t("grid.applyFilter") }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<span class="shrink-0 text-xs font-medium text-blue-600 dark:text-blue-400">{{ t("grid.filter") }}</span>
|
||||
<input v-model="filterInput" autocapitalize="off" autocorrect="off" spellcheck="false" class="h-7 min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground/60" :placeholder="t('gridfsBrowser.bucketNamePlaceholder')" @keydown.enter="applyQuery" />
|
||||
<button
|
||||
v-if="filterInput.trim()"
|
||||
class="shrink-0 text-muted-foreground hover:text-foreground"
|
||||
@click="
|
||||
filterInput = '';
|
||||
applyQuery();
|
||||
"
|
||||
>
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="h-px bg-border/70 md:h-auto md:w-px" />
|
||||
<div class="flex min-w-0 flex-1 items-center gap-1 px-2 py-1.5">
|
||||
<span class="shrink-0 text-xs font-medium text-orange-600 dark:text-orange-400">{{ t("grid.sort") }}</span>
|
||||
<input v-model="sortInput" autocapitalize="off" autocorrect="off" spellcheck="false" class="h-7 min-w-0 flex-1 bg-transparent font-mono text-xs outline-none placeholder:text-muted-foreground/60" placeholder='{"name":1}' @keydown.enter="applyQuery" />
|
||||
<button
|
||||
v-if="sortInput.trim()"
|
||||
class="shrink-0 text-muted-foreground hover:text-foreground"
|
||||
@click="
|
||||
sortInput = '';
|
||||
applyQuery();
|
||||
"
|
||||
>
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="px-4 py-3 text-sm text-destructive">
|
||||
@@ -150,9 +268,24 @@ onMounted(() => {
|
||||
<table class="min-w-full border-collapse text-sm">
|
||||
<thead class="sticky top-0 z-10 bg-background">
|
||||
<tr class="border-b border-border text-left text-xs text-muted-foreground">
|
||||
<th class="px-4 py-2 font-medium">{{ t("gridfsBrowser.name") }}</th>
|
||||
<th class="px-4 py-2 font-medium">{{ t("gridfsBrowser.fileCount") }}</th>
|
||||
<th class="px-4 py-2 font-medium">{{ t("gridfsBrowser.totalSize") }}</th>
|
||||
<th class="px-4 py-2 font-medium">
|
||||
<button type="button" class="inline-flex items-center gap-1 hover:text-foreground" @click="toggleSortForColumn('name')">
|
||||
<span>{{ t("gridfsBrowser.name") }}</span>
|
||||
<component :is="sortIconForColumn('name')" class="h-3.5 w-3.5" :class="sortIconClass('name')" />
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-2 font-medium">
|
||||
<button type="button" class="inline-flex items-center gap-1 hover:text-foreground" @click="toggleSortForColumn('fileCount')">
|
||||
<span>{{ t("gridfsBrowser.fileCount") }}</span>
|
||||
<component :is="sortIconForColumn('fileCount')" class="h-3.5 w-3.5" :class="sortIconClass('fileCount')" />
|
||||
</button>
|
||||
</th>
|
||||
<th class="px-4 py-2 font-medium">
|
||||
<button type="button" class="inline-flex items-center gap-1 hover:text-foreground" @click="toggleSortForColumn('totalBytes')">
|
||||
<span>{{ t("gridfsBrowser.totalSize") }}</span>
|
||||
<component :is="sortIconForColumn('totalBytes')" class="h-3.5 w-3.5" :class="sortIconClass('totalBytes')" />
|
||||
</button>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
Reference in new issue
Block a user