mirror of
https://github.com/immich-app/immich.git
synced 2025-12-20 01:11:46 +03:00
refactor ActionItem
This commit is contained in:
@@ -8,6 +8,7 @@ import type {
|
|||||||
SharedLinkResponseDto,
|
SharedLinkResponseDto,
|
||||||
SystemConfigDto,
|
SystemConfigDto,
|
||||||
UserAdminResponseDto,
|
UserAdminResponseDto,
|
||||||
|
WorkflowResponseDto,
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
|
|
||||||
export type Events = {
|
export type Events = {
|
||||||
@@ -42,6 +43,9 @@ export type Events = {
|
|||||||
LibraryUpdate: [LibraryResponseDto];
|
LibraryUpdate: [LibraryResponseDto];
|
||||||
LibraryDelete: [{ id: string }];
|
LibraryDelete: [{ id: string }];
|
||||||
|
|
||||||
|
WorkflowUpdate: [WorkflowResponseDto];
|
||||||
|
WorkflowDelete: [WorkflowResponseDto];
|
||||||
|
|
||||||
ReleaseEvent: [ReleaseEvent];
|
ReleaseEvent: [ReleaseEvent];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { AppRoute } from '$lib/constants';
|
import { AppRoute } from '$lib/constants';
|
||||||
|
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { getFormatter } from '$lib/utils/i18n';
|
import { getFormatter } from '$lib/utils/i18n';
|
||||||
import {
|
import {
|
||||||
@@ -377,6 +378,7 @@ export const handleToggleWorkflowEnabled = async (
|
|||||||
workflowUpdateDto: { enabled: !workflow.enabled },
|
workflowUpdateDto: { enabled: !workflow.enabled },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eventManager.emit('WorkflowUpdate', updated);
|
||||||
toastManager.success($t('workflow_updated'));
|
toastManager.success($t('workflow_updated'));
|
||||||
return updated;
|
return updated;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -398,6 +400,7 @@ export const handleDeleteWorkflow = async (workflow: WorkflowResponseDto): Promi
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteWorkflow({ id: workflow.id });
|
await deleteWorkflow({ id: workflow.id });
|
||||||
|
eventManager.emit('WorkflowDelete', workflow);
|
||||||
toastManager.success($t('workflow_deleted'));
|
toastManager.success($t('workflow_deleted'));
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import emptyWorkflows from '$lib/assets/empty-workflows.svg';
|
import emptyWorkflows from '$lib/assets/empty-workflows.svg';
|
||||||
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
|
import UserPageLayout from '$lib/components/layouts/user-page-layout.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 {
|
import {
|
||||||
getWorkflowActions,
|
getWorkflowActions,
|
||||||
getWorkflowShowSchemaAction,
|
getWorkflowShowSchemaAction,
|
||||||
handleCreateWorkflow,
|
handleCreateWorkflow,
|
||||||
handleDeleteWorkflow,
|
|
||||||
handleToggleWorkflowEnabled,
|
|
||||||
type WorkflowPayload,
|
type WorkflowPayload,
|
||||||
} from '$lib/services/workflow.service';
|
} from '$lib/services/workflow.service';
|
||||||
import type { PluginFilterResponseDto, WorkflowResponseDto } from '@immich/sdk';
|
import type { PluginFilterResponseDto, WorkflowResponseDto } from '@immich/sdk';
|
||||||
@@ -91,18 +90,14 @@
|
|||||||
|
|
||||||
const getJson = (workflow: WorkflowResponseDto) => JSON.stringify(constructPayload(workflow), null, 2);
|
const getJson = (workflow: WorkflowResponseDto) => JSON.stringify(constructPayload(workflow), null, 2);
|
||||||
|
|
||||||
const onToggleEnabled = async (workflow: WorkflowResponseDto) => {
|
const onWorkflowUpdate = (updatedWorkflow: WorkflowResponseDto) => {
|
||||||
const updated = await handleToggleWorkflowEnabled(workflow);
|
workflows = workflows.map((currentWorkflow) =>
|
||||||
if (updated) {
|
currentWorkflow.id === updatedWorkflow.id ? updatedWorkflow : currentWorkflow,
|
||||||
workflows = workflows.map((w) => (w.id === updated.id ? updated : w));
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDeleteWorkflow = async (workflow: WorkflowResponseDto) => {
|
const onWorkflowDelete = (deletedWorkflow: WorkflowResponseDto) => {
|
||||||
const deleted = await handleDeleteWorkflow(workflow);
|
workflows = workflows.filter((currentWorkflow) => currentWorkflow.id !== deletedWorkflow.id);
|
||||||
if (deleted) {
|
|
||||||
workflows = workflows.filter((w) => w.id !== workflow.id);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFilterLabel = (filterId: string) => {
|
const getFilterLabel = (filterId: string) => {
|
||||||
@@ -135,22 +130,18 @@
|
|||||||
target: event.currentTarget as HTMLElement,
|
target: event.currentTarget as HTMLElement,
|
||||||
position: 'top-left',
|
position: 'top-left',
|
||||||
items: [
|
items: [
|
||||||
{
|
ToggleEnabled,
|
||||||
...ToggleEnabled,
|
|
||||||
onAction: () => void onToggleEnabled(workflow),
|
|
||||||
},
|
|
||||||
Edit,
|
Edit,
|
||||||
getWorkflowShowSchemaAction($t, expandedWorkflows.has(workflow.id), () => toggleShowingSchema(workflow.id)),
|
getWorkflowShowSchemaAction($t, expandedWorkflows.has(workflow.id), () => toggleShowingSchema(workflow.id)),
|
||||||
MenuItemType.Divider,
|
MenuItemType.Divider,
|
||||||
{
|
Delete,
|
||||||
...Delete,
|
|
||||||
onAction: () => void onDeleteWorkflow(workflow),
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<OnEvents {onWorkflowUpdate} {onWorkflowDelete} />
|
||||||
|
|
||||||
{#snippet chipItem(title: string)}
|
{#snippet chipItem(title: string)}
|
||||||
<span class="rounded-xl border border-gray-200/80 px-3 py-1.5 text-sm dark:border-gray-600 bg-light">
|
<span class="rounded-xl border border-gray-200/80 px-3 py-1.5 text-sm dark:border-gray-600 bg-light">
|
||||||
<span class="font-medium text-dark">{title}</span>
|
<span class="font-medium text-dark">{title}</span>
|
||||||
|
|||||||
@@ -533,7 +533,7 @@
|
|||||||
isDragging: draggedActionIndex === index,
|
isDragging: draggedActionIndex === index,
|
||||||
isDragOver: dragOverActionIndex === index,
|
isDragOver: dragOverActionIndex === index,
|
||||||
})}
|
})}
|
||||||
class="mb-4 cursor-move rounded-2xl border-2 p-4 transition-all bg-light-100 border-dashed hover:border-light-300"
|
class="mb-4 cursor-move rounded-2xl border-2 p-4 transition-all bg-light-50 border-dashed hover:border-light-300"
|
||||||
>
|
>
|
||||||
<div class="flex items-start gap-4">
|
<div class="flex items-start gap-4">
|
||||||
{@render cardOrder(index)}
|
{@render cardOrder(index)}
|
||||||
|
|||||||
Reference in New Issue
Block a user