Skip to content

Commit 9f68d83

Browse files
committed
fix(condo): DOMA-4566 fix remove section
1 parent 8329913 commit 9f68d83

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

apps/condo/domains/property/components/panels/Builder/MapConstructor.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import compact from 'lodash/compact'
1616
import find from 'lodash/find'
1717
import get from 'lodash/get'
1818
import has from 'lodash/has'
19+
import isEmpty from 'lodash/isEmpty'
1920
import isObjectEmpty from 'lodash/isEmpty'
2021
import isNil from 'lodash/isNil'
2122
import last from 'lodash/last'
@@ -848,9 +849,9 @@ class MapEdit extends MapView {
848849

849850
public removeSection (id: string, renameNextUnits = true): void {
850851
const sectionIndex = this.map.sections.findIndex(mapSection => mapSection.id === id)
852+
const removedSection = { ...this.map.sections[sectionIndex] }
851853
this.map.sections.splice(sectionIndex, 1)
852-
const removeSectionIndex = (sectionIndex - 1) >= 0 ? sectionIndex - 1 : sectionIndex
853-
if (renameNextUnits) this.updateSectionNumbers(removeSectionIndex, renameNextUnits)
854+
if (renameNextUnits) this.updateSectionNumbers(sectionIndex, renameNextUnits, removedSection)
854855

855856
this.selectedSection = null
856857
this.mode = null
@@ -869,9 +870,9 @@ class MapEdit extends MapView {
869870

870871
public removeParking (id: string, renameNextUnits = true): void {
871872
const parkingIndex = this.map.parking.findIndex(mapParking => mapParking.id === id)
873+
const removedParking = { ...this.map.parking[parkingIndex] }
872874
this.map.parking.splice(parkingIndex, 1)
873-
const removeParkingIndex = (parkingIndex - 1) >= 0 ? parkingIndex - 1 : parkingIndex
874-
if (renameNextUnits) this.updateParkingNumbers(removeParkingIndex, renameNextUnits)
875+
if (renameNextUnits) this.updateParkingNumbers(parkingIndex, renameNextUnits, removedParking)
875876

876877
this.selectedParking = null
877878
this.mode = null
@@ -1085,7 +1086,8 @@ class MapEdit extends MapView {
10851086
}
10861087

10871088
this.selectedUnit = null
1088-
this.editMode = null
1089+
this.selectedSection = null
1090+
this.mode = null
10891091
this.notifyUpdater()
10901092
}
10911093

@@ -1416,15 +1418,15 @@ class MapEdit extends MapView {
14161418
}
14171419
}
14181420

1419-
private updateSectionNumbers (removedIndex: number, renameNextUnits = true): void {
1420-
if (removedIndex === this.map.sections.length) {
1421+
private updateSectionNumbers (updatedIndex: number, renameNextUnits = true, removedSection = {}): void {
1422+
if (updatedIndex === this.map.sections.length) {
14211423
return
14221424
}
1423-
let sectionNameNumber = parseInt(get(this.map.sections, `${removedIndex}.name`))
1424-
if (removedIndex === 0) sectionNameNumber = 1
1425-
let sectionIndex = removedIndex
1425+
let sectionNameNumber = parseInt(get(this.map.sections, `${updatedIndex}.name`))
1426+
if (!isEmpty(removedSection)) sectionNameNumber = get(removedSection, 'name', 1)
1427+
let sectionIndex = !isEmpty(removedSection) ? get(removedSection, 'index', 0) : updatedIndex
14261428
this.map.sections.forEach((section, index) => {
1427-
if (index >= removedIndex) {
1429+
if (index >= updatedIndex) {
14281430
section.name = String(sectionNameNumber)
14291431
section.index = sectionIndex
14301432
sectionNameNumber++
@@ -1434,15 +1436,15 @@ class MapEdit extends MapView {
14341436

14351437
}
14361438

1437-
private updateParkingNumbers (removedIndex: number, renameNextUnits = true): void {
1438-
if (removedIndex === this.map.parking.length) {
1439+
private updateParkingNumbers (updatedIndex: number, renameNextUnits = true, removedParking = {}): void {
1440+
if (updatedIndex === this.map.parking.length) {
14391441
return
14401442
}
1441-
let parkingNameNumber = parseInt(get(this.map.parking, `${removedIndex}.name`))
1442-
let parkingIndex = removedIndex
1443-
if (removedIndex === 0) parkingNameNumber = 1
1443+
let parkingNameNumber = parseInt(get(this.map.parking, `${updatedIndex}.name`))
1444+
if (!isEmpty(removedParking)) parkingNameNumber = get(removedParking, 'name', 1)
1445+
let parkingIndex = !isEmpty(removedParking) ? get(removedParking, 'index', 0) : updatedIndex
14441446
this.map.parking.forEach((parkingSection, index) => {
1445-
if (index >= removedIndex) {
1447+
if (index >= updatedIndex) {
14461448
parkingSection.name = String(parkingNameNumber)
14471449
parkingSection.index = parkingIndex
14481450
parkingNameNumber++

0 commit comments

Comments
 (0)