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/11 13:11:08 UTC

[GitHub] [superset] michael-s-molina commented on a diff in pull request #21760: feat: Cross-referenced Dashboards in Chart list (Column + Filter)

michael-s-molina commented on code in PR #21760:
URL: https://github.com/apache/superset/pull/21760#discussion_r992294388


##########
superset-frontend/src/components/ListView/CrossLinks.test.tsx:
##########
@@ -0,0 +1,97 @@
+/**
+ * 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 } from 'spec/helpers/testing-library';
+import CrossLinks, { CrossLinksProps } from './CrossLinks';
+
+const mockedProps = {
+  crossLinks: [
+    {
+      id: 1,
+      title: 'Test dashboard',
+    },
+    {
+      id: 2,
+      title: 'Test dashboard 2',
+    },
+    {
+      id: 3,
+      title: 'Test dashboard 3',
+    },
+    {
+      id: 4,
+      title: 'Test dashboard 4',
+    },
+  ],
+};
+
+function setup(overrideProps: CrossLinksProps | {} = {}) {
+  return render(<CrossLinks {...{ ...mockedProps, ...overrideProps }} />, {
+    useRouter: true,
+  });
+}
+
+test('should render', () => {
+  const { container } = setup();
+  expect(container).toBeInTheDocument();
+});
+
+test('should not render links', () => {
+  setup({
+    crossLinks: [],
+  });
+  expect(screen.queryByRole('link')).not.toBeInTheDocument();
+});
+
+test('should render the link with just one item', () => {
+  setup({
+    crossLinks: [
+      {
+        id: 1,
+        title: 'Test dashboard',
+      },
+    ],
+  });
+  expect(screen.getByText('Test dashboard')).toBeInTheDocument();
+  expect(screen.getByRole('link')).toHaveAttribute(
+    'href',
+    `/superset/dashboard/1`,
+  );
+});
+
+test('should render a custom prefix link', () => {
+  setup({
+    crossLinks: [
+      {
+        id: 1,
+        title: 'Test dashboard',
+      },
+    ],
+    linkPrefix: '/preset/dashboard/',
+  });
+  expect(screen.getByRole('link')).toHaveAttribute(
+    'href',
+    `/preset/dashboard/1`,

Review Comment:
   ```suggestion
       `/custom/dashboard/1`,
   ```



##########
superset-frontend/src/components/ListView/CrossLinks.test.tsx:
##########
@@ -0,0 +1,97 @@
+/**
+ * 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 } from 'spec/helpers/testing-library';
+import CrossLinks, { CrossLinksProps } from './CrossLinks';
+
+const mockedProps = {
+  crossLinks: [
+    {
+      id: 1,
+      title: 'Test dashboard',
+    },
+    {
+      id: 2,
+      title: 'Test dashboard 2',
+    },
+    {
+      id: 3,
+      title: 'Test dashboard 3',
+    },
+    {
+      id: 4,
+      title: 'Test dashboard 4',
+    },
+  ],
+};
+
+function setup(overrideProps: CrossLinksProps | {} = {}) {
+  return render(<CrossLinks {...{ ...mockedProps, ...overrideProps }} />, {

Review Comment:
   ```suggestion
     return render(<CrossLinks {...mockedProps} {...overrideProps} />, {
   ```



##########
superset-frontend/src/views/CRUD/chart/ChartList.tsx:
##########
@@ -324,6 +397,7 @@ function ChartList(props: ChartListProps) {
         disableSortBy: true,
         size: 'xl',
       },
+      ...(enableCrossRef ? [dashboardsCol] : []),

Review Comment:
   ```suggestion
         ...(crossRefEnabled ? [dashboardsCol] : []),
   ```



##########
superset-frontend/src/views/CRUD/chart/ChartList.tsx:
##########
@@ -568,6 +655,7 @@ function ChartList(props: ChartListProps) {
         fetchSelects: createFetchDatasets,
         paginate: true,
       },
+      ...(enableCrossRef ? [dashboardsFilter] : []),

Review Comment:
   ```suggestion
         ...(crossRefEnabled ? [dashboardsFilter] : []),
   ```



##########
superset-frontend/src/components/ListView/CrossLinks.test.tsx:
##########
@@ -0,0 +1,97 @@
+/**
+ * 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 } from 'spec/helpers/testing-library';
+import CrossLinks, { CrossLinksProps } from './CrossLinks';
+
+const mockedProps = {
+  crossLinks: [
+    {
+      id: 1,
+      title: 'Test dashboard',
+    },
+    {
+      id: 2,
+      title: 'Test dashboard 2',
+    },
+    {
+      id: 3,
+      title: 'Test dashboard 3',
+    },
+    {
+      id: 4,
+      title: 'Test dashboard 4',
+    },
+  ],
+};
+
+function setup(overrideProps: CrossLinksProps | {} = {}) {
+  return render(<CrossLinks {...{ ...mockedProps, ...overrideProps }} />, {
+    useRouter: true,
+  });
+}
+
+test('should render', () => {
+  const { container } = setup();
+  expect(container).toBeInTheDocument();
+});
+
+test('should not render links', () => {
+  setup({
+    crossLinks: [],
+  });
+  expect(screen.queryByRole('link')).not.toBeInTheDocument();
+});
+
+test('should render the link with just one item', () => {
+  setup({
+    crossLinks: [
+      {
+        id: 1,
+        title: 'Test dashboard',
+      },
+    ],
+  });
+  expect(screen.getByText('Test dashboard')).toBeInTheDocument();
+  expect(screen.getByRole('link')).toHaveAttribute(
+    'href',
+    `/superset/dashboard/1`,
+  );
+});
+
+test('should render a custom prefix link', () => {
+  setup({
+    crossLinks: [
+      {
+        id: 1,
+        title: 'Test dashboard',
+      },
+    ],
+    linkPrefix: '/preset/dashboard/',

Review Comment:
   ```suggestion
       linkPrefix: '/custom/dashboard/',
   ```



##########
superset-frontend/src/views/CRUD/chart/ChartList.tsx:
##########
@@ -135,6 +137,47 @@ const createFetchDatasets = async (
   };
 };
 
+const createFetchDashboards = async (

Review Comment:
   Why is this named with a `create` prefix? Should it just be `fetchDashboards`?



##########
superset-frontend/src/views/CRUD/chart/ChartList.tsx:
##########
@@ -217,6 +265,7 @@ function ChartList(props: ChartListProps) {
   const initialSort = [{ id: 'changed_on_delta_humanized', desc: true }];
   const enableBroadUserAccess =
     bootstrapData?.common?.conf?.ENABLE_BROAD_ACTIVITY_ACCESS;
+  const enableCrossRef = isFeatureEnabled(FeatureFlag.CROSS_REFERENCES);

Review Comment:
   ```suggestion
     const crossRefEnabled = isFeatureEnabled(FeatureFlag.CROSS_REFERENCES);
   ```



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