From 3b89c1964900d389905ec7e1edf5cb820b8b0aee Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Fri, 27 Nov 2026 13:05:02 +0000 Subject: [PATCH] Show full-form hierarchy errors and keep workspace Undo one-step --- PlotLine.Tests/Browser/locations-workspace-dev.cjs | 5 +++-- PlotLine.Tests/Browser/locations-workspace.cjs | 4 ++-- PlotLine/Views/Locations/Edit.cshtml | 1 + PlotLine/wwwroot/js/locations-workspace.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PlotLine.Tests/Browser/locations-workspace-dev.cjs b/PlotLine.Tests/Browser/locations-workspace-dev.cjs index 221d8911..28ffc77c 100644 --- a/PlotLine.Tests/Browser/locations-workspace-dev.cjs +++ b/PlotLine.Tests/Browser/locations-workspace-dev.cjs @@ -18,12 +18,13 @@ const identity=JSON.parse(fs.readFileSync(file,'utf8'));assert.equal(identity.Da await peer.locator(`[data-location-id="${id}"] [aria-label="Fictional"]`).waitFor({timeout:20000}); await row().focus();await page.keyboard.press('F2');await row().getByRole('textbox',{name:'Location name'}).fill('Meridian renamed');await row().getByRole('textbox',{name:'Location name'}).press('Enter');await row().getByRole('button',{name:'Meridian renamed',exact:true}).waitFor();data=await directory();assert.equal(data.locations.find(r=>r.id===child.id).parent,id); await row().locator('[data-location-name]').click();await page.getByRole('button',{name:'Edit description',exact:true}).click();await page.getByRole('textbox',{name:'Location description'}).fill('Author-controlled synthetic description.');await page.locator('[data-details]').getByRole('button',{name:'Save',exact:true}).click();await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===id).description,'Author-controlled synthetic description.'); + await page.getByRole('button',{name:'Undo',exact:true}).first().click();await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===id).description,'');assert(await page.locator('[data-undo]').isHidden());await page.getByRole('button',{name:'Edit description',exact:true}).click();await page.getByRole('textbox',{name:'Location description'}).fill('Author-controlled synthetic description.');await page.locator('[data-details]').getByRole('button',{name:'Save',exact:true}).click();await page.waitForTimeout(200);data=await directory(); const bulk=await api('Assign',{projectId:identity.ProjectID,attribute:'quickAdd',changes:data.locations.map(r=>({id:r.id,value:'1',version:r.version}))});assert.equal(bulk.status,200);assert.equal(bulk.body.changes.length,2);assert(bulk.body.undoToken);const restored=await api('Undo',{token:bulk.body.undoToken});assert.equal(restored.status,200);data=await directory();assert(data.locations.every(r=>r.quickAdd==='0')); const current=data.locations.find(r=>r.id===id),bad=await api('Assign',{projectId:identity.ProjectID,attribute:'parent',changes:[{id,value:String(child.id),version:current.version}]});assert.equal(bad.status,409);const unauthorised=await api('Assign',{projectId:2147483647,attribute:'classification',changes:[{id,value:'Real',version:current.version}]});assert([403,404].includes(unauthorised.status)); const out='/tmp/pd-locations-evidence';await page.screenshot({path:out+'/development-workspace.png'}); - await page.goto(base+`/Locations/Edit/${id}`);await page.locator('[name=ParentLocationID]').selectOption(String(child.id));await page.getByRole('button',{name:'Save location',exact:true}).click();await page.waitForLoadState();assert.match(await page.locator('[data-valmsg-summary=true]').textContent(),/descendant/);data=await directory();assert.equal(data.locations.find(r=>r.id===id).parent,null);assert.equal(data.locations.find(r=>r.id===id).description,'Author-controlled synthetic description.'); + await page.goto(base+`/Locations/Edit/${id}`);await page.locator('[name=ParentLocationID]').selectOption(String(child.id));await page.getByRole('button',{name:'Save location',exact:true}).click();await page.waitForLoadState();assert.match(await page.locator('.validation-summary-errors').textContent(),/descendant/);data=await directory();assert.equal(data.locations.find(r=>r.id===id).parent,null);assert.equal(data.locations.find(r=>r.id===id).description,'Author-controlled synthetic description.'); const checks=[];for(const route of [`/Characters?${q}`,`/Names?${q}`,`/RelationshipMap?${q}`,`/Maps?${q}`,`/FloorPlans?${q}`,`/StoryAssets?${q}`,`/Locations/Details/${id}`,`/Locations/Edit/${id}`,`/Writer?${q}&bookId=${identity.BookID}`]){const response=await page.goto(base+route);assert.equal(response.status(),200,route);assert(!page.url().includes('/Account/'));checks.push(route.split('?')[0]);} await page.goto(base+`/Locations/Details/${id}`);await page.locator('[name=ToLocationID]').selectOption(String(child.id));await page.locator('[name=Notes]').fill('Disposable non-hierarchical relationship');await page.getByRole('button',{name:'Add relationship',exact:true}).click();await page.waitForLoadState();assert(await page.getByText('Disposable non-hierarchical relationship',{exact:true}).count()); await page.goto(base+`/Locations?${q}`);await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.getByRole('button',{name:'Expand all',exact:true}).click();await page.locator(`[data-location-id="${child.id}"]`).getByRole('button',{name:'Actions for Observatory acceptance'}).click();await page.getByRole('menuitem',{name:'Merge with another location…',exact:true}).click();await page.getByRole('combobox',{name:'Surviving location'}).selectOption(String(id));await page.locator('[data-location-dialog] input[type=checkbox]').check();await page.locator('[data-dialog-save]').click();await page.locator('[data-location-dialog]').waitFor({state:'hidden'});data=await directory();assert.equal(data.locations.length,1);assert.equal(data.locations[0].id,id);assert.equal(data.locations[0].description,'Author-controlled synthetic description.'); - fs.writeFileSync(out+'/development-smoke.json',JSON.stringify({status:'passed',target:'Development',checks:['real Directory/Create/Assign/Undo/Merge endpoints','bulk assignment and protected Undo','normal non-hierarchical relationship form','reviewed merge archives source and retains survivor','inline child Enter-save','context menu for a selection hidden in a collapsed branch','classification','inline rename preserves child identifiers','description save','server cycle rejection','traditional full Edit rejects cycles without losing posted data','cross-project mutation rejection','actual second-window live invalidation',...checks]},null,2));console.log('PASS authenticated Development workspace mutations, hierarchy safeguards, cross-window live updates and related route smoke; disposable data only.'); + fs.writeFileSync(out+'/development-smoke.json',JSON.stringify({status:'passed',target:'Development',checks:['real Directory/Create/Assign/Undo/Merge endpoints','bulk assignment and protected Undo','one-step workspace Undo clears after restoration','normal non-hierarchical relationship form','reviewed merge archives source and retains survivor','inline child Enter-save','context menu for a selection hidden in a collapsed branch','classification','inline rename preserves child identifiers','description save','server cycle rejection','traditional full Edit rejects cycles without losing posted data','cross-project mutation rejection','actual second-window live invalidation',...checks]},null,2));console.log('PASS authenticated Development workspace mutations, hierarchy safeguards, cross-window live updates and related route smoke; disposable data only.'); }finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/Browser/locations-workspace.cjs b/PlotLine.Tests/Browser/locations-workspace.cjs index 24ae6f42..88cf4d1c 100644 --- a/PlotLine.Tests/Browser/locations-workspace.cjs +++ b/PlotLine.Tests/Browser/locations-workspace.cjs @@ -9,7 +9,7 @@ const installed=process.argv.includes('--installed'),origin='http://127.0.0.1:52 if(count>=500){for(let i=count-100;i{const snapshot=structuredClone(records);if(delayDirectory){delayDirectory=false;await new Promise(resolve=>releaseDirectory=resolve);}await r.fulfill({json:{canEdit:true,types,locations:snapshot}});}); await page.route('**/LocationWorkspace/Assign',async route=>{assert(route.request().headers().requestverificationtoken);const input=route.request().postDataJSON();requests.push(input);if(rejectNext){rejectNext=false;return route.fulfill({status:409,json:{message:'Simulated concurrent edit rejected.'}});}let changes=input.changes;const ids=new Set(changes.map(c=>c.id));if(input.attribute==='parent')changes=changes.filter(c=>{let p=records.find(r=>r.id===c.id).parent;const seen=new Set();while(p&&!seen.has(p)){if(ids.has(p))return false;seen.add(p);p=records.find(r=>r.id===p)?.parent;}return true;});const previous=[],changed=[];for(const c of changes){const r=records.find(r=>r.id===c.id);if(r.version!==c.version)return route.fulfill({status:409,json:{message:'Changed in another window.'}});previous.push({id:r.id,value:r[input.attribute],version:r.version});r[input.attribute]=input.attribute==='parent'?(c.value?Number(c.value):null):c.value;r.version=`v${clock++}`;changed.push({id:r.id,value:c.value,version:r.version});}const token=`u${clock}`;undo.set(token,{attribute:input.attribute,previous});await route.fulfill({json:{saved:true,changes:changed,attribute:input.attribute,undoToken:token}});}); - await page.route('**/LocationWorkspace/Undo',async route=>{const receipt=undo.get(route.request().postDataJSON().token),changes=[];for(const old of receipt.previous){const r=records.find(r=>r.id===old.id);r[receipt.attribute]=old.value;r.version=`v${clock++}`;changes.push({id:r.id,value:old.value?.toString()||'',version:r.version});}await route.fulfill({json:{saved:true,changes,attribute:receipt.attribute}});}); + await page.route('**/LocationWorkspace/Undo',async route=>{const receipt=undo.get(route.request().postDataJSON().token),changes=[];for(const old of receipt.previous){const r=records.find(r=>r.id===old.id);r[receipt.attribute]=old.value;r.version=`v${clock++}`;changes.push({id:r.id,value:old.value?.toString()||'',version:r.version});}await route.fulfill({json:{saved:true,changes,attribute:receipt.attribute,undoToken:'unused-redo-token'}});}); await page.route('**/LocationWorkspace/Create',async route=>{const input=route.request().postDataJSON(),id=records.length+1;records.push({id,name:input.name,parent:input.parentId,type:'',classification:'',description:'',quickAdd:'0',detection:'0',version:`v${clock++}`,aliases:[],maps:[],floors:[],scenes:0});await route.fulfill({json:{id}});}); const shot=async name=>{if(count===50){await page.evaluate(()=>document.querySelectorAll('[data-toast-host] button[aria-label^=Dismiss]').forEach(b=>b.click()));await page.screenshot({path:`${out}/${name}.png`});}};const row=id=>page.locator(`[data-location-id="${id}"]`),attribute=(a,v)=>page.locator(`[data-attribute="${a}"][data-value="${v}"]`); const start=performance.now();await page.goto(`${origin}/locations-workspace-fixture?count=${count}`);await row(1).waitFor();const loadMs=Math.round(performance.now()-start);const detailsStart=performance.now();await row(1).locator('[data-location-name]').click();timings.detailsMs=Math.round(performance.now()-detailsStart);assert.equal(await page.locator('[data-related] a[href^="/Maps"]').count(),2);assert.equal(await page.locator('[data-related] a[href^="/FloorPlans"]').count(),2);assert.equal(await page.locator('[data-related] a[target]').count(),0);await shot('workspace'); @@ -18,7 +18,7 @@ const installed=process.argv.includes('--installed'),origin='http://127.0.0.1:52 await row(1).focus();await page.keyboard.press('Space');assert(await row(1).locator('[data-select-location]').isChecked());await page.keyboard.press('Space');assert(!(await row(1).locator('[data-select-location]').isChecked())); } const drag=async(source,target)=>{await source.dragTo(target);await page.waitForTimeout(100);}; - await drag(attribute('type','6').locator('button').first(),row(1));await page.waitForFunction(()=>document.querySelector('[data-undo]').hidden===false);assert.equal(records[0].type,'6');await shot('attribute-assignment');await page.getByRole('button',{name:'Undo',exact:true}).first().click();await page.waitForTimeout(60);assert.equal(records[0].type,'1'); + await drag(attribute('type','6').locator('button').first(),row(1));await page.waitForFunction(()=>document.querySelector('[data-undo]').hidden===false);assert.equal(records[0].type,'6');await shot('attribute-assignment');await page.getByRole('button',{name:'Undo',exact:true}).first().click();await page.waitForTimeout(60);assert.equal(records[0].type,'1');assert(await page.locator('[data-undo]').isHidden()); if(count===50){await page.evaluate(()=>{window.fixtureHints={};document.dispatchEvent(new CustomEvent('pd-presence-connection',{detail:{on:(name,fn)=>window.fixtureHints[name]=fn,onreconnected:()=>{}}}));});delayDirectory=true;await page.evaluate(()=>{const handlers=Object.values(window.PlotDirectorPresenceConnection||{}).find(v=>v&&typeof v==='object'&&Array.isArray(v.contextinvalidated))?.contextinvalidated;if(handlers?.length)for(const handler of handlers)handler({projectId:7});else if(window.fixtureHints.ContextInvalidated)window.fixtureHints.ContextInvalidated({projectId:7});else throw Error('No live invalidation handler registered.');});for(let attempt=0;!releaseDirectory&&attempt<50;attempt++)await page.waitForTimeout(20);assert(releaseDirectory,'live invalidation requests fresh data');await page.waitForTimeout(30);await drag(attribute('type','6').locator('button').first(),row(1));assert.equal(records[0].type,'6');releaseDirectory();await page.waitForTimeout(150);assert.equal(await row(1).getByRole('img',{name:'Room',exact:true}).count(),1);await page.getByRole('button',{name:'Undo',exact:true}).first().click();await page.waitForTimeout(100);} const noOpRequests=requests.length;await drag(attribute('type','1').locator('button').first(),row(1));assert.equal(requests.length,noOpRequests);rejectNext=true;await drag(attribute('type','6').locator('button').first(),row(1));assert.equal(records[0].type,'1');assert.match(await page.locator('[data-workspace-error]').textContent(),/concurrent/); await row(2).locator('[data-select-location]').check();await row(3).locator('[data-select-location]').check();const bulkStart=performance.now();await attribute('classification','Real').getByRole('button',{name:/Assign/}).click();await page.waitForTimeout(100);assert.equal(records[1].classification,'Real');assert.equal(records[2].classification,'Real');timings.bulkMs=Math.round(performance.now()-bulkStart);await shot('bulk-assignment');await page.getByRole('button',{name:'Undo',exact:true}).first().click();await page.waitForTimeout(60);assert.equal(records[1].classification,'');if(count===50){await page.locator('.locations-centre').evaluate(n=>n.scrollTo({top:0,behavior:'instant'}));await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));await page.locator('[data-selection-menu]').click();await page.getByRole('menuitem',{name:'2 locations selected',exact:true}).waitFor();assert.equal(await page.getByRole('menuitem',{name:'Rename',exact:true}).count(),0);await shot('bulk-context-menu');await page.keyboard.press('Escape');} diff --git a/PlotLine/Views/Locations/Edit.cshtml b/PlotLine/Views/Locations/Edit.cshtml index 58c54ca6..b3d67023 100644 --- a/PlotLine/Views/Locations/Edit.cshtml +++ b/PlotLine/Views/Locations/Edit.cshtml @@ -27,6 +27,7 @@
+
Names
diff --git a/PlotLine/wwwroot/js/locations-workspace.js b/PlotLine/wwwroot/js/locations-workspace.js index d175edad..61a11ea3 100644 --- a/PlotLine/wwwroot/js/locations-workspace.js +++ b/PlotLine/wwwroot/js/locations-workspace.js @@ -25,7 +25,7 @@ busy=true;readEpoch++;$('[data-workspace-error]').textContent='';selection();try{const data=await post(isUndo?'Undo':'Assign',isUndo?{token}:{projectId:project,attribute,changes:ids.map(id=>({id,value:newValue,version:records.get(id).version}))}); if(!data.changes.length)return true; for(const c of data.changes){const r=records.get(c.id);if(!r)continue;r.version=c.version;const a=data.attribute;if(a==='parent')r.parent=c.value?Number(c.value):null;else r[a]=a==='name'?c.value.trim():c.value;if(a==='type')r.typeName=types.find(t=>t.value===c.value)?.label;} - undo=data.undoToken;$('[data-undo]').hidden=!undo;index();render();renderDetails();if(data.changes.length){const receipt=undo;toast?.success(isUndo?'Location changes restored.':`${data.changes.length} location${data.changes.length===1?'':'s'} updated.`,receipt?{action:{label:'Undo',run:()=>assign(null,null,[],true,receipt)}}:undefined);} + undo=isUndo?null:data.undoToken;$('[data-undo]').hidden=!undo;index();render();renderDetails();if(data.changes.length){const receipt=undo;toast?.success(isUndo?'Location changes restored.':`${data.changes.length} location${data.changes.length===1?'':'s'} updated.`,receipt?{action:{label:'Undo',run:()=>assign(null,null,[],true,receipt)}}:undefined);} return true; }catch(e){failure(e);return false;}finally{busy=false;selection();if(pendingRefresh&&!dirty()){pendingRefresh=false;void refresh();}}} function informational(id,label,yes,no,iconName){return {id,label,editable:false,values:[{value:'yes',label:yes,icon:iconName},{value:'no',label:no,icon:'help'}]};}