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:38:29 UTC

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

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


##########
superset-frontend/src/explore/components/useExploreAdditionalActionsMenu/DashboardsSubMenu.test.tsx:
##########
@@ -0,0 +1,78 @@
+/**
+ * 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 from 'react';
+import { render, screen, waitFor } from 'spec/helpers/testing-library';
+import userEvent from '@testing-library/user-event';
+import { Menu } from 'src/components/Menu';
+import DashboardItems from './DashboardsSubMenu';
+
+const asyncRender = (numberOfItems: number) =>
+  waitFor(() => {
+    const dashboards = [];
+    for (let i = 1; i <= numberOfItems; i += 1) {
+      dashboards.push({ id: i, dashboard_title: `Dashboard ${i}` });
+    }

Review Comment:
   Just a shortcut if you like
   ```suggestion
       const dashboards = Array.from({ length: numberOfItems }, (_, i) => ({ id: i+1, dashboard_title: `Dashboard ${i+1}`}));
   ```



##########
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)
+          ? t(
+              'To preview the list of dashboards go to "more" settings on the right.',

Review Comment:
   I think this text can be improved. I wouldn't mention "on the right" as it's easy to lose sight of this if the position should ever change. I believe something more generic like "You can preview the list of dashboards on the chart settings dropdown" or something like that



##########
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}`}

Review Comment:
   ```suggestion
               key={String(dashboard.id)}
   ```



##########
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

Review Comment:
   Should we move this to its own directory and enhance it like we did for all other Antd components? Definitely not a blocker for the PR though



-- 
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