Skip to content

Modern Docker Management, Designed for Everyone

2.0 KB
Raw Blame
<script module lang="ts">
	import { m } from '#lib/paraglide/messages.js';

	export interface NotificationProviderTestOption {
		label: string;
		testType?: string;
	}

	export function getDefaultNotificationProviderTestOptions(): NotificationProviderTestOption[] {
		return [
			{ label: m.notifications_email_test_simple(), testType: 'simple' },
			{ label: m.notifications_email_test_image_update(), testType: 'image-update' },
			{ label: m.notifications_email_test_batch_image_update(), testType: 'batch-image-update' },
			{ label: m.notifications_test_vulnerability_notification(), testType: 'vulnerability-found' },
			{ label: m.notifications_test_prune_report_notification(), testType: 'prune-report' },
			{ label: m.notifications_test_auto_heal_notification(), testType: 'auto-heal' }
		];
	}
</script>

<script lang="ts">
	import { ArcaneButton } from '#lib/components/arcane-button/index.js';
	import * as DropdownMenu from '#lib/components/ui/dropdown-menu/index.js';
	import { ArrowDownIcon, SendEmailIcon } from '#lib/icons/index.js';

	interface Props {
		disabled?: boolean;
		isTesting?: boolean;
		onTest?: (testType?: string) => void;
		options?: NotificationProviderTestOption[];
	}

	let { disabled = false, isTesting = false, onTest, options = getDefaultNotificationProviderTestOptions() }: Props = $props();
</script>

{#if onTest}
	<div class="flex justify-end px-5 py-4">
		<DropdownMenu.Root>
			<DropdownMenu.Trigger>
				<ArcaneButton
					action="base"
					tone="outline"
					disabled={disabled || isTesting}
					loading={isTesting}
					icon={SendEmailIcon}
					customLabel={m.notifications_test_notification()}
				>
					<ArrowDownIcon class="ml-2 size-4" />
				</ArcaneButton>
			</DropdownMenu.Trigger>
			<DropdownMenu.Content align="start">
				{#each options as option (`${option.label}-${option.testType ?? 'default'}`)}
					<DropdownMenu.Item onclick={() => onTest(option.testType)}>
						<SendEmailIcon class="size-4" />
						{option.label}
					</DropdownMenu.Item>
				{/each}
			</DropdownMenu.Content>
		</DropdownMenu.Root>
	</div>
{/if}