1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2024-12-01 13:20:54 +00:00

Indexes: context menu

This commit is contained in:
Romein van Buren 2023-01-17 21:03:01 +01:00
parent 9262c92591
commit 1571eaa897
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
2 changed files with 16 additions and 11 deletions

View File

@ -19,10 +19,11 @@
if (Array.isArray(data)) {
for (const item of data) {
const _item = {};
_item.key = item[key];
_item.children = dissectObject(item);
items = [ ...items, _item ];
const newItem = {};
newItem.key = item[key];
newItem.children = dissectObject(item);
newItem.menu = item.menu;
items = [ ...items, newItem ];
}
}
else {
@ -57,7 +58,7 @@
return entries.map(([ key, value ]) => {
key = key + '';
const type = getType(value);
const child = { key, value, type };
const child = { key, value, type, menu: value.menu };
if (type.startsWith('object') || type.startsWith('array')) {
child.children = dissectObject(value);

View File

@ -16,13 +16,14 @@
}
}
async function dropActive() {
if (!activeKey) {
async function drop(key = activeKey) {
if (!key) {
return;
}
const success = await DropIndex(collection.hostKey, collection.dbKey, collection.key, activeKey);
const success = await DropIndex(collection.hostKey, collection.dbKey, collection.key, key);
if (success) {
await getIndexes();
activeKey = '';
}
}
@ -35,14 +36,17 @@
<div class="indexes">
<div class="actions">
<button class="btn" on:click={getIndexes}>Get indexes</button>
<button class="btn danger" on:click={dropActive} disabled={!indexes?.length || !activeKey}>
<button class="btn danger" on:click={drop} disabled={!indexes?.length || !activeKey}>
Drop selected
</button>
<button class="btn">Create&hellip;</button>
<button class="btn">Create</button>
</div>
<div class="grid">
<ObjectGrid key="name" data={indexes} bind:activeKey on:trigger={e => openJson(e.detail)} />
<ObjectGrid key="name" data={indexes.map(idx => ({
...idx,
menu: [ { label: 'Drop this index…', fn: () => drop(idx.name) } ],
}))} bind:activeKey on:trigger={e => openJson(e.detail)} />
</div>
</div>