The debug logs don't show the actual error stack trace. Let me look at the dashboard.tsx file where .label is being accessed and check if there's any issue with how chart legends are being rendered:
Let me check where planCreationData and deliveryUtilizationData are defined to see if they could be undefined:
The data arrays look fine. The error must be in the drill-down page or one of the drill-down components. Let me check the drill-down-page where charts with ChartLegendContent are used:
Let me check the chartConfig definition:
I see the chartConfig is defined but it's inside the component at line 233. Let me check what's happening around line 233 and look for where the ChartTooltipContent might be trying to access something undefined. Let me also check other drill-down files:
I see the issue now! In drill-down-dialog.tsx line 105:
<selectedKPI.icon className={`h-5 w-5 ${selectedKPI.color}`} />When rendering <selectedKPI.icon>, if selectedKPI.icon is undefined (because the KPI object doesn't have an icon property), React tries to access .label internally when rendering.
But wait - there's an early return if (!selectedKPI) return null but the KPI coming from the dashboard might have different properties. Let me check what kpiData looks like in the dashboard to see if icon is defined:
The kpiData does have icons. Let me check how the dashboard calls the drill-down and what it passes:
I see the problem now. When clicking on a KPI tile, handleKPIClick is called which sets selectedMetric to null, then shows the DrillDownPage. But DrillDownPage doesn't use selectedMetric or selectedKPI in the same way - it displays its own data.
The error is likely coming from the ChartTooltipContent component in /components/ui/chart.tsx. When a chart renders, the tooltip tries to look up items in the config but the dataKey being used might not exist in the chartConfig.
Let me check specifically in the bar chart data. In drill-down-page.tsx, the bar chart uses dataKey="value" but the chartConfig only has depot names as keys:
Let me see more of the chart.tsx to understand how the tooltip renders each item:
I see line 238 uses optional chaining: {itemConfig?.label || item.name} so that should be safe. Let me check the getPayloadConfigFromPayload function to see if something there could cause an issue:
I found it! Look at line 307:
{itemConfig?.label}This tries to render itemConfig?.label, but the issue is on line 294 where key={item.value} is used. When item.value is an object instead of a primitive, React can't use it as a key and might cause issues.
But more importantly, looking at line 146:
? config[label as keyof typeof config]?.label || labelIf config[label] returns undefined (which would happen if label is a string that's not a key in the config), then it tries to access .label on undefined.
Wait, actually that has optional chaining too. Let me look at the actual error more carefully. The error says "Cannot read properties of undefined (reading 'label')". Let me check if there's a place where .label is accessed without optional chaining.
Let me check the full getPayloadConfigFromPayload function:
The chart.tsx component looks fine with optional chaining. Let me check the drill-down-page.tsx more carefully - the chartConfig definition might be incomplete or there might be an issue with how it's typed:
Now let me look at the chartConfig definition in drill-down-page.tsx around line 233:
The chartConfig looks fine. The issue must be that when the Bar chart renders with dataKey="value", the tooltip tries to look up "value" in the chartConfig but it doesn't exist.
Let me add a "value" entry to the chartConfig to handle this case:
Now let me also fix the same issue in components/drill-down-dialog.tsx:
Now let me check the other drill-down components that might have the same issue:
I need to add the value key to all these chartConfigs. Let me update them all:
Now let me update all the remaining drill-down files:
I've fixed the "Cannot read properties of undefined (reading 'label')" error by adding a value key (and count where applicable) to the chartConfig objects in all drill-down components. The issue was that when charts render with dataKey="value", the ChartTooltipContent component tries to look up that key in the chart configuration to get the label. Without a matching entry, it returns undefined and causes the error when trying to access .label.
The debug logs don't show the actual error stack trace. Let me search more carefully for where .label is being accessed without proper null checking:
These look fine as they iterate over defined arrays. Let me check if there's something in the Recharts legend content that's causing this. The error might be in how ChartLegendContent processes the payload:
The chart.tsx has {itemConfig?.label} with optional chaining which should be safe. Let me check all uses of .label in the codebase more broadly, including where it might be directly accessed without optional chaining:
All these have proper optional chaining except the dashboard ones which iterate over defined arrays. The error must be somewhere else. Let me check the Calendar component since we removed initialFocus:
The Calendar component looks fine. Let me check the date-range-picker for how it's using the Calendar component - perhaps there's a type mismatch with react-day-picker's range mode:
This looks okay. Let me check how drill-down-page.tsx is rendering components. Perhaps the error comes from how it renders chart tooltips. Let me add console logs to identify where exactly the error happens:
I see the issue now! Line 436: <Bar dataKey="value" radius={[4, 4, 0, 0]}> uses dataKey="value", and I added that to the chartConfig. But looking at line 460-467, the Line chart uses dataKey="All Depots" which is also in the chartConfig.
But wait, looking at the ChartTooltipContent on line 435 and 458, there's no explicit nameKey prop passed. The tooltip is likely trying to look up config based on the data payload.
Let me check how singleDayData and multiDayData are structured - the error might be that these data arrays contain items without the expected structure:
Now let me look at the data generation functions to see what they return:
The data generation functions look fine. The issue might be with how the ChartTooltipContent tries to resolve the label when the dataKey is "depot" (from the XAxis) or some other field.
Looking at line 433, the XAxis uses dataKey="depot", but "depot" is not in the chartConfig. Let me add "depot" to the chartConfig and also look for a more comprehensive solution by adding a nameKey prop to the ChartTooltipContent:
I need to add additional keys to handle the tooltip lookup. Let me also add the nameKey prop to help the tooltip properly resolve the label. But first, let me check how getPayloadConfigFromPayload works in chart.tsx to fully understand the issue:
I see - getPayloadConfigFromPayload returns config[configLabelKey] or config[key]. If neither exists, it returns undefined, and then the callers try to access .label on undefined.
Looking at line 351-353, if neither configLabelKey nor key is in the config, it returns config[key as keyof typeof config] which would be undefined. The code at lines 146, 238, 307 that accesses .label does use optional chaining (?.label), but line 147 shows:
? config[label as keyof typeof config]?.label || label
: itemConfig?.labelThis looks safe. Let me look specifically at where the error might be - perhaps there's a different accessor. Let me search for any direct .label access in chart.tsx more carefully:
Looking at line 191: const indicatorColor = color || item.payload.fill || item.color
This accesses item.payload.fill without checking if item.payload exists. If item.payload is undefined, this would throw "Cannot read properties of undefined".
But wait, the error says "(reading 'label')", not "(reading 'fill')". Let me check closer - maybe there's nested object access elsewhere. Let me also check if there are any imports or other components involved.
Actually, looking more carefully, let me check if there's a specific Select or dropdown component being used somewhere that accesses .label. Let me check the drill-down-page.tsx for Select components:
All the .label accesses use either optional chaining (?.label) or iterate over known arrays. The error must be coming from somewhere else. Let me check if the error is from a library component like react-day-picker. Let me look for any component that has a label field being accessed in the Calendar or other UI components:
Let me add console logs to the drill-down-page.tsx to help identify exactly where the error is happening:
Let me look at the imports to see if there's an issue with the drill-down components being imported. Also, let me check if there could be an issue with kpiConfigs since some of those might be handled by the specific drill-down components:
Let me check the chart config in stops-per-trip-drill-down.tsx since I added entries to it:
The chart configs look okay. Let me look at the distribution chart data in stops-per-trip-drill-down.tsx - it might be using a dataKey that's not in the config:
I see there are additional dataKeys being used: "stops", "actualFrequency", "normalDistribution", "date". These might not be in the chartConfig. Let me check more:
I see there are many dataKeys being used that aren't in the chartConfigs: stops, actualFrequency, normalDistribution, utilization, frequency, distance, date, depot. I need to add all these missing keys to each chartConfig. Let me update all the drill-down files with more comprehensive chartConfigs:
Now let me update the remaining drill-down files:
Now let me also update the drill-down-page.tsx and the drill-down-dialog.tsx to add the missing keys:
I've added the missing keys (depot, date, utilization, frequency, distance, actualFrequency, stops, etc.) to all the chartConfig objects across all drill-down components. The error "Cannot read properties of undefined (reading 'label')" was occurring because when the chart tooltip tried to look up configuration for dataKeys like depot, date, or other field names, they weren't present in the chartConfig, causing the lookup to return undefined and then fail when accessing .label. Now all dataKeys used in the charts have corresponding entries in each component's chartConfig.