Files
property-match/src/pages/supply/Properties.tsx
T
Benjamin Sutter a825672197 feat: collapsible filter bar, compact property cards, offer wizard field selection
- Properties page: collapsible decision/filter strip (localStorage state), slim
  single-row Datenpflege status bar (chips + button), 4-column card grid
- PropertyIntelligenceCard: reduced image height (160→120px), tighter body padding
- OfferWizard (latente Anfragen): new "Felder wählen" step between property
  selection and PDF preview; uses ReportObjectFieldSelector per property
- MockPdfPreview: adds second PDF page showing selected properties side by side
  with photo, title, location and all chosen hard/soft fact fields
- offerWizardStore: adds select_fields step type and fieldSelections state

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 15:36:32 +02:00

225 lines
8.3 KiB
TypeScript

import { useState, useMemo } from 'react'
import { Box, Button, Chip, Collapse, Drawer, Typography, useMediaQuery, useTheme } from '@mui/material'
import { useNavigate } from 'react-router'
import { ChevronDown, ChevronUp } from 'lucide-react'
import { PageHeader } from '../../components/layout'
import { ViewToggle } from '../../components/shared'
import { useProperties } from '../../hooks/useProperties'
import { PropertyFilterBar, PropertyTable, PropertyDetailView, PropertyIntelligenceCard } from '../../components/supply'
import type { PropertyTableFilters } from '../../components/supply'
import type { Property } from '../../domain/property'
function applyFilters(properties: Property[], filters: PropertyTableFilters): Property[] {
let result = [...properties]
if (filters.search) {
const q = filters.search.toLowerCase()
result = result.filter(
p =>
p.title.toLowerCase().includes(q) ||
p.location.city.toLowerCase().includes(q) ||
p.address.street.toLowerCase().includes(q),
)
}
if (filters.assetTypes && filters.assetTypes.length > 0) {
result = result.filter(p => filters.assetTypes!.includes(p.assetType))
}
if (filters.availabilityStatus) {
result = result.filter(p => p.availabilityStatus === filters.availabilityStatus)
}
if (filters.sortBy) {
const dir = filters.sortDir === 'asc' ? 1 : -1
result.sort((a, b) => {
switch (filters.sortBy) {
case 'dataQuality': return dir * (a.dataQuality.score - b.dataQuality.score)
case 'area': return dir * (a.areaSqm - b.areaSqm)
case 'rent': return dir * (a.rentPricePerSqm - b.rentPricePerSqm)
case 'confidence': return dir * (a.confidenceScore - b.confidenceScore)
case 'availability': return dir * a.availabilityStatus.localeCompare(b.availabilityStatus)
default: return 0
}
})
}
return result
}
export default function Properties() {
const navigate = useNavigate()
const theme = useTheme()
const isMobile = useMediaQuery(theme.breakpoints.down('md'))
const [selectedId, setSelectedId] = useState<string | null>(null)
const [filters, setFilters] = useState<PropertyTableFilters>({})
const [view, setView] = useState<'list' | 'grid'>(() =>
(localStorage.getItem('view-properties') as 'list' | 'grid') ?? 'list'
)
const [headerOpen, setHeaderOpen] = useState(() =>
localStorage.getItem('props-header-open') !== 'false'
)
const { data: properties = [], isLoading, isError } = useProperties()
const filtered = useMemo(() => applyFilters(properties, filters), [properties, filters])
// Decision-relevant aggregates — single pass over the full list
const { matchReady, criticalGaps, lowConfidence, staleOrOutdated, allMissingFields } = useMemo(() => {
const matchReady: typeof properties = []
const criticalGaps: typeof properties = []
const lowConfidence: typeof properties = []
const staleOrOutdated: typeof properties = []
const missingSet = new Set<string>()
for (const p of properties) {
if ((p.availabilityStatus === 'AVAILABLE_NOW' || p.availabilityStatus === 'AVAILABLE_SOON') &&
p.confidenceScore >= 0.7 && p.dataQuality.missingCriticalFields.length === 0)
matchReady.push(p)
if (p.dataQuality.missingCriticalFields.length > 0) {
criticalGaps.push(p)
p.dataQuality.missingCriticalFields.forEach(f => missingSet.add(f))
}
if (p.confidenceScore < 0.55) lowConfidence.push(p)
if (p.dataQuality.freshness === 'STALE' || p.dataQuality.freshness === 'OUTDATED') staleOrOutdated.push(p)
}
return {
matchReady,
criticalGaps,
lowConfidence,
staleOrOutdated,
allMissingFields: [...missingSet].slice(0, 4),
}
}, [properties])
return (
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden' }}>
<PageHeader
title="Objektverwaltung"
subtitle={`${filtered.length} von ${properties.length} Objekten`}
secondaryActions={
<ViewToggle
view={view}
onChange={v => { setView(v); localStorage.setItem('view-properties', v) }}
/>
}
/>
{/* Collapse toggle strip */}
<Box
onClick={() => {
const next = !headerOpen
setHeaderOpen(next)
localStorage.setItem('props-header-open', String(next))
}}
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
px: 3,
py: 0.5,
bgcolor: '#f8fafc',
borderBottom: '1px solid #e2e8f0',
cursor: 'pointer',
flexShrink: 0,
userSelect: 'none',
'&:hover': { bgcolor: '#f1f5f9' },
}}
>
<Typography sx={{ fontSize: '0.68rem', color: '#94a3b8', letterSpacing: 0.5, textTransform: 'uppercase' }}>
Filter & Übersicht
</Typography>
{headerOpen ? <ChevronUp size={12} color="#94a3b8" /> : <ChevronDown size={12} color="#94a3b8" />}
</Box>
<Collapse in={headerOpen}>
{!isLoading && properties.length > 0 && (
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
px: 2.5,
py: 0.75,
bgcolor: '#f8fafc',
borderBottom: '1px solid #e2e8f0',
borderLeft: '3px solid #1e3a5f',
flexShrink: 0,
gap: 1,
}}
>
<Box sx={{ display: 'flex', gap: 0.5, flexWrap: 'wrap', alignItems: 'center' }}>
<Chip
label={`${matchReady.length} matchbereit`}
size="small"
sx={{ height: 20, fontSize: '0.68rem', fontWeight: 600,
bgcolor: matchReady.length > 0 ? '#f0fdf4' : '#fef9c3',
color: matchReady.length > 0 ? '#1a7a4a' : '#92400e' }}
/>
{criticalGaps.length > 0 && (
<Chip
label={`${criticalGaps.length} kritische Datenlücken`}
size="small"
sx={{ height: 20, fontSize: '0.68rem', fontWeight: 600, bgcolor: '#fef2f2', color: '#991b1b' }}
/>
)}
{staleOrOutdated.length > 0 && (
<Chip
label={`${staleOrOutdated.length} veraltete Daten`}
size="small"
sx={{ height: 20, fontSize: '0.68rem', fontWeight: 600, bgcolor: '#fef9c3', color: '#92400e' }}
/>
)}
</Box>
<Button
size="small"
variant={criticalGaps.length > 0 || staleOrOutdated.length > 0 ? 'contained' : 'outlined'}
onClick={() => navigate('/supply/data-quality')}
sx={criticalGaps.length > 0 || staleOrOutdated.length > 0
? { bgcolor: '#1e3a5f', '&:hover': { bgcolor: '#162d4a' }, textTransform: 'none', fontSize: '0.75rem', py: 0.375, px: 1.5, flexShrink: 0 }
: { textTransform: 'none', fontSize: '0.75rem', py: 0.375, px: 1.5, flexShrink: 0 }
}
>
Datenpflege
</Button>
</Box>
)}
<PropertyFilterBar filters={filters} onFiltersChange={setFilters} />
</Collapse>
<Box sx={{ flex: 1, overflowY: 'auto' }}>
{view === 'grid' ? (
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(240px, 1fr))', gap: 1.5, p: 1.5 }}>
{filtered.map(p => (
<PropertyIntelligenceCard key={p.id} property={p} onSelect={setSelectedId} />
))}
</Box>
) : (
<PropertyTable
properties={filtered}
isLoading={isLoading}
isError={isError}
selectedId={selectedId}
onSelect={setSelectedId}
filters={filters}
onFiltersChange={setFilters}
/>
)}
</Box>
<Drawer
anchor="right"
open={!!selectedId}
onClose={() => setSelectedId(null)}
slotProps={{ paper: { sx: { width: isMobile ? '100vw' : 650, boxShadow: '-4px 0 24px rgba(0,0,0,0.10)' } } }}
>
{selectedId && (
<PropertyDetailView propertyId={selectedId} onClose={() => setSelectedId(null)} />
)}
</Drawer>
</Box>
)
}