Skip to content

Commit 58d2be8

Browse files
committed
feat(dashboard): default Custom date range to yesterday-today
1 parent 6240b98 commit 58d2be8

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

webview-ui/src/components/dashboard/DashboardView.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ const DashboardView = memo(({ onDone }: DashboardViewProps) => {
5656
const [clearNonce, setClearNonce] = useState<string | null>(null)
5757

5858
// Custom range date inputs (YYYY-MM-DD). Only used when preset === "custom".
59-
const [customFrom, setCustomFrom] = useState<string>("")
60-
const [customTo, setCustomTo] = useState<string>("")
59+
// Default to yesterday~today so the inputs are never empty on first selection.
60+
const toLocalDateString = useCallback((d: Date) => {
61+
const year = d.getFullYear()
62+
const month = String(d.getMonth() + 1).padStart(2, "0")
63+
const day = String(d.getDate()).padStart(2, "0")
64+
return `${year}-${month}-${day}`
65+
}, [])
66+
67+
const defaultDateRange = useMemo(() => {
68+
const now = new Date()
69+
const yesterday = new Date(now)
70+
yesterday.setDate(now.getDate() - 1)
71+
return { from: toLocalDateString(yesterday), to: toLocalDateString(now) }
72+
}, [toLocalDateString])
73+
74+
const [customFrom, setCustomFrom] = useState<string>(defaultDateRange.from)
75+
const [customTo, setCustomTo] = useState<string>(defaultDateRange.to)
6176

6277
// Track the latest request to ignore stale responses
6378
const latestRequestIdRef = useRef<string>("")

0 commit comments

Comments
 (0)