Skip to content

Commit

Permalink
fix(permalink): adding anchor to dashboard permalink generation (#28744)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisjac authored and eschutho committed Jul 24, 2024
1 parent 94d025d commit ae02302
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';
import { HeaderDropdownProps } from 'src/dashboard/components/Header/types';
import injectCustomCss from 'src/dashboard/util/injectCustomCss';
import HeaderActionsDropdown from '.';
import { HeaderActionsDropdown } from '.';

const createProps = () => ({
const createProps = (): HeaderDropdownProps => ({
addSuccessToast: jest.fn(),
addDangerToast: jest.fn(),
customCss: '.ant-menu {margin-left: 100px;}',
Expand Down Expand Up @@ -66,6 +66,7 @@ const createProps = () => ({
userCanCurate: false,
lastModifiedTime: 0,
isDropdownVisible: true,
manageEmbedded: jest.fn(),
dataMask: {},
logEvent: jest.fn(),
});
Expand Down Expand Up @@ -228,9 +229,9 @@ test('should show the properties modal', async () => {

describe('UNSAFE_componentWillReceiveProps', () => {
let wrapper: any;

const mockedProps = createProps();
const props = { ...mockedProps, customCss: '' };

beforeEach(() => {
wrapper = shallow(<HeaderActionsDropdown {...props} />);
wrapper.setState({ css: props.customCss });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { isEmpty } from 'lodash';
import { connect } from 'react-redux';
import { t } from '@superset-ui/core';
import { Menu } from 'src/components/Menu';
import { URL_PARAMS } from 'src/constants';
Expand Down Expand Up @@ -46,6 +47,7 @@ const propTypes = {
customCss: PropTypes.string,
colorNamespace: PropTypes.string,
colorScheme: PropTypes.string,
directPathToChild: PropTypes.array,
onChange: PropTypes.func.isRequired,
updateCss: PropTypes.func.isRequired,
forceRefreshAllCharts: PropTypes.func.isRequired,
Expand Down Expand Up @@ -77,7 +79,11 @@ const defaultProps = {
refreshWarning: null,
};

class HeaderActionsDropdown extends PureComponent {
const mapStateToProps = state => ({
directPathToChild: state.dashboardState.directPathToChild,
});

export class HeaderActionsDropdown extends PureComponent {
static discardChanges() {
window.location.reload();
}
Expand Down Expand Up @@ -173,6 +179,7 @@ class HeaderActionsDropdown extends PureComponent {
addDangerToast,
setIsDropdownVisible,
isDropdownVisible,
directPathToChild,
...rest
} = this.props;

Expand All @@ -191,6 +198,8 @@ class HeaderActionsDropdown extends PureComponent {
const refreshIntervalOptions =
dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS;

const dashboardComponentId = [...(directPathToChild || [])].pop();

return (
<Menu selectable={false} data-test="header-actions-menu" {...rest}>
{!editMode && (
Expand Down Expand Up @@ -286,6 +295,7 @@ class HeaderActionsDropdown extends PureComponent {
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
dashboardId={dashboardId}
dashboardComponentId={dashboardComponentId}
/>
</Menu.SubMenu>
)}
Expand Down Expand Up @@ -354,4 +364,4 @@ class HeaderActionsDropdown extends PureComponent {
HeaderActionsDropdown.propTypes = propTypes;
HeaderActionsDropdown.defaultProps = defaultProps;

export default HeaderActionsDropdown;
export default connect(mapStateToProps)(HeaderActionsDropdown);
4 changes: 2 additions & 2 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { AntdButton } from 'src/components/';
import { findPermission } from 'src/utils/findPermission';
import { Tooltip } from 'src/components/Tooltip';
import { safeStringify } from 'src/utils/safeStringify';
import HeaderActionsDropdown from 'src/dashboard/components/Header/HeaderActionsDropdown';
import ConnectedHeaderActionsDropdown from 'src/dashboard/components/Header/HeaderActionsDropdown';
import PublishedStatus from 'src/dashboard/components/PublishedStatus';
import UndoRedoKeyListeners from 'src/dashboard/components/UndoRedoKeyListeners';
import PropertiesModal from 'src/dashboard/components/PropertiesModal';
Expand Down Expand Up @@ -672,7 +672,7 @@ class Header extends PureComponent {
onVisibleChange: this.setIsDropdownVisible,
}}
additionalActionsMenu={
<HeaderActionsDropdown
<ConnectedHeaderActionsDropdown
addSuccessToast={this.props.addSuccessToast}
addDangerToast={this.props.addDangerToast}
dashboardId={dashboardInfo.id}
Expand Down
6 changes: 6 additions & 0 deletions superset-frontend/src/dashboard/components/Header/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ export interface HeaderDropdownProps {
updateCss: () => void;
userCanEdit: boolean;
userCanSave: boolean;
userCanShare: boolean;
userCanCurate: boolean;
isDropdownVisible: boolean;
manageEmbedded: () => void;
dataMask: any;
lastModifiedTime: number;
logEvent: () => void;
}

export interface HeaderProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';

import RefreshIntervalModal from 'src/dashboard/components/RefreshIntervalModal';
import HeaderActionsDropdown from 'src/dashboard/components/Header/HeaderActionsDropdown';
import { HeaderActionsDropdown } from 'src/dashboard/components/Header/HeaderActionsDropdown';

const createProps = () => ({
addSuccessToast: jest.fn(),
Expand Down

0 comments on commit ae02302

Please sign in to comment.