Repository navigation
DistrictDisplay
The DistrictDisplay component is a specialized wrapper for HeaderDistrictDisplay that fetches and displays the currently selected district for IDIR (government) users.
| Name | Type | Required | Description |
|---|---|---|---|
isActive |
boolean |
✅ | Whether the header panel is currently open |
import DistrictDisplay from '@/components/Layout/HeaderDistrictDisplay/DistrictDisplay';
<DistrictDisplay isActive={isHeaderPanelOpen} />Fetches all available district codes from the codes service.
Displays the currently selected district from user preferences, showing:
- District name
- Panel state indicator (chevron up/down)
Uses React Query to fetch district codes and automatically finds the selected district from the user's preference.
const { data, isLoading } = useQuery({
queryKey: ['districtOptions'],
queryFn: async () => await APIs.codes.getDistricts(),
enabled: true,
select: (data) =>
data
.map((district) => ({
id: district.code,
name: district.description,
kind: 'D'
}))
.find((client) => client.id === userPreference.selectedDistrict),
});Raw district data is transformed to DistrictType format:
-
id:
district.code -
name:
district.description -
kind:
'D'(District type)
Then filters to find the selected district matching userPreference.selectedDistrict.
const { userPreference } = usePreference();Retrieves selectedDistrict preference key to identify which district is currently selected.
enabled: trueThe query executes immediately as district data is publicly available and doesn't depend on user permissions.
queryKey: ['districtOptions']Simple cache key as district data is the same for all users.
The select function:
- Maps all districts to
DistrictTypeformat - Finds the district matching
userPreference.selectedDistrict - Returns single district object or
undefined
<HeaderDistrictDisplay
isActive={isActive}
noSelectionText="No district selected"
queryHook={() => ({ data, isLoading })}
/>- isActive: Passed through from props
- noSelectionText: "No district selected" (shown when no preference set)
- queryHook: Returns current query state
-
PreferenceProvider: For
selectedDistrictpreference - QueryClientProvider: For React Query functionality
- APIs.codes.getDistricts: Fetches district codes
- HeaderDistrictDisplay: Generic display component
This component is specifically for government users who:
- Have access to all districts
- Need to see which district context they're working in
- Want to quickly identify their selected district in the header
Districts are loaded from the codes service and are available to all users.
User may or may not have a selected district:
- With selection: Displays district name
- No selection: Displays "No district selected"
Inherits responsive behavior from HeaderDistrictDisplay:
- Mobile: Hidden (only avatar shown)
- Desktop/Tablet: Full display with district name and chevron
import { PreferenceProvider } from '@/context/preference/PreferenceProvider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import DistrictDisplay from '@/components/Layout/HeaderDistrictDisplay/DistrictDisplay';
const queryClient = new QueryClient();
function HeaderGlobalBar() {
const { isHeaderPanelOpen } = useLayout();
return (
<QueryClientProvider client={queryClient}>
<PreferenceProvider>
<HeaderGlobalAction>
<AvatarImage />
<DistrictDisplay isActive={isHeaderPanelOpen} />
</HeaderGlobalAction>
</PreferenceProvider>
</QueryClientProvider>
);
}District data is cached by React Query, reducing unnecessary API calls.
Uses default stale time, but district codes rarely change so cached data is usually fresh.
- On mount (if stale)
- On window focus (if stale)
- Manual invalidation
Consider setting a longer staleTime for district data:
useQuery({
queryKey: ['districtOptions'],
queryFn: async () => await APIs.codes.getDistricts(),
staleTime: Infinity, // Districts rarely change
// ...
});If the query fails:
- Component continues to render
- Shows "No district selected" text
- Error can be caught by Error Boundary if needed
- HeaderDistrictDisplay: Base display component
- ClientDisplay: Alternative for BCeID Business users
- LayoutHeaderGlobalBar: Parent component
- DistrictListing: Selection interface in profile panel
- Cache Management: Consider longer stale time for district data
- Error Boundaries: Wrap in error boundary for graceful error handling
- Loading States: Query handles loading automatically
- Preference Updates: Invalidate cache when districts are updated
| Aspect | ClientDisplay | DistrictDisplay |
|---|---|---|
| Users | BCeID Business | IDIR |
| Data Source | Forest Client API | Codes API |
| Enabled Logic | Based on client access | Always enabled |
| Query Dependency | User's client list | None |
| Cache Key | Includes client list | Simple key |
- Component is specifically for IDIR (government) users
- All districts are available to all users (no permission checks)
- Automatically updates when selection changes in preferences
- Data fetching is optimized with React Query caching
- Seamlessly integrates with the selection interface in HeaderPanelProfile
- Uses the same display component as ClientDisplay for consistency
This wiki documents NR Waste Plus for users and developers. Verify security and deployment guidance against the current application configuration before applying it elsewhere.
- Report an issue or ask a question in the GitHub repository.
- Follow the Contributing Guidelines to propose an update.
- Read the Code of Conduct.
Collection indexes support human browsing and machine retrieval. Keep both current when adding or moving wiki pages.
NR Waste Plus Wiki | GitHub Repository