forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display both queries result in Table mode for Mixed Chart in dr…
…ill by modal (apache#23768)
- Loading branch information
1 parent
c890c9a
commit 3126ad5
Showing
3 changed files
with
189 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
superset-frontend/src/components/Chart/DrillBy/useResultsTableView.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen, within, waitFor } from 'spec/helpers/testing-library'; | ||
import { useResultsTableView } from './useResultsTableView'; | ||
|
||
const MOCK_CHART_DATA_RESULT = [ | ||
{ | ||
colnames: ['name', 'sum__num'], | ||
coltypes: [1, 0], | ||
data: [ | ||
{ | ||
name: 'Michael', | ||
sum__num: 2467063, | ||
}, | ||
{ | ||
name: 'Christopher', | ||
sum__num: 1725265, | ||
}, | ||
{ | ||
name: 'David', | ||
sum__num: 1570516, | ||
}, | ||
{ | ||
name: 'James', | ||
sum__num: 1506025, | ||
}, | ||
], | ||
}, | ||
{ | ||
colnames: ['gender', 'year', 'count'], | ||
coltypes: [1, 0, 0], | ||
data: [ | ||
{ | ||
gender: 'boy', | ||
year: 2000, | ||
count: 1000, | ||
}, | ||
{ | ||
gender: 'girl', | ||
year: 2000, | ||
count: 2000, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
test('Displays results table for 1 query', () => { | ||
const { result } = renderHook(() => | ||
useResultsTableView(MOCK_CHART_DATA_RESULT.slice(0, 1), '1__table'), | ||
); | ||
render(result.current, { useRedux: true }); | ||
expect(screen.queryByRole('tablist')).not.toBeInTheDocument(); | ||
expect(screen.getByRole('table')).toBeInTheDocument(); | ||
expect(screen.getAllByRole('columnheader')).toHaveLength(2); | ||
expect(screen.getAllByTestId('table-row')).toHaveLength(4); | ||
}); | ||
|
||
test('Displays results for 2 queries', async () => { | ||
const { result } = renderHook(() => | ||
useResultsTableView(MOCK_CHART_DATA_RESULT, '1__table'), | ||
); | ||
render(result.current, { useRedux: true }); | ||
const getActiveTabElement = () => | ||
document.querySelector('.ant-tabs-tabpane-active') as HTMLElement; | ||
|
||
const tablistElement = screen.getByRole('tablist'); | ||
expect(tablistElement).toBeInTheDocument(); | ||
expect(within(tablistElement).getByText('Results 1')).toBeInTheDocument(); | ||
expect(within(tablistElement).getByText('Results 2')).toBeInTheDocument(); | ||
|
||
expect(within(getActiveTabElement()).getByRole('table')).toBeInTheDocument(); | ||
expect( | ||
within(getActiveTabElement()).getAllByRole('columnheader'), | ||
).toHaveLength(2); | ||
expect( | ||
within(getActiveTabElement()).getAllByTestId('table-row'), | ||
).toHaveLength(4); | ||
|
||
userEvent.click(screen.getByText('Results 2')); | ||
|
||
await waitFor(() => { | ||
expect( | ||
within(getActiveTabElement()).getAllByRole('columnheader'), | ||
).toHaveLength(3); | ||
}); | ||
expect( | ||
within(getActiveTabElement()).getAllByTestId('table-row'), | ||
).toHaveLength(2); | ||
}); |
73 changes: 73 additions & 0 deletions
73
superset-frontend/src/components/Chart/DrillBy/useResultsTableView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import { css, styled, isDefined, QueryData, t } from '@superset-ui/core'; | ||
import { SingleQueryResultPane } from 'src/explore/components/DataTablesPane/components/SingleQueryResultPane'; | ||
import Tabs from 'src/components/Tabs'; | ||
|
||
const DATA_SIZE = 15; | ||
|
||
const PaginationContainer = styled.div` | ||
${({ theme }) => css` | ||
& .pagination-container { | ||
bottom: ${-theme.gridUnit * 4}px; | ||
} | ||
`} | ||
`; | ||
|
||
export const useResultsTableView = ( | ||
chartDataResult: QueryData[] | undefined, | ||
datasourceId: string, | ||
) => { | ||
if (!isDefined(chartDataResult)) { | ||
return <div />; | ||
} | ||
if (chartDataResult.length === 1) { | ||
return ( | ||
<PaginationContainer> | ||
<SingleQueryResultPane | ||
colnames={chartDataResult[0].colnames} | ||
coltypes={chartDataResult[0].coltypes} | ||
data={chartDataResult[0].data} | ||
dataSize={DATA_SIZE} | ||
datasourceId={datasourceId} | ||
isVisible | ||
/> | ||
</PaginationContainer> | ||
); | ||
} | ||
return ( | ||
<Tabs fullWidth={false}> | ||
{chartDataResult.map((res, index) => ( | ||
<Tabs.TabPane tab={t('Results %s', index + 1)} key={index}> | ||
<PaginationContainer> | ||
<SingleQueryResultPane | ||
colnames={res.colnames} | ||
coltypes={res.coltypes} | ||
data={res.data} | ||
dataSize={DATA_SIZE} | ||
datasourceId={datasourceId} | ||
isVisible | ||
/> | ||
</PaginationContainer> | ||
</Tabs.TabPane> | ||
))} | ||
</Tabs> | ||
); | ||
}; |