Lutra/ui/src/components/deploy/SyncDialog.vue
danny 1c6c67194a
Some checks failed
ci / ci (macos-15) (push) Has been cancelled
ci / ci (ubuntu-24.04) (push) Has been cancelled
ci / ci (windows-2025) (push) Has been cancelled
D2: Remote Host browser, compare and sync preview in the UI; docs and G17
Remote Host tool window (server select, tree, read-only viewer with Edit
and Upload, rename, new folder, delete after its question), server tabs
in the diff viewer, sync preview (uploads preselected, deletions never,
extra confirmation before deleting on the server), Compare with Server
in the tree menu and Tools › Deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 19:50:14 +01:00

295 lines
6.6 KiB
Vue

<script setup lang="ts">
/**
* The sync preview (C9 D2): every file that differs between the compared
* project folders and the server, with what Sync would do.
*
* - Only in the project, or different: upload; selected by default.
* Different files offer Show Diff (a server tab in the diff viewer).
* - Only on the server: delete on the server; never selected by default.
* As soon as one is selected, a red confirmation checkbox appears and
* Sync stays disabled until it is ticked.
* - Escape or Close closes the preview. The dialog is an exclusive modal
* (`deploySync`).
*/
import { computed, watch } from "vue";
import { useModalsStore } from "../../commands/modals";
import { t } from "../../i18n";
import { useRemoteBrowserStore, type SyncItem } from "./remoteBrowser";
const browser = useRemoteBrowserStore();
const modals = useModalsStore();
/** Whether the preview is open. */
const isOpen = computed(() => browser.syncItems !== null);
/**
* What Sync does with an item, for people.
*
* @param item - the item.
*/
function action(item: SyncItem): string {
return item.status === "localOnly"
? t("deploy.sync.uploadNew")
: item.status === "different"
? t("deploy.sync.uploadChanged")
: t("deploy.sync.deleteOnServer");
}
/**
* Selects or clears an item.
*
* @param item - the item.
* @param event - the checkbox change.
*/
function toggle(item: SyncItem, event: Event): void {
item.selected = (event.target as HTMLInputElement).checked;
if (browser.deletions.length === 0) {
browser.confirmDelete = false;
}
}
/** Closes the preview. */
function close(): void {
browser.closeSync();
}
/**
* Escape closes.
*
* @param event - the key.
*/
function onKeydown(event: KeyboardEvent): void {
if (event.key === "Escape") {
event.preventDefault();
close();
}
}
watch(isOpen, (open) => {
if (open) {
modals.opened("deploySync", close);
} else {
modals.closed("deploySync");
}
});
</script>
<template>
<div
v-if="isOpen"
class="sync-dialog"
data-test="sync-dialog"
@mousedown.self="close"
>
<div
class="sync-dialog__box"
role="dialog"
aria-modal="true"
aria-labelledby="lt-sync-title"
@keydown="onKeydown"
>
<h2
id="lt-sync-title"
class="sync-dialog__title"
>
{{ t("deploy.sync.title", { server: browser.serverName }) }}
</h2>
<p
v-if="browser.syncing && (browser.syncItems ?? []).length === 0"
class="sync-dialog__note"
>
{{ t("deploy.sync.comparing") }}
</p>
<p
v-else-if="(browser.syncItems ?? []).length === 0 && browser.error === null"
class="sync-dialog__note"
data-test="sync-equal"
>
{{ t("deploy.sync.equal") }}
</p>
<ul
v-else
class="sync-dialog__list"
>
<li
v-for="item in browser.syncItems ?? []"
:key="item.path"
class="sync-dialog__item"
:class="{ 'sync-dialog__item--delete': item.status === 'remoteOnly' }"
data-test="sync-item"
>
<label class="sync-dialog__check">
<input
type="checkbox"
:checked="item.selected"
:data-path="item.path"
@change="toggle(item, $event)"
>
<span class="sync-dialog__path">{{ item.path }}</span>
</label>
<span class="sync-dialog__action">{{ action(item) }}</span>
<button
v-if="item.status === 'different'"
type="button"
class="sync-dialog__button"
data-test="sync-diff"
@click="browser.compareFile(item.path)"
>
{{ t("deploy.sync.showDiff") }}
</button>
</li>
</ul>
<label
v-if="browser.deletions.length > 0"
class="sync-dialog__confirm"
data-test="sync-confirm"
>
<input
v-model="browser.confirmDelete"
type="checkbox"
>
{{ t("deploy.sync.confirmDelete", { count: browser.deletions.length }) }}
</label>
<p
v-if="browser.error !== null"
class="sync-dialog__error"
role="alert"
>
{{ browser.error }}
</p>
<div class="sync-dialog__buttons">
<button
type="button"
class="sync-dialog__button sync-dialog__button--primary"
:disabled="!browser.canSync"
data-test="sync-run"
@click="browser.runSync()"
>
{{ t("deploy.sync.run") }}
</button>
<button
type="button"
class="sync-dialog__button"
data-test="sync-close"
@click="close"
>
{{ t("deploy.dialog.close") }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.sync-dialog {
position: fixed;
inset: 0;
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 8vh;
background: color-mix(in srgb, var(--lt-bg) 50%, transparent);
z-index: 20;
}
.sync-dialog__box {
width: min(720px, 92vw);
max-height: 80vh;
display: flex;
flex-direction: column;
gap: 10px;
padding: 16px;
color: var(--lt-fg);
background: var(--lt-bg);
border: 1px solid var(--lt-border);
border-radius: 6px;
}
.sync-dialog__title {
margin: 0;
font-size: var(--lt-font-size-ui);
font-weight: 600;
}
.sync-dialog__note {
margin: 0;
color: var(--lt-fg-muted);
}
.sync-dialog__list {
margin: 0;
padding: 0;
list-style: none;
overflow-y: auto;
}
.sync-dialog__item {
display: flex;
align-items: center;
gap: 8px;
padding: 3px 0;
border-bottom: 1px solid var(--lt-border);
}
.sync-dialog__item--delete .sync-dialog__action {
color: var(--lt-error);
}
.sync-dialog__check {
display: flex;
flex: 1;
align-items: center;
gap: 6px;
min-width: 0;
}
.sync-dialog__path {
overflow-wrap: anywhere;
font-family: var(--lt-font-mono);
}
.sync-dialog__action {
color: var(--lt-fg-muted);
white-space: nowrap;
}
.sync-dialog__confirm {
display: flex;
align-items: center;
gap: 6px;
color: var(--lt-error);
}
.sync-dialog__error {
margin: 0;
color: var(--lt-error);
overflow-wrap: anywhere;
}
.sync-dialog__buttons {
display: flex;
justify-content: flex-end;
gap: 8px;
}
.sync-dialog__button {
padding: 4px 12px;
font: inherit;
color: var(--lt-fg);
background: var(--lt-editor-bg);
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.sync-dialog__button--primary {
border-color: var(--lt-accent);
}
.sync-dialog__button:disabled {
color: var(--lt-fg-muted);
}
.sync-dialog__button:focus-visible {
outline: 1px solid var(--lt-accent);
}
</style>