Skip to content

Lookup ids (FieldTypes/Languages) are assumed fixed; visual editor SingleSelect options vanish when ids are not 1..N #8141

Closed

Description

@renemadsen

Symptom

On a freshly installed environment, the visual editor's New field modal with Type = SingleSelect ("Rullemenu") does not render the options section: the Options textarea, the "Add options" button and the per-language options table are missing. Older installations render it correctly.

Root cause

Lookup rows are seeded with whatever AUTO_INCREMENT hands out, and code compares against fixed numeric ids.

  • The seeder ignores the intended id. eform-sdk SqlController.FieldTypeAdd(int Id, ...) discards Id and inserts new FieldType { Type, Description }. Language.AddDefaultLanguages also inserts without an id.

  • Ids stop being 1..N on some servers. On a server with auto_increment_increment=3 (e.g. a Galera cluster), the seeded ids become 3, 6, 9, …:

    FieldType id on a contiguous install id with increment 3
    Text 1 3
    Picture 5 15
    SingleSelect 8 24
    MultiSelect 10 30
    FieldGroup 17 51

    Languages shift the same way: Danish 1 → 3, English 2 → 6.

  • The earlier visual-editor fix was partial (b701184 … 881b113). It remapped the Type dropdown to DB ids. Everything that reads field.fieldType back still compares against EformFieldTypesEnum, e.g. visual-editor-field-modal.component.html:2 [ngSwitch]="recursionModel.field.fieldType" with *ngSwitchCase="eformFieldTypesEnum.SingleSelect" (= 8). The stored value is 24, so nothing matches.

  • Some shifted ids collide with other enum values, which makes the wrong panels or flags apply:

    • Text (3) equals enum None.
    • Picture (15) equals enum EntitySelect.

Affected code (known so far)

eform-angular-frontend (visual editor)

  • visual-editor-field-modal.component.html: all ngSwitchCases (Number, Date, NumberStepper, SaveButton, ShowPdf, SingleSelect, MultiSelect, EntitySearch, EntitySelect, ShowPicture)
  • visual-editor-field-modal.component.ts: mandatoryIsNotNeed (L82-92) and the EntitySearch/EntitySelect reset in updateFieldType
  • eform-visual-editor-container.component.ts:130, 318-320 and .html:137: FieldGroup checks
  • visual-editor-field.component.ts:94 and .html:44, 80, 92
  • visual-editor-checklist.component.html:86

eform-angular-frontend (backend and app)

  • SitesService.cs:186: falls back to language id 1
  • auth-state.service.ts:45: currentLanguageId = 1

eform-sdk

  • Core.cs:5804, 5825: FieldTypeId != 3 && FieldTypeId != 18, meant to skip None and SaveButton

eform-angular-items-planning-plugin

  • ItemsPlanningReportService.cs:265, 473: FieldTypeId == 5 (Picture)
  • PlanningImportService: maps the |-separated name segments to Languages ids 1..3, so the Excel import throws Sequence contains no elements (found while fixing)

eform-angular-workflow-plugin

  • WorkflowCasesService.cs:184: FieldTypeId == 5, used with FirstAsync, so it throws
  • WorkflowCasesService.cs:630: FieldTypeId == 8

eform-backendconfiguration-plugin

  • BackendConfigurationAreaRulePlanningsServiceHelper.cs: LanguageId == 1/2/3
  • BackendConfigurationAreaRulesServiceHelper.cs:94
  • calendar task-create-edit-modal: danishLanguageId = 1 and EformFieldTypesEnum

eform-service-backendconfiguration-plugin

  • SearchListJob.cs:1871, 1897, 1901: .First(x => x.LanguageId == 1) in GenerateDocumentList. Correction: that method has no callers, so it never ran; it is dead code and has been removed
  • FloatingLayerCaseCompletedHandler.cs:79: reads the Danish option text by LanguageId == 1 and gets null. Correction: the value is currently only consumed by commented-out code, so there is no visible symptom today

Plan

Constraint: existing databases must not be renumbered or migrated. The fix is code-only.

  1. Tests first. Add tests that seed or run with shifted lookup ids (auto_increment_increment=3, or ids deliberately offset from the enum values) and assert that:

    • The visual editor field modal renders the correct panel for every field type, and its mandatory-flag logic matches.
    • The SDK, plugin backends and service jobs resolve field types by Type name and languages by LanguageCode.

    These tests must fail on the current code.

  2. Make the code id-agnostic.

    • Resolve field types by FieldType.Type and languages by LanguageCode.
    • In the visual editor, normalise DB FieldTypeId ⇄ EformFieldTypesEnum once, at the API/UI boundary, so the existing enum comparisons stay valid.
  3. Keep the shifted-id tests in CI as a regression guard.

Fix (PRs)

No seeder change and no data migration. Known leftovers that are out of scope are listed in each PR under "Known, out of scope".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions