From aa66fda1caba8cfd585756bdd437ff32b45c3e47 Mon Sep 17 00:00:00 2001 From: TO Date: Thu, 30 Jul 2026 01:34:35 +0200 Subject: [PATCH] refactor: delete unused condition report mode --- .../condition-report-details-section.html | 156 ------------------ .../condition-report-details-section.spec.ts | 46 +----- .../condition-report-details-section.ts | 105 +----------- .../condition-report-editor.html | 1 - 4 files changed, 7 insertions(+), 301 deletions(-) diff --git a/frontend/src/app/components/condition-report-page/condition-report-details-section.html b/frontend/src/app/components/condition-report-page/condition-report-details-section.html index 4878caf..df140f8 100644 --- a/frontend/src/app/components/condition-report-page/condition-report-details-section.html +++ b/frontend/src/app/components/condition-report-page/condition-report-details-section.html @@ -124,159 +124,3 @@ } } - -@if (!generalOnly()) { -
-

Zones et sujets observés

- @for (zone of report().zones; track zone.id; let index = $index) { -
- {{ zone.label || 'Zone' }} - - Espace privatif - - @for (area of privateAreas(); track area.id) { - {{ area.label }} - } - - - @if (fieldError('zones[' + index + '].privateAreaId')) { -

- {{ fieldError('zones[' + index + '].privateAreaId') }} -

- } - - Libellé - - - @if (fieldError('zones[' + index + '].label')) { -

- {{ fieldError('zones[' + index + '].label') }} -

- } - - Équipement - - Aucun - Climatisation - Autre - - - @if (fieldError('zones[' + index + '].equipment')) { -

- {{ fieldError('zones[' + index + '].equipment') }} -

- } - @if (canRemoveZone(zone.id)) { - - } -
- } - - @for ( - observation of report().observations; - track observation.subjectId; - let index = $index - ) { -
- {{ observationLabel(observation.subjectId) }} - - État - - @for (state of states; track state) { - {{ stateLabels[state] }} - } - - - @if (fieldError('observations[' + index + '].state')) { -

- {{ fieldError('observations[' + index + '].state') }} -

- } - - Observation{{ - needsObservation(observation.state) ? ' (obligatoire)' : '' - }} - - - @if (fieldError('observations[' + index + '].observation')) { -

- {{ fieldError('observations[' + index + '].observation') }} -

- } -
- } -
-} diff --git a/frontend/src/app/components/condition-report-page/condition-report-details-section.spec.ts b/frontend/src/app/components/condition-report-page/condition-report-details-section.spec.ts index f89bfdc..72f9d29 100644 --- a/frontend/src/app/components/condition-report-page/condition-report-details-section.spec.ts +++ b/frontend/src/app/components/condition-report-page/condition-report-details-section.spec.ts @@ -4,10 +4,11 @@ import { ConditionReportDetailsSection } from './condition-report-details-sectio import { workflowReport } from './condition-report-test-data'; describe('ConditionReportDetailsSection', () => { - it('updates general data, participants, addresses, zones and observations', () => { + it('updates date, participants, exit forwarding addresses and field paths', () => { const fixture = TestBed.createComponent(ConditionReportDetailsSection); fixture.componentRef.setInput('report', { ...structuredClone(workflowReport), + type: 'EXIT', participants: [ { partyId: 'tenant', @@ -18,16 +19,6 @@ describe('ConditionReportDetailsSection', () => { }, ], forwardingAddresses: [{ tenantPartyId: 'tenant', address: 'Old address' }], - zones: [ - { - id: 'area:floor', - privateAreaId: 'area', - label: 'Cuisine — Sol', - equipment: 'NONE', - }, - { id: 'zone', privateAreaId: 'area', label: 'Fenêtre', equipment: 'OTHER' }, - ], - observations: [{ subjectId: 'zone', state: 'BON_ETAT', observation: '' }], }); const changed = vi.fn(); const fieldChanged = vi.fn(); @@ -39,11 +30,6 @@ describe('ConditionReportDetailsSection', () => { fixture.componentInstance.updateParticipant(0, 'representativeName', inputEvent('Proxy')); fixture.componentInstance.updateForwardingAddress('tenant', inputEvent('New address')); fixture.componentInstance.updateForwardingAddress('other', inputEvent('Other address')); - fixture.componentInstance.updateZone('zone', 'label', inputEvent('Porte')); - fixture.componentInstance.updateZone('zone', 'equipment', 'CLIMATISATION'); - fixture.componentInstance.updateObservation('zone', 'state', 'DEGRADE'); - fixture.componentInstance.updateObservation('zone', 'observation', inputEvent('Rayure')); - fixture.componentInstance.removeZone('zone'); const emitted = changed.mock.calls.map(([value]) => value); expect(emitted[0]).toEqual(expect.objectContaining({ occurredOn: '2026-07-23' })); @@ -60,35 +46,15 @@ describe('ConditionReportDetailsSection', () => { tenantPartyId: 'other', address: 'Other address', }); - expect(emitted[5].zones[1]).toEqual(expect.objectContaining({ label: 'Porte' })); - expect(emitted[6].zones[1]).toEqual( - expect.objectContaining({ equipment: 'CLIMATISATION' }), - ); - expect(emitted[7].observations[0]).toEqual(expect.objectContaining({ state: 'DEGRADE' })); - expect(emitted[8].observations[0]).toEqual( - expect.objectContaining({ observation: 'Rayure' }), - ); - expect(emitted[9]).toEqual( - expect.objectContaining({ - zones: [expect.objectContaining({ id: 'area:floor' })], - observations: [], - }), - ); expect(fieldChanged).toHaveBeenCalledWith('occurredOn'); + expect(fieldChanged).toHaveBeenCalledWith('participants[0].attendance'); + expect(fieldChanged).toHaveBeenCalledWith('participants[0].representativeName'); + expect(fieldChanged).toHaveBeenCalledWith('forwardingAddresses[0].address'); + expect(fieldChanged).toHaveBeenCalledWith('forwardingAddresses[1].address'); expect(fixture.componentInstance.forwardingAddress('tenant')).toBe('Old address'); expect(fixture.componentInstance.forwardingAddress('missing')).toBe(''); expect(fixture.componentInstance.forwardingAddressIndex('tenant')).toBe(0); expect(fixture.componentInstance.forwardingAddressIndex('missing')).toBe(1); - expect(fixture.componentInstance.canRemoveZone('zone')).toBe(true); - expect(fixture.componentInstance.canRemoveZone('area:floor')).toBe(false); - expect(fixture.componentInstance.canRemoveZone('missing')).toBe(false); - expect(fixture.componentInstance.privateAreas()).toEqual([ - { id: 'area', label: 'Cuisine' }, - ]); - expect(fixture.componentInstance.observationLabel('zone')).toBe('Fenêtre'); - expect(fixture.componentInstance.observationLabel('missing')).toBe('Zone'); - expect(fixture.componentInstance.needsObservation('DEGRADE')).toBe(true); - expect(fixture.componentInstance.needsObservation('BON_ETAT')).toBe(false); expect(fixture.componentInstance.fieldError('missing')).toBe(''); expect(fixture.componentInstance.errorId('missing')).toBe('condition-report-error-missing'); fixture.detectChanges(); diff --git a/frontend/src/app/components/condition-report-page/condition-report-details-section.ts b/frontend/src/app/components/condition-report-page/condition-report-details-section.ts index fd461fc..7fcdfb7 100644 --- a/frontend/src/app/components/condition-report-page/condition-report-details-section.ts +++ b/frontend/src/app/components/condition-report-page/condition-report-details-section.ts @@ -3,23 +3,12 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; import { MatDatepickerModule } from '@angular/material/datepicker'; import { MatSelectModule } from '@angular/material/select'; -import { ConditionState, PropertyConditionReport } from '../../services/condition-report.service'; +import { PropertyConditionReport } from '../../services/condition-report.service'; import { ConditionReportFieldErrors, conditionReportErrorId, conditionReportFieldError, } from './condition-report-draft-validator'; -import { conditionReportStateLabels } from './condition-report-state-label'; -import { isAdditionalConditionZone } from './condition-report-zone'; - -const states: readonly ConditionState[] = [ - 'NEUF', - 'BON_ETAT', - 'ETAT_USAGE', - 'DEGRADE', - 'ABSENT', - 'NON_APPLICABLE', -]; @Component({ selector: 'app-condition-report-details-section', @@ -29,12 +18,9 @@ const states: readonly ConditionState[] = [ }) export class ConditionReportDetailsSection { readonly report = input.required(); - readonly generalOnly = input(false); readonly errors = input({}); readonly reportChanged = output(); readonly fieldChanged = output(); - readonly states = states; - readonly stateLabels = conditionReportStateLabels; setOccurredOn(event: Event | string): void { this.fieldChanged.emit('occurredOn'); @@ -89,87 +75,6 @@ export class ConditionReportDetailsSection { return index < 0 ? this.report().forwardingAddresses.length : index; } - addZone(): void { - const id = crypto.randomUUID(); - this.update((report) => ({ - ...report, - zones: [ - ...report.zones, - { - id, - privateAreaId: this.privateAreas()[0]?.id ?? '', - label: '', - equipment: 'NONE', - }, - ], - observations: [ - ...report.observations, - { subjectId: id, state: 'BON_ETAT', observation: '' }, - ], - })); - } - - updateZone( - id: string, - field: 'privateAreaId' | 'label' | 'equipment', - event: Event | string, - ): void { - this.fieldChanged.emit(`zones[${this.zoneIndex(id)}].${field}`); - this.update((report) => ({ - ...report, - zones: report.zones.map((zone) => - zone.id === id ? { ...zone, [field]: this.value(event) } : zone, - ), - })); - } - - removeZone(id: string): void { - this.update((report) => ({ - ...report, - zones: report.zones.filter((zone) => zone.id !== id), - observations: report.observations.filter((observation) => observation.subjectId !== id), - photoAbsences: report.photoAbsences.filter((absence) => absence.subjectId !== id), - })); - } - - canRemoveZone(id: string): boolean { - const zone = this.report().zones.find((candidate) => candidate.id === id); - return zone ? isAdditionalConditionZone(zone) : false; - } - - updateObservation(id: string, field: 'state' | 'observation', event: Event | string): void { - this.fieldChanged.emit(`observations[${this.observationIndex(id)}].${field}`); - this.update((report) => ({ - ...report, - observations: report.observations.map((observation) => - observation.subjectId === id - ? { ...observation, [field]: this.value(event) } - : observation, - ), - })); - } - - needsObservation(state: ConditionState): boolean { - return ['DEGRADE', 'ABSENT', 'NON_APPLICABLE'].includes(state); - } - - privateAreas(): { id: string; label: string }[] { - const areas = new Map(); - for (const zone of this.report().zones) { - if (!zone.privateAreaId || areas.has(zone.privateAreaId)) continue; - const separator = zone.label.indexOf(' — '); - areas.set( - zone.privateAreaId, - separator < 0 ? zone.privateAreaId : zone.label.slice(0, separator), - ); - } - return [...areas].map(([id, label]) => ({ id, label })); - } - - observationLabel(subjectId: string): string { - return this.report().zones.find((zone) => zone.id === subjectId)?.label || 'Zone'; - } - fieldError(path: string): string { return conditionReportFieldError(this.errors(), path); } @@ -178,14 +83,6 @@ export class ConditionReportDetailsSection { return conditionReportErrorId(path); } - private zoneIndex(id: string): number { - return this.report().zones.findIndex((zone) => zone.id === id); - } - - private observationIndex(id: string): number { - return this.report().observations.findIndex((observation) => observation.subjectId === id); - } - private update(change: (report: PropertyConditionReport) => PropertyConditionReport): void { this.reportChanged.emit(change(this.report())); } diff --git a/frontend/src/app/components/condition-report-page/condition-report-editor.html b/frontend/src/app/components/condition-report-page/condition-report-editor.html index f2bee9e..0dca3ea 100644 --- a/frontend/src/app/components/condition-report-page/condition-report-editor.html +++ b/frontend/src/app/components/condition-report-page/condition-report-editor.html @@ -46,7 +46,6 @@