From 816774815c09348c4bfde6b927ea8e8cd70298a0 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 20 Oct 2026 07:39:47 -0700 Subject: [PATCH] Add a little warning for empty zones --- ...r-template-editor-zone-list.component.html | 18 ++++++++++++------ ...emplate-editor-zone-list.component.spec.ts | 19 +++++++++++++++++++ ...ocr-template-editor-zone-list.component.ts | 4 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.html b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.html index fcecfc46e..668a6d797 100644 --- a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.html +++ b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.html @@ -7,12 +7,18 @@
-
- {{ getZoneTargetName(zone) }} - @if (isCombined(zone)) { - - } -
+ @if (!hasField(zone)) { +
+ No field selected +
+ } @else { +
+ {{ getZoneTargetName(zone) }} + @if (isCombined(zone)) { + + } +
+ }
@if (zone.page === -1) { diff --git a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.spec.ts b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.spec.ts index 687dcca02..b3bec5999 100644 --- a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.spec.ts +++ b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.spec.ts @@ -73,6 +73,25 @@ describe('OcrTemplateEditorZoneListComponent', () => { ).toBe(2) }) + it('warns only for zones without a field and clears the warning when assigned', () => { + component.zones = [ + zone({ custom_field: null }), + zone({ target: 'title', custom_field: null }), + zone(), + ] + fixture.detectChanges() + + const warnings = () => + fixture.nativeElement.querySelectorAll('.text-warning') + expect(warnings()).toHaveLength(1) + expect(warnings()[0].textContent).toContain('No field selected') + + component.zones[0].custom_field = 7 + fixture.componentRef.setInput('zones', [...component.zones]) + fixture.detectChanges() + expect(warnings()).toHaveLength(0) + }) + it('emits select and remove events', () => { component.zones = [zone()] const selectSpy = jest.spyOn(component.zoneSelected, 'emit') diff --git a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.ts b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.ts index d373b1f49..82ce69bf2 100644 --- a/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.ts +++ b/src-ui/src/app/components/manage/ocr-templates/ocr-template-editor/ocr-template-editor-zone-list/ocr-template-editor-zone-list.component.ts @@ -22,6 +22,10 @@ export class OcrTemplateEditorZoneListComponent { readonly zoneColor = getZoneColor + hasField(zone: OcrTemplateZone): boolean { + return getZoneFieldKey(zone) !== null + } + isCombined(zone: OcrTemplateZone): boolean { const key = getZoneFieldKey(zone) return (