You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by va...@apache.org on 2024/11/28 22:54:05 UTC

(superset) branch fix/embedded/hide-anchorlinks created (now ed63380aca)

This is an automated email from the ASF dual-hosted git repository.

vavila pushed a change to branch fix/embedded/hide-anchorlinks
in repository https://gitbox.apache.org/repos/asf/superset.git


      at ed63380aca fix(embedded): Hide anchor links in embedded mode

This branch includes the following new commits:

     new ed63380aca fix(embedded): Hide anchor links in embedded mode

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(embedded): Hide anchor links in embedded mode

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vavila pushed a commit to branch fix/embedded/hide-anchorlinks
in repository https://gitbox.apache.org/repos/asf/superset.git

commit ed63380acabf02353094d112de700d0c48a198a7
Author: Vitor Avila <vi...@preset.io>
AuthorDate: Thu Nov 28 19:53:48 2024 -0300

    fix(embedded): Hide anchor links in embedded mode
---
 .../src/dashboard/components/AnchorLink/index.tsx  |  2 +-
 .../dashboard/components/gridComponents/Header.jsx |  4 ++-
 .../components/gridComponents/Header.test.jsx      | 16 +++++++++
 .../dashboard/components/gridComponents/Tab.jsx    |  4 ++-
 .../components/gridComponents/Tab.test.tsx         | 39 ++++++++++++++++++++++
 .../dashboard/containers/DashboardComponent.jsx    |  1 +
 6 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/AnchorLink/index.tsx b/superset-frontend/src/dashboard/components/AnchorLink/index.tsx
