Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions src/components/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,24 @@ function ActiveFilterChips() {
)
}

type ListPageToolbarProps = {
hideFilter?: boolean
hideColumns?: boolean
hideDensity?: boolean
hideExport?: boolean
}

// Toolbar inside the DataGrid:
// - Row 1 (right-aligned): filter, columns, density, export buttons
// - Row 2 (only when filters are active): dismissible filter chips
// The search input lives OUTSIDE the DataGrid to avoid focus-loss on re-render.
// Built-in toolbar buttons are used (not custom icon buttons) so panels anchor correctly.
function ListPageToolbar() {
function ListPageToolbar({
hideFilter = false,
hideColumns = false,
hideDensity = false,
hideExport = false,
}: ListPageToolbarProps) {
return (
<GridToolbarContainer
sx={{
Expand All @@ -91,25 +103,39 @@ function ListPageToolbar() {
}}
>
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 0.5 }}>
<GridToolbarFilterButton
slotProps={{
button: { 'data-testid': 'grid-toolbar-filter-button' },
}}
/>
<GridToolbarColumnsButton
slotProps={{
button: { 'data-testid': 'grid-toolbar-columns-button' },
}}
/>
<GridToolbarDensitySelector
slotProps={{
button: { 'data-testid': 'grid-toolbar-density-selector' },
}}
/>
<GridToolbarExport
slotProps={{ button: { 'data-testid': 'grid-toolbar-export' } }}
/>
{!hideFilter && (
<GridToolbarFilterButton
slotProps={{
button: { 'data-testid': 'grid-toolbar-filter-button' },
}}
/>
)}

{!hideColumns && (
<GridToolbarColumnsButton
slotProps={{
button: { 'data-testid': 'grid-toolbar-columns-button' },
}}
/>
)}

{!hideDensity && (
<GridToolbarDensitySelector
slotProps={{
button: { 'data-testid': 'grid-toolbar-density-selector' },
}}
/>
)}

{!hideExport && (
<GridToolbarExport
slotProps={{
button: { 'data-testid': 'grid-toolbar-export' },
}}
/>
)}
</Box>

<ActiveFilterChips />
</GridToolbarContainer>
)
Expand All @@ -128,6 +154,7 @@ type ListPageProps = {
headerButtons?: any
disableRowClick?: boolean

toolbarOptions?: ListPageToolbarProps
searchMode?: 'client' | 'server'
searchValue?: string
onSearchChange?: (value: string) => void
Expand All @@ -148,6 +175,8 @@ export const ListPage: React.FC<ListPageProps> = ({
isLoading,
headerButtons,
disableRowClick = false,

toolbarOptions,
searchMode = 'client',
searchValue,
onSearchChange,
Expand Down Expand Up @@ -221,6 +250,10 @@ export const ListPage: React.FC<ListPageProps> = ({
}
}

const toolbarConfig = {
hideExport: restDataGridProps.paginationMode === 'server',
}

return (
<CanAccess>
<List
Expand Down Expand Up @@ -332,6 +365,12 @@ export const ListPage: React.FC<ListPageProps> = ({
showToolbar
slots={{ toolbar: ListPageToolbar }}
slotProps={{
toolbar: {
...toolbarOptions,
hideExport:
toolbarOptions?.hideExport ??
restDataGridProps.paginationMode === 'server',
},
loadingOverlay: {
variant: 'linear-progress',
noRowsVariant: 'skeleton',
Expand Down
7 changes: 5 additions & 2 deletions src/pages/ocotillo/thing/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export const WellList: React.FC = () => {
id: contact.id,
},
}}
onClick={(e) => e.stopPropagation()}
onClick={(e: React.MouseEvent<HTMLAnchorElement>) =>
e.stopPropagation()
}
>
{contact.name}
</Link>
Expand All @@ -265,7 +267,8 @@ export const WellList: React.FC = () => {
{
field: 'well_driller_name',
headerName: WellListColumnLabels.driller,
description: 'Drilling company name when it was recorded for this well.',
description:
'Drilling company name when it was recorded for this well.',
type: 'string',
minWidth: 150,
flex: 1,
Expand Down
Loading