fix: Sorting charts/dashboards makes the applied filters ineffective (#27258)
This commit is contained in:
parent
4a1f66a6c7
commit
8b4dce71d6
|
|
@ -173,6 +173,13 @@ describe('Charts list', () => {
|
||||||
orderAlphabetical();
|
orderAlphabetical();
|
||||||
cy.getBySel('styled-card').first().contains('% Rural');
|
cy.getBySel('styled-card').first().contains('% Rural');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should preserve other filters when sorting', () => {
|
||||||
|
cy.getBySel('styled-card').should('have.length', 25);
|
||||||
|
setFilter('Type', 'Big Number');
|
||||||
|
setFilter('Sort', 'Least recently modified');
|
||||||
|
cy.getBySel('styled-card').should('have.length', 3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('common actions', () => {
|
describe('common actions', () => {
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,13 @@ describe('Dashboards list', () => {
|
||||||
orderAlphabetical();
|
orderAlphabetical();
|
||||||
cy.getBySel('styled-card').first().contains('Supported Charts Dashboard');
|
cy.getBySel('styled-card').first().contains('Supported Charts Dashboard');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should preserve other filters when sorting', () => {
|
||||||
|
cy.getBySel('styled-card').should('have.length', 5);
|
||||||
|
setFilter('Status', 'Published');
|
||||||
|
setFilter('Sort', 'Least recently modified');
|
||||||
|
cy.getBySel('styled-card').should('have.length', 3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('common actions', () => {
|
describe('common actions', () => {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import { styled, t } from '@superset-ui/core';
|
||||||
import { Select } from 'src/components';
|
import { Select } from 'src/components';
|
||||||
import { FormLabel } from 'src/components/Form';
|
import { FormLabel } from 'src/components/Form';
|
||||||
import { SELECT_WIDTH } from './utils';
|
import { SELECT_WIDTH } from './utils';
|
||||||
import { CardSortSelectOption, FetchDataConfig, SortColumn } from './types';
|
import { CardSortSelectOption, SortColumn } from './types';
|
||||||
|
|
||||||
const SortContainer = styled.div`
|
const SortContainer = styled.div`
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
|
@ -32,22 +32,22 @@ const SortContainer = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface CardViewSelectSortProps {
|
interface CardViewSelectSortProps {
|
||||||
onChange: (conf: FetchDataConfig) => any;
|
onChange: (value: SortColumn[]) => void;
|
||||||
options: Array<CardSortSelectOption>;
|
options: Array<CardSortSelectOption>;
|
||||||
initialSort?: SortColumn[];
|
initialSort?: SortColumn[];
|
||||||
pageIndex: number;
|
|
||||||
pageSize: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CardSortSelect = ({
|
export const CardSortSelect = ({
|
||||||
initialSort,
|
initialSort,
|
||||||
onChange,
|
onChange,
|
||||||
options,
|
options,
|
||||||
pageIndex,
|
|
||||||
pageSize,
|
|
||||||
}: CardViewSelectSortProps) => {
|
}: CardViewSelectSortProps) => {
|
||||||
const defaultSort =
|
const defaultSort =
|
||||||
(initialSort && options.find(({ id }) => id === initialSort[0].id)) ||
|
(initialSort &&
|
||||||
|
options.find(
|
||||||
|
({ id, desc }) =>
|
||||||
|
id === initialSort[0].id && desc === initialSort[0].desc,
|
||||||
|
)) ||
|
||||||
options[0];
|
options[0];
|
||||||
|
|
||||||
const [value, setValue] = useState({
|
const [value, setValue] = useState({
|
||||||
|
|
@ -72,7 +72,7 @@ export const CardSortSelect = ({
|
||||||
desc: originalOption.desc,
|
desc: originalOption.desc,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
onChange({ pageIndex, pageSize, sortBy, filters: [] });
|
onChange(sortBy);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@ export const CardSortSelect = ({
|
||||||
ariaLabel={t('Sort')}
|
ariaLabel={t('Sort')}
|
||||||
header={<FormLabel>{t('Sort')}</FormLabel>}
|
header={<FormLabel>{t('Sort')}</FormLabel>}
|
||||||
labelInValue
|
labelInValue
|
||||||
onChange={(value: CardSortSelectOption) => handleOnChange(value)}
|
onChange={handleOnChange}
|
||||||
options={formattedOptions}
|
options={formattedOptions}
|
||||||
showSearch
|
showSearch
|
||||||
value={value}
|
value={value}
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,11 @@ function ListView<T extends object = any>({
|
||||||
pageCount = 1,
|
pageCount = 1,
|
||||||
gotoPage,
|
gotoPage,
|
||||||
applyFilterValue,
|
applyFilterValue,
|
||||||
|
setSortBy,
|
||||||
selectedFlatRows,
|
selectedFlatRows,
|
||||||
toggleAllRowsSelected,
|
toggleAllRowsSelected,
|
||||||
setViewMode,
|
setViewMode,
|
||||||
state: { pageIndex, pageSize, internalFilters, viewMode },
|
state: { pageIndex, pageSize, internalFilters, sortBy, viewMode },
|
||||||
query,
|
query,
|
||||||
} = useListViewState({
|
} = useListViewState({
|
||||||
bulkSelectColumnConfig,
|
bulkSelectColumnConfig,
|
||||||
|
|
@ -350,11 +351,9 @@ function ListView<T extends object = any>({
|
||||||
)}
|
)}
|
||||||
{viewMode === 'card' && cardSortSelectOptions && (
|
{viewMode === 'card' && cardSortSelectOptions && (
|
||||||
<CardSortSelect
|
<CardSortSelect
|
||||||
initialSort={initialSort}
|
initialSort={sortBy}
|
||||||
onChange={fetchData}
|
onChange={(value: SortColumn[]) => setSortBy(value)}
|
||||||
options={cardSortSelectOptions}
|
options={cardSortSelectOptions}
|
||||||
pageIndex={pageIndex}
|
|
||||||
pageSize={pageSize}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ export interface SortColumn {
|
||||||
desc?: boolean;
|
desc?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SortColumns = SortColumn[];
|
|
||||||
|
|
||||||
export interface SelectOption {
|
export interface SelectOption {
|
||||||
label: string;
|
label: string;
|
||||||
value: any;
|
value: any;
|
||||||
|
|
@ -84,7 +82,7 @@ export interface FilterValue {
|
||||||
export interface FetchDataConfig {
|
export interface FetchDataConfig {
|
||||||
pageIndex: number;
|
pageIndex: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
sortBy: SortColumns;
|
sortBy: SortColumn[];
|
||||||
filters: FilterValue[];
|
filters: FilterValue[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ export function useListViewState({
|
||||||
query.sortColumn && query.sortOrder
|
query.sortColumn && query.sortOrder
|
||||||
? [{ id: query.sortColumn, desc: query.sortOrder === 'desc' }]
|
? [{ id: query.sortColumn, desc: query.sortOrder === 'desc' }]
|
||||||
: initialSort,
|
: initialSort,
|
||||||
[query.sortColumn, query.sortOrder],
|
[initialSort, query.sortColumn, query.sortOrder],
|
||||||
);
|
);
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
|
@ -256,6 +256,7 @@ export function useListViewState({
|
||||||
pageCount,
|
pageCount,
|
||||||
gotoPage,
|
gotoPage,
|
||||||
setAllFilters,
|
setAllFilters,
|
||||||
|
setSortBy,
|
||||||
selectedFlatRows,
|
selectedFlatRows,
|
||||||
toggleAllRowsSelected,
|
toggleAllRowsSelected,
|
||||||
state: { pageIndex, pageSize, sortBy, filters },
|
state: { pageIndex, pageSize, sortBy, filters },
|
||||||
|
|
@ -373,6 +374,7 @@ export function useListViewState({
|
||||||
rows,
|
rows,
|
||||||
selectedFlatRows,
|
selectedFlatRows,
|
||||||
setAllFilters,
|
setAllFilters,
|
||||||
|
setSortBy,
|
||||||
state: { pageIndex, pageSize, sortBy, filters, internalFilters, viewMode },
|
state: { pageIndex, pageSize, sortBy, filters, internalFilters, viewMode },
|
||||||
toggleAllRowsSelected,
|
toggleAllRowsSelected,
|
||||||
applyFilterValue,
|
applyFilterValue,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue