From fe26b2cb48da7f8c21b6893ed8b62edaf2f3559a 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 type between table and pivot Extract the AggregationType type into common/util/aggregation-type.ts as the single shared definition for the aggregation-type set. Both table-visualization and pivot-setting now import this type; the table's local, unexported AggregationType and the pivot's untyped string[] are removed. Only the type is shared, not a value array: each component keeps its own display-order array (now typed readonly AggregationType[]). Both arrays drive an aggregation dropdown, and they use different orders, so collapsing them onto one canonical array would reorder the table column's Aggregation dropdown. Sharing just the type keeps both dropdowns exactly as they are today (zero user-visible change) while removing the duplicated/untyped definition and keeping the table's switch exhaustive. --- .../pivot-setting/pivot-setting.component.ts | 4 +++- .../common/util/aggregation-type.ts | 17 +++++++++++++++++ .../table/table-visualization.component.ts | 5 +++-- 3 files changed, 23 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..59a480b934a 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 { 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[] = ['sum', 'count', 'avg', 'min', 'max']; // 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..dfc8b3e23a1 --- /dev/null +++ b/zeppelin-web-angular/src/app/visualizations/common/util/aggregation-type.ts @@ -0,0 +1,17 @@ +/* + * 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. Only the type is shared; each +// component keeps its own display-order array (typed readonly AggregationType[]) +// so that neither aggregation dropdown changes its visible order. +export type AggregationType = 'count' | 'sum' | 'min' | 'max' | 'avg'; 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..482900644d4 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 { 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[] = ['count', 'sum', 'min', 'max', 'avg']; // eslint-disable-next-line @typescript-eslint/no-explicit-any @ViewChild(NzTableComponent, { static: false }) nzTable!: NzTableComponent;