mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
fix(alert/report): bulk select mode should be deactivated (#12977)
* close bulk delete when switch between alert and report * update test for alert/report list
This commit is contained in:
parent
6e09156598
commit
e1bb7f4364
@ -83,15 +83,23 @@ fetchMock.put(alertsEndpoint, { ...mockalerts[0], active: false });
|
|||||||
fetchMock.delete(alertEndpoint, {});
|
fetchMock.delete(alertEndpoint, {});
|
||||||
fetchMock.delete(alertsEndpoint, {});
|
fetchMock.delete(alertsEndpoint, {});
|
||||||
|
|
||||||
describe('AlertList', () => {
|
async function mountAndWait(props = {}) {
|
||||||
const wrapper = mount(
|
const mounted = mount(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<AlertList store={store} user={mockUser} />
|
<AlertList store={store} user={mockUser} {...props} />
|
||||||
</Provider>,
|
</Provider>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await waitForComponentToPaint(mounted);
|
||||||
|
|
||||||
|
return mounted;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('AlertList', () => {
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await waitForComponentToPaint(wrapper);
|
wrapper = await mountAndWait();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders', async () => {
|
it('renders', async () => {
|
||||||
@ -147,4 +155,30 @@ describe('AlertList', () => {
|
|||||||
mockalerts.length + 1, // 1 for each row and 1 for select all
|
mockalerts.length + 1, // 1 for each row and 1 for select all
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('hides bulk actions when switch between alert and report list', async () => {
|
||||||
|
expect(wrapper.find(IndeterminateCheckbox)).toHaveLength(
|
||||||
|
mockalerts.length + 1,
|
||||||
|
);
|
||||||
|
expect(wrapper.find('[data-test="alert-list"]').hasClass('active')).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(wrapper.find('[data-test="report-list"]').hasClass('active')).toBe(
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const reportWrapper = await mountAndWait({ isReportEnabled: true });
|
||||||
|
|
||||||
|
expect(fetchMock.calls(/report\/\?q/)[2][0]).toMatchInlineSnapshot(
|
||||||
|
`"http://localhost/api/v1/report/?q=(filters:!((col:type,opr:eq,value:Report)),order_column:name,order_direction:desc,page:0,page_size:25)"`,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
reportWrapper.find('[data-test="report-list"]').hasClass('active'),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
reportWrapper.find('[data-test="alert-list"]').hasClass('active'),
|
||||||
|
).toBe(false);
|
||||||
|
expect(reportWrapper.find(IndeterminateCheckbox)).toHaveLength(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -91,6 +91,7 @@ type MenuChild = {
|
|||||||
url?: string;
|
url?: string;
|
||||||
usesRouter?: boolean;
|
usesRouter?: boolean;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
|
'data-test'?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ButtonProps {
|
export interface ButtonProps {
|
||||||
@ -140,6 +141,7 @@ const SubMenu: React.FunctionComponent<SubMenuProps> = props => {
|
|||||||
return (
|
return (
|
||||||
<React.Fragment key={tab.label}>
|
<React.Fragment key={tab.label}>
|
||||||
<li
|
<li
|
||||||
|
data-test={tab['data-test']}
|
||||||
className={tab.name === props.activeChild ? 'active' : ''}
|
className={tab.name === props.activeChild ? 'active' : ''}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useState, useMemo } from 'react';
|
import React, { useState, useMemo, useEffect } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { t, SupersetClient, makeApi, styled } from '@superset-ui/core';
|
import { t, SupersetClient, makeApi, styled } from '@superset-ui/core';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
@ -137,6 +137,12 @@ function AlertList({
|
|||||||
const canDelete = hasPerm('can_write');
|
const canDelete = hasPerm('can_write');
|
||||||
const canCreate = hasPerm('can_write');
|
const canCreate = hasPerm('can_write');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (bulkSelectEnabled && canDelete) {
|
||||||
|
toggleBulkSelect();
|
||||||
|
}
|
||||||
|
}, [isReportEnabled]);
|
||||||
|
|
||||||
const handleAlertDelete = ({ id, name }: AlertObject) => {
|
const handleAlertDelete = ({ id, name }: AlertObject) => {
|
||||||
SupersetClient.delete({
|
SupersetClient.delete({
|
||||||
endpoint: `/api/v1/report/${id}`,
|
endpoint: `/api/v1/report/${id}`,
|
||||||
@ -415,12 +421,14 @@ function AlertList({
|
|||||||
label: t('Alerts'),
|
label: t('Alerts'),
|
||||||
url: '/alert/list/',
|
url: '/alert/list/',
|
||||||
usesRouter: true,
|
usesRouter: true,
|
||||||
|
'data-test': 'alert-list',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Reports',
|
name: 'Reports',
|
||||||
label: t('Reports'),
|
label: t('Reports'),
|
||||||
url: '/report/list/',
|
url: '/report/list/',
|
||||||
usesRouter: true,
|
usesRouter: true,
|
||||||
|
'data-test': 'report-list',
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
buttons={subMenuButtons}
|
buttons={subMenuButtons}
|
||||||
|
Loading…
Reference in New Issue
Block a user