PhoenixKitLocations.Web.LocationStructureLive (PhoenixKitLocations v0.3.0)

Copy Markdown View Source

The "Structure" tab of a Location's admin page — mounts the Location, loads its Space tree via Spaces.list_tree/1, and renders it through SpaceTree.space_tree/1 next to LocationTabs.location_tabs/1 (the shared tab header with LocationFormLive's "Details" tab).

Besides the mount + read-only tree render (expand/collapse via toggle_space_node, node selection via select_space), this module owns the tree's CRUD surface: creating a root or child space through a small inline form below the tree, inline rename, sibling reorder (move up/down), and hard delete. Every mutating call commits straight to Spaces — the "immediate commit" model (orchestrator decision #4 at the top of the plan): no staged drafts, no separate save step. Delete is the one exception to "immediate": a hard delete CASCADEs to the whole subtree, so delete_space only opens a confirmation modal reporting Spaces.count_descendants/1 — the actual Spaces.delete_space/2 call happens from the modal's own Delete button (confirm_delete_space), per orchestrator decision #5.

Selecting a node also opens a detail panel below the tree — a multilang (name/description), status/notes/kind edit form plus its own Files + Featured Image card, scoped to that Space's uuid via PhoenixKitLocations.Attachments. Unlike the old staged floor/room flow, the Space already exists in the DB by the time it can be selected, so the detail panel's Save button commits straight to Spaces.update_space/3 — no draft merge step.