You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/10/06 14:11:42 UTC

[superset] branch feat/d2d-charts-crud-filter-col created (now 29284e22b3)

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

diegopucci pushed a change to branch feat/d2d-charts-crud-filter-col
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 29284e22b3 Add CrossLinks component and dashboards filter

This branch includes the following new commits:

     new 29284e22b3 Add CrossLinks component and dashboards filter

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: Add CrossLinks component and dashboards filter

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

diegopucci pushed a commit to branch feat/d2d-charts-crud-filter-col
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 29284e22b38f832b3ff7e66343baee8395df219d
Author: geido <di...@gmail.com>
AuthorDate: Thu Oct 6 17:11:18 2022 +0300

    Add CrossLinks component and dashboards filter
---
 .../src/components/ListView/CrossLinks.tsx         | 104 +++++++++++++++++++++
 .../src/views/CRUD/chart/ChartList.tsx             |  74 +++++++++++++++
 2 files changed, 178 insertions(+)

diff --git a/superset-frontend/src/components/ListView/CrossLinks.tsx b/superset-frontend/src/components/ListView/CrossLinks.tsx
new file mode 100644
index 0000000000..34da77fb63
--- /dev/null
+++ b/superset-frontend/src/components/ListView/CrossLinks.tsx
@@ -0,0 +1,104 @@
+/**
+ * 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 { styled, t } from '@superset-ui/core';
+import { Tooltip } from 'src/components/Tooltip';
+import { Link } from 'react-router-dom';
+
+export type CrossLinkProps = {
+  title: string;
+  id: number;
+};
+
+interface CrossLinksProps {
+  crossLinks: Array<CrossLinkProps>;
+  maxLinks?: number;
+  linkPrefix?: string;
+}
+
+const StyledCrossLinks = styled.div`
+  color: ${({ theme }) => theme.colors.primary.dark1};
+  cursor: pointer;
+
+  .ant-tooltip-open {
+    max-width: 100%;
+  }
+
+  .truncated {
+    max-width: calc(100% - 20px);
+    white-space: nowrap;
+    display: inline-block;
+    overflow: hidden;
+    vertical-align: bottom;
+    text-overflow: ellipsis;
+  }
+`;
+
+const StyledLinkedTooltip = styled.div`
+  .link {
+    color: ${({ theme }) => theme.colors.grayscale.light5};
+    display: block;
+    text-decoration: underline;
+  }
+`;
+
+export default function CrossLinks({
+  crossLinks,
+  maxLinks = 50,
+  linkPrefix = '/superset/dashboard/',
+}: CrossLinksProps) {
+  return (
+    <StyledCrossLinks>
+      {crossLinks.length > 1 ? (
+        <Tooltip
+          title={
+            <StyledLinkedTooltip>
+              {crossLinks.slice(0, maxLinks).map(link => (
+                <Link
+                  className="link"
+                  key={link.id}
+                  to={linkPrefix + link.id}
+                  target="_blank"
+                >
+                  {link.title}
+                </Link>
+              ))}
+              {crossLinks.length > maxLinks && (
+                <span>{t('Plus %s more', crossLinks.length - maxLinks)}</span>
+              )}
+            </StyledLinkedTooltip>
+          }
+        >
+          <span className="truncated">
+            {crossLinks.map(link => link.title).join(', ')}
+          </span>{' '}
+          +{crossLinks.length}
+        </Tooltip>
+      ) : (
+        <span>
+          {crossLinks[0] && (
+            <Link to={linkPrefix + crossLinks[0].id} target="_blank">
+              {crossLinks[0].title}
+            </Link>
+          )}
+        </span>
+      )}
+    </StyledCrossLinks>
+  );
+}
diff --git a/superset-frontend/src/views/CRUD/chart/ChartList.tsx b/superset-frontend/src/views/CRUD/chart/ChartList.tsx
index 8fbf37392f..6376fa4bcb 100644
--- a/superset-frontend/src/views/CRUD/chart/ChartList.tsx
+++ b/superset-frontend/src/views/CRUD/chart/ChartList.tsx
@@ -49,6 +49,7 @@ import ListView, {
   ListViewProps,
   SelectOption,
 } from 'src/components/ListView';
+import CrossLinks from 'src/components/ListView/CrossLinks';
 import Loading from 'src/components/Loading';
 import { dangerouslyGetItemDoNotUse } from 'src/utils/localStorageHelpers';
 import withToasts from 'src/components/MessageToasts/withToasts';
@@ -135,6 +136,47 @@ const createFetchDatasets = async (
   };
 };
 
+const createFetchDashboards = async (
+  filterValue = '',
+  page: number,
+  pageSize: number,
+) => {
+  // add filters if filterValue
+  const filters = filterValue
+    ? { filters: [{ col: 'dashboards', opr: 'rel_m_m', value: filterValue }] }
+    : {};
+  const queryParams = rison.encode({
+    columns: ['dashboard_title', 'id'],
+    keys: ['none'],
+    order_column: 'dashboard_title',
+    order_direction: 'asc',
+    page,
+    page_size: pageSize,
+    ...filters,
+  });
+  const { json = {} } = await SupersetClient.get({
+    endpoint: !filterValue
+      ? `/api/v1/dashboard/?q=${queryParams}`
+      : `/api/v1/chart/?q=${queryParams}`,
+  });
+  const dashboards = json?.result?.map(
+    ({
+      dashboard_title: dashboardTitle,
+      id,
+    }: {
+      dashboard_title: string;
+      id: number;
+    }) => ({
+      label: dashboardTitle,
+      value: id,
+    }),
+  );
+  return {
+    data: uniqBy<SelectOption>(dashboards, 'value'),
+    totalCount: json?.count,
+  };
+};
+
 interface ChartListProps {
   addDangerToast: (msg: string) => void;
   addSuccessToast: (msg: string) => void;
@@ -145,6 +187,11 @@ interface ChartListProps {
   };
 }
 
+type ChartLinkedDashboard = {
+  id: number;
+  dashboard_title: string;
+};
+
 const Actions = styled.div`
   color: ${({ theme }) => theme.colors.grayscale.base};
 `;
@@ -324,6 +371,24 @@ function ChartList(props: ChartListProps) {
         disableSortBy: true,
         size: 'xl',
       },
+      {
+        Cell: ({
+          row: {
+            original: { dashboards },
+          },
+        }: any) => (
+          <CrossLinks
+            crossLinks={dashboards.map((d: ChartLinkedDashboard) => ({
+              title: d.dashboard_title,
+              id: d.id,
+            }))}
+          />
+        ),
+        Header: t('Dashboards added to'),
+        accessor: 'dashboards',
+        disableSortBy: true,
+        size: 'xxl',
+      },
       {
         Cell: ({
           row: {
@@ -568,6 +633,15 @@ function ChartList(props: ChartListProps) {
         fetchSelects: createFetchDatasets,
         paginate: true,
       },
+      {
+        Header: t('Dashboards'),
+        id: 'dashboards',
+        input: 'select',
+        operator: FilterOperator.relationManyMany,
+        unfilteredLabel: t('All'),
+        fetchSelects: createFetchDashboards,
+        paginate: true,
+      },
       ...(userId ? [favoritesFilter] : []),
       {
         Header: t('Certified'),