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: filters for alerts and reports list view #11900

Merged
merged 4 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -62,6 +62,10 @@ const mockalerts = [...new Array(3)].map((_, i) => ({
type: 'alert',
}));

const mockUser = {
userId: 1,
};

fetchMock.get(alertsEndpoint, {
ids: [2, 0, 1],
result: mockalerts,
Expand All @@ -74,7 +78,7 @@ fetchMock.put(alertEndpoint, { ...mockalerts[0], active: false });
fetchMock.put(alertsEndpoint, { ...mockalerts[0], active: false });

async function mountAndWait(props) {
const mounted = mount(<AlertList {...props} />, {
const mounted = mount(<AlertList {...props} user={mockUser} />, {
context: { store },
});
await waitForComponentToPaint(mounted);
Expand Down
88 changes: 71 additions & 17 deletions superset-frontend/src/views/CRUD/alert/AlertList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import Icon, { IconName } from 'src/components/Icon';
import { Tooltip } from 'src/common/components/Tooltip';
import { Switch } from 'src/common/components/Switch';
import FacePile from 'src/components/FacePile';
import ListView from 'src/components/ListView';
import ListView, { Filters } from 'src/components/ListView';
import SubMenu, { SubMenuProps } from 'src/components/Menu/SubMenu';
import { createFetchRelated, createErrorHandler } from 'src/views/CRUD/utils';
import withToasts from 'src/messageToasts/enhancers/withToasts';

import {
Expand All @@ -42,16 +43,19 @@ interface AlertListProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
isReportEnabled: boolean;
user: {
userId: string | number;
};
}

const StatusIcon = styled(Icon)<{ status: string }>`
color: ${({ status, theme }) => {
switch (status) {
case 'alerting':
return '#FBC700';
case 'failed':
case 'Working':
return theme.colors.alert.base;
case 'Error':
return theme.colors.error.base;
case 'ok':
case 'Success':
return theme.colors.success.base;
default:
return theme.colors.grayscale.base;
Expand All @@ -62,14 +66,15 @@ const StatusIcon = styled(Icon)<{ status: string }>`
function AlertList({
addDangerToast,
isReportEnabled = false,
user,
}: AlertListProps) {
const title = isReportEnabled ? t('report') : t('alert');
const initalFilters = useMemo(
() => [
{
id: 'type',
operator: 'eq',
value: isReportEnabled ? 'report' : 'alert',
value: isReportEnabled ? 'Report' : 'Alert',
},
],
[isReportEnabled],
Expand Down Expand Up @@ -127,25 +132,25 @@ function AlertList({
status: '',
};
switch (lastState) {
case 'ok':
case 'Success':
lastStateConfig.name = 'check';
lastStateConfig.label = t('OK');
lastStateConfig.status = 'ok';
lastStateConfig.label = t('Success');
lastStateConfig.status = 'Success';
break;
case 'alerting':
case 'Working':
lastStateConfig.name = 'exclamation';
lastStateConfig.label = t('Alerting');
lastStateConfig.status = 'alerting';
lastStateConfig.label = t('Working');
lastStateConfig.status = 'Working';
break;
case 'failed':
case 'Error':
lastStateConfig.name = 'x-small';
lastStateConfig.label = t('Failed');
lastStateConfig.status = 'failed';
lastStateConfig.label = t('Error');
lastStateConfig.status = 'Error';
break;
default:
lastStateConfig.name = 'exclamation';
lastStateConfig.label = t('Alerting');
lastStateConfig.status = 'alerting';
lastStateConfig.label = t('Working');
lastStateConfig.status = 'Working';
}
return (
<Tooltip title={lastStateConfig.label} placement="bottom">
Expand Down Expand Up @@ -181,6 +186,11 @@ function AlertList({
Header: t('Schedule'),
accessor: 'crontab',
},
{
accessor: 'created_by',
disableSortBy: true,
hidden: true,
},
{
Cell: ({
row: {
Expand Down Expand Up @@ -275,6 +285,49 @@ function AlertList({
slot: canCreate ? EmptyStateButton : null,
};

const filters: Filters = useMemo(
() => [
{
Header: t('Created By'),
id: 'created_by',
input: 'select',
operator: 'rel_o_m',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add these to an enum a recently (https://github.com/apache/incubator-superset/blob/1842c56209131757f47bf7706a601aa933c6da4b/superset-frontend/src/components/ListView/types.ts#L103) can we use that as we do in QueryList which should make their meaning a little less ambiguous.

unfilteredLabel: 'All',
fetchSelects: createFetchRelated(
'report',
'created_by',
createErrorHandler(errMsg =>
t(
'An error occurred while fetching dataset datasource values: %s',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'An error occurred while fetching dataset datasource values: %s',
'An error occurred while fetching created by values: %s',

errMsg,
),
),
user.userId,
),
paginate: true,
},
{
Header: t('Status'),
id: 'last_state',
input: 'select',
operator: 'eq',
unfilteredLabel: 'Any',
selects: [
{ label: t('Success'), value: 'Success' },
{ label: t('Working'), value: 'Working' },
{ label: t('Error'), value: 'Error' },
],
},
{
Header: t('Search'),
id: 'name',
input: 'search',
operator: 'ct',
},
],
[],
);

return (
<>
<SubMenu
Expand Down Expand Up @@ -303,6 +356,7 @@ function AlertList({
data={alerts}
emptyState={emptyState}
fetchData={fetchData}
filters={filters}
initialSort={initialSort}
loading={loading}
pageSize={PAGE_SIZE}
Expand Down
2 changes: 1 addition & 1 deletion superset/reports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi):
"name",
"type",
]
search_columns = ["name", "active", "created_by", "type"]
search_columns = ["name", "active", "created_by", "type", "last_state"]
search_filters = {"name": [ReportScheduleAllTextFilter]}
allowed_rel_fields = {"created_by", "chart", "dashboard"}
filter_rel_fields = {
Expand Down