@sfxcode/nuxt-ui-mongocamp 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/components/MongocampAggregationBuilder.d.vue.ts +6 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue +390 -0
- package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +6 -0
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +11 -1
- package/dist/runtime/components/MongocampBulkDelete.vue +1 -0
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +11 -1
- package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +29 -0
- package/dist/runtime/components/MongocampBulkEdit.vue +138 -0
- package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +29 -0
- package/dist/runtime/components/MongocampCollectionData.vue +100 -1
- package/dist/runtime/components/MongocampCollectionInfos.vue +162 -0
- package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +1 -0
- package/dist/runtime/components/MongocampFilterBuilder.vue +33 -2
- package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +1 -0
- package/dist/runtime/components/MongocampImport.d.vue.ts +10 -0
- package/dist/runtime/components/MongocampImport.vue +479 -0
- package/dist/runtime/components/MongocampImport.vue.d.ts +10 -0
- package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
- package/dist/runtime/composables/useMongocampAggregation.js +99 -0
- package/dist/runtime/composables/useMongocampBulkDelete.d.ts +1 -1
- package/dist/runtime/composables/useMongocampImport.d.ts +14 -0
- package/dist/runtime/composables/useMongocampImport.js +25 -0
- package/dist/runtime/locales/de.json +140 -2
- package/dist/runtime/locales/en.json +140 -2
- package/dist/runtime/utils/aggregationErrors.d.ts +10 -0
- package/dist/runtime/utils/aggregationErrors.js +17 -0
- package/dist/runtime/utils/aggregationPipeline.d.ts +42 -0
- package/dist/runtime/utils/aggregationPipeline.js +118 -0
- package/dist/runtime/utils/aggregationResult.d.ts +5 -0
- package/dist/runtime/utils/aggregationResult.js +17 -0
- package/dist/runtime/utils/analyzeSamples.d.ts +27 -0
- package/dist/runtime/utils/analyzeSamples.js +92 -0
- package/dist/runtime/utils/batchInsert.d.ts +22 -0
- package/dist/runtime/utils/batchInsert.js +24 -0
- package/dist/runtime/utils/bulkDelete.d.ts +6 -1
- package/dist/runtime/utils/bulkDelete.js +28 -4
- package/dist/runtime/utils/bulkEdit.d.ts +27 -0
- package/dist/runtime/utils/bulkEdit.js +45 -0
- package/dist/runtime/utils/filterSuggestions.d.ts +8 -0
- package/dist/runtime/utils/filterSuggestions.js +15 -0
- package/dist/runtime/utils/importPipeline.d.ts +21 -0
- package/dist/runtime/utils/importPipeline.js +52 -0
- package/dist/runtime/utils/importRows.d.ts +36 -0
- package/dist/runtime/utils/importRows.js +228 -0
- package/dist/runtime/utils/objectId.d.ts +1 -0
- package/dist/runtime/utils/objectId.js +4 -0
- package/package.json +1 -1
|
@@ -7,6 +7,8 @@ import { unwrapExtendedJson, wrapExtendedJson } from "../composables/useMongocam
|
|
|
7
7
|
import { isIsoDateTimeString } from "../utils/isoDate";
|
|
8
8
|
import { downloadTextFile, rowsToCsv } from "../utils/exportRows";
|
|
9
9
|
import { runBulkDelete } from "../utils/bulkDelete";
|
|
10
|
+
import { BulkMatchShortfall, BulkUnaddressableId, buildIdFilter, isEditableField, runBulkUpdate } from "../utils/bulkEdit";
|
|
11
|
+
import { isObjectIdHex } from "../utils/objectId";
|
|
10
12
|
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
11
13
|
import {
|
|
12
14
|
buildCondition,
|
|
@@ -19,6 +21,7 @@ import {
|
|
|
19
21
|
} from "../utils/filterBuilder";
|
|
20
22
|
import useMongocampDocument from "../composables/useMongocampDocument";
|
|
21
23
|
import { useMongocampQuery } from "../composables/useMongocampQuery";
|
|
24
|
+
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
22
25
|
const props = defineProps({
|
|
23
26
|
collectionName: { type: String, required: true }
|
|
24
27
|
});
|
|
@@ -29,6 +32,7 @@ const { isBucketCollection, fileIdForRow, downloadingFileIds, uploading, downloa
|
|
|
29
32
|
const { ensureMetaData } = useMongocampDocument();
|
|
30
33
|
const { and, like, or } = useMongocampQuery();
|
|
31
34
|
const { schemaFromSamples } = useMongocampSchema();
|
|
35
|
+
const { listDistinct } = useMongocampAggregation();
|
|
32
36
|
const fileInputRef = ref(null);
|
|
33
37
|
function openFilePicker() {
|
|
34
38
|
fileInputRef.value?.click();
|
|
@@ -345,6 +349,13 @@ const rowSelection = ref({});
|
|
|
345
349
|
const selectedDocIds = computed(() => Object.keys(rowSelection.value).filter((id) => rowSelection.value[id]));
|
|
346
350
|
const bulkDeleting = ref(false);
|
|
347
351
|
const bulkError = ref("");
|
|
352
|
+
const bulkEditing = ref(false);
|
|
353
|
+
const bulkEditError = ref("");
|
|
354
|
+
const bulkEditOpen = ref(false);
|
|
355
|
+
function openBulkEdit() {
|
|
356
|
+
bulkEditError.value = "";
|
|
357
|
+
bulkEditOpen.value = true;
|
|
358
|
+
}
|
|
348
359
|
function rowId(row, index) {
|
|
349
360
|
return getDocId(row) ?? String(index);
|
|
350
361
|
}
|
|
@@ -353,7 +364,20 @@ async function handleBulkDelete() {
|
|
|
353
364
|
bulkError.value = "";
|
|
354
365
|
const ids = [...selectedDocIds.value];
|
|
355
366
|
try {
|
|
356
|
-
const { failed } = await runBulkDelete(
|
|
367
|
+
const { failed } = await runBulkDelete(
|
|
368
|
+
ids,
|
|
369
|
+
(documentId) => documentApi._delete({ collectionName: props.collectionName, documentId }),
|
|
370
|
+
void 0,
|
|
371
|
+
{
|
|
372
|
+
// one request per chunk for ids a filter can address; the rest (and any chunk that does not
|
|
373
|
+
// come back fully deleted) go one by one. The generated type says string values only.
|
|
374
|
+
canHandle: isObjectIdHex,
|
|
375
|
+
run: async (chunk) => (await documentApi.deleteMany({
|
|
376
|
+
collectionName: props.collectionName,
|
|
377
|
+
requestBody: buildIdFilter(chunk)
|
|
378
|
+
})).deletedCount
|
|
379
|
+
}
|
|
380
|
+
);
|
|
357
381
|
await fetchDocuments();
|
|
358
382
|
if (failed.length > 0) {
|
|
359
383
|
rowSelection.value = Object.fromEntries(failed.map((f) => [f.item, true]));
|
|
@@ -363,6 +387,38 @@ async function handleBulkDelete() {
|
|
|
363
387
|
bulkDeleting.value = false;
|
|
364
388
|
}
|
|
365
389
|
}
|
|
390
|
+
const editableFields = computed(
|
|
391
|
+
() => filterFields.value.filter((f) => f.key !== "metaData" && isEditableField(f.key)).map((f) => ({ key: f.key, type: f.type === "array" || f.type === "object" ? "json" : f.type }))
|
|
392
|
+
);
|
|
393
|
+
function bulkEditFailureReason(error) {
|
|
394
|
+
if (error instanceof BulkMatchShortfall) return t("nuxtUiMongocamp.bulk.editShortfall", { matched: error.matched, expected: error.expected });
|
|
395
|
+
if (error instanceof BulkUnaddressableId) return t("nuxtUiMongocamp.bulk.editUnaddressable");
|
|
396
|
+
return describeError(error).message;
|
|
397
|
+
}
|
|
398
|
+
async function handleBulkEdit(edit) {
|
|
399
|
+
bulkEditing.value = true;
|
|
400
|
+
bulkEditError.value = "";
|
|
401
|
+
const ids = [...selectedDocIds.value];
|
|
402
|
+
const document = { [edit.field]: edit.value };
|
|
403
|
+
try {
|
|
404
|
+
const { failed } = await runBulkUpdate(
|
|
405
|
+
ids,
|
|
406
|
+
(chunk) => documentApi.updateMany({
|
|
407
|
+
collectionName: props.collectionName,
|
|
408
|
+
updateRequest: { filter: buildIdFilter(chunk), document }
|
|
409
|
+
})
|
|
410
|
+
);
|
|
411
|
+
await fetchDocuments();
|
|
412
|
+
if (failed.length > 0) {
|
|
413
|
+
const onScreen = new Set(documents.value.map((row) => getDocId(row)));
|
|
414
|
+
const failedIds = failed.flatMap((f) => f.ids);
|
|
415
|
+
rowSelection.value = Object.fromEntries(failedIds.filter((id) => onScreen.has(id)).map((id) => [id, true]));
|
|
416
|
+
bulkEditError.value = t("nuxtUiMongocamp.bulk.editPartialFailure", { failed: failedIds.length, total: ids.length, reason: bulkEditFailureReason(failed[0].error) });
|
|
417
|
+
}
|
|
418
|
+
} finally {
|
|
419
|
+
bulkEditing.value = false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
366
422
|
async function fetchDocuments() {
|
|
367
423
|
loading.value = true;
|
|
368
424
|
loadError.value = null;
|
|
@@ -472,7 +528,24 @@ const exportMenuItems = computed(() => [
|
|
|
472
528
|
{ label: t("nuxtUiMongocamp.collectionData.exportJson"), icon: "i-lucide-file-json", onSelect: () => exportPage("json") },
|
|
473
529
|
{ label: t("nuxtUiMongocamp.collectionData.exportCsv"), icon: "i-lucide-file-spreadsheet", onSelect: () => exportPage("csv") }
|
|
474
530
|
]);
|
|
531
|
+
const DISTINCT_SUGGESTION_LIMIT = 100;
|
|
532
|
+
let distinctCache = /* @__PURE__ */ new Map();
|
|
533
|
+
async function loadDistinctSuggestions(field) {
|
|
534
|
+
const cached = distinctCache.get(field);
|
|
535
|
+
if (cached) return cached;
|
|
536
|
+
const cache = distinctCache;
|
|
537
|
+
const collection = props.collectionName;
|
|
538
|
+
let suggestions = [];
|
|
539
|
+
try {
|
|
540
|
+
const { values, truncated } = await listDistinct(collection, field, DISTINCT_SUGGESTION_LIMIT);
|
|
541
|
+
if (!truncated) suggestions = [...new Set(values.map(String))].sort((a, b) => a.localeCompare(b));
|
|
542
|
+
} catch {
|
|
543
|
+
}
|
|
544
|
+
if (cache === distinctCache && collection === props.collectionName) cache.set(field, suggestions);
|
|
545
|
+
return suggestions;
|
|
546
|
+
}
|
|
475
547
|
async function init() {
|
|
548
|
+
distinctCache = /* @__PURE__ */ new Map();
|
|
476
549
|
isInitializing.value = true;
|
|
477
550
|
sorting.value = [];
|
|
478
551
|
pagination.value.pageIndex = 1;
|
|
@@ -541,6 +614,11 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
541
614
|
class="hidden"
|
|
542
615
|
@change="handleFileSelected"
|
|
543
616
|
>
|
|
617
|
+
<MongocampImport
|
|
618
|
+
v-if="!isBucketCollection(collectionName)"
|
|
619
|
+
:collection-name="collectionName"
|
|
620
|
+
@imported="init"
|
|
621
|
+
/>
|
|
544
622
|
<UTooltip :text="t('nuxtUiMongocamp.collectionData.reloadTooltip')">
|
|
545
623
|
<UButton
|
|
546
624
|
icon="i-lucide-refresh-cw"
|
|
@@ -607,6 +685,7 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
607
685
|
v-if="filtersOpen"
|
|
608
686
|
v-model="filterDraft"
|
|
609
687
|
:fields="filterFields"
|
|
688
|
+
:load-distinct="loadDistinctSuggestions"
|
|
610
689
|
@apply="onFilterApply"
|
|
611
690
|
/>
|
|
612
691
|
|
|
@@ -655,6 +734,26 @@ watch(() => props.collectionName, init, { immediate: true });
|
|
|
655
734
|
@open="bulkError = ''"
|
|
656
735
|
@clear="rowSelection = {}"
|
|
657
736
|
@confirm="handleBulkDelete"
|
|
737
|
+
>
|
|
738
|
+
<template #actions>
|
|
739
|
+
<UButton
|
|
740
|
+
v-if="editableFields.length > 0"
|
|
741
|
+
icon="i-lucide-pencil"
|
|
742
|
+
color="neutral"
|
|
743
|
+
variant="subtle"
|
|
744
|
+
size="sm"
|
|
745
|
+
:label="t('nuxtUiMongocamp.bulk.editSelected')"
|
|
746
|
+
@click="openBulkEdit"
|
|
747
|
+
/>
|
|
748
|
+
</template>
|
|
749
|
+
</MongocampBulkDelete>
|
|
750
|
+
<MongocampBulkEdit
|
|
751
|
+
v-model:open="bulkEditOpen"
|
|
752
|
+
:selected="selectedDocIds.length"
|
|
753
|
+
:fields="editableFields"
|
|
754
|
+
:saving="bulkEditing"
|
|
755
|
+
:error="bulkEditError"
|
|
756
|
+
@apply="handleBulkEdit"
|
|
658
757
|
/>
|
|
659
758
|
|
|
660
759
|
<UTable
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
3
|
import { useI18n, useMongocampClientApi, useMongocampIndex, useMongocampSchema, useToast } from "#imports";
|
|
4
|
+
import { useMongocampAggregation } from "../composables/useMongocampAggregation";
|
|
5
|
+
import { analyzeSamples } from "../utils/analyzeSamples";
|
|
4
6
|
const props = defineProps({
|
|
5
7
|
collectionName: { type: String, required: true },
|
|
6
8
|
sampleSize: { type: Number, required: false, default: 500 }
|
|
@@ -9,6 +11,7 @@ const { t } = useI18n();
|
|
|
9
11
|
const { collectionApi, documentApi } = useMongocampClientApi();
|
|
10
12
|
const { schemaFromSamples, schemaToTsInterface } = useMongocampSchema();
|
|
11
13
|
const { listIndexes, createIndex, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex } = useMongocampIndex();
|
|
14
|
+
const { sampleDocuments, describeAggregationError } = useMongocampAggregation();
|
|
12
15
|
const UBadge = resolveComponent("UBadge");
|
|
13
16
|
const UIcon = resolveComponent("UIcon");
|
|
14
17
|
const UButton = resolveComponent("UButton");
|
|
@@ -84,6 +87,76 @@ const schemaTableColumns = computed(() => [
|
|
|
84
87
|
cell: ({ row }) => row.original.required ? h(UIcon, { name: "i-lucide-check", class: "size-4 text-success" }) : h("span", { class: "text-dimmed" }, "\u2014")
|
|
85
88
|
}
|
|
86
89
|
]);
|
|
90
|
+
const STATS_SAMPLE_SIZES = [100, 500, 1e3];
|
|
91
|
+
const KIND_COLORS = {
|
|
92
|
+
string: "neutral",
|
|
93
|
+
number: "warning",
|
|
94
|
+
boolean: "success",
|
|
95
|
+
date: "info",
|
|
96
|
+
object: "secondary",
|
|
97
|
+
array: "primary",
|
|
98
|
+
null: "neutral"
|
|
99
|
+
};
|
|
100
|
+
const statsSampleSize = ref(500);
|
|
101
|
+
const statsLoading = ref(false);
|
|
102
|
+
const statsError = ref(null);
|
|
103
|
+
const statsAnalysis = ref(null);
|
|
104
|
+
let statsRun = 0;
|
|
105
|
+
async function analyzeFields() {
|
|
106
|
+
const run = ++statsRun;
|
|
107
|
+
statsLoading.value = true;
|
|
108
|
+
statsError.value = null;
|
|
109
|
+
try {
|
|
110
|
+
const { rows } = await sampleDocuments(props.collectionName, statsSampleSize.value);
|
|
111
|
+
if (run !== statsRun) return;
|
|
112
|
+
statsAnalysis.value = analyzeSamples(rows);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
const described = await describeAggregationError(error);
|
|
115
|
+
if (run !== statsRun) return;
|
|
116
|
+
statsAnalysis.value = null;
|
|
117
|
+
statsError.value = described;
|
|
118
|
+
} finally {
|
|
119
|
+
if (run === statsRun) statsLoading.value = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
watch(() => props.collectionName, () => {
|
|
123
|
+
statsRun++;
|
|
124
|
+
statsAnalysis.value = null;
|
|
125
|
+
statsError.value = null;
|
|
126
|
+
statsLoading.value = false;
|
|
127
|
+
});
|
|
128
|
+
function percent(share) {
|
|
129
|
+
if (share >= 1) return "100%";
|
|
130
|
+
return share > 0 && share < 0.01 ? "<1%" : `${Math.round(share * 100)}%`;
|
|
131
|
+
}
|
|
132
|
+
const statsColumns = computed(() => [
|
|
133
|
+
{
|
|
134
|
+
accessorKey: "path",
|
|
135
|
+
header: t("nuxtUiMongocamp.collectionInfos.columnField")
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "types",
|
|
139
|
+
header: t("nuxtUiMongocamp.collectionInfos.columnType"),
|
|
140
|
+
cell: ({ row }) => h("div", { class: "flex flex-wrap gap-1" }, row.original.types.map(
|
|
141
|
+
({ type, count }) => h(UBadge, {
|
|
142
|
+
label: row.original.types.length > 1 ? `${type} ${percent(count / row.original.present)}` : type,
|
|
143
|
+
color: KIND_COLORS[type] ?? "neutral",
|
|
144
|
+
variant: "subtle",
|
|
145
|
+
size: "sm"
|
|
146
|
+
})
|
|
147
|
+
))
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "present",
|
|
151
|
+
header: t("nuxtUiMongocamp.collectionInfos.statsColumnPresent"),
|
|
152
|
+
cell: ({ row }) => h("span", { title: t("nuxtUiMongocamp.collectionInfos.statsPresentTitle", { present: row.original.present, sampled: statsAnalysis.value?.sampled ?? 0 }) }, percent(row.original.share))
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
id: "values",
|
|
156
|
+
header: t("nuxtUiMongocamp.collectionInfos.statsColumnValues"),
|
|
157
|
+
cell: ({ row }) => row.original.topValues ? h("span", { class: "text-xs" }, row.original.topValues.map((v) => `${v.value} (${v.count})`).join(", ")) : h("span", { class: "text-dimmed" }, "\u2014")
|
|
158
|
+
}
|
|
159
|
+
]);
|
|
87
160
|
const indexRows = computed(
|
|
88
161
|
() => indexes.value.map((idx) => ({
|
|
89
162
|
name: idx.name,
|
|
@@ -346,6 +419,95 @@ const indexTableColumns = computed(() => [
|
|
|
346
419
|
/>
|
|
347
420
|
</UCard>
|
|
348
421
|
|
|
422
|
+
<UCard v-if="info && !loading">
|
|
423
|
+
<template #header>
|
|
424
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
425
|
+
<div class="flex items-center gap-2">
|
|
426
|
+
<UIcon
|
|
427
|
+
name="i-lucide-chart-no-axes-column"
|
|
428
|
+
class="size-4 text-(--ui-primary)"
|
|
429
|
+
/>
|
|
430
|
+
<span class="font-semibold">{{ t("nuxtUiMongocamp.collectionInfos.statsTitle") }}</span>
|
|
431
|
+
<UBadge
|
|
432
|
+
v-if="statsAnalysis"
|
|
433
|
+
:label="t('nuxtUiMongocamp.collectionInfos.statsSampled', { sampled: statsAnalysis.sampled, total: info.count })"
|
|
434
|
+
variant="subtle"
|
|
435
|
+
color="neutral"
|
|
436
|
+
size="sm"
|
|
437
|
+
/>
|
|
438
|
+
</div>
|
|
439
|
+
<div class="flex items-center gap-2">
|
|
440
|
+
<USelect
|
|
441
|
+
v-model="statsSampleSize"
|
|
442
|
+
:items="STATS_SAMPLE_SIZES"
|
|
443
|
+
size="sm"
|
|
444
|
+
class="w-24"
|
|
445
|
+
:aria-label="t('nuxtUiMongocamp.collectionInfos.statsSampleSize')"
|
|
446
|
+
/>
|
|
447
|
+
<UButton
|
|
448
|
+
icon="i-lucide-activity"
|
|
449
|
+
:label="t('nuxtUiMongocamp.collectionInfos.statsAnalyze')"
|
|
450
|
+
color="neutral"
|
|
451
|
+
variant="subtle"
|
|
452
|
+
size="sm"
|
|
453
|
+
:loading="statsLoading"
|
|
454
|
+
@click="analyzeFields"
|
|
455
|
+
/>
|
|
456
|
+
</div>
|
|
457
|
+
</div>
|
|
458
|
+
</template>
|
|
459
|
+
|
|
460
|
+
<p
|
|
461
|
+
v-if="!statsAnalysis && !statsError && !statsLoading"
|
|
462
|
+
class="text-sm text-dimmed"
|
|
463
|
+
>
|
|
464
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsHint") }}
|
|
465
|
+
</p>
|
|
466
|
+
<UAlert
|
|
467
|
+
v-if="statsError"
|
|
468
|
+
color="error"
|
|
469
|
+
variant="subtle"
|
|
470
|
+
icon="i-lucide-circle-alert"
|
|
471
|
+
:title="t('nuxtUiMongocamp.collectionInfos.statsFailed')"
|
|
472
|
+
:description="statsError.message"
|
|
473
|
+
>
|
|
474
|
+
<template #actions>
|
|
475
|
+
<UButton
|
|
476
|
+
v-if="statsError.kind === 'unauthorized'"
|
|
477
|
+
:label="t('nuxtUiMongocamp.errors.loginAgain')"
|
|
478
|
+
to="/"
|
|
479
|
+
color="error"
|
|
480
|
+
variant="subtle"
|
|
481
|
+
icon="i-lucide-log-in"
|
|
482
|
+
/>
|
|
483
|
+
<UButton
|
|
484
|
+
v-else
|
|
485
|
+
:label="t('nuxtUiMongocamp.common.retry')"
|
|
486
|
+
color="error"
|
|
487
|
+
variant="subtle"
|
|
488
|
+
icon="i-lucide-refresh-cw"
|
|
489
|
+
@click="analyzeFields"
|
|
490
|
+
/>
|
|
491
|
+
</template>
|
|
492
|
+
</UAlert>
|
|
493
|
+
<template v-if="statsAnalysis">
|
|
494
|
+
<p class="mb-2 text-xs text-dimmed">
|
|
495
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsNote") }}
|
|
496
|
+
<template v-if="statsAnalysis.truncated">
|
|
497
|
+
{{ t("nuxtUiMongocamp.collectionInfos.statsTruncated", { count: statsAnalysis.fields.length }) }}
|
|
498
|
+
</template>
|
|
499
|
+
</p>
|
|
500
|
+
<UTable
|
|
501
|
+
:data="statsAnalysis.fields"
|
|
502
|
+
:columns="statsColumns"
|
|
503
|
+
>
|
|
504
|
+
<template #empty>
|
|
505
|
+
<MongocampEmptyState :title="t('nuxtUiMongocamp.collectionInfos.statsEmpty')" />
|
|
506
|
+
</template>
|
|
507
|
+
</UTable>
|
|
508
|
+
</template>
|
|
509
|
+
</UCard>
|
|
510
|
+
|
|
349
511
|
<UModal
|
|
350
512
|
v-model:open="isCreateIndexModalOpen"
|
|
351
513
|
:title="t('nuxtUiMongocamp.collectionInfos.createIndexTitle')"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed } from "vue";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
3
|
import { useI18n } from "#imports";
|
|
4
4
|
import {
|
|
5
5
|
buildFilterQuery,
|
|
@@ -8,8 +8,10 @@ import {
|
|
|
8
8
|
operatorsFor,
|
|
9
9
|
valueCountFor
|
|
10
10
|
} from "../utils/filterBuilder";
|
|
11
|
+
import { suggestionOptions, wantsSuggestions } from "../utils/filterSuggestions";
|
|
11
12
|
const props = defineProps({
|
|
12
|
-
fields: { type: Array, required: true }
|
|
13
|
+
fields: { type: Array, required: true },
|
|
14
|
+
loadDistinct: { type: Function, required: false }
|
|
13
15
|
});
|
|
14
16
|
const model = defineModel({ type: Object, ...{ required: true } });
|
|
15
17
|
const emit = defineEmits(["apply"]);
|
|
@@ -58,6 +60,22 @@ function changeField(index, field) {
|
|
|
58
60
|
value2: ""
|
|
59
61
|
});
|
|
60
62
|
}
|
|
63
|
+
const suggestions = ref({});
|
|
64
|
+
const loading = /* @__PURE__ */ new Set();
|
|
65
|
+
async function ensureSuggestions(condition) {
|
|
66
|
+
if (!props.loadDistinct || !wantsSuggestions(typeOf(condition.field), condition.operator) || loading.has(condition.field)) return;
|
|
67
|
+
loading.add(condition.field);
|
|
68
|
+
try {
|
|
69
|
+
suggestions.value = { ...suggestions.value, [condition.field]: await props.loadDistinct(condition.field) };
|
|
70
|
+
} catch {
|
|
71
|
+
suggestions.value = { ...suggestions.value, [condition.field]: [] };
|
|
72
|
+
} finally {
|
|
73
|
+
loading.delete(condition.field);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function listId(condition) {
|
|
77
|
+
return props.loadDistinct && wantsSuggestions(typeOf(condition.field), condition.operator) ? `${condition.id}-suggestions` : void 0;
|
|
78
|
+
}
|
|
61
79
|
function setMatch(match) {
|
|
62
80
|
model.value = { ...model.value, match };
|
|
63
81
|
}
|
|
@@ -129,11 +147,24 @@ function clearAll() {
|
|
|
129
147
|
:type="typeOf(condition.field) === 'date-time' ? 'date' : 'text'"
|
|
130
148
|
:inputmode="typeOf(condition.field) === 'number' ? 'decimal' : void 0"
|
|
131
149
|
:placeholder="condition.operator === 'oneOf' ? t('nuxtUiMongocamp.filterBuilder.listPlaceholder') : void 0"
|
|
150
|
+
:list="listId(condition)"
|
|
132
151
|
size="sm"
|
|
133
152
|
class="w-48"
|
|
134
153
|
:aria-label="t('nuxtUiMongocamp.filterBuilder.value')"
|
|
154
|
+
@focus="ensureSuggestions(condition)"
|
|
135
155
|
@update:model-value="(value) => updateCondition(index, { value: String(value ?? '') })"
|
|
136
156
|
/>
|
|
157
|
+
<datalist
|
|
158
|
+
v-if="listId(condition)"
|
|
159
|
+
:id="listId(condition)"
|
|
160
|
+
>
|
|
161
|
+
<option
|
|
162
|
+
v-for="option in suggestionOptions(suggestions[condition.field] ?? [], condition.operator, condition.value ?? '')"
|
|
163
|
+
:key="option.value"
|
|
164
|
+
:value="option.value"
|
|
165
|
+
:label="option.label"
|
|
166
|
+
/>
|
|
167
|
+
</datalist>
|
|
137
168
|
<template v-if="valueCountFor(condition.operator) === 2">
|
|
138
169
|
<span class="text-sm text-dimmed">{{ t("nuxtUiMongocamp.filterBuilder.and") }}</span>
|
|
139
170
|
<UInput
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
collectionName: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
5
|
+
imported: (count: number) => any;
|
|
6
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
7
|
+
onImported?: ((count: number) => any) | undefined;
|
|
8
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|