You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by su...@apache.org on 2021/07/13 21:07:55 UTC

[superset] 01/02: get the explore chart url into the link

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

suddjian pushed a commit to branch explore-via-link
in repository https://gitbox.apache.org/repos/asf/superset.git

commit f0cfd065539b8d803ab88a3338e21bed0d766972
Author: David Aaron Suddjian <aa...@gmail.com>
AuthorDate: Tue Jul 13 13:59:44 2021 -0700

    get the explore chart url into the link
---
 .../src/dashboard/components/SliceHeader/index.tsx | 38 ++++---------------
 .../components/SliceHeaderControls/index.tsx       | 43 ++++++++++++----------
 .../dashboard/components/gridComponents/Chart.jsx  | 13 ++++---
 3 files changed, 39 insertions(+), 55 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/SliceHeader/index.tsx b/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
index 87425ec..6f82900 100644
--- a/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
+++ b/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
@@ -21,48 +21,24 @@ import { styled, t } from '@superset-ui/core';
 import { Tooltip } from 'src/components/Tooltip';
 import { useDispatch, useSelector } from 'react-redux';
 import EditableTitle from 'src/components/EditableTitle';
-import SliceHeaderControls from 'src/dashboard/components/SliceHeaderControls';
+import SliceHeaderControls, {
+  SliceHeaderControlsProps,
+} from 'src/dashboard/components/SliceHeaderControls';
 import FiltersBadge from 'src/dashboard/components/FiltersBadge';
 import Icon from 'src/components/Icon';
 import { RootState } from 'src/dashboard/types';
 import FilterIndicator from 'src/dashboard/components/FiltersBadge/FilterIndicator';
 import { clearDataMask } from 'src/dataMask/actions';
 
