memoize connection folder expand state #425

This commit is contained in:
Jan Prochazka 2023-01-01 12:24:42 +01:00
parent d5e240a701
commit 13fd7a0aad
4 changed files with 14 additions and 2 deletions

View File

@ -18,8 +18,9 @@
export let passProps;
export let onDropOnGroup = undefined;
export let groupContextMenu = null;
export let collapsedGroupNames;
let isExpanded = true;
$: isExpanded = !$collapsedGroupNames.includes(group);
$: filtered = items.filter(x => x.isMatched);
$: countText = filtered.length < items.length ? `${filtered.length}/${items.length}` : `${items.length}`;
@ -49,7 +50,11 @@
<div
class="group"
on:click={() => (isExpanded = !isExpanded)}
on:click={() =>
collapsedGroupNames.update(names => {
if (names.includes(group)) return names.filter(x => x != group);
return [...names, group];
})}
on:drop={handleDrop}
use:contextMenu={() => groupContextMenu(group)}
>

View File

@ -5,6 +5,7 @@
import { plusExpandIcon } from '../icons/expandIcons';
import AppObjectListItem from './AppObjectListItem.svelte';
import { writable } from 'svelte/store';
export let list;
export let module;
@ -26,6 +27,8 @@
export let onDropOnGroup = undefined;
export let emptyGroupNames = [];
export let collapsedGroupNames = writable([]);
$: filtered = !groupFunc
? list.filter(data => {
const matcher = module.createMatcher && module.createMatcher(data);
@ -100,6 +103,7 @@
{setIsExpanded}
{onDropOnGroup}
{groupContextMenu}
{collapsedGroupNames}
/>
{/each}
{:else}

View File

@ -57,6 +57,7 @@ export const visibleSelectedWidget = derived(
([$selectedWidget, $visibleWidgetSideBar]) => ($visibleWidgetSideBar ? $selectedWidget : null)
);
export const emptyConnectionGroupNames = writableWithStorage([], 'emptyConnectionGroupNames');
export const collapsedConnectionGroupNames = writableWithStorage([], 'collapsedConnectionGroupNames');
export const openedConnections = writable([]);
export const openedSingleDatabaseConnections = writable([]);
export const expandedConnections = writable([]);

View File

@ -15,6 +15,7 @@
openedSingleDatabaseConnections,
openedTabs,
emptyConnectionGroupNames,
collapsedConnectionGroupNames,
} from '../stores';
import runCommand from '../commands/runCommand';
import getConnectionLabel from '../utility/getConnectionLabel';
@ -149,6 +150,7 @@
emptyGroupNames={$emptyConnectionGroupNames}
sortGroups
groupContextMenu={createGroupContextMenu}
collapsedGroupNames={collapsedConnectionGroupNames}
/>
{#if (connectionsWithParent?.length > 0 && connectionsWithoutParent?.length > 0) || ($emptyConnectionGroupNames.length > 0 && connectionsWithoutParent?.length > 0)}
<div class="br" />