diff --git a/zeppelin-web-angular/src/app/visualizations/common/pivot-setting/pivot-setting.component.ts b/zeppelin-web-angular/src/app/visualizations/common/pivot-setting/pivot-setting.component.ts index e3995298d31..b5ed24b5656 100644 --- a/zeppelin-web-angular/src/app/visualizations/common/pivot-setting/pivot-setting.component.ts +++ b/zeppelin-web-angular/src/app/visualizations/common/pivot-setting/pivot-setting.component.ts @@ -16,6 +16,8 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } import { GraphConfig } from '@zeppelin/sdk'; import { TableData, Visualization } from '@zeppelin/visualization'; +import { AGGREGATION_TYPES, AggregationType } from '../util/aggregation-type'; + @Component({ selector: 'zeppelin-visualization-pivot-setting', templateUrl: './pivot-setting.component.html', @@ -28,7 +30,7 @@ export class VisualizationPivotSettingComponent implements OnInit { config!: GraphConfig; columns: Array<{ name: string; index: number; aggr: string }> = []; - aggregates = ['sum', 'count', 'avg', 'min', 'max']; + aggregates: readonly AggregationType[] = AGGREGATION_TYPES; // eslint-disable-next-line drop(event: CdkDragDrop) { diff --git a/zeppelin-web-angular/src/app/visualizations/common/util/aggregation-type.ts b/zeppelin-web-angular/src/app/visualizations/common/util/aggregation-type.ts new file mode 100644 index 00000000000..9bf50326d0f --- /dev/null +++ b/zeppelin-web-angular/src/app/visualizations/common/util/aggregation-type.ts @@ -0,0 +1,18 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Single source of truth for the aggregation-type set shared by the table +// visualization and the pivot setting UI. The order is canonical and drives the +// pivot aggregation dropdown display order. +export const AGGREGATION_TYPES = ['sum', 'count', 'avg', 'min', 'max'] as const; + +export type AggregationType = (typeof AGGREGATION_TYPES)[number]; diff --git a/zeppelin-web-angular/src/app/visualizations/table/table-visualization.component.ts b/zeppelin-web-angular/src/app/visualizations/table/table-visualization.component.ts index 0eefb93ce73..e138ff0b4d5 100644 --- a/zeppelin-web-angular/src/app/visualizations/table/table-visualization.component.ts +++ b/zeppelin-web-angular/src/app/visualizations/table/table-visualization.component.ts @@ -18,8 +18,9 @@ import { utils, writeFile, WorkSheet } from 'xlsx'; import { TableData, Visualization, VISUALIZATION } from '@zeppelin/visualization'; +import { AGGREGATION_TYPES, AggregationType } from '../common/util/aggregation-type'; + type ColType = 'string' | 'date' | 'number'; -type AggregationType = 'count' | 'sum' | 'min' | 'max' | 'avg'; class FilterOption { sort: 'desc' | 'asc' | '' = ''; @@ -59,7 +60,7 @@ export class TableVisualizationComponent implements OnInit { columns: string[] = []; colOptions = new Map(); types: ColType[] = ['string', 'number', 'date']; - aggregations: AggregationType[] = ['count', 'sum', 'min', 'max', 'avg']; + aggregations: readonly AggregationType[] = AGGREGATION_TYPES; // eslint-disable-next-line @typescript-eslint/no-explicit-any @ViewChild(NzTableComponent, { static: false }) nzTable!: NzTableComponent;