Skip to content

Commit

Permalink
feat: report/alert list CRUD view (#11802)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang authored Dec 2, 2020
1 parent d041d3a commit a76eadd
Show file tree
Hide file tree
Showing 17 changed files with 656 additions and 43 deletions.
21 changes: 21 additions & 0 deletions superset-frontend/images/icons/exclamation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions superset-frontend/images/icons/slack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions superset-frontend/spec/javascripts/views/CRUD/alert/AlertList_spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import { styledMount as mount } from 'spec/helpers/theming';

import AlertList from 'src/views/CRUD/alert/AlertList';
import ListView from 'src/components/ListView';
import SubMenu from 'src/components/Menu/SubMenu';
import { Switch } from 'src/common/components/Switch';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';

// store needed for withToasts(AlertList)
const mockStore = configureStore([thunk]);
const store = mockStore({});

const alertsEndpoint = 'glob:*/api/v1/report/?*';
const alertEndpoint = 'glob:*/api/v1/report/*';
const alertsInfoEndpoint = 'glob:*/api/v1/report/_info*';

const mockalerts = [...new Array(3)].map((_, i) => ({
active: true,
changed_by: {
first_name: `user ${i}`,
id: i,
},
changed_on_delta_humanized: `${i} day(s) ago`,
created_by: {
first_name: `user ${i}`,
id: i,
},
created_on: new Date().toISOString,
id: i,
last_eval_dttm: Date.now(),
last_state: 'ok',
name: `alert ${i} `,
owners: [],
recipients: [
{
id: `${i}`,
type: 'email',
},
],
type: 'alert',
}));

fetchMock.get(alertsEndpoint, {
ids: [2, 0, 1],
result: mockalerts,
count: 3,
});
fetchMock.get(alertsInfoEndpoint, {
permissions: ['can_delete', 'can_edit'],
});
fetchMock.put(alertEndpoint, { ...mockalerts[0], active: false });
fetchMock.put(alertsEndpoint, { ...mockalerts[0], active: false });

async function mountAndWait(props) {
const mounted = mount(<AlertList {...props} />, {
context: { store },
});
await waitForComponentToPaint(mounted);

return mounted;
}

describe('AlertList', () => {
let wrapper;

beforeAll(async () => {
wrapper = await mountAndWait();
});

it('renders', () => {
expect(wrapper.find(AlertList)).toExist();
});

it('renders a SubMenu', () => {
expect(wrapper.find(SubMenu)).toExist();
});

it('renders a ListView', () => {
expect(wrapper.find(ListView)).toExist();
});

it('renders switches', () => {
expect(wrapper.find(Switch)).toHaveLength(3);
});
});
30 changes: 30 additions & 0 deletions superset-frontend/src/common/components/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { styled } from '@superset-ui/core';
import { Switch as BaseSwitch } from 'src/common/components';
import { SwitchProps } from 'antd/lib/switch';

const StyledSwitch = styled(BaseSwitch)`
.ant-switch-checked {
background-color: ${({ theme }) => theme.colors.primary.base};
}
`;

export const Switch = (props: SwitchProps) => <StyledSwitch {...props} />;
9 changes: 9 additions & 0 deletions superset-frontend/src/common/components/common.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Tabs, { EditableTabs } from './Tabs';
import AntdPopover from './Popover';
import { Tooltip as AntdTooltip } from './Tooltip';
import { Menu } from '.';
import { Switch as AntdSwitch } from './Switch';
import { Dropdown } from './Dropdown';
import InfoTooltip from './InfoTooltip';
import {
Expand Down Expand Up @@ -237,3 +238,11 @@ export const DateRangePicker = () => (
use12Hours
/>
);

export const Switch = () => (
<>
<AntdSwitch defaultChecked />
<br />
<AntdSwitch size="small" defaultChecked />
</>
);
1 change: 1 addition & 0 deletions superset-frontend/src/common/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export {
Popover,
Select,
Skeleton,
Switch,
Tabs,
Tooltip,
} from 'antd';
Expand Down
Loading

0 comments on commit a76eadd

Please sign in to comment.