fix: reset stale price analysis selection

This commit is contained in:
2026-09-06 16:34:58 +03:00
parent f647e037c7
commit 42088cf5f0
2 changed files with 10 additions and 1 deletions
+5 -1
View File
@@ -1,4 +1,4 @@
import React, { useState, useMemo } from 'react';
import React, { useState, useMemo, useEffect } from 'react';
import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, Cell } from 'recharts';
import { TrendingUp, Download, Sparkles, Inbox } from 'lucide-react';
import { useApp } from '../../context/AppContext';
@@ -10,6 +10,10 @@ export const PriceAnalysis = () => {
const { items, itemCount, uniqueItems } = useMemo(() => itemStats(tenders), [tenders]);
const [selectedKey, setSelectedKey] = useState(null);
useEffect(() => {
if (selectedKey && !items.some((item) => `${item.ad}||${item.birim}` === selectedKey)) setSelectedKey(null);
}, [items, selectedKey]);
const selected = useMemo(() => {
if (!items.length) return null;
const found = items.find((i) => `${i.ad}||${i.birim}` === selectedKey);