1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 21:17:59 +00:00

Update hosttree menus

This commit is contained in:
Romein van Buren 2023-01-23 13:17:07 +01:00
parent 4d50d43f4d
commit c76e5c9503
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
3 changed files with 51 additions and 49 deletions

View File

@ -1,10 +1,10 @@
<script> <script>
import GridItems from './grid-items.svelte'; import GridItems from './grid-items.svelte';
import Icon from './icon.svelte'; // import Icon from './icon.svelte';
export let columns = []; export let columns = [];
export let items = []; export let items = [];
export let actions = []; // export let actions = [];
export let key = 'id'; export let key = 'id';
export let activePath = []; export let activePath = [];
export let striped = true; export let striped = true;
@ -13,7 +13,7 @@
</script> </script>
<div class="grid"> <div class="grid">
{#if actions?.length} <!-- {#if actions?.length}
<div class="actions"> <div class="actions">
{#each actions as action} {#each actions as action}
<button class="btn" on:click={action.fn} disabled={action.disabled}> <button class="btn" on:click={action.fn} disabled={action.disabled}>
@ -22,7 +22,7 @@
</button> </button>
{/each} {/each}
</div> </div>
{/if} {/if} -->
<table> <table>
{#if showHeaders && columns.some(col => col.title)} {#if showHeaders && columns.some(col => col.title)}
@ -59,14 +59,14 @@
background-color: #fff; background-color: #fff;
} }
.actions { /* .actions {
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
padding: 0.5rem; padding: 0.5rem;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
} }
.actions button { .actions button {
margin-right: 0.2rem; margin-right: 0.2rem;
} } */
table { table {
border-collapse: collapse; border-collapse: collapse;

View File

@ -1,5 +1,5 @@
<script> <script>
import { busy, contextMenu, connections } from '../../stores'; import { busy, connections } from '../../stores';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { DropCollection, DropDatabase, OpenCollection, OpenConnection, OpenDatabase } from '../../../wailsjs/go/app/App'; import { DropCollection, DropDatabase, OpenCollection, OpenConnection, OpenDatabase } from '../../../wailsjs/go/app/App';
import Grid from '../../components/grid.svelte'; import Grid from '../../components/grid.svelte';
@ -75,28 +75,6 @@
await reload(); await reload();
busy.end(); busy.end();
} }
function buildMenu(hostKey, dbKey, collKey, context = [ 'new', 'edit', 'drop' ]) {
// context: n = new, d = drop
const menu = [];
if (context.includes('edit')) {
hostKey && menu.push({ label: `Edit host ${hosts[hostKey].name}`, fn: () => dispatch('editHost', hostKey) });
collKey && menu.push({ label: `Rename collection ${collKey}`, fn: () => dispatch('editCollection', collKey) });
}
if (context.includes('drop')) {
menu.length && menu.push({ separator: true });
dbKey && menu.push({ label: `Drop database ${dbKey}`, fn: () => dropDatabase(dbKey) });
collKey && menu.push({ label: `Drop collection ${collKey}`, fn: () => dropCollection(dbKey, collKey) });
}
if (context.includes('new')) {
menu.length && menu.push({ separator: true });
hostKey && menu.push({ label: 'New database…', fn: () => dispatch('newDatabase') });
dbKey && menu.push({ label: 'New collection…', fn: () => dispatch('newCollection') });
}
return menu;
}
</script> </script>
<Grid <Grid
@ -115,17 +93,25 @@
id: collKey, id: collKey,
name: collKey, name: collKey,
icon: 'list', icon: 'list',
menu: buildMenu(hostKey, dbKey, collKey), menu: [
{ label: `Rename ${collKey} collection`, fn: () => dispatch('renameCollection', collKey) },
{ label: `Drop ${collKey}`, fn: () => dropCollection(dbKey, collKey) },
{ separator: true },
{ label: 'New collection…', fn: () => dispatch('newCollection') },
],
})) || [], })) || [],
menu: buildMenu(hostKey, dbKey), menu: [
{ label: `Drop database ${dbKey}`, fn: () => dropDatabase(dbKey) },
{ separator: true },
{ label: 'New database…', fn: () => dispatch('newDatabase') },
],
})), })),
menu: [
{ label: 'New database…', fn: () => dispatch('newDatabase') },
{ separator: true },
{ label: `Edit host ${hosts[hostKey].name}`, fn: () => dispatch('editHost', hostKey) },
],
}))} }))}
actions={[
{ icon: 'reload', fn: reload },
{ icon: '+', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'new')) },
{ icon: 'edit', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'edit')), disabled: !activeHostKey },
{ icon: '-', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'drop')), disabled: !activeDbKey },
]}
bind:activePath={activeGridPath} bind:activePath={activeGridPath}
on:select={e => { on:select={e => {
const key = e.detail.itemKey; const key = e.detail.itemKey;
@ -136,3 +122,12 @@
} }
}} }}
/> />
<!--
actions={[
{ icon: 'reload', fn: reload },
{ icon: '+', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'new')) },
{ icon: 'edit', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'edit')), disabled: !activeHostKey },
{ icon: '-', fn: evt => contextMenu.show(evt, buildMenu(activeHostKey, activeDbKey, activeCollKey, 'drop')), disabled: !activeDbKey },
]}
-->

View File

@ -75,7 +75,8 @@
onMount(getHosts); onMount(getHosts);
</script> </script>
<HostTree <div class="tree">
<HostTree
{hosts} {hosts}
bind:activeHostKey bind:activeHostKey
bind:activeCollKey bind:activeCollKey
@ -85,8 +86,9 @@
on:newDatabase={() => newDb = {}} on:newDatabase={() => newDb = {}}
on:newCollection={() => newColl = {}} on:newCollection={() => newColl = {}}
on:editHost={e => editHost(e.detail)} on:editHost={e => editHost(e.detail)}
on:editCollection={e => openEditCollModal(e.detail)} on:renameCollection={e => openEditCollModal(e.detail)}
/> />
</div>
<CollectionDetail <CollectionDetail
collection={$connections[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]} collection={$connections[activeHostKey]?.databases[activeDbKey]?.collections?.[activeCollKey]}
@ -156,6 +158,11 @@
justify-content: space-between; justify-content: space-between;
} }
.tree {
padding: 0.5rem;
background-color: #fff;
}
.rename { .rename {
text-align: center; text-align: center;
display: flex; display: flex;