fix(maps): protect uncommitted fields during spatial refresh
This commit is contained in:
parent
0e87593401
commit
1b9d231a95
@ -1,2 +1,2 @@
|
||||
const{chromium}=require('playwright'),assert=require('node:assert/strict');(async()=>{const browser=await chromium.launch();try{const p=await browser.newPage();const errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto('http://127.0.0.1:5238/fixture?page=maps');await p.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);await p.addScriptTag({url:'http://127.0.0.1:5238/js/spatial-live-updates.js'});await p.waitForFunction(()=>!!window.PlotDirectorSpatialLiveUpdates);await p.evaluate(()=>PlotDirectorMapWorkspace.setView({x:30,y:40,w:900,h:650}));const doc=await p.evaluate(()=>structuredClone(PlotDirectorMapWorkspace.document));doc.map.revision++;doc.features.push({featureID:'11111111-2222-4333-8444-555555555555',mapID:1,name:'Persisted elsewhere',type:'Custom',geometryClass:'Marker',layer:'Places',x:90,y:100,width:48,height:48,isPlaced:true,showLabel:true,geometryJson:'{}'});let reads=0;await p.route('**/Maps/State?*',r=>{reads++;return r.fulfill({json:doc});});await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features.length),1);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.view.w),900);await p.evaluate(()=>PlotDirectorMapWorkspace.edit(()=>PlotDirectorMapWorkspace.document.features[0].x=333));const before=reads;await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(reads,before);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features[0].x),333);
|
||||
const{chromium}=require('playwright'),assert=require('node:assert/strict');(async()=>{const browser=await chromium.launch();try{const p=await browser.newPage();const errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto('http://127.0.0.1:5238/fixture?page=maps');await p.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);await p.addScriptTag({url:'http://127.0.0.1:5238/js/spatial-live-updates.js'});await p.waitForFunction(()=>!!window.PlotDirectorSpatialLiveUpdates);await p.evaluate(()=>PlotDirectorMapWorkspace.setView({x:30,y:40,w:900,h:650}));const doc=await p.evaluate(()=>structuredClone(PlotDirectorMapWorkspace.document));doc.map.revision++;doc.features.push({featureID:'11111111-2222-4333-8444-555555555555',mapID:1,name:'Persisted elsewhere',type:'Custom',geometryClass:'Marker',layer:'Places',x:90,y:100,width:48,height:48,isPlaced:true,showLabel:true,geometryJson:'{}'});let reads=0;await p.route('**/Maps/State?*',r=>{reads++;return r.fulfill({json:doc});});await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features.length),1);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.view.w),900);await p.evaluate(()=>PlotDirectorMapWorkspace.select(PlotDirectorMapWorkspace.document.features[0].featureID));const name=p.locator('[data-field=name]');await name.fill('Uncommitted typed name');const typedReads=reads;await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(reads,typedReads);assert.equal(await name.inputValue(),'Uncommitted typed name');await name.blur();await p.evaluate(()=>PlotDirectorMapWorkspace.edit(()=>PlotDirectorMapWorkspace.document.features[0].x=333));const before=reads;await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(reads,before);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features[0].x),333);
|
||||
await p.goto('http://127.0.0.1:5238/fixture?page=floorplans');await p.waitForSelector('[data-floor-plan-initialized=true]');await p.route('**/FloorPlans/Edit/31',async r=>{const response=await r.fetch({url:'http://127.0.0.1:5238/fixture?page=floorplans'});return r.fulfill({response,body:(await response.text()).replace('data-location-id=""','data-location-id="99"')});});const original=await p.locator('[data-floor-plan-workspace]').elementHandle();await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'floorplans'}));assert.equal(await original.evaluate(n=>n.isConnected),false);await p.waitForSelector('[data-floor-plan-initialized=true]');const current=await p.locator('[data-floor-plan-workspace]').elementHandle();await p.evaluate(()=>document.querySelector('[data-save-status]').dataset.saveState='dirty');await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'floorplans'}));assert.equal(await current.evaluate(n=>n.isConnected),true);assert.deepEqual(errors,[]);console.log('PASS main spatial live updates: existing connection, in-place clean map refresh, retained viewport, clean floor workspace refresh, unsaved map/floor protection');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});
|
||||
|
||||
@ -510,5 +510,5 @@
|
||||
$('mapsWelcome').hidden=!!doc;svg.style.visibility=doc?'visible':'hidden';$('mapsList').innerHTML=boot.maps.map(m=>`<a href="${url(m.mapID)}">${esc(m.name)} · ${esc(m.kind)}${m.parentMapID?' · detail of '+esc(boot.maps.find(p=>p.mapID===m.parentMapID)?.name||'parent map'):''}</a>`).join('');
|
||||
if(doc)fit();if(new URLSearchParams(location.search).get('featureId')){const id=new URLSearchParams(location.search).get('featureId');if(doc?.features.some(f=>f.featureID===id)){select(id);const f=doc.features.find(f=>f.featureID===id);view.x=f.x-view.w/2;view.y=f.y-view.h/2;applyView();}}if(new URLSearchParams(location.search).get('mode')==='explore'||location.pathname==='/SpatialContext/Map')document.querySelector('[data-mode=explore]').click();
|
||||
// Expose semantic operations for browser regression fixtures, never credentials or a bypass.
|
||||
window.PlotDirectorMapWorkspace={get document(){return doc;},get view(){return view;},get mode(){return mode;},get dirty(){return dirty;},get selected(){return [...selected];},setMode(value){document.querySelector(`button[data-mode="${value}"]`)?.click();},refreshDetails:details,clearSelection(){selected.clear();render();details();},focus(id){const f=doc?.features.find(f=>f.featureID===id);if(f){view.x=f.x-view.w/2;view.y=f.y-view.h/2;applyView();}},select,fit,zoom,world,setView(next){if(['x','y','w','h'].every(k=>Number.isFinite(next?.[k]))&&next.w>0&&next.h>0){view={...next};applyView();}},replaceDocument(next){if(next?.map?.mapID!==doc?.map?.mapID)return;doc=clone(next);savedDocument=clone(doc);containmentDirty=true;selected=new Set([...selected].filter(id=>doc.features.some(f=>f.featureID===id)));render();details();},save,requestLeave,edit:safeEdit,render,status,get busy(){return busy;},beginAdjustment(){if(!doc||mode!=='create'||busy||preview)return null;const transaction={before:snapshot(),redo:future.slice(),wasDirty:dirty};checkpoint();updateButtons();return transaction;},commitAdjustment(transaction){if(snapshot()===transaction.before){history.pop();future=transaction.redo;}else changed();render();details();updateButtons();},markAdjustmentChanged(){if(!dirty)changed();},cancelAdjustment(transaction){doc=JSON.parse(transaction.before);dirty=transaction.wasDirty;status(dirty?'Unsaved changes':'Adjustment cancelled');history.pop();future=transaction.redo;render();details();updateButtons();}};
|
||||
window.PlotDirectorMapWorkspace={get document(){return doc;},get view(){return view;},get mode(){return mode;},get dirty(){return dirty;},get isEditing(){return dirty||busy||!!preview||!!pending||!!rotationEdit||!!(drag&&drag.kind!=='pan')||app.contains(document.activeElement?.closest('input,textarea,select'))||!!window.PlotDirectorMapAppearance?.adjusting;},get selected(){return [...selected];},setMode(value){document.querySelector(`button[data-mode="${value}"]`)?.click();},refreshDetails:details,clearSelection(){selected.clear();render();details();},focus(id){const f=doc?.features.find(f=>f.featureID===id);if(f){view.x=f.x-view.w/2;view.y=f.y-view.h/2;applyView();}},select,fit,zoom,world,setView(next){if(['x','y','w','h'].every(k=>Number.isFinite(next?.[k]))&&next.w>0&&next.h>0){view={...next};applyView();}},replaceDocument(next){if(next?.map?.mapID!==doc?.map?.mapID)return;doc=clone(next);savedDocument=clone(doc);containmentDirty=true;selected=new Set([...selected].filter(id=>doc.features.some(f=>f.featureID===id)));render();details();},save,requestLeave,edit:safeEdit,render,status,get busy(){return busy;},beginAdjustment(){if(!doc||mode!=='create'||busy||preview)return null;const transaction={before:snapshot(),redo:future.slice(),wasDirty:dirty};checkpoint();updateButtons();return transaction;},commitAdjustment(transaction){if(snapshot()===transaction.before){history.pop();future=transaction.redo;}else changed();render();details();updateButtons();},markAdjustmentChanged(){if(!dirty)changed();},cancelAdjustment(transaction){doc=JSON.parse(transaction.before);dirty=transaction.wasDirty;status(dirty?'Unsaved changes':'Adjustment cancelled');history.pop();future=transaction.redo;render();details();updateButtons();}};
|
||||
})();
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
pending=hint;if(flight)return;flight=true;
|
||||
try{
|
||||
let done=false;
|
||||
if(map){if(!map.dirty&&!map.busy&&!window.PlotDirectorMapAppearance?.adjusting){const response=await fetch(`/Maps/State?projectId=${project}&id=${map.document.map.mapID}`,{cache:'no-store'});if(!response.ok||response.redirected)return;const next=await response.json();if(window.PlotDirectorMapWorkspace===map&&!map.dirty&&!map.busy&&!window.PlotDirectorMapAppearance?.adjusting&&next.map.mapID===map.document.map.mapID){if(next.map.revision>map.document.map.revision)map.replaceDocument(next);done=true;}}}
|
||||
if(map){if(!map.isEditing&&!map.dirty&&!map.busy&&!window.PlotDirectorMapAppearance?.adjusting){const response=await fetch(`/Maps/State?projectId=${project}&id=${map.document.map.mapID}`,{cache:'no-store'});if(!response.ok||response.redirected)return;const next=await response.json();if(window.PlotDirectorMapWorkspace===map&&!map.isEditing&&!map.dirty&&!map.busy&&!window.PlotDirectorMapAppearance?.adjusting&&next.map.mapID===map.document.map.mapID){if(next.map.revision>map.document.map.revision)map.replaceDocument(next);done=true;}}}
|
||||
else done=await floor.refreshSpatialReference?.()===true;
|
||||
if(done){pending=null;warned=false;}else if(!warned){warned=true;window.PlotDirector?.toast?.info('Saved spatial information changed elsewhere. Your active edits remain here; finish them before refreshing.');}
|
||||
}catch{/* Persisted changes remain authoritative; normal navigation can retry. */}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user