feat(ui): revert single changes in settings and workflow review
This commit is contained in:
1 parent
f10199f0b6
commit
55deeaa88c
11 files changed
+203
-98
No files matched your search
@@ -35,7 +35,9 @@ import WorkflowCanvas from "./WorkflowCanvas.vue";
|
||||
import WorkflowHistory from "./WorkflowHistory.vue";
|
||||
import { useWorkflowHistory } from "./workflow-history";
|
||||
import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
|
||||
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, stepAt, workflowField, type StepPath } from "./workflow-edit";
|
||||
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, type StepPath } from "./workflow-edit";
|
||||
import ChangeList from "@/components/ChangeList.vue";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { useWorkflowRuns } from "./workflow-runs";
|
||||
import { useWorkflowTriggers } from "./workflow-triggers";
|
||||
import { cloneControlPlaneValue, useSettingsStore } from "@/stores/settings";
|
||||
@@ -240,6 +242,7 @@ const vocabulary = computed(() => workflows.stepTypes);
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value));
|
||||
const stored = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.yaml);
|
||||
const dirty = computed(() => yaml.value !== (stored.value ?? ""));
|
||||
const changes = computed(() => (dirty.value ? workflowChanges(stored.value ?? "", yaml.value) : []));
|
||||
const view = ref("canvas");
|
||||
// What each step lacks, read the way its editor reads it.
|
||||
const problems = computed(() =>
|
||||
@@ -300,7 +303,15 @@ function syncScroll(event: Event): void {
|
||||
<span v-if="!parsed.ok" class="ml-auto max-w-md truncate text-xs text-danger" role="status" :title="validationLabel(parsed)">
|
||||
{{ validationLabel(parsed) }}
|
||||
</span>
|
||||
<span v-else-if="dirty" class="ml-auto text-xs text-fg-subtle">Unsaved changes</span>
|
||||
<Popover v-else-if="dirty">
|
||||
<PopoverTrigger as-child>
|
||||
<Button type="button" variant="ghost" size="sm" class="ml-auto text-xs text-fg-subtle">
|
||||
{{ changes.length || "" }} Unsaved {{ changes.length === 1 ? "change" : "changes" }}</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" class="max-h-96 w-96 overflow-y-auto p-0">
|
||||
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<span v-else class="ml-auto" />
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
||||
import { diffValues, pathSegments, type Change } from "../lib/changes.ts";
|
||||
|
||||
/**
|
||||
* Canvas edits as edits to the workflow's YAML document. The text stays the
|
||||
@@ -203,3 +204,30 @@ export function setWorkflowField(source: string, key: string, value: unknown): s
|
||||
else document.set(key, document.createNode(pruned));
|
||||
return document.toString();
|
||||
}
|
||||
|
||||
/** The changes between two versions of a workflow, one per changed leaf. */
|
||||
export function workflowChanges(before: string, after: string): Change[] {
|
||||
const data = (source: string) => {
|
||||
try { return parseDocument(source).toJSON() ?? {}; } catch { return {}; }
|
||||
};
|
||||
return diffValues(data(before), data(after), "", true);
|
||||
}
|
||||
|
||||
/** Puts one change's before value back, keeping every other edit and the
|
||||
* document's comments and layout. */
|
||||
export function revertWorkflowChange(source: string, change: Change): string {
|
||||
const document = parseDocument(source);
|
||||
const path = pathSegments(change.path);
|
||||
if (change.before !== undefined) {
|
||||
document.setIn(path, document.createNode(change.before));
|
||||
return document.toString();
|
||||
}
|
||||
// Removing a row's last leaf removes the row, not just its contents.
|
||||
document.deleteIn(path);
|
||||
for (let parent = path.slice(0, -1); parent.length > 0; parent = parent.slice(0, -1)) {
|
||||
const node = document.getIn(parent, true);
|
||||
if (!((isMap(node) || isSeq(node)) && node.items.length === 0)) break;
|
||||
document.deleteIn(parent);
|
||||
}
|
||||
return document.toString();
|
||||
}
|
||||
Reference in new issue
Block a user