diff --git a/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx b/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx index 9a6240daff71..edfd88ab77f5 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx +++ b/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx @@ -26,6 +26,7 @@ import { ParentSize } from '@vx/responsive'; import { createSelector } from 'reselect'; import { withTheme } from '@emotion/react'; import { parseLength, Dimension } from '../../dimension'; +import getChartMetadataRegistry from '../registries/ChartMetadataRegistrySingleton'; import SuperChartCore, { Props as SuperChartCoreProps } from './SuperChartCore'; import DefaultFallbackComponent from './FallbackComponent'; import ChartProps, { ChartPropsConfig } from '../models/ChartProps'; @@ -140,6 +141,9 @@ class SuperChart extends React.PureComponent { this.core = core; }; + private getQueryCount = () => + getChartMetadataRegistry().get(this.props.chartType)?.queryObjectCount ?? 1; + renderChart(width: number, height: number) { const { id, @@ -174,9 +178,11 @@ class SuperChart extends React.PureComponent { const noResultQueries = enableNoResults && (!queriesData || - queriesData.every( - ({ data }) => !data || (Array.isArray(data) && data.length === 0), - )); + queriesData + .slice(0, this.getQueryCount()) + .every( + ({ data }) => !data || (Array.isArray(data) && data.length === 0), + )); if (noResultQueries) { chart = noResults || ( { + const metadata = getChartMetadataRegistry().get( + queryFormData?.viz_type || queryFormData?.vizType, + ); + const [resultResp, setResultResp] = useState([]); const [isLoading, setIsLoading] = useState(true); const [responseError, setResponseError] = useState(''); - const queryCount = getQueryCount( - queryFormData?.viz_type || queryFormData?.vizType, - ); + const queryCount = metadata?.queryObjectCount ?? 1; useEffect(() => { // it's an invalid formData when gets a errorMessage @@ -122,15 +128,17 @@ export const useResultsPane = ({ ); } - return resultResp.map((result, idx) => ( - - )); + return resultResp + .slice(0, queryCount) + .map((result, idx) => ( + + )); }; diff --git a/superset-frontend/src/explore/components/DataTablesPane/test/ResultsPaneOnDashboard.test.tsx b/superset-frontend/src/explore/components/DataTablesPane/test/ResultsPaneOnDashboard.test.tsx index 19980ff71147..d45149528b0b 100644 --- a/superset-frontend/src/explore/components/DataTablesPane/test/ResultsPaneOnDashboard.test.tsx +++ b/superset-frontend/src/explore/components/DataTablesPane/test/ResultsPaneOnDashboard.test.tsx @@ -24,7 +24,7 @@ import { waitForElementToBeRemoved, } from 'spec/helpers/testing-library'; import { exploreActions } from 'src/explore/actions/exploreActions'; -import { promiseTimeout } from '@superset-ui/core'; +import { ChartMetadata, ChartPlugin, promiseTimeout } from '@superset-ui/core'; import { ResultsPaneOnDashboard } from '../components'; import { createResultsPaneOnDashboardProps } from './fixture'; @@ -147,6 +147,19 @@ describe('ResultsPaneOnDashboard', () => { }); test('multiple results pane', async () => { + const FakeChart = () => test; + const metadata = new ChartMetadata({ + name: 'test-chart', + thumbnail: '', + queryObjectCount: 2, + }); + + const plugin = new ChartPlugin({ + metadata, + Chart: FakeChart, + }); + plugin.configure({ key: 'mixed_timeseries' }).register(); + const props = createResultsPaneOnDashboardProps({ sliceId: 196, vizType: 'mixed_timeseries', diff --git a/superset-frontend/src/explore/components/DataTablesPane/utils.ts b/superset-frontend/src/explore/components/DataTablesPane/utils.ts deleted file mode 100644 index c6394fb9b67f..000000000000 --- a/superset-frontend/src/explore/components/DataTablesPane/utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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. - */ -const queryObjectCount = { - mixed_timeseries: 2, -}; - -export const getQueryCount = (vizType: string): number => - queryObjectCount?.[vizType] || 1;