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

Fix host/database selection bug in grid

This commit is contained in:
Romein van Buren 2023-06-07 21:12:09 +02:00
parent b29b534b2f
commit ea376f5ba7
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
5 changed files with 57 additions and 31 deletions

View File

@ -1,13 +1,17 @@
## Unreleased ## Unreleased
* Added version number of the running Rolens instance in the about dialog (#25, #28) * Added version number of the running Rolens instance in the about dialog (#25, #28).
* Fixed host/database selection bug in grid.
## [v0.2.0](https://github.com/garraflavatra/rolens/releases/tag/v0.2.0) ## [v0.2.0]
* Added some external links related to Rolens to the application menu. * Added some external links related to Rolens to the application menu.
* Fix an infinite loop bug when a document in the find view has been double clicked. * Fix an infinite loop bug when a document in the find view has been double clicked.
* Find view: added the ability to make changes to single documents from within the object editor. * Find view: added the ability to make changes to single documents from within the object editor.
## [v0.1.0](https://github.com/garraflavatra/rolens/releases/tag/v0.1.0) ## [v0.1.0]
Initial release. Initial release.
[v0.2.0]: https://github.com/garraflavatra/rolens/releases/tag/v0.2.0
[v0.1.0]: https://github.com/garraflavatra/rolens/releases/tag/v0.1.0

View File

@ -1 +1 @@
541b97f7203adc96312cfd007c0d8b97 21089cd8ec83c35046acb2c9ab02da9e

View File

@ -1,5 +1,5 @@
<script> <script>
import { resolveKeypath, setValue } from '$lib/objects'; import { pathsAreEqual, resolveKeypath, setValue } from '$lib/objects';
import contextMenu from '$lib/stores/contextmenu'; import contextMenu from '$lib/stores/contextmenu';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import FormInput from './forminput.svelte'; import FormInput from './forminput.svelte';
@ -62,18 +62,9 @@
return false; return false;
} }
toggleChildren(itemKey, false); activeKey = itemKey;
activePath = [ ...path.slice(0, level), itemKey ];
if (activeKey !== itemKey) { dispatch('select', { level, itemKey, index });
activeKey = itemKey;
if (level === 0) {
activePath = [ itemKey ];
}
else {
activePath = [ ...path, itemKey ];
}
dispatch('select', { level, itemKey, index });
}
} }
function closeAll() { function closeAll() {
@ -89,7 +80,7 @@
} }
function doubleClick(itemKey, index) { function doubleClick(itemKey, index) {
// toggleChildren(itemKey, false); toggleChildren(itemKey, false);
dispatch('trigger', { level, itemKey, index }); dispatch('trigger', { level, itemKey, index });
childrenOpen[itemKey] = true; childrenOpen[itemKey] = true;
} }
@ -136,7 +127,7 @@
on:dblclick={() => doubleClick(item[key], index)} on:dblclick={() => doubleClick(item[key], index)}
on:contextmenu|preventDefault={evt => showContextMenu(evt, item)} on:contextmenu|preventDefault={evt => showContextMenu(evt, item)}
class:selectable={canSelect} class:selectable={canSelect}
class:selected={canSelect && !activePath[level + 1] && activePath.every(k => path.includes(k) || k === item[key]) && (activePath[level] === item[key])} class:selected={canSelect && pathsAreEqual(activePath, [ ...path, item[key] ])}
class:striped class:striped
> >
{#if !hideChildrenToggles} {#if !hideChildrenToggles}

View File

@ -58,6 +58,20 @@ export function setValue(object, path, value) {
} }
export function deepClone(obj) { export function deepClone(obj) {
// Room for improvement below // @todo: Room for improvement below
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
export function pathsAreEqual(x, y) {
const lengthOfLongest = (x.length >= y.length) ? x.length : y.length;
console.log(x, y)
for (let i = 0; i < lengthOfLongest; i++) {
console.log(x[i], y[i])
if (x[i] !== y[i]) {
return false;
}
}
return true;
}

View File

@ -14,9 +14,9 @@
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
let activeGridPath = []; let activeGridPath = [];
$: activeHostKey = activeGridPath[0] || activeHostKey; // $: activeGridPath[0] = activeHostKey || undefined;
$: activeDbKey = activeGridPath[1]; // $: activeGridPath[1] = activeDbKey || undefined;
$: activeCollKey = activeGridPath[2]; // $: activeGridPath[2] = activeCollKey || undefined;
$: host = $hosts[activeHostKey]; $: host = $hosts[activeHostKey];
$: connection = $connections[activeHostKey]; $: connection = $connections[activeHostKey];
$: database = connection?.databases[activeDbKey]; $: database = connection?.databases[activeDbKey];
@ -30,12 +30,16 @@
async function openConnection(hostKey) { async function openConnection(hostKey) {
const progress = startProgress(`Connecting to "${hostKey}"…`); const progress = startProgress(`Connecting to "${hostKey}"…`);
activeCollKey = '';
activeDbKey = '';
activeHostKey = hostKey;
const databases = await OpenConnection(hostKey); const databases = await OpenConnection(hostKey);
if (databases) { if (databases) {
$connections[hostKey] = { databases: {} }; $connections[hostKey] = { databases: {} };
databases.forEach(dbKey => { databases.forEach(dbKey => {
$connections[hostKey].databases[dbKey] = { collections: {} }; $connections[hostKey].databases[dbKey] =
$connections[hostKey].databases[dbKey] || { collections: {} };
}); });
activeHostKey = hostKey; activeHostKey = hostKey;
dispatch('connected', hostKey); dispatch('connected', hostKey);
@ -49,17 +53,22 @@
activeCollKey = ''; activeCollKey = '';
activeDbKey = ''; activeDbKey = '';
activeHostKey = ''; activeHostKey = '';
await tick(); await tick();
await RemoveHost(hostKey); await RemoveHost(hostKey);
hosts.update(); await reload();
await hosts.update();
} }
async function openDatabase(dbKey) { async function openDatabase(dbKey) {
const progress = startProgress(`Opening database "${dbKey}"…`); const progress = startProgress(`Opening database "${dbKey}"…`);
const collections = await OpenDatabase(activeHostKey, dbKey); const collections = await OpenDatabase(activeHostKey, dbKey);
activeDbKey = dbKey;
activeCollKey = '';
for (const collKey of collections || []) { for (const collKey of collections || []) {
$connections[activeHostKey].databases[dbKey].collections[collKey] = {}; $connections[activeHostKey].databases[dbKey].collections[collKey] =
$connections[activeHostKey].databases[dbKey].collections[collKey] ||{};
} }
progress.end(); progress.end();
@ -67,14 +76,19 @@
async function dropDatabase(dbKey) { async function dropDatabase(dbKey) {
const progress = startProgress(`Dropping database "${dbKey}"…`); const progress = startProgress(`Dropping database "${dbKey}"…`);
await DropDatabase(activeHostKey, dbKey); const success = await DropDatabase(activeHostKey, dbKey);
await reload(); if (success) {
activeCollKey = '';
activeDbKey = '';
await reload();
}
progress.end(); progress.end();
} }
async function openCollection(collKey) { async function openCollection(collKey) {
const progress = startProgress(`Opening collection "${collKey}"…`); const progress = startProgress(`Opening collection "${collKey}"…`);
const stats = await OpenCollection(activeHostKey, activeDbKey, collKey); const stats = await OpenCollection(activeHostKey, activeDbKey, collKey);
activeCollKey = collKey;
$connections[activeHostKey].databases[activeDbKey].collections[collKey] = $connections[activeHostKey].databases[activeDbKey].collections[collKey] || {}; $connections[activeHostKey].databases[activeDbKey].collections[collKey] = $connections[activeHostKey].databases[activeDbKey].collections[collKey] || {};
$connections[activeHostKey].databases[activeDbKey].collections[collKey].stats = stats; $connections[activeHostKey].databases[activeDbKey].collections[collKey].stats = stats;
progress.end(); progress.end();
@ -89,8 +103,11 @@
async function dropCollection(dbKey, collKey) { async function dropCollection(dbKey, collKey) {
const progress = startProgress(`Dropping collection "${collKey}"…`); const progress = startProgress(`Dropping collection "${collKey}"…`);
await DropCollection(activeHostKey, dbKey, collKey); const success = await DropCollection(activeHostKey, dbKey, collKey);
await reload(); if (success) {
activeCollKey = '';
await reload();
}
progress.end(); progress.end();
} }
</script> </script>
@ -98,6 +115,7 @@
<Grid <Grid
striped={false} striped={false}
columns={[ { key: 'name' }, { key: 'count', right: true } ]} columns={[ { key: 'name' }, { key: 'count', right: true } ]}
bind:activePath={activeGridPath}
items={Object.keys($hosts).map(hostKey => ({ items={Object.keys($hosts).map(hostKey => ({
id: hostKey, id: hostKey,
name: $hosts[hostKey].name, name: $hosts[hostKey].name,
@ -136,7 +154,6 @@
{ label: `Remove host…`, fn: () => removeHost(hostKey) }, { label: `Remove host…`, fn: () => removeHost(hostKey) },
], ],
}))} }))}
bind:activePath={activeGridPath}
on:select={e => { on:select={e => {
const key = e.detail.itemKey; const key = e.detail.itemKey;
switch (e.detail?.level) { switch (e.detail?.level) {