michael-s-molina commented on code in PR #42088:
URL: https://github.com/apache/superset/pull/42088#discussion_r3624007617
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/AgGridTableChart.tsx:
##########
@@ -368,6 +378,114 @@ export default function TableChart<D extends DataRecord =
DataRecord>(
[emitCrossFilters, setDataMask, timeGrain, timestampFormatter],
);
+ const drillColumns = isUsingTimeComparison
+ ? (filteredColumns as InputColumn[])
+ : (columns as InputColumn[]);
+
+ const handleContextMenu = useCallback(
+ (event: CellContextMenuEvent) => {
+ if (!onContextMenu || isRawRecords || !event.column || !event.data) {
+ return;
+ }
+ const nativeEvent = event.event as MouseEvent | null | undefined;
+ if (!nativeEvent) return;
+ nativeEvent.preventDefault();
+ nativeEvent.stopPropagation();
+
+ const rowData = event.data as Record<string, DataRecordValue>;
+ const key = event.column.getColId();
+ const cellValue = event.value as DataRecordValue;
+ const colDef = event.column.getColDef();
+ const isMetric = Boolean(
+ colDef.context?.isMetric || colDef.context?.isPercentMetric,
+ );
+
+ const drillToDetailFilters: BinaryQueryObjectFilterClause[] = [];
+ drillColumns.forEach(col => {
+ if (col.isMetric || col.isPercentMetric) return;
+ const dataRecordValue = rowData[col.key];
+
+ if (
+ dataRecordValue == null ||
+ (dataRecordValue instanceof DateWithFormatter &&
+ dataRecordValue.input == null)
+ ) {
+ drillToDetailFilters.push({
+ col: col.key,
+ op: 'IS NULL' as any,
+ val: null,
+ });
+ } else if (col.dataType === GenericDataType.Temporal && timeGrain) {
+ const startTime =
+ dataRecordValue instanceof Date
+ ? dataRecordValue
+ : new Date(dataRecordValue as string | number);
+
+ const [rangeStartTime, rangeEndTime] = getTimeRangeFromGranularity(
+ startTime,
+ timeGrain,
+ );
+ const timeRangeValue = `${rangeStartTime.toISOString()} :
${rangeEndTime.toISOString()}`;
+
+ drillToDetailFilters.push({
+ col: col.key,
+ op: 'TEMPORAL_RANGE',
+ val: timeRangeValue,
+ grain: timeGrain,
+ formattedVal: formatColumnValue(col, dataRecordValue)[1],
+ });
+ } else {
+ const sanitizedValue = extractTextFromHTML(dataRecordValue);
+ drillToDetailFilters.push({
+ col: col.key,
+ op: '==',
+ val: sanitizedValue as string | number | boolean,
+ formattedVal: formatColumnValue(col, sanitizedValue)[1],
+ });
+ }
+ });
+
+ onContextMenu(nativeEvent.clientX, nativeEvent.clientY, {
+ drillToDetail: drillToDetailFilters,
+ crossFilter: isMetric
+ ? undefined
+ : getCrossFilterDataMask({
+ key,
+ value: cellValue,
+ filters,
+ timeGrain,
+ isActiveFilterValue,
+ timestampFormatter,
+ }),
+ drillBy: isMetric
+ ? undefined
+ : {
+ filters: [
+ {
+ col: key,
+ op: (cellValue == null ||
+ (cellValue instanceof DateWithFormatter &&
+ cellValue.input == null)
+ ? 'IS NULL'
+ : '==') as any,
Review Comment:
Same underlying issue as the other `IS NULL` cast above — this is the
ternary version of the same pattern, and the same core-type limitation
(`drillBy.filters` typed as `BinaryQueryObjectFilterClause[]`) applies. Left
unchanged for the same reason.
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/test/drillToDetail.test.tsx:
##########
@@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+import { render, waitFor } from '@superset-ui/core/spec';
+import { TimeGranularity } from '@superset-ui/core';
+import { ProviderWrapper } from '../../plugin-chart-table/test/testHelpers';
+import testData from '../../plugin-chart-table/test/testData';
+
+// Capture the props the grid is rendered with, so we can invoke the
+// onCellContextMenu handler directly without depending on AG Grid's DOM
+// rendering or the (unregistered) Enterprise context-menu module.
+const captured: { props?: Record<string, any> } = {};
Review Comment:
Fixed in 4292578 — replaced `Record<string, any>` with a concrete
`CapturedGridProps` interface typing just the field the tests actually exercise
(`onCellContextMenu`).
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/test/drillToDetail.test.tsx:
##########
@@ -0,0 +1,222 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+import { render, waitFor } from '@superset-ui/core/spec';
+import { TimeGranularity } from '@superset-ui/core';
+import { ProviderWrapper } from '../../plugin-chart-table/test/testHelpers';
+import testData from '../../plugin-chart-table/test/testData';
+
+// Capture the props the grid is rendered with, so we can invoke the
+// onCellContextMenu handler directly without depending on AG Grid's DOM
+// rendering or the (unregistered) Enterprise context-menu module.
+const captured: { props?: Record<string, any> } = {};
+
+jest.mock('@superset-ui/core/components/ThemedAgGridReact', () => ({
+ __esModule: true,
+ ThemedAgGridReact: (props: Record<string, any>) => {
Review Comment:
Fixed in 4292578 alongside the above — the same `CapturedGridProps`
interface is now used for the mock component's prop type.
##########
tests/unit_tests/migrations/viz/table_v1_v2_test.py:
##########
@@ -0,0 +1,223 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+from typing import Any
+
+import pytest
+
+from superset.migrations.shared.migrate_viz import MigrateTableChart
+from tests.unit_tests.migrations.viz.utils import migrate_and_assert
+
+SOURCE_FORM_DATA: dict[str, Any] = {
+ "datasource": "1__table",
+ "any_other_key": "untouched",
+ "viz_type": "table",
+ "query_mode": "aggregate",
+ "groupby": ["name"],
+ "metrics": ["count"],
+ "percent_metrics": [],
+ "all_columns": [],
+ "row_limit": 1000,
+ "order_desc": True,
+ "table_timestamp_format": "smart_date",
+ "page_length": 20,
+ "include_search": False,
+ "show_cell_bars": True,
+ "align_pn": False,
+ "color_pn": True,
+ "allow_rearrange_columns": True,
+ "allow_render_html": True,
+}
+
+TARGET_FORM_DATA: dict[str, Any] = {
+ "datasource": "1__table",
+ "any_other_key": "untouched",
+ "viz_type": "ag-grid-table",
+ "query_mode": "aggregate",
+ "groupby": ["name"],
+ "metrics": ["count"],
+ "percent_metrics": [],
+ "all_columns": [],
+ "row_limit": 1000,
+ "order_desc": True,
+ "table_timestamp_format": "smart_date",
+ "page_length": 20,
+ "include_search": False,
+ "show_cell_bars": True,
+ "align_pn": False,
+ "color_pn": True,
+ "form_data_bak": SOURCE_FORM_DATA,
+}
+
+
+def test_migration() -> None:
+ migrate_and_assert(MigrateTableChart, SOURCE_FORM_DATA, TARGET_FORM_DATA)
+
+
+def test_migration_without_datasource_key_in_params() -> None:
+ """Some slices don't have a "datasource" key inside params, relying
+ instead on the datasource_id/datasource_type columns — that key is
+ normally injected on the fly by Slice.form_data, which the migration
+ framework bypasses by reading params directly. upgrade_slice must
+ synthesize the same "id__type" string from those columns, or
+ _build_query() raises KeyError('datasource') for charts missing it."""
+ from superset.models.slice import Slice
+ from superset.utils import json
+
+ source: dict[str, Any] = {
+ k: v for k, v in SOURCE_FORM_DATA.items() if k != "datasource"
+ }
+ dumped_form_data = json.dumps(source)
Review Comment:
Fixed in 4292578 — added a `: str` annotation to `dumped_form_data`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]