-type SliceHeaderProps = {
+type SliceHeaderProps = SliceHeaderControlsProps & {
   innerRef?: string;
-  slice: {
-    description: string;
-    viz_type: string;
-    slice_name: string;
-    slice_id: number;
-    slice_description: string;
-  };
-  isExpanded?: boolean;
-  isCached?: boolean[];
-  cachedDttm?: string[];
-  updatedDttm?: number;
   updateSliceName?: (arg0: string) => void;
-  toggleExpandSlice?: () => void;
-  forceRefresh?: () => void;
-  exploreChart?: () => void;
-  exportCSV?: () => void;
-  exportFullCSV?: () => void;
   editMode?: boolean;
-  isFullSize?: boolean;
   annotationQuery?: object;
   annotationError?: object;
   sliceName?: string;
-  supersetCanExplore?: boolean;
-  supersetCanShare?: boolean;
-  supersetCanCSV?: boolean;
-  sliceCanEdit?: boolean;
-  componentId: string;
-  dashboardId: number;
   filters: object;
-  addSuccessToast: () => void;
-  addDangerToast: () => void;
   handleToggleFullSize: () => void;
-  chartStatus: string;
   formData: object;
 };
 
@@ -84,7 +60,8 @@ const SliceHeader: FC<SliceHeaderProps> = ({
   forceRefresh = () => ({}),
   updateSliceName = () => ({}),
   toggleExpandSlice = () => ({}),
-  exploreChart = () => ({}),
+  logExploreChart = () => ({}),
+  exploreUrl = '#',
   exportCSV = () => ({}),
   editMode = false,
   annotationQuery = {},
@@ -188,7 +165,8 @@ const SliceHeader: FC<SliceHeaderProps> = ({
               updatedDttm={updatedDttm}
               toggleExpandSlice={toggleExpandSlice}
               forceRefresh={forceRefresh}
-              exploreChart={exploreChart}
+              logExploreChart={logExploreChart}
+              exploreUrl={exploreUrl}
               exportCSV={exportCSV}
               exportFullCSV={exportFullCSV}
               supersetCanExplore={supersetCanExplore}
diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx
index 294ff39..ffa9b58 100644
--- a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx
+++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx
@@ -80,7 +80,8 @@ const VerticalDotsTrigger = () => (
     <span className="dot" />
   </VerticalDotsContainer>
 );
-interface Props {
+
+export interface SliceHeaderControlsProps {
   slice: {
     description: string;
     viz_type: string;
@@ -88,35 +89,43 @@ interface Props {
     slice_id: number;
     slice_description: string;
   };
+
   componentId: string;
-  chartStatus: string;
   dashboardId: number;
-  addDangerToast: () => void;
+  chartStatus: string;
   isCached: boolean[];
   cachedDttm: string[] | null;
   isExpanded?: boolean;
   updatedDttm: number | null;
-  supersetCanExplore: boolean;
-  supersetCanShare: boolean;
-  supersetCanCSV: boolean;
-  sliceCanEdit: boolean;
   isFullSize?: boolean;
   formData: object;
-  toggleExpandSlice?: (sliceId: number) => void;
+  exploreUrl?: string;
+
   forceRefresh: (sliceId: number, dashboardId: number) => void;
-  exploreChart?: (sliceId: number) => void;
+  logExploreChart?: (sliceId: number) => void;
+  toggleExpandSlice?: (sliceId: number) => void;
   exportCSV?: (sliceId: number) => void;
   exportFullCSV?: (sliceId: number) => void;
-  addSuccessToast: (message: string) => void;
   handleToggleFullSize: () => void;
+
+  addDangerToast: (message: string) => void;
+  addSuccessToast: (message: string) => void;
+
+  supersetCanExplore?: boolean;
+  supersetCanShare?: boolean;
+  supersetCanCSV?: boolean;
+  sliceCanEdit?: boolean;
 }
 interface State {
   showControls: boolean;
   showCrossFilterScopingModal: boolean;
 }
 
-class SliceHeaderControls extends React.PureComponent<Props, State> {
-  constructor(props: Props) {
+class SliceHeaderControls extends React.PureComponent<
+  SliceHeaderControlsProps,
+  State
+> {
+  constructor(props: SliceHeaderControlsProps) {
     super(props);
     this.toggleControls = this.toggleControls.bind(this);
     this.refreshChart = this.refreshChart.bind(this);
@@ -164,8 +173,8 @@ class SliceHeaderControls extends React.PureComponent<Props, State> {
         break;
       case MENU_KEYS.EXPLORE_CHART:
         // eslint-disable-next-line no-unused-expressions
-        this.props.exploreChart &&
-          this.props.exploreChart(this.props.slice.slice_id);
+        this.props.logExploreChart &&
+          this.props.logExploreChart(this.props.slice.slice_id);
         break;
       case MENU_KEYS.EXPORT_CSV:
         // eslint-disable-next-line no-unused-expressions
@@ -272,11 +281,7 @@ class SliceHeaderControls extends React.PureComponent<Props, State> {
 
         {this.props.supersetCanExplore && (
           <Menu.Item key={MENU_KEYS.EXPLORE_CHART}>
-            <a
-              href="https://ant.design"
-              rel="noopener noreferrer"
-              onClick={event => event.stopPropagation()}
-            >
+            <a href={this.props.exploreUrl} rel="noopener noreferrer">
               {t('View chart in Explore')}
             </a>
           </Menu.Item>
diff --git a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
index 1b492d2..e0a8cc5 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
@@ -21,7 +21,7 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import { styled } from '@superset-ui/core';
 
-import { exploreChart, exportChart } from 'src/explore/exploreUtils';
+import { exportChart, getExploreLongUrl } from 'src/explore/exploreUtils';
 import ChartContainer from 'src/chart/ChartContainer';
 import {
   LOG_ACTIONS_CHANGE_DASHBOARD_FILTER,
@@ -110,7 +110,6 @@ export default class Chart extends React.Component {
     this.changeFilter = this.changeFilter.bind(this);
     this.handleFilterMenuOpen = this.handleFilterMenuOpen.bind(this);
     this.handleFilterMenuClose = this.handleFilterMenuClose.bind(this);
-    this.exploreChart = this.exploreChart.bind(this);
     this.exportCSV = this.exportCSV.bind(this);
     this.exportFullCSV = this.exportFullCSV.bind(this);
     this.forceRefresh = this.forceRefresh.bind(this);
@@ -221,13 +220,14 @@ export default class Chart extends React.Component {
     this.props.unsetFocusedFilterField(chartId, column);
   }
 
-  exploreChart() {
+  logExploreChart = () => {
     this.props.logEvent(LOG_ACTIONS_EXPLORE_DASHBOARD_CHART, {
       slice_id: this.props.slice.slice_id,
       is_cached: this.props.isCached,
     });
-    exploreChart(this.props.formData);
-  }
+  };
+
+  getChartUrl = () => getExploreLongUrl(this.props.formData);
 
   exportCSV(isFullCSV = false) {
     this.props.logEvent(LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART, {
@@ -327,7 +327,8 @@ export default class Chart extends React.Component {
           forceRefresh={this.forceRefresh}
           editMode={editMode}
           annotationQuery={chart.annotationQuery}
-          exploreChart={this.exploreChart}
+          logExploreChart={this.logExploreChart}
+          exploreUrl={this.getChartUrl()}
           exportCSV={this.exportCSV}
           exportFullCSV={this.exportFullCSV}
           updateSliceName={updateSliceName}