Preserve original Book action and resume unfinished book imports safely
This commit is contained in:
parent
90492f65f0
commit
0d11a6b408
@ -24,11 +24,11 @@ A second confirmed navigation defect made the failure look like nothing had star
|
||||
## Correction — existing components only
|
||||
|
||||
- The existing global progress model/service now also projects the current authorised unfinished wizard, scan and build state. No new session store, import engine, hub, database table or parallel progress strip.
|
||||
- The same strip and button area show Word reading, chapter review, scene detection, location/character review, failure or saved setup as appropriate. Both the strip text and action link navigate to the existing matching wizard route/preview. Pending setup is not labelled as running analysis.
|
||||
- The same strip and button area show Word reading, chapter review, scene detection, location/character review, failure or saved setup as appropriate. The strip text links to the existing matching wizard route/preview; the right-hand **Book** button keeps its original book-details destination. Pending setup is not labelled as running analysis.
|
||||
- Core capture completion alone does not remove the strip: it remains through mandatory review, and disappears when persistent core completion is recorded. Optional Story Intelligence continues to use its existing counts, events and **Book** action independently.
|
||||
- Existing in-memory scene-build progress has a read-only getter and is hydrated on wizard reload. The existing scene-detection button stays disabled while that build is running; re-entry does not launch another build.
|
||||
- While core work exists, the existing authoritative SignalR watcher refreshes its snapshot every 15 seconds on a visible page and on return/reconnect. No extra connection or scanning request is created.
|
||||
- The normal Import action resumes an unfinished selected-book setup without clearing capture/session/preferences. Explicit creation of a new setup after completed onboarding remains available through the existing flow.
|
||||
- The normal global and same-book Import actions resume an unfinished selected-book setup without clearing capture/session/preferences. Explicit creation of a new setup after completed onboarding remains available through the existing flow.
|
||||
|
||||
## Returning to today's book
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
const {chromium}=require('playwright'),fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict');
|
||||
(async()=>{const browser=await chromium.launch();try{const page=await browser.newPage();const core={BookID:10,BookTitle:'Fixture',Stage:'Scanning Word',Message:'Reading paragraphs',PercentComplete:42,ResumeUrl:'/onboarding'};
|
||||
async function boot(seed){await page.goto('about:blank');await page.setContent(`<div data-story-intelligence-global-strip hidden><a data-story-intelligence-global-link><strong data-story-intelligence-global-title></strong><span data-story-intelligence-global-detail></span></a><span data-story-intelligence-global-bar></span><a data-story-intelligence-global-link data-story-intelligence-global-action></a><div data-story-intelligence-global-runs></div></div>`);await page.evaluate(seed=>{const strip=document.querySelector('[data-story-intelligence-global-strip]');strip.dataset.coreImport=JSON.stringify(seed);window.snapshot={coreImport:seed,books:[]};window.calls=[];window.handlers={};window.signalR={HubConnectionBuilder:class{withUrl(){return this;}withAutomaticReconnect(){return this;}build(){return{state:'Connected',on(n,f){handlers[n]=f;},onreconnected(){},onclose(){},start:async()=>{},invoke:async n=>{calls.push(n);return snapshot;}}}}};},seed);await page.addScriptTag({content:fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/story-intelligence-global-progress.js'),'utf8')});await page.waitForFunction(()=>calls.includes('WatchGlobalStoryIntelligenceProgress'));}
|
||||
await boot(core);const strip=page.locator('[data-story-intelligence-global-strip]'),link=page.locator('[data-story-intelligence-global-action]');await page.waitForTimeout(50);assert.equal(await strip.isVisible(),true);assert.match(await strip.innerText(),/Scanning Word/);assert.equal(await link.getAttribute('href'),'/onboarding');assert.equal(await link.innerText(),'Return to import');assert.match(await page.locator('[data-story-intelligence-global-bar]').getAttribute('style'),/42%/);
|
||||
async function boot(seed){await page.goto('about:blank');await page.setContent(`<div data-story-intelligence-global-strip hidden><a data-story-intelligence-global-link><strong data-story-intelligence-global-title></strong><span data-story-intelligence-global-detail></span></a><span data-story-intelligence-global-bar></span><a data-story-intelligence-global-action></a><div data-story-intelligence-global-runs></div></div>`);await page.evaluate(seed=>{const strip=document.querySelector('[data-story-intelligence-global-strip]');strip.dataset.coreImport=JSON.stringify(seed);window.snapshot={coreImport:seed,books:[]};window.calls=[];window.handlers={};window.signalR={HubConnectionBuilder:class{withUrl(){return this;}withAutomaticReconnect(){return this;}build(){return{state:'Connected',on(n,f){handlers[n]=f;},onreconnected(){},onclose(){},start:async()=>{},invoke:async n=>{calls.push(n);return snapshot;}}}}};},seed);await page.addScriptTag({content:fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/story-intelligence-global-progress.js'),'utf8')});await page.waitForFunction(()=>calls.includes('WatchGlobalStoryIntelligenceProgress'));}
|
||||
await boot(core);const strip=page.locator('[data-story-intelligence-global-strip]'),link=page.locator('[data-story-intelligence-global-link]'),book=page.locator('[data-story-intelligence-global-action]');await page.waitForTimeout(50);assert.equal(await strip.isVisible(),true);assert.match(await strip.innerText(),/Scanning Word/);assert.equal(await link.getAttribute('href'),'/onboarding');assert.equal(await book.innerText(),'Book');assert.equal(await book.getAttribute('href'),'/Books/Details/10');assert.match(await page.locator('[data-story-intelligence-global-bar]').getAttribute('style'),/42%/);
|
||||
await boot(core);assert.equal(await strip.isVisible(),true);assert.equal(await link.getAttribute('href'),'/onboarding');
|
||||
await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:{bookTitle:'Fixture',stage:'Review chapters',message:'Capture saved',resumeUrl:'/onboarding/scan-review?previewId=123'},books:[]}));assert.match(await link.getAttribute('href'),/scan-review\?previewId=123/);assert.match(await strip.innerText(),/Review chapters/);
|
||||
await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:{bookID:10,bookTitle:'Fixture',stage:'Review chapters',message:'Capture saved',resumeUrl:'/onboarding/scan-review?previewId=123'},books:[]}));assert.match(await link.getAttribute('href'),/scan-review\?previewId=123/);assert.match(await strip.innerText(),/Review chapters/);
|
||||
await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:null,books:[]}));assert.equal(await strip.isVisible(),false);
|
||||
await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:null,books:[{bookID:10,projectID:9,bookTitle:'Fixture',status:'Pending',pendingRunCount:1,hasActiveRuns:true,totalExpectedScenes:4,completedScenes:0,updatedUtc:new Date().toISOString()}],hasActiveWork:true,activeBookCount:1,status:'Running',totalExpectedScenes:4,completedScenes:0}));assert.equal(await strip.isVisible(),true);assert.equal(await link.getAttribute('href'),'/Books/Details/10');assert.equal(await link.innerText(),'Book');
|
||||
await page.evaluate(()=>handlers.StoryIntelligenceGlobalProgressChanged({coreImport:null,books:[{bookID:10,projectID:9,bookTitle:'Fixture',status:'Pending',pendingRunCount:1,hasActiveRuns:true,totalExpectedScenes:4,completedScenes:0,updatedUtc:new Date().toISOString()}],hasActiveWork:true,activeBookCount:1,status:'Running',totalExpectedScenes:4,completedScenes:0}));assert.equal(await strip.isVisible(),true);assert.equal(await link.getAttribute('href'),'/Books/Details/10');assert.equal(await book.innerText(),'Book');
|
||||
assert.equal(await page.evaluate(()=>calls.some(n=>/Start|Scan|Build/.test(n))),false);console.log('PASS existing global strip: Word scan visibility, recreated-page restore, exact review navigation, core completion hiding, independent optional AI Book link, and watch-only requests');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1);});
|
||||
|
||||
@ -35,9 +35,9 @@ internal static class ImportProgressNavigationTests
|
||||
var started=await scans.StartAsync(7,8,9,10);await scans.ProgressAsync(7,new(){OnboardingID=8,Message="Reading paragraphs",PercentComplete=42});
|
||||
var first=await Progress().GetForCurrentUserAsync();var second=await Progress().GetForCurrentUserAsync();
|
||||
Check(first.HasActiveWork&&first.CoreImport?.Stage=="Scanning Word"&&second.CoreImport?.PercentComplete==42&&(await scans.GetStateAsync(7,8)).ScanID==started.ScanID,"navigation away and refresh keep the same running Word scan and expose it through existing global progress");
|
||||
var ctor=typeof(OnboardingService).GetConstructors().Single();var deps=new Dictionary<Type,object>{{typeof(IOnboardingRepository),onboarding},{typeof(ICurrentUserService),user},{typeof(IManuscriptScanPreviewStore),scans}};
|
||||
var ctor=typeof(OnboardingService).GetConstructors().Single();var deps=new Dictionary<Type,object>{{typeof(IOnboardingRepository),onboarding},{typeof(ICurrentUserService),user},{typeof(IManuscriptScanPreviewStore),scans},{typeof(IProjectRepository),projects},{typeof(IBookRepository),books}};
|
||||
var service=(OnboardingService)ctor.Invoke(ctor.GetParameters().Select(p=>deps.GetValueOrDefault(p.ParameterType)).ToArray());
|
||||
await service.StartManuscriptImportSetupAsync();Check(calls.All(c=>c=="GetAsync")&&capture.Clears==0&&(await scans.GetStateAsync(7,8)).ScanID==started.ScanID,"existing Import action resumes unfinished book without resetting preferences, scan ID or capture");
|
||||
await service.StartManuscriptImportSetupAsync();await service.BeginManuscriptImportForBookAsync(9,10);Check(calls.All(c=>c=="GetAsync")&&capture.Clears==0&&(await scans.GetStateAsync(7,8)).ScanID==started.ScanID,"global and book Import actions resume unfinished book without resetting preferences, scan ID or capture");
|
||||
var preview=new ManuscriptScanPreview{UserID=7,OnboardingID=8,ProjectID=9,BookID=10,Source="NativeWordCompanion",ChapterCount=2};await scans.CompleteAsync(7,preview);
|
||||
Check((await Progress().GetForCurrentUserAsync()).CoreImport?.ResumeUrl=="/onboarding/scan-review?previewId="+preview.PreviewID.ToString("D"),"capture completion keeps global indicator visible and returns to exact chapter-review preview");
|
||||
scans=Store();Check((await Progress().GetForCurrentUserAsync()).CoreImport?.Stage=="Review chapters","reopening restores accepted capture navigation from existing durable repository");
|
||||
|
||||
@ -1786,6 +1786,10 @@ public sealed class OnboardingService(
|
||||
throw new InvalidOperationException("Choose one of your active books before importing a manuscript.");
|
||||
}
|
||||
|
||||
var existing = await onboarding.GetAsync(userId);
|
||||
if (existing is { OnboardingCompletedUtc: null } && existing.BookID == bookId && existing.ProjectID == projectId
|
||||
&& existing.WritingJourney == WritingJourneyValues.ManuscriptMostlyComplete) return;
|
||||
|
||||
await onboarding.SaveWritingJourneyAsync(userId, WritingJourneyValues.ManuscriptMostlyComplete);
|
||||
await onboarding.SaveWritingSoftwareAsync(userId, WritingSoftwareValues.MicrosoftWord);
|
||||
await onboarding.SaveProjectAsync(userId, project.ProjectID);
|
||||
|
||||
@ -239,7 +239,7 @@
|
||||
<div class="story-intelligence-global-strip__meter" aria-hidden="true">
|
||||
<span data-story-intelligence-global-bar style="width: @(coreImport?.PercentComplete ?? storyIntelligenceProgress.ProgressPercent)%"></span>
|
||||
</div>
|
||||
<a class="btn btn-outline-secondary btn-sm" data-story-intelligence-global-link data-story-intelligence-global-action href="@progressUrl">@(coreImport is null ? "Book" : "Return to import")</a>
|
||||
<a class="btn btn-outline-secondary btn-sm" data-story-intelligence-global-action href="/Books/Details/@(coreImport?.BookID ?? primaryBook?.BookID)">Book</a>
|
||||
</div>
|
||||
<div hidden aria-hidden="true" data-story-intelligence-global-runs>
|
||||
@foreach (var book in storyIntelligenceProgress.Books)
|
||||
|
||||
@ -35,10 +35,10 @@
|
||||
const field = (state, camel, pascal) => state?.[camel] ?? state?.[pascal] ?? null;
|
||||
let coreImport = null;
|
||||
try { coreImport = JSON.parse(strip.dataset.coreImport || "null"); } catch { /* Legacy page without a core snapshot. */ }
|
||||
const setLink = (url, label) => {
|
||||
const setLink = (url, bookId) => {
|
||||
if (typeof url !== "string" || !/^\/(onboarding(?:[/?]|$)|Books\/Details\/\d+)/i.test(url) || url.startsWith("//")) return;
|
||||
strip.querySelectorAll("[data-story-intelligence-global-link]").forEach(node => { node.href = url; });
|
||||
const action = strip.querySelector("[data-story-intelligence-global-action]"); if (action) action.textContent = label;
|
||||
const action = strip.querySelector("[data-story-intelligence-global-action]"); if (action && Number.isInteger(Number(bookId)) && Number(bookId) > 0) { action.href = `/Books/Details/${bookId}`; action.textContent = "Book"; }
|
||||
};
|
||||
const renderCore = () => {
|
||||
if (!coreImport) return false;
|
||||
@ -46,7 +46,7 @@
|
||||
if (title) title.textContent = `${field(coreImport,"bookTitle","BookTitle") || "Manuscript"} · ${field(coreImport,"stage","Stage") || "Import"}`;
|
||||
if (detail) detail.textContent = field(coreImport,"message","Message") || "Return to your existing import";
|
||||
if (bar) bar.style.width = `${Math.max(0, Math.min(100, readNumber(field(coreImport,"percentComplete","PercentComplete")) || 0))}%`;
|
||||
setLink(field(coreImport,"resumeUrl","ResumeUrl"), "Return to import");
|
||||
setLink(field(coreImport,"resumeUrl","ResumeUrl"), field(coreImport,"bookID","BookID"));
|
||||
return true;
|
||||
};
|
||||
const isActiveStatus = (status) => status === "Pending" || status === "Running";
|
||||
@ -210,7 +210,7 @@
|
||||
seedRunsFromSnapshot(progress);
|
||||
const primarySnapshot = snapshotBooks.find((book) => book.hasActiveRuns || book.HasActiveRuns) || snapshotBooks[0];
|
||||
const primary = books.get(keyFor(primarySnapshot.projectID ?? primarySnapshot.projectId, primarySnapshot.bookID ?? primarySnapshot.bookId)) || seedBook(primarySnapshot);
|
||||
setLink(`/Books/Details/${primary.bookId}`, "Book");
|
||||
setLink(`/Books/Details/${primary.bookId}`, primary.bookId);
|
||||
const runSummary = runSummaryForBook(primary);
|
||||
const activeBookCount = readNumber(progress.activeBookCount ?? progress.ActiveBookCount) || snapshotBooks.length;
|
||||
const status = progress.status || progress.Status || primary.status || primary.Status || "";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user