@@ -9,6 +9,7 @@ import { ChartFieldOption } from './ChartFieldOption';
99import { QueryModel } from '../../../public/QueryModel/QueryModel' ;
1010import { TrendlineOption } from './TrendlineOption' ;
1111import { deepCopyChartConfig , hasTrendline } from './utils' ;
12+ import classNames from 'classnames' ;
1213
1314type LabelKey = keyof ChartConfig [ 'labels' ] ;
1415
@@ -60,16 +61,34 @@ const BoolSettingInput: FC<BoolSettingInputProps> = memo(({ label, name, onChang
6061} ) ;
6162BoolSettingInput . displayName = 'BoolSettingInput' ;
6263
63- // TODO: use the same icons as the ChartMenu
64- // - Not the most straightforward because those icons are set server-side
65- function chartTypeOptionRenderer ( option : SelectInputOption ) {
66- const data = option . data . data ;
64+ interface ChartTypeOptionRendererProps {
65+ chartType : ChartTypeInfo ;
66+ isValueRenderer : boolean ;
67+ }
68+ const ChartTypeOptionRenderer : FC < ChartTypeOptionRendererProps > = memo ( ( { chartType, isValueRenderer } ) => {
69+ const icon = ICONS [ chartType . name ] ;
70+ const isSvg = icon . endsWith ( '.svg' ) ;
71+ const className = classNames ( 'chart-builder-type-option' , { 'chart-builder-type-option--value' : isValueRenderer } ) ;
6772 return (
68- < div className = "chart-builder-type-option" >
69- < SVGIcon height = { null } iconSrc = { ICONS [ data . name ] + '_gray' } width = { 32 } />
70- < span > { data . title } </ span >
71- </ div >
73+ < span className = { className } >
74+ { isSvg && (
75+ < SVGIcon height = { null } iconDir = "visualization/report" iconSrc = { icon . replace ( '.svg' , '' ) } width = { 16 } />
76+ ) }
77+ { ! isSvg && < span className = { `fa ${ icon } ` } /> }
78+ < span > { chartType . title } </ span >
79+ </ span >
7280 ) ;
81+ } ) ;
82+ ChartTypeOptionRenderer . displayName = 'ChartTypeOptionRenderer' ;
83+
84+ function chartTypeOptionRenderer ( option ) {
85+ const chartType : ChartTypeInfo = option . data as ChartTypeInfo ;
86+ return < ChartTypeOptionRenderer chartType = { chartType } isValueRenderer = { false } /> ;
87+ }
88+
89+ function chartTypeValueRenderer ( option ) {
90+ const chartType : ChartTypeInfo = option . data as ChartTypeInfo ;
91+ return < ChartTypeOptionRenderer chartType = { chartType } isValueRenderer /> ;
7392}
7493
7594interface ChartTypeDropdownProps {
@@ -80,17 +99,11 @@ interface ChartTypeDropdownProps {
8099const ChartTypeDropdown : FC < ChartTypeDropdownProps > = memo ( ( { onChange, selectedType } ) => {
81100 const chartTypes = useMemo ( ( ) => {
82101 const allTypes = LABKEY_VIS ?. GenericChartHelper . getRenderTypes ( ) ;
83- return allTypes
84- . filter ( type => ! type . hidden && ! HIDDEN_CHART_TYPES . includes ( type . name ) )
85- . map ( type => ( {
86- data : type ,
87- label : type . title ,
88- value : type . name ,
89- } ) ) ;
102+ return allTypes . filter ( type => ! type . hidden && ! HIDDEN_CHART_TYPES . includes ( type . name ) ) ;
90103 } , [ ] ) ;
91104 const onChange_ = useCallback (
92105 ( _ , __ , opt ) => {
93- onChange ( opt . data ) ;
106+ onChange ( opt ) ;
94107 } ,
95108 [ onChange ]
96109 ) ;
@@ -103,13 +116,14 @@ const ChartTypeDropdown: FC<ChartTypeDropdownProps> = memo(({ onChange, selected
103116 clearable = { false }
104117 containerClass = ""
105118 inputClass = "col-xs-12"
119+ labelKey = "title"
106120 name = "chartType"
107121 onChange = { onChange_ }
108122 optionRenderer = { chartTypeOptionRenderer }
109123 options = { chartTypes }
110124 value = { selectedType . name }
111- // TODO: using chartTypeOptionRenderer as valueRenderer makes the dropdown too tall
112- // valueRenderer={chartTypeOptionRenderer }
125+ valueKey = "name"
126+ valueRenderer = { chartTypeValueRenderer }
113127 />
114128 </ div >
115129 </ div >
0 commit comments