Continue new-map creation after explicitly discarding a new feature

This commit is contained in:
Nick Beckley 2026-11-02 21:34:01 +00:00
parent 19a6067c18
commit c8a73f26d5
3 changed files with 5 additions and 3 deletions

View File

@ -16,7 +16,7 @@ Stage 3 refines the existing Stage 1 SVG workspace and Stage 2 batched Story pro
`PlotDirectorDialogs.choose` extends the existing shared Bootstrap confirmation-dialog partial and styling. Maps uses it for unsaved edits, Rename and Delete. There are no direct Maps calls to browser confirm, alert or prompt.
One pending action retains the first destination. The unsaved modal offers Save and continue, Discard changes and Keep editing. Successful explicit save precedes continuation. A failed save keeps the modal, error, edits and current map. Discard restores the last saved document before performing the action. Keep editing, X and Escape leave the document, viewport, selection and editing state intact and restore focus. Escape is contained within the modal so it cannot also clear canvas selection. Rapid navigation cannot stack dialogs or replace the first action.
One pending action retains the first destination. The unsaved modal offers Save and continue, Discard changes and Keep editing. Successful explicit save precedes continuation. A failed save keeps the modal, error, edits and current map. Discard restores the last saved document before performing the action. Keep editing, X and Escape leave the document, viewport, selection and editing state intact and restore focus. Escape is contained within the modal so it cannot also clear canvas selection. Rapid navigation cannot stack dialogs or replace the first action. If Discard removes a brand-new feature whose detailed map was requested, the intended New map form still opens under the current parent map and explicitly explains that the discarded feature cannot supply a feature link.
The guard covers map selection, hierarchy and other same-origin in-application links and navigation forms (including Logout), new/detailed maps, duplication, Floor Plans and transitions to Story. Explore retains edits and can explicitly save through the navigation modal. Modified/new-window links leave the current workspace intact. True unload still uses the minimal standards `beforeunload` guard; browsers own refresh/tab-close confirmation. Browser Back/Forward that actually unloads the page is covered there, without claiming asynchronous UI can intercept every browser navigation.

View File

@ -25,6 +25,7 @@ const base=process.env.PD_MAPS_STAGE3_URL||'http://127.0.0.1:5251';
await dirty();await page.evaluate(()=>{window.PlotDirectorMapWorkspace.requestLeave(()=>window.__continued.push('discarded'));});await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await modal.waitFor({state:'detached'});assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),false);assert.deepEqual(await page.evaluate(()=>window.__continued),['saved','discarded']);
console.log('Destination test');await dirty();await page.evaluate(()=>{for(const n of [1,2]){const a=document.createElement('a');a.href='/stage3-destination-'+n;a.id='destination'+n;document.body.append(a);}document.getElementById('destination1').click();document.getElementById('destination2').click();});await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await page.waitForURL('**/stage3-destination-1');
await open();await dirty();await page.evaluate(()=>{const form=document.createElement('form');form.action='/stage3-destination-form';form.innerHTML='<input name=retained value=42><button type=submit>Continue</button>';document.body.append(form);form.requestSubmit();});await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await page.waitForURL(/stage3-destination-form/);assert.equal(new URL(page.url()).searchParams.get('retained'),'42');
await open();const unsavedFeature=await place('Town');const proposedName=await page.evaluate(id=>window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id).name,unsavedFeature);await page.locator('[data-action=child]').click();await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await page.locator('#mapsNewDialog').waitFor();assert.equal(await page.locator('#mapsNewForm [name=Name]').inputValue(),proposedName+' detail');assert.equal(await page.locator('#mapsNewForm [name=ParentMapID]').inputValue(),'1');assert(await page.locator('[data-map-new-context]').isVisible());assert.equal(await page.evaluate(id=>window.PlotDirectorMapWorkspace.document.features.some(f=>f.featureID===id),unsavedFeature),false);await page.locator('#mapsNewCancel').click();
console.log('Unload test');await open();await dirty();await page.locator('#mapsCanvas').click({position:{x:20,y:150}});await page.reload({waitUntil:'domcontentloaded'}).catch(()=>{});assert.deepEqual(dialogs,['beforeunload'],'only genuine unload invokes browser dialog');
// Discard the retained edits deliberately, then test manipulation without native dialogs.
await page.evaluate(()=>{void window.PlotDirectorMapWorkspace.requestLeave(()=>{});});await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await modal.waitFor({state:'detached'});

View File

@ -199,8 +199,9 @@
doc.features.push(f);selected=new Set([f.featureID]);
});dialog.close();};
}
async function newMap(feature=null){return requestLeave(()=>openNewMap(feature?.featureID));}
function openNewMap(featureID){if(busy)return;const feature=doc?.features.find(f=>f.featureID===featureID);if(featureID&&!feature){status('Save this new feature before creating its detailed map.',true);return;}parentFeature=feature?.featureID||null;const form=$('mapsNewForm');form.reset();form.elements.Name.value=feature?feature.name+' detail':'';form.elements.ParentMapID.value=feature?doc.map.mapID:'';$('mapsNewDialog').showModal();}
async function newMap(feature=null){const intent=feature?{featureID:feature.featureID,name:feature.name}:null;return requestLeave(()=>openNewMap(intent));}
function openNewMap(intent){if(busy)return;const feature=doc?.features.find(f=>f.featureID===intent?.featureID);parentFeature=feature?.featureID||null;const form=$('mapsNewForm');form.reset();form.elements.Name.value=intent?(feature?.name||intent.name)+' detail':'';form.elements.ParentMapID.value=intent?doc.map.mapID:'';
let note=form.querySelector('[data-map-new-context]');if(!note){note=document.createElement('p');note.dataset.mapNewContext='';note.className='maps-hint';note.setAttribute('role','status');form.querySelector('h2').after(note);}note.hidden=!intent||!!feature;note.textContent='The unsaved feature was discarded. You can still create this map under the current map, without a feature link.';$('mapsNewDialog').showModal();}
async function createMap(e){e.preventDefault();const values=Object.fromEntries(new FormData(e.target));
const data={ProjectID:boot.projectId,Name:values.Name,Kind:values.Kind};if(values.ParentMapID)data.ParentMapID=values.ParentMapID;if(parentFeature)data.ParentFeatureID=parentFeature;
const submit=e.target.querySelector('[type=submit]');submit.disabled=true;