forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Self subscribe reports (apache#16027)
Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com> Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
- Loading branch information
1 parent
31d79ff
commit 5031a67
Showing
21 changed files
with
1,040 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
superset-frontend/src/components/ReportModal/EmailReportModal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* 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 userEvent from '@testing-library/user-event'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import ReportModal from '.'; | ||
|
||
describe('Email Report Modal', () => { | ||
it('inputs respond correctly', () => { | ||
render(<ReportModal show />, { useRedux: true }); | ||
|
||
// ----- Report name textbox | ||
// Initial value | ||
const reportNameTextbox = screen.getByTestId('report-name-test'); | ||
expect(reportNameTextbox).toHaveDisplayValue('Weekly Report'); | ||
// Type in the textbox and assert that it worked | ||
userEvent.type(reportNameTextbox, 'Report name text test'); | ||
expect(reportNameTextbox).toHaveDisplayValue('Report name text test'); | ||
|
||
// ----- Report description textbox | ||
// Initial value | ||
const reportDescriptionTextbox = screen.getByTestId( | ||
'report-description-test', | ||
); | ||
expect(reportDescriptionTextbox).toHaveDisplayValue(''); | ||
// Type in the textbox and assert that it worked | ||
userEvent.type(reportDescriptionTextbox, 'Report description text test'); | ||
expect(reportDescriptionTextbox).toHaveDisplayValue( | ||
'Report description text test', | ||
); | ||
|
||
// ----- Crontab | ||
const crontabInputs = screen.getAllByRole('combobox'); | ||
expect(crontabInputs).toHaveLength(5); | ||
}); | ||
}); |
114 changes: 114 additions & 0 deletions
114
superset-frontend/src/components/ReportModal/HeaderReportActionsDropdown/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* 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, { useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { t, SupersetTheme, css } from '@superset-ui/core'; | ||
import Icons from 'src/components/Icons'; | ||
import { Switch } from 'src/components/Switch'; | ||
import { AlertObject } from 'src/views/CRUD/alert/types'; | ||
import { Menu, NoAnimationDropdown } from 'src/common/components'; | ||
|
||
import DeleteModal from 'src/components/DeleteModal'; | ||
|
||
const deleteColor = (theme: SupersetTheme) => css` | ||
color: ${theme.colors.error.base}; | ||
`; | ||
|
||
export default function HeaderReportActionsDropDown({ | ||
showReportModal, | ||
toggleActive, | ||
deleteActiveReport, | ||
}: { | ||
showReportModal: () => void; | ||
toggleActive: (data: AlertObject, checked: boolean) => void; | ||
deleteActiveReport: (data: AlertObject) => void; | ||
}) { | ||
const reports = useSelector<any, AlertObject>(state => state.reports); | ||
const reportsIds = Object.keys(reports); | ||
const report = reports[reportsIds[0]]; | ||
const [ | ||
currentReportDeleting, | ||
setCurrentReportDeleting, | ||
] = useState<AlertObject | null>(null); | ||
|
||
const toggleActiveKey = async (data: AlertObject, checked: boolean) => { | ||
if (data?.id) { | ||
toggleActive(data, checked); | ||
} | ||
}; | ||
|
||
const handleReportDelete = (report: AlertObject) => { | ||
deleteActiveReport(report); | ||
setCurrentReportDeleting(null); | ||
}; | ||
|
||
const menu = () => ( | ||
<Menu selectable={false}> | ||
<Menu.Item> | ||
{t('Email reports active')} | ||
<Switch | ||
data-test="toggle-active" | ||
checked={report?.active} | ||
onClick={(checked: boolean) => toggleActiveKey(report, checked)} | ||
size="small" | ||
/> | ||
</Menu.Item> | ||
<Menu.Item onClick={showReportModal}>{t('Edit email report')}</Menu.Item> | ||
<Menu.Item | ||
onClick={() => setCurrentReportDeleting(report)} | ||
css={deleteColor} | ||
> | ||
{t('Delete email report')} | ||
</Menu.Item> | ||
</Menu> | ||
); | ||
|
||
return ( | ||
<> | ||
<NoAnimationDropdown | ||
// ref={ref} | ||
overlay={menu()} | ||
trigger={['click']} | ||
getPopupContainer={(triggerNode: any) => | ||
triggerNode.closest('.action-button') | ||
} | ||
> | ||
<span role="button" className="action-button" tabIndex={0}> | ||
<Icons.Calendar /> | ||
</span> | ||
</NoAnimationDropdown> | ||
{currentReportDeleting && ( | ||
<DeleteModal | ||
description={t( | ||
'This action will permanently delete %s.', | ||
currentReportDeleting.name, | ||
)} | ||
onConfirm={() => { | ||
if (currentReportDeleting) { | ||
handleReportDelete(currentReportDeleting); | ||
} | ||
}} | ||
onHide={() => setCurrentReportDeleting(null)} | ||
open | ||
title={t('Delete Report?')} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.