feat(explore): Move chart actions into dropdown (#19446)

* feat(explore): Move chart actions to a dropdown menu

* Fix tests and add some new ones

* Add background color to embed code button

* Fix cypress tests

* Move copy permalink to actions menu

* Remove unused function

* Move share by email above embed code

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test
This commit is contained in:
Kamil Gabryjelski
2022-03-31 20:41:15 +02:00
committed by GitHub
parent 85e330e94b
commit 1a1322d3d9
16 changed files with 908 additions and 854 deletions

View File

@@ -96,14 +96,11 @@ const createProps = () => ({
test('Cancelling changes to the properties should reset previous properties', () => {
const props = createProps();
render(<ExploreHeader {...props} />, { useRedux: true });
const openModal = screen.getByRole('button', {
name: 'Edit chart properties',
});
const newChartName = 'New chart name';
const prevChartName = props.slice_name;
userEvent.click(openModal);
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.click(screen.getByText('Edit chart properties'));
const nameInput = screen.getByRole('textbox', { name: 'Name' });
@@ -114,7 +111,8 @@ test('Cancelling changes to the properties should reset previous properties', ()
userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
userEvent.click(openModal);
userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.click(screen.getByText('Edit chart properties'));
expect(screen.getByDisplayValue(prevChartName)).toBeInTheDocument();
});

View File

@@ -20,22 +20,18 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import PropTypes from 'prop-types';
import Icons from 'src/components/Icons';
import {
CategoricalColorNamespace,
SupersetClient,
styled,
t,
} from '@superset-ui/core';
import { Tooltip } from 'src/components/Tooltip';
import ReportModal from 'src/components/ReportModal';
import {
fetchUISpecificReport,
toggleActive,
deleteActiveReport,
} from 'src/reports/actions/reports';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
import HeaderReportActionsDropdown from 'src/components/ReportModal/HeaderReportActionsDropdown';
import { chartPropShape } from 'src/dashboard/util/propShapes';
import EditableTitle from 'src/components/EditableTitle';
import AlteredSliceTag from 'src/components/AlteredSliceTag';
@@ -45,8 +41,9 @@ import CachedLabel from 'src/components/CachedLabel';
import PropertiesModal from 'src/explore/components/PropertiesModal';
import { sliceUpdated } from 'src/explore/actions/exploreActions';
import CertifiedBadge from 'src/components/CertifiedBadge';
import ExploreActionButtons from '../ExploreActionButtons';
import withToasts from 'src/components/MessageToasts/withToasts';
import RowCountLabel from '../RowCountLabel';
import ExploreAdditionalActionsMenu from '../ExploreAdditionalActionsMenu';
const CHART_STATUS_MAP = {
failed: 'danger',
@@ -113,13 +110,9 @@ export class ExploreChartHeader extends React.PureComponent {
super(props);
this.state = {
isPropertiesModalOpen: false,
showingReportModal: false,
};
this.openPropertiesModal = this.openPropertiesModal.bind(this);
this.closePropertiesModal = this.closePropertiesModal.bind(this);
this.showReportModal = this.showReportModal.bind(this);
this.hideReportModal = this.hideReportModal.bind(this);
this.renderReportModal = this.renderReportModal.bind(this);
this.fetchChartDashboardData = this.fetchChartDashboardData.bind(this);
}
@@ -209,38 +202,6 @@ export class ExploreChartHeader extends React.PureComponent {
});
}
showReportModal() {
this.setState({ showingReportModal: true });
}
hideReportModal() {
this.setState({ showingReportModal: false });
}
renderReportModal() {
const attachedReportExists = !!Object.keys(this.props.reports).length;
return attachedReportExists ? (
<HeaderReportActionsDropdown
showReportModal={this.showReportModal}
hideReportModal={this.hideReportModal}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
</>
);
}
canAddReports() {
if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
return false;
@@ -315,20 +276,6 @@ export class ExploreChartHeader extends React.PureComponent {
slice={this.props.slice}
/>
)}
<Tooltip
id="edit-desc-tooltip"
title={t('Edit chart properties')}
>
<span
aria-label={t('Edit chart properties')}
role="button"
tabIndex={0}
className="edit-desc-icon"
onClick={this.openPropertiesModal}
>
<i className="fa fa-edit" />
</span>
</Tooltip>
{this.props.chart.sliceFormData && (
<AlteredSliceTag
className="altered"
@@ -358,27 +305,13 @@ export class ExploreChartHeader extends React.PureComponent {
isRunning={chartStatus === 'loading'}
status={CHART_STATUS_MAP[chartStatus]}
/>
{this.canAddReports() && this.renderReportModal()}
<ReportModal
show={this.state.showingReportModal}
onHide={this.hideReportModal}
props={{
userId: this.props.user.userId,
userEmail: this.props.user.email,
chart: this.props.chart,
creationMethod: 'charts',
}}
/>
<ExploreActionButtons
actions={{
...this.props.actions,
openPropertiesModal: this.openPropertiesModal,
}}
<ExploreAdditionalActionsMenu
onOpenInEditor={this.props.actions.redirectSQLLab}
onOpenPropertiesModal={this.openPropertiesModal}
slice={this.props.slice}
canDownloadCSV={this.props.can_download}
chartStatus={chartStatus}
latestQueryFormData={latestQueryFormData}
queryResponse={queryResponse}
canAddReports={this.canAddReports()}
/>
</div>
</StyledHeader>
@@ -395,4 +328,7 @@ function mapDispatchToProps(dispatch) {
);
}
export default connect(null, mapDispatchToProps)(ExploreChartHeader);
export default connect(
null,
mapDispatchToProps,
)(withToasts(ExploreChartHeader));