Skip to content

Rework plant identification view: surface & link created plant instance in history #630

Description

@nolte

Summary

Rework the plant identification view (/pflanzen/identifikation) so that the identification history/overview makes it visible when a plant instance was created from an identification result, and exposes that instance as a clickable linked element leading to its detail page.

Today the link between an identification result and the plant instance it produced is purely ephemeral in the frontend: after a suggestion is selected, PlantInstanceCreateDialog creates the instance and handlePlantCreated navigates to /pflanzen/plant-instances/{key}. Nothing is persisted back onto the identification record, so the history list cannot show whether an entry led to an instance, nor link to it.

Current state

  • Route + page: src/frontend/src/routes/AppRoutes.tsx:555src/frontend/src/pages/ki-recognition/PlantIdentificationPage.tsx
  • History/overview list is implemented inline in the page: PlantIdentificationPage.tsx:126-176 (identification-history-list / identification-history-item)
  • Data flow: Redux identificationSlice.ts (fetchIdentificationHistory) → API src/frontend/src/api/endpoints/identification.ts:96GET /t/{slug}/identification/history
  • Instance detail route pattern: /pflanzen/plant-instances/:key (AppRoutes.tsx:538)
  • No link field exists yet on the identification record:
    • Backend model src/backend/app/domain/models/identification.py:36-54 (IdentificationRequest) — no plant_instance_key
    • Response DTO src/backend/app/api/v1/recognition/schemas.py:87-97 (HistoryEntryResponse) — no instance field
    • Frontend type src/frontend/src/api/types.ts:4776-4785 (IdentificationHistoryEntry) — no instance field
    • (Note: plant_instance_key at types.ts:4812 belongs to PestDetectionResult, unrelated to identification.)

Proposed changes

Backend

  • Add a nullable plant_instance_key (reference to the created plant instance) to the IdentificationRequest model and HistoryEntryResponse DTO.
  • Persist this reference when a plant instance is created from an identification result (link the identification record to the newly created instance). Provide a migration for existing records (backfill left null).
  • Ensure tenant scoping / authorization is respected for the linked instance.

Frontend

  • Extend IdentificationHistoryEntry with the optional plant_instance_key.
  • In the history/overview list (PlantIdentificationPage.tsx:126-176), when an entry has a linked instance:
    • Visually indicate that an instance was created from this identification (e.g. status chip / icon).
    • Render the instance as a clickable linked element navigating to /pflanzen/plant-instances/{key}.
  • When no instance was created, keep the existing behaviour (offer to create one).

i18n

  • Add DE/EN keys under pages.plantIdentification (.../de/translation.json:810, .../en/translation.json:810), e.g. historyInstanceCreated, historyOpenInstance. DE is canonical, EN mirrored.

Acceptance criteria

  • The identification history/overview clearly indicates, per entry, whether a plant instance was created from it.
  • For entries with a created instance, a clickable linked element navigates to that instance's detail page (/pflanzen/plant-instances/{key}).
  • The link is persisted on the backend identification record and survives page reloads (no longer ephemeral).
  • Creating a new instance from an identification result populates the link.
  • Entries without an instance keep the current "create instance" flow.
  • DE + EN translations present; no missing i18n keys.
  • Mobile-first layout; the linked element is touch-friendly.

Notes

  • Follow the 5-layer backend architecture (NFR-001) and the versioned migration framework for the new field.
  • Frontend: custom hooks returning objects/arrays must be memoised; enum/i18n conventions apply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendenhancementNew functionality.featConventional Commits type `feat` — new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions