Keep description drafts intact while updating selected location attributes

This commit is contained in:
Nick Beckley 2026-11-27 12:32:47 +00:00
parent 7e27aba3ce
commit 39c34d9f1b
4 changed files with 9 additions and 7 deletions

View File

@ -40,7 +40,8 @@ No AI processing or geocoding is invoked by these workspace commands.
- Physical attribute/location dragging, hover-expand reparenting, root drops and invalid target
rejection; bulk assignment, individual-value Undo, no-op assignment, simulated save failure,
inline rename Save/Escape, child creation, right-click/keyboard/visible menus, unsaved-description
protection, filters, cards, sorting, and a delayed live-refresh race.
protection, local attribute updates while retaining a description draft, filters, cards, sorting,
and a delayed live-refresh race.
- Both divider pointer drags and keyboard resizing; saved widths, collapsed panels, view, attribute
groups and expanded branches survive reload. View changes retain selection and filters.
- All seven available theme choices; 390/768/1024/1280/1440/1920-pixel viewport checks without

View File

@ -44,7 +44,8 @@ The response returns exact post-save versions and changed values. A user-bound,
expires after ten minutes; Undo compares the current version before applying the original value.
A stale receipt cannot overwrite later edits. The browser updates its directory, counts and details
without navigating/reloading. Live invalidations refresh other windows; dirty descriptions defer
refresh. Explicit Save/Cancel and discard confirmation protect unsaved descriptions.
refresh. Local attribute changes refresh the rest of Details while retaining the existing
description editor and its draft. Explicit Save/Cancel and discard confirmation protect unsaved descriptions.
Migration 336 gives the traditional `Location_Save` procedure the same project-first locking,
project membership and cycle checks, while preserving unchanged historical archived-parent references.

View File

