mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
chore: use context menu for library table (#25429)
* chore: use context menu for library table * chore: add user detail link and menu divider --------- Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
parent
1b032339aa
commit
2f1d1edf10
2 changed files with 30 additions and 11 deletions
|
|
@ -20,7 +20,7 @@ import {
|
||||||
type UpdateLibraryDto,
|
type UpdateLibraryDto,
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
|
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
|
||||||
import { mdiPencilOutline, mdiPlusBoxOutline, mdiSync, mdiTrashCanOutline } from '@mdi/js';
|
import { mdiInformationOutline, mdiPencilOutline, mdiPlusBoxOutline, mdiSync, mdiTrashCanOutline } from '@mdi/js';
|
||||||
import type { MessageFormatter } from 'svelte-i18n';
|
import type { MessageFormatter } from 'svelte-i18n';
|
||||||
|
|
||||||
export const getLibrariesActions = ($t: MessageFormatter, libraries: LibraryResponseDto[]) => {
|
export const getLibrariesActions = ($t: MessageFormatter, libraries: LibraryResponseDto[]) => {
|
||||||
|
|
@ -45,6 +45,13 @@ export const getLibrariesActions = ($t: MessageFormatter, libraries: LibraryResp
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLibraryActions = ($t: MessageFormatter, library: LibraryResponseDto) => {
|
export const getLibraryActions = ($t: MessageFormatter, library: LibraryResponseDto) => {
|
||||||
|
const Detail: ActionItem = {
|
||||||
|
icon: mdiInformationOutline,
|
||||||
|
type: $t('command'),
|
||||||
|
title: $t('details'),
|
||||||
|
onAction: () => goto(Route.viewLibrary(library)),
|
||||||
|
};
|
||||||
|
|
||||||
const Edit: ActionItem = {
|
const Edit: ActionItem = {
|
||||||
icon: mdiPencilOutline,
|
icon: mdiPencilOutline,
|
||||||
type: $t('command'),
|
type: $t('command'),
|
||||||
|
|
@ -84,7 +91,7 @@ export const getLibraryActions = ($t: MessageFormatter, library: LibraryResponse
|
||||||
shortcuts: { shift: true, key: 'r' },
|
shortcuts: { shift: true, key: 'r' },
|
||||||
};
|
};
|
||||||
|
|
||||||
return { Edit, Delete, AddFolder, AddExclusionPattern, Scan };
|
return { Detail, Edit, Delete, AddFolder, AddExclusionPattern, Scan };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLibraryFolderActions = ($t: MessageFormatter, library: LibraryResponseDto, folder: string) => {
|
export const getLibraryFolderActions = ($t: MessageFormatter, library: LibraryResponseDto, folder: string) => {
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,16 @@
|
||||||
import OnEvents from '$lib/components/OnEvents.svelte';
|
import OnEvents from '$lib/components/OnEvents.svelte';
|
||||||
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
|
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
|
||||||
import { Route } from '$lib/route';
|
import { Route } from '$lib/route';
|
||||||
import { getLibrariesActions } from '$lib/services/library.service';
|
import { getLibrariesActions, getLibraryActions } from '$lib/services/library.service';
|
||||||
import { locale } from '$lib/stores/preferences.store';
|
import { locale } from '$lib/stores/preferences.store';
|
||||||
import { getBytesWithUnit } from '$lib/utils/byte-units';
|
import { getBytesWithUnit } from '$lib/utils/byte-units';
|
||||||
import { getLibrary, getLibraryStatistics, type LibraryResponseDto } from '@immich/sdk';
|
import { getLibrary, getLibraryStatistics, type LibraryResponseDto } from '@immich/sdk';
|
||||||
import {
|
import {
|
||||||
Button,
|
|
||||||
CommandPaletteDefaultProvider,
|
CommandPaletteDefaultProvider,
|
||||||
Container,
|
Container,
|
||||||
|
ContextMenuButton,
|
||||||
|
Link,
|
||||||
|
MenuItemType,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
|
|
@ -58,13 +60,18 @@
|
||||||
|
|
||||||
const { Create, ScanAll } = $derived(getLibrariesActions($t, libraries));
|
const { Create, ScanAll } = $derived(getLibrariesActions($t, libraries));
|
||||||
|
|
||||||
|
const getActionsForLibrary = (library: LibraryResponseDto) => {
|
||||||
|
const { Detail, Scan, Edit, Delete } = getLibraryActions($t, library);
|
||||||
|
return [Detail, Scan, Edit, MenuItemType.Divider, Delete];
|
||||||
|
};
|
||||||
|
|
||||||
const classes = {
|
const classes = {
|
||||||
column1: 'w-4/12',
|
column1: 'w-4/12',
|
||||||
column2: 'w-4/12',
|
column2: 'w-4/12',
|
||||||
column3: 'w-2/12',
|
column3: 'w-1/12',
|
||||||
column4: 'w-2/12',
|
column4: 'w-1/12',
|
||||||
column5: 'w-2/12',
|
column5: 'w-1/12',
|
||||||
column6: 'w-2/12',
|
column6: 'w-1/12 flex justify-end',
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -89,14 +96,19 @@
|
||||||
{#each libraries as library (library.id + library.name)}
|
{#each libraries as library (library.id + library.name)}
|
||||||
{@const { photos, usage, videos } = statistics[library.id]}
|
{@const { photos, usage, videos } = statistics[library.id]}
|
||||||
{@const [diskUsage, diskUsageUnit] = getBytesWithUnit(usage, 0)}
|
{@const [diskUsage, diskUsageUnit] = getBytesWithUnit(usage, 0)}
|
||||||
|
{@const owner = owners[library.id]}
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell class={classes.column1}>{library.name}</TableCell>
|
<TableCell class={classes.column1}>
|
||||||
<TableCell class={classes.column2}>{owners[library.id].name}</TableCell>
|
<Link href={Route.viewLibrary(library)}>{library.name}</Link>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell class={classes.column2}>
|
||||||
|
<Link href={Route.viewUser(owner)}>{owner.name}</Link>
|
||||||
|
</TableCell>
|
||||||
<TableCell class={classes.column3}>{photos.toLocaleString($locale)}</TableCell>
|
<TableCell class={classes.column3}>{photos.toLocaleString($locale)}</TableCell>
|
||||||
<TableCell class={classes.column4}>{videos.toLocaleString($locale)}</TableCell>
|
<TableCell class={classes.column4}>{videos.toLocaleString($locale)}</TableCell>
|
||||||
<TableCell class={classes.column5}>{diskUsage} {diskUsageUnit}</TableCell>
|
<TableCell class={classes.column5}>{diskUsage} {diskUsageUnit}</TableCell>
|
||||||
<TableCell class={classes.column6}>
|
<TableCell class={classes.column6}>
|
||||||
<Button size="small" href={Route.viewLibrary(library)}>{$t('view')}</Button>
|
<ContextMenuButton color="primary" aria-label={$t('open')} items={getActionsForLibrary(library)} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue