mirror of
https://github.com/Matysh/houseplan-card
synced 2026-10-07 23:19:14 +00:00
fix: preserve markers when deleting final space
Issue: #244 User-Visible: yes
This commit is contained in:
+17
-6
@@ -14460,11 +14460,15 @@ class HouseplanCard extends LitElement {
|
||||
private async _deleteSpace(): Promise<void> {
|
||||
const d = this._spaceDialog;
|
||||
if (!d || d.mode !== 'edit') return;
|
||||
const sp = this._serverCfg!.spaces.find((x: any) => x.id === d.spaceId);
|
||||
const serverCfg = this._serverCfg;
|
||||
if (!serverCfg) return;
|
||||
const sp = serverCfg.spaces.find((x: any) => x.id === d.spaceId);
|
||||
const dependencies = collectSpaceMarkerDependencies(
|
||||
this._serverCfg, this._layout || {}, d.spaceId || '',
|
||||
serverCfg, this._layout || {}, d.spaceId || '',
|
||||
);
|
||||
if (dependencies.count) {
|
||||
const deletingLastSpace = serverCfg.spaces.length === 1
|
||||
&& serverCfg.spaces[0]?.id === d.spaceId;
|
||||
if (dependencies.count && !deletingLastSpace) {
|
||||
this._spaceDialog = { ...d, deleteBlockers: dependencies.count };
|
||||
return;
|
||||
}
|
||||
@@ -14496,11 +14500,18 @@ class HouseplanCard extends LitElement {
|
||||
if (e?.code === 'conflict' || e?.code === 'space_in_use') {
|
||||
await Promise.all([this._reloadConfigOnly(true), this._reloadLayoutOnly()]);
|
||||
}
|
||||
if (this._spaceDialog) {
|
||||
const refreshedConfig = this._serverCfg;
|
||||
if (this._spaceDialog && refreshedConfig) {
|
||||
const refreshed = collectSpaceMarkerDependencies(
|
||||
this._serverCfg, this._layout || {}, d.spaceId || '',
|
||||
refreshedConfig, this._layout || {}, d.spaceId || '',
|
||||
);
|
||||
this._spaceDialog = { ...this._spaceDialog, busy: false, deleteBlockers: refreshed.count };
|
||||
const stillLastSpace = refreshedConfig.spaces.length === 1
|
||||
&& refreshedConfig.spaces[0]?.id === d.spaceId;
|
||||
this._spaceDialog = {
|
||||
...this._spaceDialog,
|
||||
busy: false,
|
||||
deleteBlockers: stillLastSpace ? 0 : refreshed.count,
|
||||
};
|
||||
}
|
||||
this._showToast(this._t('toast.delete_failed', { err: this._errText(e) }));
|
||||
}
|
||||
|
||||
+13
-1
@@ -34,7 +34,9 @@ export function createSpaceDeletionCandidate(
|
||||
const dependencies = collectSpaceMarkerDependencies(configIn, layoutIn, spaceId);
|
||||
const config = clone(configIn);
|
||||
const layout = clone(layoutIn || {});
|
||||
if (dependencies.count) return { config, layout, dependencies };
|
||||
const spaces = config.spaces || [];
|
||||
const deletingLastSpace = spaces.length === 1 && spaces[0]?.id === spaceId;
|
||||
if (dependencies.count && !deletingLastSpace) return { config, layout, dependencies };
|
||||
|
||||
const space = (config.spaces || []).find((item: any) => item?.id === spaceId);
|
||||
const roomIds = new Set(
|
||||
@@ -42,6 +44,16 @@ export function createSpaceDeletionCandidate(
|
||||
);
|
||||
config.spaces = (config.spaces || []).filter((item: any) => item?.id !== spaceId);
|
||||
for (const marker of config.markers || []) {
|
||||
const markerOwnsPosition = typeof marker?.id === 'string'
|
||||
&& layout?.[marker.id]?.s === spaceId;
|
||||
const referencesDeletedSpace = marker?.space === spaceId
|
||||
|| (typeof marker?.room_id === 'string' && roomIds.has(marker.room_id))
|
||||
|| markerOwnsPosition;
|
||||
if (deletingLastSpace && referencesDeletedSpace) {
|
||||
delete marker.space;
|
||||
delete marker.room_id;
|
||||
continue;
|
||||
}
|
||||
if (marker?.removed !== true) continue;
|
||||
if (marker.space === spaceId) delete marker.space;
|
||||
if (typeof marker.room_id === 'string' && roomIds.has(marker.room_id)) delete marker.room_id;
|
||||
|
||||
Reference in New Issue
Block a user