Repository navigation
HeaderDistrictDisplay
The HeaderDistrictDisplay component is a generic display component that shows selected district or client information in the header global bar. It displays the entity name and a chevron icon indicating the panel state.
| Name | Type | Required | Description |
|---|---|---|---|
queryHook |
() => { data: DistrictType | undefined; isLoading: boolean } |
✅ | Hook that returns the selected entity data and loading state |
noSelectionText |
string |
✅ | Text to display when no entity is selected |
isActive |
boolean |
✅ | Whether the header panel is currently open |
type DistrictType = {
id: string; // Entity identifier
name: string; // Entity display name
kind: string; // Entity type code
};import HeaderDistrictDisplay from '@/components/Layout/HeaderDistrictDisplay';
// With district data
<HeaderDistrictDisplay
isActive={isHeaderPanelOpen}
noSelectionText="No district selected"
queryHook={() => ({ data: selectedDistrict, isLoading: false })}
/>
// With client data
<HeaderDistrictDisplay
isActive={isHeaderPanelOpen}
noSelectionText="No client selected"
queryHook={() => ({ data: selectedClient, isLoading: true })}
/>The component adapts to screen size:
- Small screens (sm): Hides text and chevron, shows only in avatar button
- Larger screens: Shows entity name and chevron indicator
Displays different chevron icons based on panel state:
-
Panel Open:
ChevronUpicon -
Panel Closed:
ChevronDownicon
Shows either:
- Selected entity name (if data exists)
- "No selection" text (if no data)
const breakpoint = useBreakpoint();
const showSimpleView = useMemo(() => breakpoint === "sm", [breakpoint]);When showSimpleView is true:
- Returns
null(renders nothing) - Entity info shown only in expanded panel
When showSimpleView is false:
- Displays entity name or fallback text
- Shows chevron icon indicating panel state
{
showSimpleView ? null : (
<p className="client-name" data-testid="client-name">
{data ? data.name : noSelectionText}
</p>
);
}
{
showSimpleView ? null : isActive ? (
<ChevronUp data-testid="active" />
) : (
<ChevronDown data-testid="inactive" />
);
}- Displayed when panel is active/open
- Indicates "click to close"
- Test ID:
active
- Displayed when panel is inactive/closed
- Indicates "click to open"
- Test ID:
inactive
The component uses a query hook to fetch data:
const { data } = queryHook();The hook expects an object with:
-
data: The current entity (orundefinedif no selection) -
isLoading: Loading state (prepared but not currently used in rendering)
This allows different implementations (ClientDisplay, DistrictDisplay) to provide their own data sources while maintaining a consistent interface.
- Client name:
data-testid="client-name" - Active state:
data-testid="active" - Inactive state:
data-testid="inactive"
- useBreakpoint: Detects current screen size breakpoint
-
ChevronUp: Upward chevron for open state -
ChevronDown: Downward chevron for closed state
| Breakpoint | Screen Width | showSimpleView |
|---|---|---|
sm |
< 672px | true |
md |
672px - 1056px | false |
lg |
1056px - 1312px | false |
xlg |
1312px - 1584px | false |
max |
≥ 1584px | false |
const ClientDisplay: FC<ClientDisplayProps> = ({ isActive }) => {
const { getClients } = useAuth();
const { userPreference } = usePreference();
const selectedClient = userPreference.selectedClient as
| CodeDescriptionDto
| undefined;
const { data, isLoading } = useQuery({
queryKey: ["forest-clients", "search", getClients()],
queryFn: () =>
APIs.forestclient.searchByClientNumbers(
getClients(),
0,
getClients().length,
),
enabled: !!getClients().length,
select: (data) =>
data
.map((client) => ({
id: client.clientNumber,
name: client.name ?? client.clientName,
acronym: client.acronym,
kind: client.clientTypeCode?.code,
}))
.find((client) => client.id === selectedClient?.code),
});
return (
<HeaderDistrictDisplay
isActive={isActive}
noSelectionText="No client selected"
queryHook={() => ({ data, isLoading })}
/>
);
};const DistrictDisplay: FC<DistrictDisplayProps> = ({ isActive }) => {
const { userPreference } = usePreference();
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((district) => district.id === userPreference.selectedDistrict),
});
return (
<HeaderDistrictDisplay
isActive={isActive}
noSelectionText="No district selected"
queryHook={() => ({ data, isLoading })}
/>
);
};The component relies on parent styling from LayoutHeaderGlobalBar:
.profile-action-button {
display: flex;
gap: 0.5rem;
.client-name {
// Inherits text color from parent
}
}- ClientDisplay: Implementation for business client display
- DistrictDisplay: Implementation for district display
- LayoutHeaderGlobalBar: Parent container component
- AvatarImage: Displayed alongside this component
- Query Hook Pattern: Use the query hook pattern for flexible data sources
- Loading States: Handle loading states in the query hook
- Responsive Design: Component automatically adapts to screen size
- Consistent Text: Provide clear "no selection" text
- Test IDs: Use provided test IDs for component testing
- Chevron icons have test IDs for testing
- Client name has semantic paragraph tag
- Component respects user's screen size preferences
- Icons provide visual indication of panel state
- Business Users: Display selected client in header
- Government Users: Display selected district in header
- Multi-Entity Access: Show which entity context is active
- Panel State: Indicate whether profile panel is open
- Component is fully responsive and hides on small screens
- Uses memoization for breakpoint detection to avoid unnecessary re-renders
- Data fetching is delegated to wrapper components (ClientDisplay, DistrictDisplay)
- Chevron direction matches Carbon Design System patterns
- Component is purely presentational; state management is external
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