Skip to content

Commit

Permalink
fix(embedded): Hide anchor links in embedded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila committed Nov 28, 2024
1 parent dbcb473 commit ed63380
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -166,6 +167,7 @@ class Header extends PureComponent {
index,
handleComponentDrop,
editMode,
embeddedMode,
} = this.props;

const headerStyle = headerStyleOptions.find(
Expand Down Expand Up @@ -234,7 +236,7 @@ class Header extends PureComponent {
onSaveTitle={this.handleChangeText}
showTooltip={false}
/>
{!editMode && (
{!editMode && !embeddedMode &&(

Check failure on line 239 in superset-frontend/src/dashboard/components/gridComponents/Header.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Insert `·`
<AnchorLink id={component.id} dashboardId={dashboardId} />
)}
</HeaderStyles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Header', () => {
parentComponent: newComponentFactory(DASHBOARD_GRID_TYPE),
index: 0,
editMode: false,
embeddedMode: false,
filters: {},
handleComponentDrop() {},
deleteComponent() {},
Expand Down Expand Up @@ -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();
})

Check failure on line 136 in superset-frontend/src/dashboard/components/gridComponents/Header.test.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Insert `;`
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -282,6 +283,7 @@ class Tab extends PureComponent {
isHighlighted,
onDropPositionChange,
onDragTab,
embeddedMode,
} = this.props;

return (
Expand Down Expand Up @@ -313,7 +315,7 @@ class Tab extends PureComponent {
showTooltip={false}
editing={editMode && isFocused}
/>
{!editMode && (
{!editMode && !embeddedMode && (
<AnchorLink
id={component.id}
dashboardId={this.props.dashboardId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const createProps = () => ({
type: 'TABS',
},
editMode: false,
embeddedMode: false,
undoLength: 0,
redoLength: 0,
filters: {},
Expand Down Expand Up @@ -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';

Check failure on line 412 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
render(<Tab {...props} />, {
useRedux: true,
useDnd: true,
});

Check failure on line 417 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
expect(screen.queryByTestId('anchor-link')).toBeInTheDocument();
});

test('AnchorLink does not render in edit mode', () => {
const props = createProps();
props.editMode = true;
props.renderType = 'RENDER_TAB';

Check failure on line 425 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
render(<Tab {...props} />, {
useRedux: true,
useDnd: true,
});

Check failure on line 430 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
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';

Check failure on line 438 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
render(<Tab {...props} />, {
useRedux: true,
useDnd: true,
});

Check failure on line 443 in superset-frontend/src/dashboard/components/gridComponents/Tab.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
expect(screen.queryByTestId('anchor-link')).not.toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed63380

Please sign in to comment.