diff --git a/react-openapi/components/FilterBar.tsx b/react-openapi/components/FilterBar.tsx index ba40068..fd7f3a3 100644 --- a/react-openapi/components/FilterBar.tsx +++ b/react-openapi/components/FilterBar.tsx @@ -11,7 +11,7 @@ import { import DoneIcon from "@mui/icons-material/Done"; import FilterListIcon from "@mui/icons-material/FilterList"; import { ResourceField, ResourceMode } from "../types/config"; -import { FilterBarComponents } from "../types/overrides"; +import { FilterBarComponents, FieldComponents } from "../types/overrides"; import { getFieldOptions, resolveTemplate } from "../utils/options"; export function FilterAutocomplete({ @@ -158,6 +158,7 @@ function renderFilterInput( value: any, onChange: (key: string, val: any) => void, components?: FilterBarComponents, + fieldComponents?: FieldComponents, ) { const CustomInput = components?.filterInputs?.[fieldName]; if (CustomInput) { @@ -167,6 +168,16 @@ function renderFilterInput( const filterType = field.filterType; if (filterType === "number-range") { + const NumberComponent = fieldComponents?.number; + if (NumberComponent) { + const rangeVal = (value as { min?: string; max?: string }) || {}; + return ( + + onChange("min", val === "" ? undefined : val)} /> + onChange("max", val === "" ? undefined : val)} /> + + ); + } const rangeVal = (value as { min?: string; max?: string }) || {}; return ( @@ -179,17 +190,35 @@ function renderFilterInput( } if (filterType === "date-range") { + const DateComponent = fieldComponents?.date; + if (DateComponent) { + const rangeVal = (value as { start?: string; end?: string }) || {}; + const dateField = { ...field, type: 'date' as const }; + return ( + + onChange("start", val || undefined)} /> + onChange("end", val || undefined)} /> + + ); + } const rangeVal = (value as { start?: string; end?: string }) || {}; return ( - onChange("start", e.target.value || undefined)} InputLabelProps={{ shrink: true }} sx={{ width: 170 }} /> - onChange("end", e.target.value || undefined)} InputLabelProps={{ shrink: true }} sx={{ width: 170 }} /> ); } + const FormFieldComponent = fieldComponents?.FormField; + if (FormFieldComponent) { + return ( + onChange("value", val)} /> + ); + } + const selected = Array.isArray(value) ? value : []; return ( @@ -211,6 +240,7 @@ export interface FilterBarProps { onApply: (values: Record) => void; onClear: () => void; components?: FilterBarComponents; + fieldComponents?: FieldComponents; } export default function FilterBar({ @@ -221,6 +251,7 @@ export default function FilterBar({ onApply, onClear, components: filterComponents, + fieldComponents, }: FilterBarProps) { const [open, setOpen] = React.useState(false); const [draft, setDraft] = React.useState>(() => ({ ...appliedValues })); @@ -298,7 +329,7 @@ export default function FilterBar({ {field.label} {renderFilterInput(fieldName, field, options, raw, (key, val) => - updateDraft(fieldName, key, val), filterComponents + updateDraft(fieldName, key, val), filterComponents, fieldComponents )} ); diff --git a/react-openapi/components/ResourceView.tsx b/react-openapi/components/ResourceView.tsx index d12fe2f..e270713 100644 --- a/react-openapi/components/ResourceView.tsx +++ b/react-openapi/components/ResourceView.tsx @@ -184,6 +184,7 @@ export default function ResourceView({ config, onNavigateToResource, fieldCompon appliedValues={appliedFilters} onApply={setAppliedFilters} onClear={() => setAppliedFilters({})} + fieldComponents={components} /> )} > & { relation?: FieldComponent; image?: FieldComponent; default?: FieldComponent; + FormField?: React.ComponentType; + GenericForm?: React.ComponentType; }; export interface CellRendererProps { diff --git a/src/ReportSnapshots.tsx b/src/ReportSnapshots.tsx index bde7a37..671a98e 100644 --- a/src/ReportSnapshots.tsx +++ b/src/ReportSnapshots.tsx @@ -4,7 +4,6 @@ import { Container, Paper, Typography, - TextField, Button, IconButton, CircularProgress, @@ -15,8 +14,6 @@ import { DialogContent, DialogContentText, DialogActions, - Switch, - FormControlLabel, Chip, } from "@mui/material"; import DeleteIcon from "@mui/icons-material/Delete"; @@ -125,22 +122,17 @@ export default function ReportSnapshots() { - {ignoreSelfField && components?.FormField ? ( + {ignoreSelfField && components?.FormField && ( setIgnoreSelf(val)} /> - ) : ( - setIgnoreSelf(e.target.checked)} />} - label="Ignore self-transfers" - /> )} - {startDateField && components?.datetime ? ( + {startDateField && components?.datetime && ( setStartDate(val)} /> - ) : ( - setStartDate(e.target.value)} - size="small" - InputLabelProps={{ shrink: true }} - sx={{ flex: 1 }} - /> )} - {endDateField && components?.datetime ? ( + {endDateField && components?.datetime && ( setEndDate(val)} /> - ) : ( - setEndDate(e.target.value)} - size="small" - InputLabelProps={{ shrink: true }} - sx={{ flex: 1 }} - /> )} - {minAmountField && components?.FormField ? ( + {minAmountField && components?.FormField && ( setMinAmount(val)} /> - ) : ( - setMinAmount(e.target.value)} - size="small" - sx={{ flex: 1 }} - /> )} - {maxAmountField && components?.FormField ? ( + {maxAmountField && components?.FormField && ( setMaxAmount(val)} /> - ) : ( - setMaxAmount(e.target.value)} - size="small" - sx={{ flex: 1 }} - /> )} diff --git a/src/openapi-config.ts b/src/openapi-config.ts index d5e9861..98d7179 100644 --- a/src/openapi-config.ts +++ b/src/openapi-config.ts @@ -4,7 +4,7 @@ export const configuration: Record = { expenses: { filterOptions: { mode: "client", - fields: ["account", "payee", "tags", "occurred_at", "amount"], + fields: ["account", "payee.name", "tags", "occurred_at", "amount"], }, fields: { payee: { @@ -57,12 +57,12 @@ export const configuration: Record = { format: { path: 'source.format', }, - account: { - refers: 'accounts', - }, - tags: { - refers: 'tags', - }, + // account: { + // refers: 'accounts', + // }, + // tags: { + // refers: 'tags', + // }, }, }, accounts: {