forked from r.muellner/velum-raycast
fix: reapply saved person merges to project files
This commit is contained in:
@@ -76,9 +76,11 @@ export function planProjectRevision(
|
||||
if (finalRoot === key) delete mapping[key].merged_into;
|
||||
else mapping[key].merged_into = finalRoot;
|
||||
}
|
||||
if (finalRoot !== oldRoot) {
|
||||
// Older files can still contain an alias even when the mapping already
|
||||
// points at its canonical person. Reapply that substitution on revisions.
|
||||
if (finalRoot !== key) {
|
||||
replacements[key] = { original: finalRoot, type: entry.type };
|
||||
merged.push(key);
|
||||
if (finalRoot !== oldRoot) merged.push(key);
|
||||
}
|
||||
}
|
||||
// A saved alias may still occur in older output files. Rewrite it together
|
||||
@@ -95,6 +97,8 @@ export async function reviseProjectRun(args: {
|
||||
previousDirectory: string;
|
||||
release: Set<string>;
|
||||
merges: Record<string, string>;
|
||||
/** Re-run already saved person merges against files from an older project stand. */
|
||||
reapplyMerges?: boolean;
|
||||
rewriteDocument: (filename: string, data: Buffer, replacements: PlaceholderMapping) => Promise<Buffer>;
|
||||
support?: string;
|
||||
}): Promise<{ run: ProjectRun; directory: string }> {
|
||||
@@ -104,7 +108,10 @@ export async function reviseProjectRun(args: {
|
||||
throw new Error("Es gibt bereits einen neueren Projektstand. Bitte die Liste aktualisieren.");
|
||||
}
|
||||
const plan = planProjectRevision(previous.mapping, args.release, args.merges);
|
||||
if (!plan.released.length && !plan.merged.length) throw new Error("Bitte mindestens einen Begriff freigeben oder Personen zusammenführen.");
|
||||
if (!plan.released.length && !plan.merged.length
|
||||
&& !(args.reapplyMerges && Object.keys(plan.replacements).length)) {
|
||||
throw new Error("Bitte mindestens einen Begriff freigeben oder Personen zusammenführen.");
|
||||
}
|
||||
const inPlace = Boolean(previous.inPlace || previous.sourceInPlace);
|
||||
const previousWhitelist = plan.whitelist.length
|
||||
? await loadProjectWhitelist(previous.projectPath, support) : [];
|
||||
|
||||
@@ -293,6 +293,30 @@ export default function Command() {
|
||||
title: "Projektstände nicht lesbar", message: error.message })).finally(() => setBusy(false));
|
||||
}, []);
|
||||
async function refresh() { setRuns(await listAllRuns()); }
|
||||
async function repairMergedPeople(saved: SavedRun) {
|
||||
const { run, directory } = saved;
|
||||
const inPlace = Boolean(run.inPlace || run.sourceInPlace);
|
||||
if (inPlace && !(await confirmAlert({
|
||||
title: "Zusammengeführte Personen in Projektdateien reparieren?",
|
||||
message: "Der aktuelle Projektordner wird aktualisiert. Vorher erstellt Velum außerhalb des Projektordners eine Sicherung. Zwischenzeitlich geänderte Dateien werden nicht überschrieben.",
|
||||
primaryAction: { title: "Projektdateien reparieren", style: Alert.ActionStyle.Destructive },
|
||||
}))) return;
|
||||
setBusy(true);
|
||||
const toast = await showToast({ style: Toast.Style.Animated, title: "Personenplatzhalter werden bereinigt" });
|
||||
try {
|
||||
const result = await reviseProjectRun({ previous: run, previousDirectory: directory,
|
||||
release: new Set(), merges: {}, reapplyMerges: true, rewriteDocument: depseudonymizeDocument });
|
||||
await refresh();
|
||||
toast.style = Toast.Style.Success;
|
||||
toast.title = "Projektstand repariert";
|
||||
toast.message = "Zusammengeführte Personen wurden in Dateien und Dateinamen erneut angewendet.";
|
||||
await showInFinder(inPlace ? run.projectPath : runCopiesPath(result.run, result.directory)).catch(() => undefined);
|
||||
} catch (error) {
|
||||
toast.style = Toast.Style.Failure;
|
||||
toast.title = "Reparatur fehlgeschlagen";
|
||||
toast.message = (error as Error).message;
|
||||
} finally { setBusy(false); }
|
||||
}
|
||||
const projects = new Map<string, SavedRun[]>();
|
||||
for (const entry of runs) {
|
||||
const path = canonicalProjectPath(entry.run.projectPath);
|
||||
@@ -318,6 +342,9 @@ export default function Command() {
|
||||
<Action.CopyToClipboard title="Speicherpfad kopieren" content={runCopiesPath(run, directory)} />
|
||||
<Action title="Aktuellen Stand nachbearbeiten" icon={Icon.Pencil}
|
||||
onAction={() => push(<RevisionReview saved={{ run, directory }} onSaved={refresh} />)} />
|
||||
{Object.values(run.mapping).some((entry) => entry.type === "PERSON" && entry.merged_into)
|
||||
&& <Action title="Zusammengeführte Personen in Dateien reparieren" icon={Icon.Pencil}
|
||||
onAction={() => repairMergedPeople({ run, directory })} />}
|
||||
{entries.length > 1 && <Action title="Frühere Stände anzeigen" icon={Icon.Clock}
|
||||
onAction={() => push(<ProjectHistory projectName={run.projectName} entries={entries.slice(1)} />)} />}
|
||||
</ActionPanel>} />;
|
||||
|
||||
Reference in New Issue
Block a user