Skip to content

Modern Docker Management, Designed for Everyone

3.0 KB
Raw Blame
<script lang="ts">
	import { goto } from '$app/navigation';

	import { ArcaneButton } from '#lib/components/arcane-button/index.js';
	import EnvironmentSwitcherDialog from '#lib/components/dialogs/environment-switcher-dialog.svelte';
	import * as Empty from '#lib/components/ui/empty/index.js';
	import { ErrorNotFoundIcon } from '#lib/icons/index.js';
	import { m } from '#lib/paraglide/messages.js';
	import settingsStore from '#lib/stores/config-store.svelte.js';
	import { environmentStore } from '#lib/stores/environment.store.svelte.js';

	let {
		message,
		status,
		title = m.error_generic(),
		showButton = true,
		actionHref = '/dashboard',
		actionLabel = m.error_go_to_dashboard()
	}: {
		message: string;
		status?: number;
		title?: string;
		showButton?: boolean;
		actionHref?: string;
		actionLabel?: string;
	} = $props();

	let envSwitcherOpen = $state(false);

	// Check if this is a connection error
	const isConnectionError = $derived.by(() => {
		const lowerMessage = message.toLowerCase();
		const connectionTerms = [
			'cannot connect to the docker daemon',
			'failed to connect to docker',
			'error during connect:',
			'edge agent is not connected',
			'no active tunnel for environment',
			'tunnel connection closed',
			'proxy request failed'
		];
		return connectionTerms.some((term) => lowerMessage.includes(term));
	});

	const connectionErrorTitle = $derived.by(() => {
		if (environmentStore.selected?.id === '0') {
			return m.error_connection_local_docker();
		} else {
			return m.error_connection_remote_environment({ name: environmentStore.selected?.name || 'Unknown' });
		}
	});

	const connectionErrorMessage = $derived.by(() => {
		if (environmentStore.selected?.id === '0') {
			const host = settingsStore.current ? settingsStore.current?.dockerHost : 'unix:///var/run/docker.sock';
			return m.error_connection_local_docker_desc({
				host: host || 'unix:///var/run/docker.sock'
			});
		} else {
			return m.error_connection_remote_environment_desc({
				name: environmentStore.selected?.name || 'Unknown',
				url: environmentStore.selected?.apiUrl || 'Unknown URL'
			});
		}
	});
</script>

<div class="grid h-full min-h-screen place-items-center px-6">
	<Empty.Root>
		<Empty.Header>
			<Empty.Media variant="icon">
				<ErrorNotFoundIcon class="size-20 text-destructive" aria-hidden="true" />
			</Empty.Media>
			<Empty.Title role="heading" aria-level={1}>{isConnectionError ? connectionErrorTitle : title}</Empty.Title>
			<Empty.Description>{isConnectionError ? connectionErrorMessage : message} - {status}</Empty.Description>
		</Empty.Header>
		<Empty.Content>
			<div class="flex flex-col gap-3">
				{#if status !== 404}
					<ArcaneButton
						action="base"
						tone="outline"
						customLabel={m.sidebar_select_environment()}
						onclick={() => (envSwitcherOpen = true)}
					/>
				{/if}
				{#if showButton}
					<ArcaneButton action="base" customLabel={actionLabel} onclick={() => goto(actionHref)} />
				{/if}
			</div>
		</Empty.Content>
	</Empty.Root>
</div>

<EnvironmentSwitcherDialog bind:open={envSwitcherOpen} />