forked from getarcaneapp/arcane
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComposeEditorWrapper.svelte
More file actions
88 lines (81 loc) · 2.44 KB
/
ComposeEditorWrapper.svelte
File metadata and controls
88 lines (81 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<script lang="ts">
import * as Alert from '$lib/components/ui/alert/index.js';
import { ArcaneButton } from '$lib/components/arcane-button';
import { AlertIcon, ExternalLinkIcon } from '$lib/icons';
import * as m from '$lib/paraglide/messages';
import { toast } from 'svelte-sonner';
import { invalidateAll } from '$app/navigation';
import type { Snippet } from 'svelte';
let {
projectId,
projectName,
gitOpsManagedBy = undefined,
fileTitle,
serviceName = undefined,
isDirty,
onSave,
children
}: {
projectId: string;
projectName: string;
gitOpsManagedBy?: string;
fileTitle: string;
serviceName?: string;
isDirty: boolean;
onSave: () => Promise<void>;
children: Snippet;
} = $props();
const isReadOnly = $derived(!!gitOpsManagedBy);
let isSaving = $state(false);
async function handleSave() {
isSaving = true;
try {
await onSave();
toast.success(m.container_compose_save_success());
await invalidateAll();
} catch (err: unknown) {
const message = err instanceof Error ? err.message : m.container_compose_save_failed();
toast.error(message);
} finally {
isSaving = false;
}
}
</script>
<div class="flex h-full min-h-0 flex-col gap-4 p-4">
{#if gitOpsManagedBy}
<Alert.Root variant="default">
<AlertIcon class="size-4" />
<Alert.Title>{m.container_compose_gitops_managed_title()}</Alert.Title>
<Alert.Description>
{m.container_compose_gitops_managed_description({ provider: gitOpsManagedBy })}
</Alert.Description>
</Alert.Root>
{/if}
<div class="bg-muted flex items-start gap-2 rounded-lg border px-4 py-3 text-sm">
<span>
{#if serviceName}
{isReadOnly
? m.container_compose_viewing_info({ file: fileTitle, project: projectName, service: serviceName })
: m.container_compose_editing_info({ file: fileTitle, project: projectName, service: serviceName })}
{:else}
{isReadOnly
? m.compose_editor_viewing_info({ file: fileTitle, project: projectName })
: m.compose_editor_editing_info({ file: fileTitle, project: projectName })}
{/if}
</span>
</div>
<div class="flex min-h-0 flex-1 flex-col">
{@render children()}
</div>
<div class="flex shrink-0 items-center gap-2">
{#if !isReadOnly}
<ArcaneButton action="save" loading={isSaving} disabled={!isDirty} onclick={handleSave} />
{/if}
<ArcaneButton
action="base"
href="/projects/{projectId}"
icon={ExternalLinkIcon}
customLabel={m.container_compose_view_project()}
/>
</div>
</div>