# Layout and Page Patterns
This document describes the page layout patterns used in konflux-ui and how to compose new pages.
## Page Types
Every page in the application follows one of four patterns:
1. **List Page** -- Table with filters, toolbar, and empty states
2. **Detail Page** -- Tabs, breadcrumbs, actions dropdown
3. **Form Page** -- Create/edit form with validation and submission
4. **Modal Workflow** -- Dialog-based operations (delete, confirm)
## Layout Components
### `PageLayout` -- List and Form Pages
Location: `src/components/PageLayout/PageLayout.tsx`
Used for pages without tabs (list views, form pages). Renders a title bar with optional actions.
```tsx
import PageLayout from '~/components/PageLayout/PageLayout';
navigate(createPath),
disabled: !canCreate,
disabledTooltip: 'You do not have permission to create secrets',
},
]}
footer={} {/* Optional: for form pages */}
>
{children}
```
### `DetailsPage` -- Detail Pages with Tabs
Location: `src/components/DetailsPage/DetailsPage.tsx`
Used for resource detail views. Renders breadcrumbs, title, actions dropdown, and router-synced tabs.
```tsx
import DetailsPage from '~/components/DetailsPage/DetailsPage';
{resourceName}
}
breadcrumbs={[
...applicationBreadcrumbs,
{ path: listPath, name: 'My Resources' },
{ path: '#', name: resourceName },
]}
actions={[
{ key: 'edit', label: 'Edit', onClick: handleEdit },
{ type: 'separator', key: 'sep-1', label: '' },
{
key: 'delete',
label: 'Delete',
onClick: handleDelete,
isDisabled: !canDelete,
disabledTooltip: 'You do not have permission to delete this resource',
},
]}
tabs={[
{ key: '', label: 'Overview', isFilled: true }, // index route
{ key: 'pipelineruns', label: 'Pipeline runs', isFilled: true },
{ key: 'activity', label: 'Activity', partial: true }, // matches /activity/*
]}
baseURL={baseURL}
/>;
```
**Action type for DetailsPage:**
```ts
type Action = {
key: string;
label: React.ReactNode;
onClick?: () => void;
component?: React.ReactElement; // For Link-based actions
isDisabled?: boolean;
disabledTooltip?: React.ReactNode;
type?: 'separator' | 'section-label'; // Structural items
hidden?: boolean; // Conditionally hide
};
```
**Tab type:**
```ts
type DetailsPageTabProps = {
key: string; // Route path segment ('' for index)
label: string; // Tab display text
isFilled?: boolean; // Tab content fills remaining height
partial?: boolean; // Match any path starting with key
featureFlag?: string; // Show flag indicator badge
};
```
### `TabsLayout` -- Router-Synced Tabs
Location: `src/components/TabsLayout/TabsLayout.tsx`
Used inside `DetailsPage`. Renders PatternFly Tabs wired to React Router. Each tab renders `` for its child route content.
```tsx
// Tab navigation is automatic -- TabsLayout reads location.pathname
// and matches it against the basePath + tab keys
navigate(`${basePath}/${key}`)}
mountOnEnter
unmountOnExit
>
```
Always use `mountOnEnter` and `unmountOnExit` to avoid rendering inactive tab content.
## Page Patterns
### List Page Pattern
```
FilterContextProvider filterParams={['name', 'status']}
|
+-- PageLayout (title, description, actions)
|
+-- PageSection isFilled variant="light"
|
+-- BaseTextFilterToolbar
| +-- SearchInput (debounced)
| +-- Primary action button (ButtonWithAccessTooltip)
|
+-- Table (when data exists)
| +-- Header: getMyFeatureHeader()
| +-- Row: MyFeatureListRow
|
+-- FilteredEmptyState (filtered to zero results)
+-- AppEmptyState (no data at all)
```
Key behaviors:
- Filter state lives in URL via `useSearchParamBatch`.
- `FilterContextProvider` declares which params are tracked.
- Primary action button uses `ButtonWithAccessTooltip` for RBAC gating.
- Loading state returns early: ``.
### Detail Page Pattern
```
MyFeatureDetailsView (parent route element)
|
+-- DetailsPage
+-- breadcrumbs: useApplicationBreadcrumbs() + resource-specific
+-- title: complex JSX with status icon
+-- actions: Action[] (dropdown items)
+-- tabs: DetailsPageTabProps[]
+-- TabsLayout ->
+-- index -> MyFeatureOverviewTab
+-- 'pipelineruns' -> PipelineRunsListView
+-- 'activity/:activityTab' -> ActivityTab
```
**Overview tab content structure:**
```tsx
const MyFeatureOverviewTab: React.FC = () => (
<>
Resource details
Name
{resource.metadata.name}
{/* More fields... */}
{/* Second column */}
>
);
```
#### Tab data-fetching responsibilities
When implementing tabs within a detail view, split responsibilities cleanly between the **tab container** and the **tab content**:
- **Tab container (route-level component):** Fetches the primary resource, handles the loading spinner, error empty state, and not-found case. It only renders the tab content component once data is fully resolved and guaranteed valid. Examples: `VulnerabilitiesTab`, `PipelineRunVulnerabilitiesTab`.
- **Tab content (presentational component):** Receives guaranteed non-null resource props. It focuses on display logic rather than the fetch lifecycle of the primary resource. It may perform secondary queries (such as fetching reports or child resources), but it must not duplicate the tab container's loading or error handling for the primary resource. Example: `VulnerabilitiesTabContent`.
**Before (anti-pattern):** The tab content component accepts nullable or optional props and handles all fetch lifecycle states internally:
```tsx
// Before: tab content handles primary fetch lifecycle and nullable resource
type VulnerabilitiesTabContentProps = {
taskRun?: TaskRunKind;
loaded?: boolean;
error?: unknown;
};
export const VulnerabilitiesTabContent: React.FC = ({
taskRun,
loaded,
error,
}) => {
if (!loaded) {
return (
);
}
if (error || !taskRun) {
return getErrorState(error ?? { code: 404, message: 'Task run not found' }, loaded, 'task run');
}
return (
);
};
```
**After (recommended pattern):** The tab container resolves the resource and handles states; the tab content receives a guaranteed non-null resource:
```tsx
// After: tab container handles loading, error, and not-found states
export const VulnerabilitiesTab: React.FC = () => {
const { taskRunName = '' } = useParams();
const namespace = useNamespace();
const [taskRun, taskRunLoaded, taskRunError] = useTaskRunV2(namespace, taskRunName);
if (!taskRunLoaded) {
return (
);
}
if (taskRunError) {
return getErrorState(taskRunError, taskRunLoaded, 'task run');
}
if (!taskRun) {
return getErrorState({ code: 404, message: 'Task run not found' }, true, 'task run');
}
return ;
};
// Tab content receives guaranteed non-null resource props
type VulnerabilitiesTabContentProps = {
taskRun: TaskRunKind;
};
export const VulnerabilitiesTabContent: React.FC = ({
taskRun,
}) => {
const { data, isLoading, error } = useRoxctlCveReport(taskRun);
if (isLoading) {
return (
);
}
if (error) {
return getErrorState(error, !isLoading, 'vulnerabilities');
}
return (
);
};
```
**Scope and exceptions:** This pattern applies to detail-view tabs where the tab container represents a distinct route responsible for resolving its primary resource before rendering. Whether this pattern applies universally across all tabs in the application is currently an open question; detail-view tabs must always adhere to this container/content separation. For other tab types or self-contained workflows, evaluate whether hoisting data fetching and lifecycle states to a separate container provides a cleaner design or unnecessary indirection.
### Form Page Pattern
```
MyFeatureView (Formik wrapper)
|
+-- Formik initialValues, validationSchema, handleSubmit
|
+-- MyFeatureForm (form fields)
|
+-- PageLayout (breadcrumbs, title, footer=)
|
+-- PageSection isFilled variant="light"
|
+--