@ -31,7 +31,7 @@ const installed=process.argv.includes('--installed'),origin='http://127.0.0.1:52
await row(4).focus();await page.keyboard.press('F2');const rename=row(4).getByRole('textbox',{name:'Location name'});await rename.fill('West observatory');await shot('inline-rename');const renameStart=performance.now();await rename.press('Enter');await page.waitForTimeout(80);timings.renameMs=Math.round(performance.now()-renameStart);assert.equal(records[3].name,'West observatory');if(count===50){await row(4).focus();await page.keyboard.press('F2');await row(4).getByRole('textbox',{name:'Location name'}).fill('Discard this name');await page.keyboard.press('Escape');assert.equal(records[3].name,'West observatory');}
await row(4).click({button:'right'});await page.getByRole('menu').first().waitFor();await shot('context-menu');await page.keyboard.press('Escape');if(count===50){await row(4).focus();await page.keyboard.press('Shift+F10');await page.getByRole('menu').first().waitFor();await page.keyboard.press('Escape');}
await row(4).locator('[data-location-name]').click();await page.getByRole('button',{name:'Create child location',exact:true}).click();await page.getByRole('textbox',{name:'New location name'}).fill('Chart room');await shot('create-child');await page.locator('[data-dialog-save]').click();await page.waitForTimeout(150);assert.equal(records.at(-1).parent,4);
await row(4).locator('[data-location-name]').click();await page.getByRole('button',{name:'Edit description',exact:true}).click();const description=page.getByRole('textbox',{name:'Location description'});await description.fill('Preserved author prose.\nSecond paragraph.');page.once('dialog',d=>d.dismiss());await row(1).locator('[data-location-name]').click();assert.equal(await description.inputValue(),'Preserved author prose.\nSecond paragraph.');await shot('details-edit');await page.locator('[data-details]').getByRole('button',{name:'Save',exact:true}).click();await page.waitForTimeout(100);assert.equal(records[3].description,'Preserved author prose.\nSecond paragraph.');
await row(4).locator('[data-location-name]').click();await page.getByRole('button',{name:'Edit description',exact:true}).click();const description=page.getByRole('textbox',{name:'Location description'});await description.fill('Preserved author prose.\nSecond paragraph.');page.once('dialog',d=>d.dismiss());await row(1).locator('[data-location-name]').click();assert.equal(await description.inputValue(),'Preserved author prose.\nSecond paragraph.');await shot('details-edit');if(count===50){await drag(attribute('type','6').locator('button').first(),row(4));assert.equal(await description.inputValue(),'Preserved author prose.\nSecond paragraph.');assert.equal(await page.locator('[data-details]').getByRole('combobox',{name:'Location type',exact:true}).inputValue(),'6');}await page.locator('[data-details]').getByRole('button',{name:'Save',exact:true}).click();await page.waitForTimeout(100);assert.equal(records[3].description,'Preserved author prose.\nSecond paragraph.');
const searchStart=performance.now();await page.locator('[data-search]').fill('Quiet study');await page.waitForTimeout(80);assert(await row(5).isVisible());assert(await row(1).isVisible());const searchMs=Math.round(performance.now()-searchStart);await shot('search-context');await page.locator('[data-clear-search]').click();
await row(1).locator('[data-select-location]').check();const cardsStart=performance.now();await page.getByRole('button',{name:'Cards',exact:true}).click();timings.cardsMs=Math.round(performance.now()-cardsStart);assert(await row(1).locator('[data-select-location]').isChecked());await shot('cards');const heights=await page.locator('.location-record').evaluateAll(ns=>ns.slice(0,12).map(n=>n.getBoundingClientRect().height));assert(new Set(heights.map(Math.round)).size>3);
if(count===50){

View File

@ -21,7 +21,7 @@
async function post(action,data){const response=await fetch(`/LocationWorkspace/${action}`,{method:'POST',headers:{'Content-Type':'application/json','RequestVerificationToken':$('[name=__RequestVerificationToken]').value},body:JSON.stringify(data)});if(response.redirected)throw Error('Your session has expired. Sign in again before saving.');const result=await response.json().catch(()=>({message:'The change could not be saved.'}));if(!response.ok)throw Error(result.message||'The change could not be saved.');return result;}
function failure(e){$('[data-workspace-error]').textContent=e.message;toast?.error(e.message);}
async function refresh(){if(refreshing)return refreshing;if(busy||dirty()){pendingRefresh=true;return;}const epoch=readEpoch;refreshing=(async()=>{try{const response=await fetch(`/LocationWorkspace/Directory?projectId=${project}`,{cache:'no-store'});if(!response.ok||response.redirected)throw Error('Locations could not be loaded. Reload to retry.');const data=await response.json();if(epoch!==readEpoch||dirty()){pendingRefresh=true;return;}canEdit=data.canEdit;records=new Map(data.locations.map(r=>[r.id,r]));types=[{value:'',label:'Unclassified',icon:'help',path:'M9 8a3 3 0 1 1 4 3c-1 1-1 2-1 3 M12 18v1 M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0',tone:'secondary'},...data.types];index();buildGroups();render();renderDetails();$('[data-workspace-error]').textContent='';}catch(e){failure(e);}finally{refreshing=null;host.setAttribute('aria-busy','false');if(pendingRefresh&&!busy&&!dirty()){pendingRefresh=false;queueMicrotask(()=>void refresh());}}})();return refreshing;}
async function assign(attribute,newValue,ids,isUndo=false,token=null){if(busy||!canEdit)return;if(!isUndo){ids=ids.filter(id=>records.has(id)&&(attribute==='parent'||value(records.get(id),attribute)!==newValue));if(!ids.length)return;}
async function assign(attribute,newValue,ids,isUndo=false,token=null){if(busy){toast?.info('A location update is still saving. Try again in a moment.');return false;}if(!canEdit)return false;if(!isUndo){ids=ids.filter(id=>records.has(id)&&(attribute==='parent'||value(records.get(id),attribute)!==newValue));if(!ids.length)return;}
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;}
@ -74,12 +74,12 @@
function createChild(parent){if(!canEdit||!leaveDraft())return;descriptionDraft=null;const body=el('div'),input=el('input');input.className='form-control';input.maxLength=200;input.setAttribute('aria-label','New location name');body.append(el('p',parent?`Inside ${path(parent)}`:'Create a root location','muted'),input);openDialog('Create child location',body,async()=>{if(!input.value.trim())throw Error('Enter a name.');const result=await post('Create',{projectId:project,name:input.value,parentId:parent});if(parent)expanded.add(parent);if(!leaveDraft())return false;descriptionDraft=null;readEpoch++;if(refreshing)await refreshing;await refresh();reveal(result.id);toast?.success('Location created.');});}
function field(label,control){const n=el('label',label);n.append(control);return n;}
function attributeSelect(attribute,r){const select=el('select');select.className='form-select form-select-sm';select.setAttribute('aria-label',groups.find(g=>g.id===attribute).label);for(const v of groups.find(g=>g.id===attribute).values)select.add(new Option(v.label,v.value));if(attribute==='type'&&r.type&&!types.some(t=>t.value===r.type)){const recorded=new Option(`${r.typeName||'Recorded type'} (unavailable)`,r.type);recorded.disabled=true;select.add(recorded);}select.value=value(r,attribute);select.disabled=!canEdit;select.addEventListener('change',async()=>{const old=value(r,attribute);select.disabled=true;const ok=await assign(attribute,select.value,[r.id]);if(!ok){select.value=old;select.disabled=!canEdit;}});return select;}
function renderDetails(){if(dirty())return;const r=records.get(active);details.replaceChildren();if(!r){details.append(el('h2','Your world, in detail'),el('p','Select a location to edit its attributes and explore its connections.','muted'));return;}
function renderDetails(){const held=dirty()?details.querySelector('[data-description-section]'):null,heldFocus=held?.contains(document.activeElement)?document.activeElement:null;const r=records.get(active);details.replaceChildren();if(!r){details.append(el('h2','Your world, in detail'),el('p','Select a location to edit its attributes and explore its connections.','muted'));return;}
const heading=el('div',undefined,'location-detail-heading');heading.append(icon(type(r)),el('h2',r.name));details.append(heading,el('p',path(r.id),'location-details-path'));const actions=el('div',undefined,'location-detail-actions');for(const [label,action]of [['Full details','Details'],['Edit location','Edit']]){const a=el('a',label,'btn btn-outline-secondary btn-sm');a.href=`/Locations/${action}/${r.id}`;actions.append(a);}if(canEdit)actions.append(button('Rename',()=>{reveal(r.id);rename(r.id);}));details.append(actions);
const attrs=el('div',undefined,'location-detail-attributes');for(const a of ['type','classification','quickAdd','detection'])attrs.append(field(groups.find(g=>g.id===a).label,attributeSelect(a,r)));const p=button(r.parent?path(r.id,false):'Root level',()=>parentDialog('Change parent',id=>void assign('parent',id,[r.id]),false,[r.id]));p.disabled=!canEdit;attrs.append(field('Parent',p));details.append(attrs);
const description=el('section');description.append(el('h3','Description'));description.append(el('p',r.description||'No description recorded.','locations-description'));if(canEdit)description.append(button('Edit description',()=>{description.replaceChildren(el('h3','Description'));const input=el('textarea');input.dataset.descriptionEditor='';input.className='form-control';input.value=r.description;input.setAttribute('aria-label','Location description');descriptionDraft={id:r.id,original:r.description,value:r.description};input.addEventListener('input',()=>descriptionDraft.value=input.value);const controls=el('div',undefined,'location-detail-actions');controls.append(button('Save',async()=>{const draft=descriptionDraft;descriptionDraft=null;if(!await assign('description',input.value,[r.id])){descriptionDraft=draft;input.focus();}}),button('Cancel',()=>{descriptionDraft=null;renderDetails();if(pendingRefresh){pendingRefresh=false;void refresh();}}));description.append(input,controls);input.focus();}));details.append(description);
const description=el('section');description.dataset.descriptionSection='';description.append(el('h3','Description'));description.append(el('p',r.description||'No description recorded.','locations-description'));if(canEdit)description.append(button('Edit description',()=>{description.replaceChildren(el('h3','Description'));const input=el('textarea');input.dataset.descriptionEditor='';input.className='form-control';input.value=r.description;input.setAttribute('aria-label','Location description');descriptionDraft={id:r.id,original:r.description,value:r.description};input.addEventListener('input',()=>descriptionDraft.value=input.value);const controls=el('div',undefined,'location-detail-actions');controls.append(button('Save',async()=>{const draft=descriptionDraft;descriptionDraft=null;if(!await assign('description',input.value,[r.id])){descriptionDraft=draft;input.focus();}}),button('Cancel',()=>{descriptionDraft=null;renderDetails();if(pendingRefresh){pendingRefresh=false;void refresh();}}));description.append(input,controls);input.focus();}));details.append(held||description);
const contained=el('section');contained.append(el('h3',`Contained locations · ${children.get(r.id)?.length||0}`));for(const id of children.get(r.id)||[])contained.append(button(records.get(id).name,()=>reveal(id),'btn btn-link btn-sm location-child-link'));if(canEdit)contained.append(button('Create child location',()=>createChild(r.id)));details.append(contained);
const related=el('section');related.dataset.related='';related.append(el('h3','Connections'));for(const [label,items,route]of [['Maps',r.maps,'Maps'],['Floor plans',r.floors,'FloorPlans']]){related.append(el('h4',`${label} · ${items.length}`,'small'));for(const link of items){const a=el('a',link.name);a.href=route==='Maps'?`/Maps?projectId=${project}&id=${link.id}`:`/FloorPlans/Edit/${link.id}`;related.append(a);}}const a=el('a',`${r.scenes} recorded scene appearance(s) · relationships and characters`);a.href=`/Locations/Details/${r.id}`;related.append(a,el('p',`${r.relationships||0} relationships · ${r.characters||0} explicitly located characters · ${r.assets||0} assets currently here`,'small muted'));details.append(related);
const related=el('section');related.dataset.related='';related.append(el('h3','Connections'));for(const [label,items,route]of [['Maps',r.maps,'Maps'],['Floor plans',r.floors,'FloorPlans']]){related.append(el('h4',`${label} · ${items.length}`,'small'));for(const link of items){const a=el('a',link.name);a.href=route==='Maps'?`/Maps?projectId=${project}&id=${link.id}`:`/FloorPlans/Edit/${link.id}`;related.append(a);}}const a=el('a',`${r.scenes} recorded scene appearance(s) · relationships and characters`);a.href=`/Locations/Details/${r.id}`;related.append(a,el('p',`${r.relationships||0} relationships · ${r.characters||0} explicitly located characters · ${r.assets||0} assets currently here`,'small muted'));details.append(related);if(heldFocus?.isConnected)heldFocus.focus({preventScroll:true});
}
function commands(id){const r=records.get(id);if(!r)return null;const ids=scope(id),bulk=ids.length>1,commands=[{label:bulk?`${ids.length} locations selected`:r.name,icon:'locations',disabled:true}];if(!bulk)commands.push({label:'View Location Details',icon:'details',run:()=>location.assign(`/Locations/Details/${id}`)},{label:'Edit Location',icon:'writer',run:()=>location.assign(`/Locations/Edit/${id}`)});
if(canEdit){commands.push({separator:true});if(!bulk)commands.push({label:'Rename',icon:'writer',run:()=>rename(id)},{label:'Create child location',icon:'add',run:()=>createChild(id)});for(const g of groups.filter(g=>g.editable))commands.push({label:g.label,icon:g.values[0].icon,children:g.values.map(v=>({label:v.label,icon:v.icon,checked:ids.every(id=>value(records.get(id),g.id)===v.value),disabled:busy,run:()=>void assign(g.id,v.value,ids)}))});commands.push({label:'Change parent…',icon:'location-level',run:()=>parentDialog('Change parent',p=>void assign('parent',p,ids),false,ids)},{label:'Move to root',icon:'locations',disabled:busy,run:()=>void assign('parent','',ids)});if(!bulk){commands.push({separator:true},{label:'Merge with another location…',icon:'merge',run:()=>mergeDialog(id)});for(const [name,links,route]of [['Open associated map',r.maps,'Maps'],['Open associated floor plan',r.floors,'FloorPlans']])if(links.length)commands.push({label:name,icon:route==='Maps'?'maps':'floorplans',children:links.map(l=>({label:l.name,icon:route==='Maps'?'maps':'floorplans',run:()=>location.assign(route==='Maps'?`/Maps?projectId=${project}&id=${l.id}`:`/FloorPlans/Edit/${l.id}`)}))});commands.push({label:'Archive location',icon:'archive',destructive:true,run:()=>archive(id)});}}