Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,18 @@ const AgGridDataTable: FunctionComponent<AgGridTableProps> = memo(
)}
{includeSearch && (
<div className="search-container">
{serverPagination && (
<div className="search-by-text-container">
<span className="search-by-text"> {t('Search by')}:</span>
<SearchSelectDropdown
onChange={onSearchColChange}
searchOptions={searchOptions}
value={serverPaginationData?.searchColumn || ''}
/>
</div>
)}
{serverPagination &&
searchOptions &&
searchOptions.length > 0 && (
<div className="search-by-text-container">
<span className="search-by-text"> {t('Search by')}:</span>
<SearchSelectDropdown
onChange={onSearchColChange}
searchOptions={searchOptions}
value={serverPaginationData?.searchColumn || ''}
/>
</div>
)}
<div className="input-wrapper">
<div className="input-container">
<SearchOutlined />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
* under the License.
*/
import { t } from '@apache-superset/core/translation';
import { ColDef } from '@superset-ui/core/components/ThemedAgGridReact';
import {
ColDef,
ValueFormatterParams,
ValueGetterParams,
CellClassParams,
} from '@superset-ui/core/components/ThemedAgGridReact';
import { useCallback, useMemo } from 'react';
import { DataRecord, DataRecordValue, JsonObject } from '@superset-ui/core';
import { GenericDataType } from '@apache-superset/core/common';
Expand Down Expand Up @@ -290,9 +295,9 @@ export const useColDefs = ({
return {
field: colId,
headerName: getHeaderLabel(col),
valueFormatter: p => valueFormatter(p, col),
valueGetter: p => valueGetter(p, col),
cellStyle: p => {
valueFormatter: (p: ValueFormatterParams) => valueFormatter(p, col),
valueGetter: (p: ValueGetterParams) => valueGetter(p, col),
cellStyle: (p: CellClassParams) => {
const cellSurfaceColor =
p.node?.rowPinned != null
? theme.colorBgBase
Expand All @@ -316,7 +321,7 @@ export const useColDefs = ({

return getCellStyle(cellStyleParams);
},
cellClass: p =>
cellClass: (p: CellClassParams) =>
getCellClass({
...p,
col,
Expand Down Expand Up @@ -478,7 +483,7 @@ export const useColDefs = ({
headerName: t('№'),
headerClass: 'ag-header-center',
field: ROW_NUMBER_COL_ID,
valueGetter: params => {
valueGetter: (params: ValueGetterParams) => {
if (params.node?.rowPinned != null) return '';
if (serverPagination && serverPaginationData) {
return currentPage * pageSize + (params.node?.rowIndex ?? 0) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,70 @@ test('AgGridTableChart renders with search enabled', async () => {
expect(searchInput).toHaveAttribute('id', 'filter-text-box');
});

test('AgGridTableChart hides Search by dropdown if includeSearch is false', async () => {
const props = transformProps({
...testData.basic,
rawFormData: {
...testData.basic.rawFormData,
server_pagination: true,
include_search: false,
},
});
props.serverPagination = true;
props.includeSearch = false;

render(
ProviderWrapper({
children: (
<AgGridTableChart
{...props}
setDataMask={mockSetDataMask}
slice_id={1}
/>
),
}),
);

await waitFor(() => {
const grid = document.querySelector('.ag-container');
expect(grid).toBeInTheDocument();
});

expect(screen.queryByText(/Search by/i)).not.toBeInTheDocument();
});

test('AgGridTableChart renders Search by dropdown if includeSearch is true and there are search options', async () => {
const props = transformProps({
...testData.basic,
rawFormData: {
...testData.basic.rawFormData,
server_pagination: true,
include_search: true,
},
});
props.serverPagination = true;
props.includeSearch = true;

render(
ProviderWrapper({
children: (
<AgGridTableChart
{...props}
setDataMask={mockSetDataMask}
slice_id={1}
/>
),
}),
);

await waitFor(() => {
const grid = document.querySelector('.ag-container');
expect(grid).toBeInTheDocument();
});

expect(screen.getByText(/Search by/i)).toBeInTheDocument();
});

test('AgGridTableChart renders with totals', async () => {
const props = transformProps({
...testData.basic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,18 @@ export default typedMemo(function DataTable<D extends object>({
<Flex wrap align="center" gap="middle">
{searchInput && (
<>
{serverPagination && (
<Space direction="vertical" size={4}>
{t('Search by')}
<SearchSelectDropdown
searchOptions={searchOptions}
value={serverPaginationData?.searchColumn || ''}
onChange={onSearchColChange}
/>
</Space>
)}
{serverPagination &&
searchOptions &&
searchOptions.length > 0 && (
<Space direction="vertical" size={4}>
{t('Search by')}
<SearchSelectDropdown
searchOptions={searchOptions}
value={serverPaginationData?.searchColumn || ''}
onChange={onSearchColChange}
/>
</Space>
)}
<GlobalFilter<D>
searchInput={
typeof searchInput === 'boolean' ? undefined : searchInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,56 @@ describe('plugin-chart-table', () => {
expect(filters[0].val).toEqual(['Michael']);
});
});

test('does not render "Search by" if there are no search options (server pagination enabled)', () => {
const props = transformProps({
...testData.raw,
rawFormData: {
...testData.raw.rawFormData,
server_pagination: true,
include_search: true,
},
queriesData: [
{
...testData.raw.queriesData[0],
colnames: ['num'],
coltypes: [GenericDataType.Numeric],
data: [{ num: 1 }, { num: 2 }],
},
],
});
render(
ProviderWrapper({
children: <TableChart {...props} sticky={false} />,
}),
);
expect(screen.queryByText('Search by')).not.toBeInTheDocument();
});

test('renders "Search by" if include_search is true and there are search options (server pagination enabled)', () => {
const props = transformProps({
...testData.raw,
rawFormData: {
...testData.raw.rawFormData,
server_pagination: true,
include_search: true,
},
queriesData: [
{
...testData.raw.queriesData[0],
colnames: ['name'],
coltypes: [GenericDataType.String],
data: [{ name: 'Michael' }, { name: 'John' }],
},
],
});
render(
ProviderWrapper({
children: <TableChart {...props} sticky={false} />,
}),
);
expect(screen.queryByText('Search by')).toBeInTheDocument();
});
});

/**
Expand Down
Loading