Skip to content

Commit

Permalink
Do not throw on tab not found
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Dec 16, 2024
1 parent 5b05174 commit 99801e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const meta: Meta<typeof DaiSavingsCharts> = {
error: null,
},
shouldDisplayMyEarnings: true,
selectedTimeframe: 'All',
selectedTimeframe: '1M',
setSelectedTimeframe: () => {},
availableTimeframes: MY_EARNINGS_TIMEFRAMES,
},
Expand Down
8 changes: 6 additions & 2 deletions packages/app/src/ui/charts/components/ChartTabsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Panel } from '@/ui/atoms/panel/Panel'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/ui/atoms/tabs/Tabs'
import { useResizeObserver } from '@/ui/utils/useResizeObserver'
import { assert } from '@/utils/assert'
import { raise } from '@marsfoundation/common-universal'
import { AlertTriangle, Loader2 } from 'lucide-react'
import { useRef, useState } from 'react'
import { Timeframe } from '../defaults'
Expand Down Expand Up @@ -59,7 +58,12 @@ export function ChartTabsPanel({ tabs, height = 300 }: ChartTabsPanelProps) {
assert(firstTab, 'ChartTabsPanel: at least 1 tab is required')

const [selectedTabId, setSelectedTabId] = useState(firstTab.id)
const selectedTab = tabs.find((tab) => tab.id === selectedTabId) ?? raise('ChartTabsPanel: selectedTab not found')
if (!tabs.some((tab) => tab.id === selectedTabId)) {
// If selectedTabId is not found, set it to the first tab.
// This is possible when the list of tabs is updated.
setSelectedTabId(firstTab.id)
}
const selectedTab = tabs.find((tab) => tab.id === selectedTabId) ?? firstTab

if (tabs.length === 1) {
const { selectedTimeframe, setSelectedTimeframe, availableTimeframes } = firstTab
Expand Down

0 comments on commit 99801e3

Please sign in to comment.