index a0162baef2..837444412a 100644
--- a/superset-frontend/src/dashboard/components/AnchorLink/index.tsx
+++ b/superset-frontend/src/dashboard/components/AnchorLink/index.tsx
@@ -64,7 +64,7 @@ export default function AnchorLink({
   }, [id, scrollIntoView]);
 
   return (
-    <span className="anchor-link-container" id={id}>
+    <span className="anchor-link-container" id={id} data-test="anchor-link">
       {showShortLinkButton && dashboardId && (
         <URLShortLinkButton
           anchorLinkId={id}
diff --git a/superset-frontend/src/dashboard/components/gridComponents/Header.jsx b/superset-frontend/src/dashboard/components/gridComponents/Header.jsx
index e643cb071b..4abbc984e2 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Header.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Header.jsx
@@ -47,6 +47,7 @@ const propTypes = {
   parentComponent: componentShape.isRequired,
   index: PropTypes.number.isRequired,
   editMode: PropTypes.bool.isRequired,
+  embeddedMode: PropTypes.bool.isRequired,
 
   // redux
   handleComponentDrop: PropTypes.func.isRequired,
@@ -166,6 +167,7 @@ class Header extends PureComponent {
       index,
       handleComponentDrop,
       editMode,
+      embeddedMode,
     } = this.props;
 
     const headerStyle = headerStyleOptions.find(
@@ -234,7 +236,7 @@ class Header extends PureComponent {
                   onSaveTitle={this.handleChangeText}
                   showTooltip={false}
                 />
-                {!editMode && (
+                {!editMode && !embeddedMode &&(
                   <AnchorLink id={component.id} dashboardId={dashboardId} />
                 )}
               </HeaderStyles>
diff --git a/superset-frontend/src/dashboard/components/gridComponents/Header.test.jsx b/superset-frontend/src/dashboard/components/gridComponents/Header.test.jsx
index ddf9edd7cf..187d85af02 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Header.test.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Header.test.jsx
@@ -45,6 +45,7 @@ describe('Header', () => {
     parentComponent: newComponentFactory(DASHBOARD_GRID_TYPE),
     index: 0,
     editMode: false,
+    embeddedMode: false,
     filters: {},
     handleComponentDrop() {},
     deleteComponent() {},
@@ -118,4 +119,19 @@ describe('Header', () => {
 
     expect(deleteComponent.callCount).toBe(1);
   });
+
+  it('should render the AnchorLink in view mode', () => {
+    const wrapper = setup();
+    expect(wrapper.find('AnchorLink')).toExist();
+  });
+
+  it('should not render the AnchorLink in edit mode', () => {
+    const wrapper = setup({ editMode: true });
+    expect(wrapper.find('AnchorLink')).not.toExist();
+  });
+
+  it('should not render the AnchorLink in embedded mode', () => {
+    const wrapper = setup({ embeddedMode: true });
+    expect(wrapper.find('AnchorLink')).not.toExist();
+  })
 });
diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tab.jsx b/superset-frontend/src/dashboard/components/gridComponents/Tab.jsx
index 7b9bc8d483..4d75f8edaf 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Tab.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Tab.jsx
@@ -52,6 +52,7 @@ const propTypes = {
   onHoverTab: PropTypes.func,
   editMode: PropTypes.bool.isRequired,
   canEdit: PropTypes.bool.isRequired,
+  embeddedMode: PropTypes.bool,
 
   // grid related
   availableColumnCount: PropTypes.number,
@@ -282,6 +283,7 @@ class Tab extends PureComponent {
       isHighlighted,
       onDropPositionChange,
       onDragTab,
+      embeddedMode,
     } = this.props;
 
     return (
@@ -313,7 +315,7 @@ class Tab extends PureComponent {
               showTooltip={false}
               editing={editMode && isFocused}
             />
-            {!editMode && (
+            {!editMode && !embeddedMode && (
               <AnchorLink
                 id={component.id}
                 dashboardId={this.props.dashboardId}
diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx b/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx
index 5b6d9a7553..8166fc70c6 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx
@@ -90,6 +90,7 @@ const createProps = () => ({
     type: 'TABS',
   },
   editMode: false,
+  embeddedMode: false,
   undoLength: 0,
   redoLength: 0,
   filters: {},
@@ -404,3 +405,41 @@ test('Render tab content with no children, editMode: true, canEdit: true', () =>
     screen.getByRole('link', { name: 'create a new chart' }),
   ).toHaveAttribute('href', '/chart/add?dashboard_id=23');
 });
+
+test('AnchorLink renders in view mode', () => {
+  const props = createProps();
+  props.renderType = 'RENDER_TAB';
+  
+  render(<Tab {...props} />, {
+    useRedux: true,
+    useDnd: true,
+  });
+  
+  expect(screen.queryByTestId('anchor-link')).toBeInTheDocument();
+});
+
+test('AnchorLink does not render in edit mode', () => {
+  const props = createProps();
+  props.editMode = true;
+  props.renderType = 'RENDER_TAB';
+  
+  render(<Tab {...props} />, {
+    useRedux: true,
+    useDnd: true,
+  });
+  
+  expect(screen.queryByTestId('anchor-link')).not.toBeInTheDocument();
+});
+
+test('AnchorLink does not render in embedded mode', () => {
+  const props = createProps();
+  props.embeddedMode = true;
+  props.renderType = 'RENDER_TAB';
+  
+  render(<Tab {...props} />, {
+    useRedux: true,
+    useDnd: true,
+  });
+  
+  expect(screen.queryByTestId('anchor-link')).not.toBeInTheDocument();
+});
diff --git a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx
index bf92c5dcec..b811f398ab 100644
--- a/superset-frontend/src/dashboard/containers/DashboardComponent.jsx
+++ b/superset-frontend/src/dashboard/containers/DashboardComponent.jsx
@@ -80,6 +80,7 @@ function mapStateToProps(
     dashboardId: dashboardInfo.id,
     dashboardInfo,
     fullSizeChartId: dashboardState.fullSizeChartId,
+    embeddedMode: !dashboardInfo?.userId,
   };
 
   // rows and columns need more data about their child dimensions