PhoenixKitLocations. Web. Components. PlacePicker
(PhoenixKitLocations v0.3.0)
Copy Markdown
View Source
LiveComponent for picking a Location, and optionally a Space inside
it, in one widget — a search-combobox for the Location half and the
existing SpaceTree (read-only picker mode) for the Space half.
Drop one into any LiveView. Each instance owns its own search/tree state; the parent only reacts to one message:
{:place_picker_select, id, %{location_uuid: uuid, space_uuid: uuid_or_nil}}space_uuid is nil when the user picks "Use this location (no
specific space)" instead of drilling into the tree. The tree stays
open after a selection, so a consumer can immediately pick a
different node without re-searching for the Location.
Two halves
- Location — a search-combobox mirroring
PhoenixKitCatalogue.Web.Components.ItemPicker: type to filter, click a result to select. Locations are typically few, so filtering happens in Elixir overLocations.list_locations/1's full result rather than a dedicated search function (unlikeCatalogue.search_items/2). - Space — once a Location is picked, its tree
(
Spaces.list_tree/1) renders throughSpaceTree.space_tree/1withshow_actions={false}— the same read-only mode built for this purpose. Selecting a node, or the "Use this location" button above the tree, sends the:place_picker_selectmessage.
Attrs
:id(required) — unique DOM/component id, echoed back in every:place_picker_selectmessage.:location_type_uuid— restricts the Location search to this type. Resolve the uuid yourself viaLocations.get_location_type_by_name/1first — this component doesn't resolve type names itself, keeping its own API small.nil(default) searches every active Location.:selected_location_uuid,:selected_space_uuid— optional, defaultnil.:selected_space_uuidseeds the tree's initial highlight (space_tree/1'sselected_uuid). The component'supdate/2applies these attrs only on first mount (seed-once semantics); from then on it tracks selection locally as the user picks nodes (clearing back tonilonselect_location/clear_location/ "Use this location"). A consumer can pass a staticselected_space_uuidwithout having to echo every local update back — the seed is honored once and then the component manages the highlight itself.:selected_location_uuidis accepted for symmetry but not currently consumed — the Location half is always driven by the search-combobox in this version.:locale— when given, Location names (search results and the selected-location heading) show the translated name, same_name/namefallback chain asSpaces.full_path/2.nil(default) always shows the primary-language name. Space names inside the tree are not translated —SpaceTreeitself doesn't support that (existing limitation, unrelated to this component).
Usage
type = Locations.get_location_type_by_name("Warehouse")
<.live_component
module={PhoenixKitLocations.Web.Components.PlacePicker}
id="picker-1"
location_type_uuid={type && type.uuid}
/>