feat: render album's name in workflow step card (#28680)
* feat: render album name in step card body * clean up * i18n
This commit is contained in:
@@ -1,5 +1,25 @@
|
|||||||
|
<script module lang="ts">
|
||||||
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||||
|
import { getAlbumInfo } from '@immich/sdk';
|
||||||
|
|
||||||
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||||
|
const albumNameCache = new Map<string, Promise<string>>();
|
||||||
|
|
||||||
|
const getAlbumName = (id: string): Promise<string> => {
|
||||||
|
let albumName = albumNameCache.get(id);
|
||||||
|
if (!albumName) {
|
||||||
|
albumName = getAlbumInfo({ ...authManager.params, id })
|
||||||
|
.then((album) => album.albumName)
|
||||||
|
.catch(() => id);
|
||||||
|
albumNameCache.set(id, albumName);
|
||||||
|
}
|
||||||
|
return albumName;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { pluginManager } from '$lib/managers/plugin-manager.svelte';
|
import { pluginManager } from '$lib/managers/plugin-manager.svelte';
|
||||||
|
import type { JSONSchemaProperty } from '$lib/types';
|
||||||
import type { WorkflowStepDto } from '@immich/sdk';
|
import type { WorkflowStepDto } from '@immich/sdk';
|
||||||
import { Badge, Card, CardBody, CardDescription, CardHeader, CardTitle, Icon, IconButton } from '@immich/ui';
|
import { Badge, Card, CardBody, CardDescription, CardHeader, CardTitle, Icon, IconButton } from '@immich/ui';
|
||||||
import {
|
import {
|
||||||
@@ -27,9 +47,13 @@
|
|||||||
|
|
||||||
const method = $derived(pluginManager.getMethod(step.method));
|
const method = $derived(pluginManager.getMethod(step.method));
|
||||||
const isFilter = $derived(method?.uiHints?.includes('Filter') ?? false);
|
const isFilter = $derived(method?.uiHints?.includes('Filter') ?? false);
|
||||||
|
const schema = $derived(method?.schema as JSONSchemaProperty | undefined);
|
||||||
const configEntries = $derived(
|
const configEntries = $derived(
|
||||||
Object.entries(step.config ?? {}).filter(([, value]) => value !== null && value !== undefined && value !== ''),
|
Object.entries(step.config ?? {}).filter(([, value]) => value !== null && value !== undefined && value !== ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getUiHint = (key: string) => schema?.properties?.[key]?.uiHint;
|
||||||
|
const toIds = (value: unknown): string[] => (Array.isArray(value) ? value.map(String) : [String(value)]);
|
||||||
let dragImage = $state<Element>();
|
let dragImage = $state<Element>();
|
||||||
let isDropTarget = $state(false);
|
let isDropTarget = $state(false);
|
||||||
let hoverDrag = $state(false);
|
let hoverDrag = $state(false);
|
||||||
@@ -204,15 +228,28 @@
|
|||||||
{#if configEntries.length > 0}
|
{#if configEntries.length > 0}
|
||||||
<CardBody class="py-3">
|
<CardBody class="py-3">
|
||||||
<div class="flex flex-wrap items-center gap-1.5">
|
<div class="flex flex-wrap items-center gap-1.5">
|
||||||
{#each configEntries as [key, value] (key)}
|
{#snippet badge(key: string, content: string)}
|
||||||
<Badge
|
<Badge
|
||||||
color={isFilter ? 'info' : 'warning'}
|
color={isFilter ? 'info' : 'warning'}
|
||||||
shape="round"
|
shape="round"
|
||||||
size="small"
|
size="small"
|
||||||
class="border font-mono {isFilter ? 'border-primary-200' : 'border-warning-200'}"
|
class="border font-mono {isFilter ? 'border-primary-200' : 'border-warning-200'}"
|
||||||
>
|
>
|
||||||
<span class="opacity-60">{key}</span>{formatConfigValue(value)}
|
<span class="opacity-60">{key}</span>{content}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
{/snippet}
|
||||||
|
{#each configEntries as [key, value] (key)}
|
||||||
|
{#if getUiHint(key) === 'AlbumId'}
|
||||||
|
{#each toIds(value) as albumId (albumId)}
|
||||||
|
{#await getAlbumName(albumId)}
|
||||||
|
{@render badge($t('album'), '…')}
|
||||||
|
{:then albumName}
|
||||||
|
{@render badge($t('album'), `"${truncate(albumName)}"`)}
|
||||||
|
{/await}
|
||||||
|
{/each}
|
||||||
|
{:else}
|
||||||
|
{@render badge(key, formatConfigValue(value))}
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|||||||
Reference in New Issue
Block a user