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 passProps;
export let onDropOnGroup = undefined; export let onDropOnGroup = undefined;
export let groupContextMenu = null; export let groupContextMenu = null;
export let collapsedGroupNames;
let isExpanded = true; $: isExpanded = !$collapsedGroupNames.includes(group);
$: filtered = items.filter(x => x.isMatched); $: filtered = items.filter(x => x.isMatched);
$: countText = filtered.length < items.length ? `${filtered.length}/${items.length}` : `${items.length}`; $: countText = filtered.length < items.length ? `${filtered.length}/${items.length}` : `${items.length}`;
@ -49,7 +50,11 @@
<div <div
class="group" 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} on:drop={handleDrop}
use:contextMenu={() => groupContextMenu(group)} use:contextMenu={() => groupContextMenu(group)}
> >

View File

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

View File

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

View File

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