You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/10/06 15:42:49 UTC

[GitHub] [superset] kgabryje commented on a diff in pull request #21685: feat: Shows related dashboards in Explore

kgabryje commented on code in PR #21685:
URL: https://github.com/apache/superset/pull/21685#discussion_r989186762


##########
superset-frontend/src/dashboard/actions/hydrate.js:
##########
@@ -291,8 +292,26 @@ export const hydrateDashboard =
       future: [],
     };
 
+    // Searches for a focused_chart parameter in the URL to automatically focus a chart
+    const { focused_chart: focusedChartId } = regularUrlParams;
+    let focusedChartLayoutId;
+    if (focusedChartId) {
+      // Converts focused_chart to dashboard layout id
+      const found = Object.values(dashboardLayout.present).find(
+        // eslint-disable-next-line eqeqeq

Review Comment:
   eqeqeq? 😄 



##########
superset-frontend/src/explore/components/ExploreChartHeader/index.jsx:
##########
@@ -162,6 +165,13 @@ export const ExploreChartHeader = ({
         metadata.dashboards.length > 0
           ? t('Added to %s dashboard(s)', metadata.dashboards.length)
           : t('Not added to any dashboard'),
+      description:
+        metadata.dashboards.length > 0 &&
+        isFeatureEnabled(FeatureFlag.CROSS_REFERENCES)

Review Comment:
   Why do we lock it behind a feature flag? (sorry if I missed that conversation)



##########
superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/index.jsx:
##########
@@ -246,14 +249,25 @@ export const useExploreAdditionalActionsMenu = (
         openKeys={openSubmenus}
         onOpenChange={setOpenSubmenus}
       >
-        {slice && (
-          <>
+        <>
+          {slice && (
             <Menu.Item key={MENU_KEYS.EDIT_PROPERTIES}>
               {t('Edit chart properties')}
             </Menu.Item>
-            <Menu.Divider />
-          </>
-        )}
+          )}
+          {isFeatureEnabled(FeatureFlag.CROSS_REFERENCES) && (

Review Comment:
   this should be behind the `slice &&` check too. If you create a new chart, slice is undefined before saving, so there's no point in showing "Dashboards added to" because it's always empty. If you do that, you can also make `chartId` required instead of optional in types of `DashboardSubMenu`



##########
superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/DashboardsSubMenu.tsx:
##########
@@ -0,0 +1,145 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import React, { useState } from 'react';
+import { css, t, useTheme } from '@superset-ui/core';
+import { AntdInput } from 'src/components';
+import Icons from 'src/components/Icons';
+import { Menu } from 'src/components/Menu';
+import { Link } from 'react-router-dom';
+
+export interface DashboardsSubMenuProps {
+  chartId?: number;
+  dashboards?: { id: number; dashboard_title: string }[];
+}
+
+const WIDTH = 220;
+const HEIGHT = 300;
+const SEARCH_THRESHOLD = 10;
+
+const DashboardsSubMenu = ({
+  chartId,
+  dashboards = [],
+  ...menuProps
+}: DashboardsSubMenuProps) => {
+  const theme = useTheme();
+  const [dashboardSearch, setDashboardSearch] = useState<string>();
+  const [hoveredItem, setHoveredItem] = useState<number | null>();
+  const showSearch = dashboards.length > SEARCH_THRESHOLD;
+  const filteredDashboards = dashboards.filter(
+    dashboard =>
+      !dashboardSearch ||
+      dashboard.dashboard_title
+        .toLowerCase()
+        .includes(dashboardSearch.toLowerCase()),
+  );
+  const noResults = dashboards.length === 0;
+  const noResultsFound = dashboardSearch && filteredDashboards.length === 0;
+  const urlQueryString = chartId ? `?focused_chart=${chartId}` : '';
+  return (
+    <>
+      {showSearch && (
+        <AntdInput
+          allowClear
+          placeholder={t('Search')}
+          prefix={<Icons.Search iconSize="l" />}
+          css={css`
+            width: ${WIDTH}px;
+            margin: ${theme.gridUnit * 2}px ${theme.gridUnit * 3}px;
+          `}
+          value={dashboardSearch}
+          onChange={e => setDashboardSearch(e.currentTarget.value?.trim())}
+        />
+      )}
+      <div
+        css={css`
+          max-height: ${HEIGHT}px;
+          overflow: auto;
+        `}
+      >
+        {filteredDashboards.map(dashboard => (
+          <Menu.Item
+            key={`${dashboard.id}`}
+            onMouseEnter={() => setHoveredItem(dashboard.id)}
+            onMouseLeave={() => {
+              if (hoveredItem === dashboard.id) {
+                setHoveredItem(null);
+              }
+            }}
+            {...menuProps}
+          >
+            <Link
+              target="_blank"

Review Comment:
   ```suggestion
                 target="_blank" rel="noreferer noopener"
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org