Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dashboard, chart] fix ordering and filtering in listviews #9212

Merged
merged 3 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 29 additions & 26 deletions superset-frontend/src/components/ListView/TableCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,49 @@
*/
import React from 'react';
import cx from 'classnames';
import { Cell, HeaderGroup, Row } from 'react-table';
import { TableInstance } from 'react-table';

interface Props<D extends object = {}> {
interface Props {
getTableProps: (userProps?: any) => any;
getTableBodyProps: (userProps?: any) => any;
prepareRow: (row: Row<D>) => any;
headerGroups: Array<HeaderGroup<D>>;
rows: Array<Row<D>>;
prepareRow: TableInstance['prepareRow'];
headerGroups: TableInstance['headerGroups'];
rows: TableInstance['rows'];
loading: boolean;
}
/* tslint:disable:jsx-key */
export default function TableCollection({
getTableProps,
getTableBodyProps,
prepareRow,
headerGroups,
rows,
loading,
}: Props<any>) {
}: Props) {
return (
<table {...getTableProps()} className="table table-hover">
<thead>
{headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column: any) => (
<th
{...column.getHeaderProps(column.getSortByToggleProps())}
data-test="sort-header"
>
{column.render('Header')}
{' '}
{column.sortable && (
<i
className={cx('text-primary fa', {
'fa-sort': !column.isSorted,
'fa-sort-down': column.isSorted && column.isSortedDesc,
'fa-sort-up': column.isSorted && !column.isSortedDesc,
})}
/>
)}
</th>
))}
{headerGroup.headers.map(column =>
column.hidden ? null : (
<th
{...column.getHeaderProps(column.getSortByToggleProps())}
data-test="sort-header"
>
{column.render('Header')}
{' '}
{column.sortable && (
<i
className={cx('text-primary fa', {
'fa-sort': !column.isSorted,
'fa-sort-down': column.isSorted && column.isSortedDesc,
'fa-sort-up': column.isSorted && !column.isSortedDesc,
})}
/>
)}
</th>
),
)}
</tr>
))}
</thead>
Expand All @@ -76,7 +77,9 @@ export default function TableCollection({
row.setState && row.setState({ hover: false })
}
>
{row.cells.map((cell: Cell<any>) => {
{row.cells.map(cell => {
if (cell.column.hidden) return null;

const columnCellProps = cell.column.cellProps || {};

return (
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/types/react-table-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ declare module 'react-table' {
UseGroupByColumnOptions<D>,
UseResizeColumnsColumnOptions<D>,
UseSortByColumnOptions<D> {
hidden?: boolean;
sortable?: boolean;
cellProps?: any;
}

Expand Down
34 changes: 25 additions & 9 deletions superset-frontend/src/views/chartList/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ChartList extends React.PureComponent<Props, State> {
},
}: any) => <a href={dsLink}>{dsNameTxt}</a>,
Header: t('Datasource'),
accessor: 'datasource_name_text',
accessor: 'datasource_name',
sortable: true,
},
{
Expand All @@ -158,9 +158,9 @@ class ChartList extends React.PureComponent<Props, State> {
changed_by_url: changedByUrl,
},
},
}: any) => <a href={changedByName}>{changedByUrl}</a>,
}: any) => <a href={changedByUrl}>{changedByName}</a>,
Header: t('Creator'),
accessor: 'creator',
accessor: 'changed_by_fk',
sortable: true,
},
{
Expand All @@ -173,6 +173,14 @@ class ChartList extends React.PureComponent<Props, State> {
accessor: 'changed_on',
sortable: true,
},
{
accessor: 'description',
hidden: true,
},
{
accessor: 'owners',
hidden: true,
},
{
Cell: ({ row: { state, original } }: any) => {
const handleDelete = () => this.handleChartDelete(original);
Expand Down Expand Up @@ -280,11 +288,20 @@ class ChartList extends React.PureComponent<Props, State> {
};

fetchData = ({ pageIndex, pageSize, sortBy, filters }: FetchDataConfig) => {
this.setState({ loading: true });
const filterExps = Object.keys(filters).map(fk => ({
col: fk,
opr: filters[fk].filterId,
value: filters[fk].filterValue,
// set loading state, cache the last config for fetching data in this component.
this.setState({
lastFetchDataConfig: {
filters,
pageIndex,
pageSize,
sortBy,
},
loading: true,
});
const filterExps = filters.map(({ id: col, operator: opr, value }) => ({
col,
opr,
value,
}));

const queryParams = JSON.stringify({
Expand Down Expand Up @@ -329,7 +346,6 @@ class ChartList extends React.PureComponent<Props, State> {
{
Header: 'Description',
id: 'description',
input: 'textarea',
operators: filterOperators.slice_name.map(convertFilter),
},
{
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/views/dashboardList/DashboardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ class DashboardList extends React.PureComponent<Props, State> {
},
{
accessor: 'slug',
hidden: true,
},
{
accessor: 'owners',
hidden: true,
},
{
Cell: ({ row: { state, original } }: any) => {
Expand Down
10 changes: 8 additions & 2 deletions superset/views/chart/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ class ChartRestApi(SliceMixin, BaseOwnedModelRestApi):
"params",
"cache_timeout",
]
order_columns = [
"slice_name",
"viz_type",
"datasource_name",
"changed_by_fk",
"changed_on",
]

# Will just affect _info endpoint
edit_columns = ["slice_name"]
add_columns = edit_columns

# exclude_route_methods = ("info",)

add_model_schema = ChartPostSchema()
edit_model_schema = ChartPutSchema()

Expand Down