michael-s-molina commented on code in PR #42088:
URL: https://github.com/apache/superset/pull/42088#discussion_r3624009214


##########
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)
+
+    slc = Slice(

Review Comment:
   Fixed in 4292578 — added a `: Slice` annotation to `slc`.
   



##########
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)
+
+    slc = Slice(
+        viz_type=MigrateTableChart.source_viz_type,
+        datasource_id=1,
+        datasource_type="table",
+        params=dumped_form_data,
+        query_context=f'{{"form_data": {dumped_form_data}, "queries": []}}',
+    )
+
+    MigrateTableChart.upgrade_slice(slc)
+
+    assert slc.viz_type == MigrateTableChart.target_viz_type
+    new_form_data = json.loads(slc.params)

Review Comment:
   Fixed in 4292578 — added a `: dict[str, Any]` annotation to `new_form_data`.
   



##########
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)
+
+    slc = Slice(
+        viz_type=MigrateTableChart.source_viz_type,
+        datasource_id=1,
+        datasource_type="table",
+        params=dumped_form_data,
+        query_context=f'{{"form_data": {dumped_form_data}, "queries": []}}',
+    )
+
+    MigrateTableChart.upgrade_slice(slc)
+
+    assert slc.viz_type == MigrateTableChart.target_viz_type
+    new_form_data = json.loads(slc.params)
+    assert new_form_data["datasource"] == "1__table"
+
+
+def test_migration_raw_mode() -> None:
+    source: dict[str, Any] = {
+        **SOURCE_FORM_DATA,
+        "query_mode": "raw",
+        "groupby": [],
+        "metrics": [],
+        "all_columns": ["name", "sales"],
+    }
+    target: dict[str, Any] = {
+        **TARGET_FORM_DATA,
+        "query_mode": "raw",
+        "groupby": [],
+        "metrics": [],
+        "all_columns": ["name", "sales"],
+        "form_data_bak": source,
+    }
+    migrate_and_assert(MigrateTableChart, source, target)
+
+
+def test_migration_page_length_all_maps_to_max() -> None:
+    """page_length: 0 ('All rows') has no v2 dropdown choice; map to 200,
+    the max of v2's PAGE_SIZE_OPTIONS, so migrated charts keep showing as
+    many rows per page as v2 supports."""
+    source: dict[str, Any] = {**SOURCE_FORM_DATA, "page_length": 0}
+    target: dict[str, Any] = {
+        **TARGET_FORM_DATA,
+        "page_length": 200,
+        "form_data_bak": source,
+    }
+    migrate_and_assert(MigrateTableChart, source, target)
+
+
+def test_migration_page_length_all_as_string_maps_to_max() -> None:
+    source: dict[str, Any] = {**SOURCE_FORM_DATA, "page_length": "0"}
+    target: dict[str, Any] = {
+        **TARGET_FORM_DATA,
+        "page_length": 200,
+        "form_data_bak": source,
+    }
+    migrate_and_assert(MigrateTableChart, source, target)
+
+
+def test_migration_percent_metric_calculation_all_records_carries_over() -> 
None:
+    """percent_metric_calculation now has a v2 equivalent (control panel +
+    buildQuery all_records branch), so it should carry over unchanged."""
+    source: dict[str, Any] = {
+        **SOURCE_FORM_DATA,
+        "percent_metrics": ["sum__sales"],
+        "percent_metric_calculation": "all_records",
+    }
+    target: dict[str, Any] = {
+        **TARGET_FORM_DATA,
+        "percent_metrics": ["sum__sales"],
+        "percent_metric_calculation": "all_records",
+        "form_data_bak": source,
+    }
+    migrate_and_assert(MigrateTableChart, source, target)
+
+
+def test_migration_entire_row_conditional_formatting_carries_over() -> None:
+    """'entire row' conditional formatting now has a v2 equivalent (control
+    panel + getCellStyle.ts), so it should carry over unchanged."""
+    conditional_formatting = [

Review Comment:
   Fixed in 4292578 — added a `: list[dict[str, Any]]` annotation to 
`conditional_formatting`.
   



##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/AgGridTable/index.tsx:
##########
@@ -416,6 +422,41 @@ const AgGridDataTable: FunctionComponent<AgGridTableProps> 
= memo(
       serverPaginationData?.agGridFilterModel,
     ]);
 
+    // Captures the "current view" (post-filter/sort, all rows across all
+    // pages) for the "Export Current View" menu, mirroring Table V1's
+    // clientView snapshot. Client-side mode only: in server pagination mode
+    // the grid only ever holds a single page's rows, so a client-derived
+    // snapshot can't represent the full filtered/sorted result and export
+    // falls back to a fresh backend query instead (see 
useExploreAdditionalActionsMenu).
+    const lastClientViewSignatureRef = useRef<string | null>(null);
+    const handleModelUpdated = useCallback(() => {
+      if (serverPagination || !onClientViewChange || !gridRef.current?.api) {
+        return;
+      }
+      const { api } = gridRef.current;
+      const displayedColumns = api
+        .getAllDisplayedColumns()
+        .filter(column => column.getColId() !== ROW_NUMBER_COL_ID);
+      const columns = displayedColumns.map(column => ({
+        key: column.getColId(),
+        label: column.getColDef().headerName || column.getColId(),
+      }));
+
+      const rows: Record<string, unknown>[] = [];
+      api.forEachNodeAfterFilterAndSort(node => {
+        if (node.data) {
+          rows.push(node.data);
+        }
+      });
+
+      const signature = `${rows.length}|${columns.map(c => c.key).join(',')}`;
+      if (signature === lastClientViewSignatureRef.current) {
+        return;
+      }
+      lastClientViewSignatureRef.current = signature;
+      onClientViewChange({ rows, columns, count: rows.length });

Review Comment:
   Confirmed and fixed in 4292578 — the signature now includes the ordered 
sequence of filtered+sorted node ids (not just row count), so a pure sort or a 
same-count filter swap changes the signature and `onClientViewChange` fires 
correctly.
   



-- 
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]

Reply via email to