@@ -20,6 +20,7 @@ import {
2020} from '@deephaven/components' ;
2121import type { DraggableRenderItemProps , Range } from '@deephaven/components' ;
2222import { ModelIndex } from '@deephaven/grid' ;
23+ import { dh as DhType } from '@deephaven/jsapi-types' ;
2324import AggregationOperation from './AggregationOperation' ;
2425import AggregationUtils , { SELECTABLE_OPTIONS } from './AggregationUtils' ;
2526import './Aggregations.scss' ;
@@ -40,36 +41,48 @@ export type AggregationSettings = {
4041export type AggregationsProps = {
4142 isRollup : boolean ;
4243 settings : AggregationSettings ;
43- onChange : ( settings : AggregationSettings ) => void ;
44+ onChange : (
45+ settings : AggregationSettings ,
46+ added : AggregationOperation [ ] ,
47+ removed : AggregationOperation [ ]
48+ ) => void ;
4449 onEdit : ( aggregation : Aggregation ) => void ;
50+ dh : typeof DhType ;
4551} ;
4652
4753function Aggregations ( {
4854 isRollup,
4955 settings,
5056 onChange,
5157 onEdit,
58+ dh,
5259} : AggregationsProps ) : JSX . Element {
5360 const { aggregations, showOnTop } = settings ;
5461 const options = useMemo (
5562 ( ) =>
5663 SELECTABLE_OPTIONS . filter (
5764 option =>
58- ! aggregations . some ( aggregation => aggregation . operation === option )
65+ ! aggregations . some ( aggregation => aggregation . operation === option ) &&
66+ ! (
67+ option === AggregationOperation . MEDIAN &&
68+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69+ // @ts -ignore - MEDIAN is not defined in older version of Core
70+ dh . AggregationOperation . MEDIAN === undefined
71+ )
5972 ) ,
60- [ aggregations ]
73+ [ aggregations , dh ]
6174 ) ;
6275 const [ selectedOperation , setSelectedOperation ] = useState ( options [ 0 ] ) ;
6376 const [ selectedRanges , setSelectedRanges ] = useState < Range [ ] > ( [ ] ) ;
6477 const changeSettings = useCallback (
65- changedSettings => {
66- onChange ( { ...settings , ...changedSettings } ) ;
78+ ( changedSettings , added = [ ] , removed = [ ] ) => {
79+ onChange ( { ...settings , ...changedSettings } , added , removed ) ;
6780 } ,
6881 [ onChange , settings ]
6982 ) ;
7083 const changeAggregations = useCallback (
71- newAggregations => {
72- changeSettings ( { aggregations : newAggregations } ) ;
84+ ( newAggregations , added = [ ] , removed = [ ] ) => {
85+ changeSettings ( { aggregations : newAggregations } , added , removed ) ;
7386 } ,
7487 [ changeSettings ]
7588 ) ;
@@ -130,17 +143,29 @@ function Aggregations({
130143 ) ;
131144
132145 const handleAdd = useCallback ( ( ) => {
133- changeAggregations ( [
134- ...aggregations ,
135- { operation : selectedOperation , selected : [ ] , invert : true } ,
136- ] ) ;
146+ changeAggregations (
147+ [
148+ ...aggregations ,
149+ { operation : selectedOperation , selected : [ ] , invert : true } ,
150+ ] ,
151+ [ selectedOperation ]
152+ ) ;
137153 } , [ aggregations , selectedOperation , changeAggregations ] ) ;
138154
139155 const handleDeleteClicked = useCallback (
140156 ( itemIndex : ModelIndex ) => {
141- changeAggregations (
142- aggregations . filter ( ( aggregation , index ) => index !== itemIndex )
157+ const [ keep , remove ] = aggregations . reduce (
158+ ( [ keepSoFar , removeSoFar ] , aggregation , index ) => {
159+ if ( index === itemIndex ) {
160+ removeSoFar . push ( aggregation . operation ) ;
161+ } else {
162+ keepSoFar . push ( aggregation ) ;
163+ }
164+ return [ keepSoFar , removeSoFar ] ;
165+ } ,
166+ [ [ ] , [ ] ] as [ Aggregation [ ] , AggregationOperation [ ] ]
143167 ) ;
168+ changeAggregations ( keep , [ ] , remove ) ;
144169 } ,
145170 [ aggregations , changeAggregations ]
146171 ) ;
@@ -191,6 +216,9 @@ function Aggregations({
191216 const isRollupOperation = AggregationUtils . isRollupOperation (
192217 item . operation
193218 ) ;
219+ const isRollupProhibited = AggregationUtils . isRollupProhibited (
220+ item . operation
221+ ) ;
194222 const isEditable = ! isClone && ! isRollupOperation ;
195223 return (
196224 < >
@@ -208,6 +236,12 @@ function Aggregations({
208236 < FontAwesomeIcon icon = { dhWarningFilled } /> Requires rollup
209237 </ span >
210238 ) }
239+ { isRollup && isRollupProhibited && (
240+ < span className = "small text-warning" >
241+ < FontAwesomeIcon icon = { dhWarningFilled } /> Not available on
242+ rollups
243+ </ span >
244+ ) }
211245 </ span >
212246 { DraggableItemList . renderBadge ( { text : badgeText } ) }
213247 { DraggableItemList . renderHandle ( ) }
0 commit comments