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

feat: View all fav charts and dashboards #12060

Merged
merged 13 commits into from
Dec 18, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ describe('ListView', () => {
Object {
"filters": Array [
Object {
"col": undefined,
"id": "id",
"operator": "eq",
"value": "bar",
Expand All @@ -431,11 +432,13 @@ describe('ListView', () => {
Object {
"filters": Array [
Object {
"col": undefined,
"id": "id",
"operator": "eq",
"value": "bar",
},
Object {
"col": undefined,
"id": "name",
"operator": "ct",
"value": "something",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('SavedQueries', () => {
expect(wrapper.find(SavedQueries)).toExist();
});

it('fetches queries favorites and renders listviewcard cards', async () => {
it('fetches queries mine and renders listviewcard cards', async () => {
clickTab(0);
await waitForComponentToPaint(wrapper);
expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(1);
Expand All @@ -105,9 +105,9 @@ describe('SavedQueries', () => {

it('it renders a submenu with clickable tables and buttons', async () => {
expect(wrapper.find(SubMenu)).toExist();
expect(wrapper.find('li')).toHaveLength(2);
expect(wrapper.find('li')).toHaveLength(1);
expect(wrapper.find('button')).toHaveLength(2);
clickTab(1);
clickTab(0);
await waitForComponentToPaint(wrapper);
expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(2);
});
Expand Down
8 changes: 7 additions & 1 deletion superset-frontend/src/components/ListView/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ type FilterOperator =
| 'all_text'
| 'chart_all_text'
| 'dataset_is_null_or_empty'
| 'between';
| 'between'
| 'dashboard_is_fav'
| 'chart_is_fav';
geido marked this conversation as resolved.
Show resolved Hide resolved

export interface Filter {
Header: ReactNode;
id: string;
col?: string;
geido marked this conversation as resolved.
Show resolved Hide resolved
operator?: FilterOperator;
input?:
| 'text'
Expand All @@ -85,6 +88,7 @@ export type ViewModeType = 'card' | 'table';

export interface FilterValue {
id: string;
col?: string;
operator?: string;
value: string | boolean | number | null | undefined | string[] | number[];
}
Expand Down Expand Up @@ -119,4 +123,6 @@ export enum FilterOperators {
chartAllText = 'chart_all_text',
datasetIsNullOrEmpty = 'dataset_is_null_or_empty',
between = 'between',
dashboardIsFav = 'dashboard_is_fav',
chartIsFav = 'chart_is_fav',
}
11 changes: 8 additions & 3 deletions superset-frontend/src/components/ListView/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ type QueryFilterState = {
};

function mergeCreateFilterValues(list: Filter[], updateObj: QueryFilterState) {
return list.map(({ id, operator }) => {
return list.map(({ id, operator, col }) => {
const update = updateObj[id];

return { id, operator, value: update };
return { id, col, operator, value: update };
});
}

Expand All @@ -97,26 +97,29 @@ export function convertFilters(fts: InternalFilter[]): FilterValue[] {
(Array.isArray(f.value) && !f.value.length)
),
)
.map(({ value, operator, id }) => {
.map(({ value, operator, id, col }) => {
// handle between filter using 2 api filters
if (operator === 'between' && Array.isArray(value)) {
return [
{
value: value[0],
operator: 'gt',
id,
col,
},
{
value: value[1],
operator: 'lt',
id,
col,
},
];
}
return {
value,
operator,
id,
col,
};
})
.flat();
Expand Down Expand Up @@ -147,6 +150,7 @@ export function convertFiltersRison(

if (filter) {
filter.operator = value.operator;
filter.col = value.col;
}
});

Expand Down Expand Up @@ -318,6 +322,7 @@ export function useListViewState({
: 'replace';

setQuery(queryParams, method);

fetchData({ pageIndex, pageSize, sortBy, filters });
}, [fetchData, pageIndex, pageSize, sortBy, filters, viewMode]);

Expand Down
12 changes: 12 additions & 0 deletions superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ function ChartList(props: ChartListProps) {
),
paginate: false,
},
{
Header: t('Favorite'),
id: 'favorite',
col: 'id',
geido marked this conversation as resolved.
Show resolved Hide resolved
input: 'select',
operator: 'chart_is_fav',
geido marked this conversation as resolved.
Show resolved Hide resolved
unfilteredLabel: 'Any',
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
},
{
Header: t('Search'),
id: 'slice_name',
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/src/views/CRUD/dashboard/DashboardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ interface Dashboard {
dashboard_title: string;
id: number;
published: boolean;
favorite: boolean;
geido marked this conversation as resolved.
Show resolved Hide resolved
url: string;
thumbnail_url: string;
owners: Owner[];
Expand Down Expand Up @@ -101,6 +102,7 @@ function DashboardList(props: DashboardListProps) {
dashboardIds,
addDangerToast,
);

const [dashboardToEdit, setDashboardToEdit] = useState<Dashboard | null>(
null,
);
Expand Down Expand Up @@ -400,6 +402,18 @@ function DashboardList(props: DashboardListProps) {
{ label: t('Unpublished'), value: false },
],
},
{
Header: t('Favorite'),
id: 'favorite',
col: 'id',
input: 'select',
operator: 'dashboard_is_fav',
unfilteredLabel: 'Any',
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
},
{
Header: t('Search'),
id: 'dashboard_title',
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export function useListViewResource<D extends object = any>(

const filterExps = baseFilters
.concat(filterValues)
.map(({ id: col, operator: opr, value }) => ({
col,
.map(({ id, operator: opr, value, col }) => ({
col: col || id,
opr,
value,
}));
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/ChartTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ function ChartTable({
name: 'View All »',
buttonStyle: 'link',
onClick: () => {
window.location.href = '/chart/list';
window.location.href =
chartFilter === 'Favorite'
? '/chart/list/?filters=(favorite:!t)'
: '/chart/list/';
geido marked this conversation as resolved.
Show resolved Hide resolved
},
},
]}
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ function DashboardTable({
name: 'View All »',
buttonStyle: 'link',
onClick: () => {
window.location.href = '/dashboard/list/';
window.location.href =
dashboardFilter === 'Favorite'
? '/dashboard/list/?filters=(favorite:!t)'
: '/dashboard/list/';
geido marked this conversation as resolved.
Show resolved Hide resolved
},
},
]}
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,15 @@ const SavedQueries = ({
<SubMenu
activeChild={queryFilter}
tabs={[
/* @TODO uncomment when fav functionality is implemented
{
name: 'Favorite',
label: t('Favorite'),
onClick: () => {
getData('Favorite').then(() => setQueryFilter('Favorite'));
},
},
*/
{
name: 'Mine',
label: t('Mine'),
Expand Down