(chartId, projectId)
| 104 | |
| 105 | // Function to fetch chart data when a chart is created |
| 106 | const fetchChartData = async (chartId, projectId) => { |
| 107 | try { |
| 108 | const result = await dispatch(getChart({ |
| 109 | project_id: projectId, |
| 110 | chart_id: chartId |
| 111 | })); |
| 112 | |
| 113 | if (result?.payload) { |
| 114 | setCreatedCharts(prevCharts => { |
| 115 | // Check if chart already exists |
| 116 | const existingIndex = prevCharts.findIndex(c => c.id === result.payload.id); |
| 117 | if (existingIndex >= 0) { |
| 118 | // Update existing chart |
| 119 | const updatedCharts = [...prevCharts]; |
| 120 | updatedCharts[existingIndex] = result.payload; |
| 121 | return updatedCharts; |
| 122 | } else { |
| 123 | // Add new chart |
| 124 | return [...prevCharts, result.payload]; |
| 125 | } |
| 126 | }); |
| 127 | return result.payload; |
| 128 | } |
| 129 | } catch (error) { |
| 130 | console.error("Failed to fetch chart data:", error); |
| 131 | toast.error("Failed to load chart data"); |
| 132 | } |
| 133 | return null; |
| 134 | }; |
| 135 | |
| 136 | // Auto-scroll to bottom when messages change |
| 137 | useEffect(() => { |
no test coverage detected