@@ -30,7 +30,7 @@ const LocationsPage: React.FC = () => {
3030 // Sorting and filtering state
3131 const [ sortOrder , setSortOrder ] = useState < 'asc' | 'desc' > ( 'asc' ) ;
3232 const [ selectedLocation , setSelectedLocation ] = useState < Location | null > ( null ) ;
33- const { units, loading : unitsLoading } = useUnit ( ) ;
33+ const { units, loading : unitsLoading , selectedUnit , setSelectedUnit } = useUnit ( ) ;
3434 const { selectedIncident } = useIncident ( ) ;
3535
3636 const handleAdd = ( ) => {
@@ -77,8 +77,11 @@ const LocationsPage: React.FC = () => {
7777 // Filter and sort locations before rendering
7878 const filteredLocations = ( locations || [ ] )
7979 . filter ( l => {
80- if ( ! selectedLocation ) return true ;
81- return l . locationId === selectedLocation . locationId ;
80+ // Filter by selected unit if set
81+ if ( selectedUnit && l . unitId !== selectedUnit . unitId ) return false ;
82+ // Then filter by selected location if set
83+ if ( selectedLocation && l . locationId !== selectedLocation . locationId ) return false ;
84+ return true ;
8285 } )
8386 . sort ( ( a , b ) => {
8487 const aName = a . name ? a . name . toLowerCase ( ) : '' ;
@@ -95,6 +98,15 @@ const LocationsPage: React.FC = () => {
9598 < Row className = "align-items-center" >
9699 < Col > < strong > Locations</ strong > </ Col >
97100 < Col md = "auto" className = "d-flex align-items-center gap-2" >
101+ < ContextSelect
102+ label = "Unit"
103+ options = { units }
104+ value = { selectedUnit ? selectedUnit . unitId : null }
105+ onSelect = { id => setSelectedUnit ( id ? units . find ( u => u . unitId === id ) ?? null : null ) }
106+ loading = { unitsLoading }
107+ getOptionLabel = { u => u . name }
108+ getOptionValue = { u => u . unitId }
109+ />
98110 < ContextSelect
99111 label = "Location"
100112 options = { locations }
0 commit comments