From ae2f0c84a6afc507ab62f8940c1f392e9f63d7d1 Mon Sep 17 00:00:00 2001 From: kimyenac Date: Fri, 17 Jul 2026 20:19:40 +0900 Subject: [PATCH] [ZEPPELIN-6471] Share a single aggregation-type constant between table and pivot Extract AGGREGATION_TYPES and the AggregationType type into common/util/aggregation-type.ts as the single source of truth for the aggregation-type set. Both table-visualization and pivot-setting now import this shared definition; the duplicated literal arrays and the local, unexported AggregationType type are removed. pivot-setting's aggregates field is now typed as readonly AggregationType[], consistent with the table component. The canonical order keeps the pivot's existing order (sum, count, avg, min, max), so the aggregation dropdown display order is unchanged (zero user-visible change). --- .../pivot-setting/pivot-setting.component.ts | 4 +++- .../common/util/aggregation-type.ts | 18 ++++++++++++++++++ .../table/table-visualization.component.ts | 5 +++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 zeppelin-web-angular/src/app/visualizations/common/util/aggregation-type.ts 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;