兼容旧草稿避免项目信息被清空

This commit is contained in:
Cheng Zhou
2026-05-11 09:02:14 +08:00
parent f6a7a3d6ee
commit 8d061a1520
2 changed files with 19 additions and 1 deletions
@@ -50,6 +50,17 @@ describe("ProjectDetail setup draft publish workflow", () => {
expect(source.indexOf("applySetupDraft(createDefaultSetupDraft(siteOptions.value));", functionIndex)).toBe(-1);
});
it("does not let legacy empty projectInfo overwrite project master data", () => {
const source = readProjectDetail();
const functionIndex = source.indexOf("const applySetupDraft = (draft: SetupConfigDraft) => {");
const emptyGuardIndex = source.indexOf("!isProjectPublishSnapshotEmpty(projectInfo) || isSetupDraftEffectivelyEmpty(setupDraft)", functionIndex);
const fallbackIndex = source.indexOf("setupDraft.projectInfo = buildProjectPublishSnapshot();", emptyGuardIndex);
expect(functionIndex).toBeGreaterThan(-1);
expect(emptyGuardIndex).toBeGreaterThan(functionIndex);
expect(fallbackIndex).toBeGreaterThan(emptyGuardIndex);
});
it("keeps early termination out of regular visit schedule options", () => {
const source = readProjectDetail();
+8 -1
View File
@@ -4009,6 +4009,9 @@ const isProjectPublishSnapshotShape = (value: unknown): value is ProjectPublishS
);
};
const isProjectPublishSnapshotEmpty = (snapshot: ProjectPublishSnapshot): boolean =>
JSON.stringify(snapshot) === JSON.stringify(emptyProjectInfoDraft());
const applyProjectInfoDraft = (snapshot: ProjectPublishSnapshot) => {
suppressEnrollmentFieldSync.value = true;
form.value.code = snapshot.code || "";
@@ -4044,7 +4047,11 @@ const applySetupDraft = (draft: SetupConfigDraft) => {
setupDraft.siteEnrollmentPlans = normalizeSiteEnrollmentPlans(clone(draft.siteEnrollmentPlans));
setupDraft.monitoringStrategies = clone(draft.monitoringStrategies);
setupDraft.centerConfirm = clone(draft.centerConfirm);
applyProjectInfoDraft(projectInfo);
if (!isProjectPublishSnapshotEmpty(projectInfo) || isSetupDraftEffectivelyEmpty(setupDraft)) {
applyProjectInfoDraft(projectInfo);
} else {
setupDraft.projectInfo = buildProjectPublishSnapshot();
}
formBaselineSnapshot.value = serializeFormForCompare();
suppressDraftWatch.value = false;
};