Skip to content

[UI] Navigation context management — context-return and org switch wipe (Phase 11) #438

@CRamsan

Description

@CRamsan

Phase 11 — Navigation Context Management

Implement context-return navigation and organization context wipe. This is split from #411 which covered Deep Link Registration, Context-Return Navigation, and Org Context Wipe together.

POL-08: Context-Return Navigation

When a user initiates a child flow from within a specific parent context, successful completion must return them to that parent context.

Cases requiring context-return:

  • Unit Detail: Create task from "+" in unit context → return to Unit Detail (Tasks tab) on save
  • Unit Detail: View a document → return to Unit Detail (Documents tab) on back
  • Request Review List: Approve request, fill AddEditTask → return to Request Review List on save

Implementation: pass returnRoute: Route? as a serialized navigation argument when navigating to the child screen. On successful completion the ViewModel navigates to returnRoute ?: defaultDestination.

POL-09: Organization Context Wipe on Org Switch

When a user switches organizations via the org switcher (from #392):

  1. Clear the navigation back stack: navController.navigate(Route.Dashboard) { popUpTo(0) { inclusive = true } }
  2. Clear in-memory caches in all Managers — each Manager observes currentOrgId: StateFlow<String?> from OrgContext and calls invalidateCache() on change
  3. Update OrgContext singleton with new org ID
  4. No stale org-scoped IDs remain in any ViewModel or Manager after the switch

Manager cache invalidation pattern:

init {
    orgContext.currentOrgId
        .distinctUntilChanged()
        .onEach { invalidateCache() }
        .launchIn(managerScope)
}

Dependencies

What type of task is this?

Development

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions