From ad4ca2223e3842722d2e7e50c9a957dc8cba33cb Mon Sep 17 00:00:00 2001
From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com>
Date: Wed, 17 Feb 2021 19:14:08 -0300
Subject: [PATCH] feat: one-click copy chart and dashboard URL (#13037)
Closes #10328
---
.../cypress/integration/explore/link.test.ts | 9 +-
.../components/HeaderActionsDropdown_spec.jsx | 26 +--
.../components/gridComponents/Chart_spec.jsx | 1 +
.../components/EmbedCodeButton_spec.jsx | 12 +-
.../components/ExploreActionButtons_spec.jsx | 9 +-
.../common/hooks/useUrlShortener.ts} | 41 ++--
.../src/components/Button/index.tsx | 20 +-
.../src/components/CopyToClipboard.jsx | 24 +--
.../src/components/URLShortLinkModal.tsx | 105 ---------
.../components/HeaderActionsDropdown.jsx | 31 +--
.../src/dashboard/components/SliceHeader.jsx | 3 +
.../components/SliceHeaderControls.jsx | 29 +--
.../components/gridComponents/Chart.jsx | 3 +
.../components/menu/ShareMenuItems.tsx | 85 ++++++++
.../src/dashboard/containers/Chart.jsx | 3 +-
.../explore/components/EmbedCodeButton.jsx | 20 +-
.../components/ExploreActionButtons.jsx | 120 -----------
.../components/ExploreActionButtons.tsx | 204 ++++++++++++++++++
superset-frontend/src/utils/copy.ts | 4 +-
.../src/views/CRUD/welcome/ChartTable.tsx | 4 +-
.../src/views/CRUD/welcome/DashboardTable.tsx | 7 +-
.../src/views/CRUD/welcome/SavedQueries.tsx | 6 +-
22 files changed, 422 insertions(+), 344 deletions(-)
rename superset-frontend/{spec/javascripts/components/URLShortLinkModal_spec.jsx => src/common/hooks/useUrlShortener.ts} (52%)
delete mode 100644 superset-frontend/src/components/URLShortLinkModal.tsx
create mode 100644 superset-frontend/src/dashboard/components/menu/ShareMenuItems.tsx
delete mode 100644 superset-frontend/src/explore/components/ExploreActionButtons.jsx
create mode 100644 superset-frontend/src/explore/components/ExploreActionButtons.tsx
diff --git a/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts
index fdbf6f5f983..f825fe01d09 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/explore/link.test.ts
@@ -48,7 +48,7 @@ describe('Test explore links', () => {
});
});
- it('Visit short link', () => {
+ it('Test if short link is generated', () => {
cy.intercept('POST', 'r/shortner/').as('getShortUrl');
cy.visitChartByName('Growth Rate');
@@ -58,13 +58,6 @@ describe('Test explore links', () => {
// explicitly wait for the url response
cy.wait('@getShortUrl');
-
- cy.get('#shorturl-popover [data-test="short-url"]')
- .invoke('text')
- .then(text => {
- cy.visit(text);
- });
- cy.verifySliceSuccess({ waitAlias: '@chartData' });
});
it('Test iframe link', () => {
diff --git a/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx
index 17bc7bc3c4e..ea3b65ca28e 100644
--- a/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx
+++ b/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx
@@ -20,11 +20,11 @@ import React from 'react';
import { shallow } from 'enzyme';
import { Menu, NoAnimationDropdown } from 'src/common/components';
import RefreshIntervalModal from 'src/dashboard/components/RefreshIntervalModal';
-import URLShortLinkModal from 'src/components/URLShortLinkModal';
import HeaderActionsDropdown from 'src/dashboard/components/HeaderActionsDropdown';
import SaveModal from 'src/dashboard/components/SaveModal';
import CssEditor from 'src/dashboard/components/CssEditor';
import fetchMock from 'fetch-mock';
+import ShareMenuItems from 'src/dashboard/components/menu/ShareMenuItems';
fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {});
@@ -79,9 +79,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(SaveModal)).not.toExist();
});
- it('should render five Menu items', () => {
+ it('should render available Menu items', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(Menu.Item)).toHaveLength(5);
+ expect(menu.find(Menu.Item)).toHaveLength(4);
});
it('should render the RefreshIntervalModal', () => {
@@ -89,9 +89,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(RefreshIntervalModal)).toExist();
});
- it('should render the URLShortLinkModal', () => {
+ it('should render the ShareMenuItems', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(URLShortLinkModal)).toExist();
+ expect(menu.find(ShareMenuItems)).toExist();
});
it('should not render the CssEditor', () => {
@@ -113,9 +113,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(SaveModal)).toExist();
});
- it('should render six Menu items', () => {
+ it('should render available Menu items', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(Menu.Item)).toHaveLength(6);
+ expect(menu.find(Menu.Item)).toHaveLength(5);
});
it('should render the RefreshIntervalModal', () => {
@@ -123,9 +123,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(RefreshIntervalModal)).toExist();
});
- it('should render the URLShortLinkModal', () => {
+ it('should render the ShareMenuItems', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(URLShortLinkModal)).toExist();
+ expect(menu.find(ShareMenuItems)).toExist();
});
it('should not render the CssEditor', () => {
@@ -147,9 +147,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(SaveModal)).toExist();
});
- it('should render seven MenuItems', () => {
+ it('should render available MenuItems', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(Menu.Item)).toHaveLength(7);
+ expect(menu.find(Menu.Item)).toHaveLength(6);
});
it('should render the RefreshIntervalModal', () => {
@@ -157,9 +157,9 @@ describe('HeaderActionsDropdown', () => {
expect(menu.find(RefreshIntervalModal)).toExist();
});
- it('should render the URLShortLinkModal', () => {
+ it('should render the ShareMenuItems', () => {
const { menu } = setup(overrideProps);
- expect(menu.find(URLShortLinkModal)).toExist();
+ expect(menu.find(ShareMenuItems)).toExist();
});
it('should render the CssEditor', () => {
diff --git a/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Chart_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Chart_spec.jsx
index 52dc41c2e18..513fe4923fc 100644
--- a/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Chart_spec.jsx
+++ b/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Chart_spec.jsx
@@ -57,6 +57,7 @@ describe('Chart', () => {
changeFilter() {},
setFocusedFilterField() {},
unsetFocusedFilterField() {},
+ addSuccessToast() {},
addDangerToast() {},
componentId: 'test',
dashboardId: 111,
diff --git a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
index 74c0d21e38c..2c61cceaaee 100644
--- a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
@@ -86,8 +86,12 @@ describe('EmbedCodeButton', () => {
const stub = sinon
.stub(exploreUtils, 'getURIDirectory')
.callsFake(() => 'endpoint_url');
- const wrapper = mount(