1- // src/components/AddChartDialog.js
1+ /**
2+ * AddChartDialog
3+ * Dialog for creating a new chart/visualization. Lets user select chart type, data source, axes, and measure(s).
4+ *
5+ * Props:
6+ * open (bool): Whether the dialog is open
7+ * onClose (func): Callback to close dialog
8+ * onAddChart (func): Callback to add chart, receives chart config
9+ * dataSources (object): Map of data source names to data arrays
10+ */
211import React , { useState } from 'react' ;
312import {
413 Dialog ,
@@ -18,27 +27,27 @@ import {
1827 ListItemText ,
1928} from '@mui/material' ;
2029import BarChartIcon from '@mui/icons-material/BarChart' ;
21- import ShowChartIcon from '@mui/icons-material/ShowChart' ; // line
22- import TimelineIcon from '@mui/icons-material/Timeline' ; // area
30+ import ShowChartIcon from '@mui/icons-material/ShowChart' ;
31+ import TimelineIcon from '@mui/icons-material/Timeline' ;
2332import PieChartIcon from '@mui/icons-material/PieChart' ;
24- import ActivityIcon from '@mui/icons-material/AutoAwesomeMotion' ; // or similar for KPI
33+ import ActivityIcon from '@mui/icons-material/AutoAwesomeMotion' ;
2534
2635function AddChartDialog ( {
2736 open,
2837 onClose,
2938 onAddChart,
30- dataSources, // e.g. Object with data arrays
31- queries, // e.g. for advanced referencing
39+ dataSources,
3240} ) {
41+ // State for form fields
3342 const [ title , setTitle ] = useState ( '' ) ;
3443 const [ chartType , setChartType ] = useState ( '' ) ;
3544 const [ dataSource , setDataSource ] = useState ( '' ) ;
3645 const [ xAxis , setXAxis ] = useState ( '' ) ;
3746 const [ yAxes , setYAxes ] = useState ( [ ] ) ; // multi-select
3847 const [ errorMsg , setErrorMsg ] = useState ( '' ) ;
3948
49+ // Reset all fields and close dialog
4050 const handleClose = ( ) => {
41- // Reset
4251 setTitle ( '' ) ;
4352 setChartType ( '' ) ;
4453 setDataSource ( '' ) ;
@@ -48,9 +57,8 @@ function AddChartDialog({
4857 onClose ( ) ;
4958 } ;
5059
51- // Attempt to create a new chart
60+ // Validate and submit chart config
5261 const handleAddChart = ( ) => {
53- // Basic validation
5462 if ( ! title . trim ( ) || ! chartType || ! dataSource ) {
5563 setErrorMsg ( 'Please fill all required fields' ) ;
5664 return ;
@@ -63,25 +71,23 @@ function AddChartDialog({
6371 setErrorMsg ( 'Please select at least one Y axis/measure' ) ;
6472 return ;
6573 }
66-
67- // Build the new chart config
6874 onAddChart ( {
6975 id : `chart-${ Date . now ( ) } ` ,
7076 title,
7177 chartType,
7278 dataSource,
7379 xKey : xAxis ,
74- yKeys : yAxes , // multi-series
80+ yKeys : yAxes ,
7581 } ) ;
7682 handleClose ( ) ;
7783 } ;
7884
79- // Build the array of columns for the selected data source
85+ // Get columns for selected data source
8086 const columns = dataSource && dataSources [ dataSource ] && dataSources [ dataSource ] . length > 0
8187 ? Object . keys ( dataSources [ dataSource ] [ 0 ] )
8288 : [ ] ;
8389
84- // For multi-select Y axis
90+ // Handle Y axis selection (multi-select)
8591 const handleYAxesChange = ( e ) => {
8692 const value = e . target . value ;
8793 setYAxes ( typeof value === 'string' ? value . split ( ',' ) : value ) ;
@@ -98,6 +104,7 @@ function AddChartDialog({
98104 fullWidth
99105 value = { title }
100106 onChange = { ( e ) => setTitle ( e . target . value ) }
107+ inputProps = { { 'aria-label' : 'Chart title' } }
101108 />
102109
103110 < Typography variant = "body2" sx = { { fontWeight : 600 } } >
@@ -107,30 +114,35 @@ function AddChartDialog({
107114 < IconButton
108115 color = { chartType === 'bar' ? 'primary' : 'default' }
109116 onClick = { ( ) => setChartType ( 'bar' ) }
117+ aria-label = "Bar chart"
110118 >
111119 < BarChartIcon />
112120 </ IconButton >
113121 < IconButton
114122 color = { chartType === 'line' ? 'primary' : 'default' }
115123 onClick = { ( ) => setChartType ( 'line' ) }
124+ aria-label = "Line chart"
116125 >
117126 < ShowChartIcon />
118127 </ IconButton >
119128 < IconButton
120129 color = { chartType === 'area' ? 'primary' : 'default' }
121130 onClick = { ( ) => setChartType ( 'area' ) }
131+ aria-label = "Area chart"
122132 >
123133 < TimelineIcon />
124134 </ IconButton >
125135 < IconButton
126136 color = { chartType === 'pie' ? 'primary' : 'default' }
127137 onClick = { ( ) => setChartType ( 'pie' ) }
138+ aria-label = "Pie chart"
128139 >
129140 < PieChartIcon />
130141 </ IconButton >
131142 < IconButton
132143 color = { chartType === 'kpi' ? 'primary' : 'default' }
133144 onClick = { ( ) => setChartType ( 'kpi' ) }
145+ aria-label = "KPI"
134146 >
135147 < ActivityIcon />
136148 </ IconButton >
@@ -142,6 +154,7 @@ function AddChartDialog({
142154 value = { dataSource }
143155 label = "Data Source"
144156 onChange = { ( e ) => setDataSource ( e . target . value ) }
157+ inputProps = { { 'aria-label' : 'Data source' } }
145158 >
146159 { Object . keys ( dataSources ) . map ( ( ds ) => (
147160 < MenuItem key = { ds } value = { ds } >
@@ -158,6 +171,7 @@ function AddChartDialog({
158171 value = { xAxis }
159172 label = "X Axis"
160173 onChange = { ( e ) => setXAxis ( e . target . value ) }
174+ inputProps = { { 'aria-label' : 'X axis' } }
161175 >
162176 { columns . map ( ( col ) => (
163177 < MenuItem key = { col } value = { col } >
@@ -180,6 +194,7 @@ function AddChartDialog({
180194 label = "Y Axis"
181195 onChange = { handleYAxesChange }
182196 renderValue = { ( selected ) => ( Array . isArray ( selected ) ? selected . join ( ', ' ) : selected ) }
197+ inputProps = { { 'aria-label' : 'Y axis' } }
183198 >
184199 { columns . map ( ( col ) => (
185200 < MenuItem key = { col } value = { col } >
0 commit comments