From 914ebd9ba39bfcbf8d4a2b91d18eda5d3c7d2c86 Mon Sep 17 00:00:00 2001 From: Jack <41238731+fisjac@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:52:31 -0500 Subject: [PATCH] fix(permalink): adding anchor to dashboard permalink generation (#28744) --- .../HeaderActionsDropdown.test.tsx | 7 ++++--- .../Header/HeaderActionsDropdown/index.jsx | 14 ++++++++++++-- .../src/dashboard/components/Header/index.jsx | 4 ++-- .../src/dashboard/components/Header/types.ts | 6 ++++++ .../components/RefreshIntervalModal.test.tsx | 2 +- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index 6b0cbe3a3..3a0d25d60 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -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;}', @@ -66,6 +66,7 @@ const createProps = () => ({ userCanCurate: false, lastModifiedTime: 0, isDropdownVisible: true, + manageEmbedded: jest.fn(), dataMask: {}, logEvent: jest.fn(), }); @@ -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(); wrapper.setState({ css: props.customCss }); diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx index 8008558de..73d136e81 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx @@ -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'; @@ -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, @@ -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(); } @@ -173,6 +179,7 @@ class HeaderActionsDropdown extends PureComponent { addDangerToast, setIsDropdownVisible, isDropdownVisible, + directPathToChild, ...rest } = this.props; @@ -191,6 +198,8 @@ class HeaderActionsDropdown extends PureComponent { const refreshIntervalOptions = dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS; + const dashboardComponentId = [...(directPathToChild || [])].pop(); + return ( {!editMode && ( @@ -286,6 +295,7 @@ class HeaderActionsDropdown extends PureComponent { addSuccessToast={addSuccessToast} addDangerToast={addDangerToast} dashboardId={dashboardId} + dashboardComponentId={dashboardComponentId} /> )} @@ -354,4 +364,4 @@ class HeaderActionsDropdown extends PureComponent { HeaderActionsDropdown.propTypes = propTypes; HeaderActionsDropdown.defaultProps = defaultProps; -export default HeaderActionsDropdown; +export default connect(mapStateToProps)(HeaderActionsDropdown); diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index 7cb8ccd2b..bb0f79d1d 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -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'; @@ -672,7 +672,7 @@ class Header extends PureComponent { onVisibleChange: this.setIsDropdownVisible, }} additionalActionsMenu={ - void; userCanEdit: boolean; userCanSave: boolean; + userCanShare: boolean; + userCanCurate: boolean; + isDropdownVisible: boolean; + manageEmbedded: () => void; + dataMask: any; lastModifiedTime: number; + logEvent: () => void; } export interface HeaderProps { diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx index 471c0ec25..a8aac270d 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx @@ -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(),