Files
fs-onboarding/.cursor/plans/einab_interaction_edit_79be74e0.plan.md

6.8 KiB
Raw Permalink Blame History

name, overview, todos, isProject
name overview todos isProject
EinAb Interaction Edit Add edit mode for EinAb (Einführung) interactions by extending the existing InteractionDialog with an update path, a new ProspectService.UpdateInteraction method, and an edit button in InteractionRow — scoped to EinAb initially but designed for future interaction types.
id content status
service-update Add ProspectService.UpdateInteraction + AuditType.EditInteraction + AuditHelper case completed
id content status
dialog-edit-mode Extend InteractionDialog with IsEditMode, IsEditable helper, and unified SaveAsync completed
id content status
row-edit-button Add AllowEdit/EditClick to InteractionRow with pencil icon in item list completed
id content status
container-wire Add EditInteraction handler in ProspectContainer and enable AllowEdit on EinAb row completed
false

EinAb Interaction Edit Mode

Current State

EinAb interactions ("Einführung") are multi-entry (minimum 3) and support date, business/person fields (Info1/Info2), and feedback (thumbs up/down/neutral). Users can add via InteractionDialog and remove via the X icon in InteractionRow. There is no update path at any layer.

flowchart LR
    subgraph current [Current Flow]
        AddBtn["+ Button"] --> Dialog["InteractionDialog"]
        Dialog --> AddSvc["ProspectService.AddInteraction"]
        XBtn["X Button"] --> Confirm["ConfirmDialog"]
        Confirm --> RemoveSvc["ProspectService.RemoveInteraction"]
    end

Target Flow

flowchart LR
    subgraph target [New Edit Flow]
        EditBtn["Pencil Button"] --> EditDialog["InteractionDialog (edit mode)"]
        EditDialog --> UpdateSvc["ProspectService.UpdateInteraction"]
    end
    AddBtn["+ Button"] --> AddDialog["InteractionDialog (add mode)"]
    AddDialog --> AddSvc["ProspectService.AddInteraction"]
    XBtn["X Button"] --> RemoveSvc["ProspectService.RemoveInteraction"]

Edit and remove will coexist. Only EinAb gets the edit button initially.


1. Service Layer — UpdateInteraction

File: FoodsharingSiegen.Server/Data/Service/ProspectService.cs

Add UpdateInteraction(Interaction interaction) following the existing UpdateAsync(Prospect) pattern:

  • Load tracked entity by interaction.Id; return error if not found
  • Update editable fields only: Date, Info1, Info2, Feedback, FeedbackInfo, Alert
  • Do not change: Id, Created, UserID (preserves original creator), Type, ProspectID, NotNeeded
  • Set parent Prospect.Modified = DateTime.UtcNow
  • Audit via new AuditType.EditInteraction (prospect name + interaction type as data)
  • Detach entities after save (consistent with AddInteraction)

2. Audit Support

Files:


3. InteractionDialog — Add/Edit Mode

Files: InteractionDialog.razor.cs, InteractionDialog.razor

Follow the EditProspectDialog pattern (IsUpdateMode + conditional save):

  • Add IsEditMode parameter and a static extensibility helper:
public static bool IsEditable(InteractionType type) => type switch
{
    InteractionType.EinAb => true,
    _ => false
};
  • Extend InteractionDialogParameter with optional Interaction? ExistingInteraction = null
  • In ShowAsync: when ExistingInteraction is provided, pass it as the bound Interaction and set IsEditMode = true; otherwise keep current "new interaction" behavior
  • Replace AddInteractionAsync with a unified SaveAsync:
    • Add mode: Interaction.UserID = CurrentUser.IdProspectService.AddInteraction
    • Edit mode: ProspectService.UpdateInteraction
  • In the razor template, change OK button label: "OK" (add) / "Speichern" (edit) — same fields render in both modes (date, Betrieb, Mit wem, feedback)

Header text (in ProspectContainer): "Einführung für {Name} bearbeiten" for edit vs existing "… eintragen" for add.


4. InteractionRow — Edit Button

Files: InteractionRow.razor, InteractionRow.razor.cs

  • Add parameters:
    • bool AllowEdit { get; set; } — controls visibility
    • Func<Guid, Task>? EditClick { get; set; } — callback with interaction Id
  • In the per-item loop (lines 4666), show a pencil icon (fa-solid fa-pen-to-square) next to the existing X remove icon when AllowEdit && AllowInteraction
  • Same visibility guard as remove: hidden when prospect is complete (unless Complete-type interaction)

5. ProspectContainer — Wire Up Edit

Files: ProspectContainer.razor, ProspectContainer.razor.cs

  • Add EditInteraction(Guid interactionId):
    • Look up interaction from Prospect.Interactions
    • Guard: only proceed if InteractionDialog.IsEditable(interaction.Type)
    • Open dialog with existing interaction and header "Einführung für {Name} bearbeiten"
    • On success → OnDataChanged()
  • On the EinAb InteractionRow, add:
    • AllowEdit="true"
    • EditClick="@EditInteraction"

Other interaction rows remain unchanged (no edit button).


Extensibility Notes

To enable edit for another type later:

  1. Add the type to InteractionDialog.IsEditable()
  2. Set AllowEdit="true" on that row in ProspectContainer.razor
  3. Ensure field labels in ShowAsync's type switch cover that type (already done for several types)

No separate edit dialog component is needed — the same form handles both modes.


Files Changed (summary)

File Change
ProspectService.cs New UpdateInteraction method
AuditType.cs New EditInteraction enum value
AuditHelper.cs New audit text case
InteractionDialog.razor.cs Edit mode, IsEditable, unified save
InteractionDialog.razor Conditional button label
InteractionRow.razor / .cs Edit button + parameters
ProspectContainer.razor / .cs EditInteraction handler, EinAb wiring

No database migration required — all editable fields already exist on the Interaction entity.