2023-01-10 17:28:27 +01:00
|
|
|
<script>
|
2023-01-19 08:57:25 +01:00
|
|
|
import ObjectViewer from '../../../components/objectviewer.svelte';
|
2023-01-17 09:44:21 +01:00
|
|
|
import ObjectGrid from '../../../components/objectgrid.svelte';
|
2023-01-17 20:49:07 +01:00
|
|
|
import { DropIndex, GetIndexes } from '../../../../wailsjs/go/app/App';
|
2023-01-20 13:54:57 +01:00
|
|
|
import Icon from '../../../components/icon.svelte';
|
2023-01-17 09:44:21 +01:00
|
|
|
|
2023-01-10 17:28:27 +01:00
|
|
|
export let collection;
|
|
|
|
|
2023-01-17 09:44:21 +01:00
|
|
|
let indexes = [];
|
2023-01-19 09:02:59 +01:00
|
|
|
let activePath = [];
|
2023-01-19 08:57:25 +01:00
|
|
|
let objectViewerData = '';
|
2023-01-17 09:44:21 +01:00
|
|
|
|
2023-01-20 13:54:57 +01:00
|
|
|
$: collection && getIndexes();
|
|
|
|
|
2023-01-17 09:44:21 +01:00
|
|
|
async function getIndexes() {
|
|
|
|
const result = await GetIndexes(collection.hostKey, collection.dbKey, collection.key);
|
|
|
|
if (result) {
|
|
|
|
indexes = result;
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 17:28:27 +01:00
|
|
|
|
2023-01-18 13:59:32 +01:00
|
|
|
async function drop(key) {
|
|
|
|
if (typeof key !== 'string') {
|
2023-01-19 09:02:59 +01:00
|
|
|
key = activePath[0];
|
2023-01-17 20:49:07 +01:00
|
|
|
}
|
2023-01-17 21:03:01 +01:00
|
|
|
const success = await DropIndex(collection.hostKey, collection.dbKey, collection.key, key);
|
2023-01-17 20:49:07 +01:00
|
|
|
if (success) {
|
|
|
|
await getIndexes();
|
2023-01-19 09:02:59 +01:00
|
|
|
activePath[0] = '';
|
2023-01-17 20:49:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openJson(indexId) {
|
2023-01-19 08:59:57 +01:00
|
|
|
const item = indexes?.find(i => i.name == indexId);
|
2023-01-19 08:57:25 +01:00
|
|
|
objectViewerData = item;
|
2023-01-17 09:44:21 +01:00
|
|
|
}
|
2023-01-10 17:28:27 +01:00
|
|
|
</script>
|
|
|
|
|
2023-01-17 09:44:21 +01:00
|
|
|
<div class="indexes">
|
|
|
|
<div class="actions">
|
2023-01-20 13:54:57 +01:00
|
|
|
<button class="btn" on:click={getIndexes}>
|
|
|
|
<Icon name="reload" /> Reload
|
|
|
|
</button>
|
|
|
|
<button class="btn">
|
|
|
|
<Icon name="+" /> Create index…
|
|
|
|
</button>
|
2023-01-19 09:02:59 +01:00
|
|
|
<button class="btn danger" on:click={drop} disabled={!indexes?.length || !activePath[0]}>
|
2023-01-20 13:54:57 +01:00
|
|
|
<Icon name="x" /> Drop selected
|
2023-01-17 20:49:07 +01:00
|
|
|
</button>
|
2023-01-17 09:44:21 +01:00
|
|
|
</div>
|
|
|
|
|
2023-01-17 16:22:49 +01:00
|
|
|
<div class="grid">
|
2023-01-17 21:03:01 +01:00
|
|
|
<ObjectGrid key="name" data={indexes.map(idx => ({
|
|
|
|
...idx,
|
2023-01-18 13:59:32 +01:00
|
|
|
menu: [ { label: 'Drop this index', fn: () => drop(idx.name) } ],
|
2023-01-19 09:02:59 +01:00
|
|
|
}))} bind:activePath on:trigger={e => openJson(e.detail.itemKey)} />
|
2023-01-17 16:22:49 +01:00
|
|
|
</div>
|
2023-01-10 17:28:27 +01:00
|
|
|
</div>
|
2023-01-17 09:44:21 +01:00
|
|
|
|
2023-01-19 08:57:25 +01:00
|
|
|
<ObjectViewer bind:data={objectViewerData} />
|
2023-01-17 09:44:21 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.indexes {
|
|
|
|
display: grid;
|
|
|
|
gap: 0.5rem;
|
|
|
|
grid-template: auto 1fr / 1fr;
|
|
|
|
}
|
2023-01-17 16:22:49 +01:00
|
|
|
|
|
|
|
.indexes .grid {
|
|
|
|
min-height: 0;
|
|
|
|
min-width: 0;
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
}
|
2023-01-17 09:44:21 +01:00
|
|
|
</style>
|