From ffc0a81e852d4de285f092537d7affd9628dd1a6 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Tue, 21 Mar 2023 07:43:39 +1300 Subject: [PATCH] chore(native-filters): Fetch only the required dataset fields (#23303) Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> --- .../FiltersConfigForm/ColumnSelect.test.tsx | 6 ++--- .../FiltersConfigForm/ColumnSelect.tsx | 9 ++++++- .../FiltersConfigForm/FiltersConfigForm.tsx | 24 ++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx index 424b16835dfb3..096771e44df04 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.test.tsx @@ -24,7 +24,7 @@ import { Column, JsonObject } from '@superset-ui/core'; import userEvent from '@testing-library/user-event'; import { ColumnSelect } from './ColumnSelect'; -fetchMock.get('glob:*/api/v1/dataset/123', { +fetchMock.get('glob:*/api/v1/dataset/123?*', { body: { result: { columns: [ @@ -35,7 +35,7 @@ fetchMock.get('glob:*/api/v1/dataset/123', { }, }, }); -fetchMock.get('glob:*/api/v1/dataset/456', { +fetchMock.get('glob:*/api/v1/dataset/456?*', { body: { result: { columns: [ @@ -47,7 +47,7 @@ fetchMock.get('glob:*/api/v1/dataset/456', { }, }); -fetchMock.get('glob:*/api/v1/dataset/789', { status: 404 }); +fetchMock.get('glob:*/api/v1/dataset/789?*', { status: 404 }); const createProps = (extraProps: JsonObject = {}) => ({ filterId: 'filterId', diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx index 761817843bac8..fdd7811df2b8b 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx @@ -17,6 +17,7 @@ * under the License. */ import React, { useCallback, useState, useMemo, useEffect } from 'react'; +import rison from 'rison'; import { Column, ensureIsArray, t, useChangeEffect } from '@superset-ui/core'; import { Select, FormInstance } from 'src/components'; import { useToasts } from 'src/components/MessageToasts/withToasts'; @@ -85,7 +86,13 @@ export function ColumnSelect({ } if (datasetId != null) { cachedSupersetGet({ - endpoint: `/api/v1/dataset/${datasetId}`, + endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({ + columns: [ + 'columns.column_name', + 'columns.is_dttm', + 'columns.type_generic', + ], + })}`, }).then( ({ json: { result } }) => { const lookupValue = Array.isArray(value) ? value : [value]; diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx index 068e6300e81a7..4f1fef8716bcc 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx @@ -45,6 +45,7 @@ import React, { useMemo, useState, } from 'react'; +import rison from 'rison'; import { PluginFilterSelectCustomizeProps } from 'src/filters/components/Select/types'; import { useSelector } from 'react-redux'; import { getChartDataRequest } from 'src/components/Chart/chartAction'; @@ -654,7 +655,28 @@ const FiltersConfigForm = ( useEffect(() => { if (datasetId) { cachedSupersetGet({ - endpoint: `/api/v1/dataset/${datasetId}`, + endpoint: `/api/v1/dataset/${datasetId}?q=${rison.encode({ + columns: [ + 'columns.column_name', + 'columns.expression', + 'columns.filterable', + 'columns.is_dttm', + 'columns.type', + 'columns.verbose_name', + 'database.id', + 'database.database_name', + 'datasource_type', + 'filter_select_enabled', + 'id', + 'is_sqllab_view', + 'main_dttm_col', + 'metrics.metric_name', + 'metrics.verbose_name', + 'schema', + 'sql', + 'table_name', + ], + })}`, }) .then((response: JsonResponse) => { setMetrics(response.json?.result?.metrics);