You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2024/05/21 02:12:19 UTC
(superset) branch fix/dashboard-perf created (now 1e8db71226)
This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a change to branch fix/dashboard-perf
in repository https://gitbox.apache.org/repos/asf/superset.git
at 1e8db71226 update hooks
This branch includes the following new commits:
new 1e8db71226 update hooks
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: update hooks
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a commit to branch fix/dashboard-perf
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 1e8db712264c03794a5e6faf0fb118c774ef15b1
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Mon May 20 19:12:07 2024 -0700
update hooks
---
superset-frontend/src/components/ListView/types.ts | 1 -
.../src/pages/DashboardList/index.tsx | 31 ++++--
superset-frontend/src/views/CRUD/hooks.test.tsx | 106 +++++++++++++++++++++
superset-frontend/src/views/CRUD/hooks.ts | 5 +-
4 files changed, 129 insertions(+), 14 deletions(-)
diff --git a/superset-frontend/src/components/ListView/types.ts b/superset-frontend/src/components/ListView/types.ts
index 71e2e0feea..ca3a8b3c70 100644
--- a/superset-frontend/src/components/ListView/types.ts
+++ b/superset-frontend/src/components/ListView/types.ts
@@ -85,7 +85,6 @@ export interface FetchDataConfig {
pageSize: number;
sortBy: SortColumn[];
filters: FilterValue[];
- selectColumns: string[];
}
export interface InternalFilter extends FilterValue {
diff --git a/superset-frontend/src/pages/DashboardList/index.tsx b/superset-frontend/src/pages/DashboardList/index.tsx
index be51523333..82623c709b 100644
--- a/superset-frontend/src/pages/DashboardList/index.tsx
+++ b/superset-frontend/src/pages/DashboardList/index.tsx
@@ -111,6 +111,20 @@ const Actions = styled.div`
color: ${({ theme }) => theme.colors.grayscale.base};
`;
+const DASHBOARD_COLUMNS_TO_FETCH = [
+ 'id',
+ 'dashboard_title',
+ 'published',
+ 'url',
+ 'changed_by',
+ 'changed_on_delta_humanized',
+ 'owners',
+ 'tags',
+ 'status',
+ 'certified_by',
+ 'certification_details',
+];
+
function DashboardList(props: DashboardListProps) {
const { addDangerToast, addSuccessToast, user } = props;
@@ -135,6 +149,11 @@ function DashboardList(props: DashboardListProps) {
'dashboard',
t('dashboard'),
addDangerToast,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ DASHBOARD_COLUMNS_TO_FETCH,
);
const dashboardIds = useMemo(() => dashboards.map(d => d.id), [dashboards]);
const [saveFavoriteStatus, favoriteStatus] = useFavoriteStatus(
@@ -746,16 +765,8 @@ function DashboardList(props: DashboardListProps) {
count={dashboardCount}
data={dashboards}
disableBulkSelect={toggleBulkSelect}
- fetchData={config =>
- fetchData({
- ...config,
- selectColumns: ['dashboard_title'],
- })
- }
- refreshData={config => refreshData({
- ...config,
- selectColumns: ['dashboard_title'],
- })}
+ fetchData={fetchData}
+ refreshData={refreshData}
filters={filters}
initialSort={initialSort}
loading={loading}
diff --git a/superset-frontend/src/views/CRUD/hooks.test.tsx b/superset-frontend/src/views/CRUD/hooks.test.tsx
new file mode 100644
index 0000000000..6dd55236e5
--- /dev/null
+++ b/superset-frontend/src/views/CRUD/hooks.test.tsx
@@ -0,0 +1,106 @@
+/**
+ * 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 { renderHook } from '@testing-library/react-hooks';
+import { JsonResponse, SupersetClient } from '@superset-ui/core';
+
+import { useListViewResource } from './hooks';
+
+describe('useListViewResource', () => {
+ afterEach(() => {
+ jest.restoreAllMocks();
+ });
+
+ it('should fetch data with correct query parameters', async () => {
+ const pageIndex = 0; // Declare and initialize the pageIndex variable
+ const pageSize = 10; // Declare and initialize the pageSize variable
+ const baseFilters = [{ id: 'status', operator: 'equals', value: 'active' }];
+
+ const fetchSpy = jest.spyOn(SupersetClient, 'get').mockResolvedValue({
+ json: {
+ result: {
+ dashboard_title: 'New Title',
+ slug: '/new',
+ json_metadata: '{"something":"foo"}',
+ owners: [{ id: 1, first_name: 'Al', last_name: 'Pacino' }],
+ roles: [],
+ },
+ },
+ } as unknown as JsonResponse);
+
+ const { result } = renderHook(() =>
+ useListViewResource('example', 'Example', jest.fn()),
+ );
+ result.current.fetchData({
+ pageIndex,
+ pageSize,
+ sortBy: [{ id: 'foo' }], // Change the type of sortBy from string to SortColumn[]
+ filters: baseFilters,
+ });
+
+ expect(fetchSpy).toHaveBeenNthCalledWith(2, {
+ endpoint:
+ '/api/v1/example/?q=(filters:!((col:status,opr:equals,value:active)),order_column:foo,order_direction:asc,page:0,page_size:10)',
+ });
+ });
+
+ it('should pass the selectColumns to the fetch call', async () => {
+ const pageIndex = 0; // Declare and initialize the pageIndex variable
+ const pageSize = 10; // Declare and initialize the pageSize variable
+ const baseFilters = [{ id: 'status', operator: 'equals', value: 'active' }];
+ const selectColumns = ['id', 'name'];
+
+ const fetchSpy = jest.spyOn(SupersetClient, 'get').mockResolvedValue({
+ json: {
+ result: {
+ dashboard_title: 'New Title',
+ slug: '/new',
+ json_metadata: '{"something":"foo"}',
+ owners: [{ id: 1, first_name: 'Al', last_name: 'Pacino' }],
+ roles: [],
+ },
+ },
+ } as unknown as JsonResponse);
+
+ const { result } = renderHook(() =>
+ useListViewResource(
+ 'example',
+ 'Example',
+ jest.fn(),
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ selectColumns,
+ ),
+ );
+
+ result.current.fetchData({
+ pageIndex,
+ pageSize,
+ sortBy: [{ id: 'foo' }], // Change the type of sortBy from string to SortColumn[]
+ filters: baseFilters,
+ });
+
+ expect(fetchSpy).toHaveBeenNthCalledWith(2, {
+ endpoint:
+ '/api/v1/example/?q=(filters:!((col:status,opr:equals,value:active)),order_column:foo,order_direction:asc,page:0,page_size:10,select_columns:!(id,name))',
+ });
+ });
+});
diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts
index 3f6b01e805..6fa167d934 100644
--- a/superset-frontend/src/views/CRUD/hooks.ts
+++ b/superset-frontend/src/views/CRUD/hooks.ts
@@ -77,6 +77,7 @@ export function useListViewResource<D extends object = any>(
defaultCollectionValue: D[] = [],
baseFilters?: FilterValue[], // must be memoized
initialLoadingState = true,
+ selectColumns?: string[],
) {
const [state, setState] = useState<ListViewResourceState<D>>({
count: 0,
@@ -133,7 +134,6 @@ export function useListViewResource<D extends object = any>(
pageSize,
sortBy,
filters: filterValues,
- selectColumns = [],
}: FetchDataConfig) => {
// set loading state, cache the last config for refreshing data.
updateState({
@@ -142,7 +142,6 @@ export function useListViewResource<D extends object = any>(
pageIndex,
pageSize,
sortBy,
- selectColumns,
},
loading: true,
});
@@ -164,7 +163,7 @@ export function useListViewResource<D extends object = any>(
page: pageIndex,
page_size: pageSize,
...(filterExps.length ? { filters: filterExps } : {}),
- ...(selectColumns.length ? { select_columns: selectColumns } : {}),
+ ...(selectColumns?.length ? { select_columns: selectColumns } : {}),
});
return SupersetClient.get({