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/11/17 22:51:57 UTC

[GitHub] [superset] eric-briscoe commented on a diff in pull request #22135: feat: Adds virtualization option to antd based Table component

eric-briscoe commented on code in PR #22135:
URL: https://github.com/apache/superset/pull/22135#discussion_r1025806507


##########
superset-frontend/src/components/Table/Table.overview.mdx:
##########
@@ -183,14 +183,27 @@ The table displays a set number of rows at a time, the user navigates the table
 The default page size and page size options for the menu are configurable via the `pageSizeOptions` and `defaultPageSize` props.
 NOTE: Pagination controls will only display when the data for the table has more records than the default page size.
 
-<Story id="design-system-components-table-examples--many-columns" />
+<Story id="design-system-components-table-examples--pagination" />
 
 ```
 <Table pageSizeOptions={[5, 10, 15, 20, 25] defaultPageSize={10} />
 ```
 
 ---
 
+### Virtualization for Performance
+
+The Table virtualization can be used to enable viewing data with many columns and or rows without paging.
+Virtualization can be enabled via the `virtualize` prop. Pagination is shown in this example but can be truned off by setting `pagination={false}`

Review Comment:
   nice catch!



##########
superset-frontend/src/components/Table/Table.overview.mdx:
##########
@@ -183,14 +183,27 @@ The table displays a set number of rows at a time, the user navigates the table
 The default page size and page size options for the menu are configurable via the `pageSizeOptions` and `defaultPageSize` props.
 NOTE: Pagination controls will only display when the data for the table has more records than the default page size.
 
-<Story id="design-system-components-table-examples--many-columns" />
+<Story id="design-system-components-table-examples--pagination" />
 
 ```
 <Table pageSizeOptions={[5, 10, 15, 20, 25] defaultPageSize={10} />
 ```
 
 ---
 
+### Virtualization for Performance
+
+The Table virtualization can be used to enable viewing data with many columns and or rows without paging.

Review Comment:
   makes sense



##########
superset-frontend/src/components/Table/Table.stories.tsx:
##########
@@ -286,31 +321,37 @@ Basic.args = {
   columns: basicColumns,
   size: TableSize.SMALL,
   onRow: handlers,
+  usePagination: false,
+};
+
+export const Pagination: ComponentStory<typeof Table> = args => (
+  <Table {...args} />
+);
+
+Pagination.args = {
+  data: basicData,
+  columns: basicColumns,
+  size: TableSize.SMALL,
   pageSizeOptions: ['5', '10', '15', '20', '25'],
-  defaultPageSize: 10,
+  defaultPageSize: 5,
 };
 
-export const ManyColumns: ComponentStory<typeof Table> = args => (
-  <ThemeProvider theme={supersetTheme}>
-    <div style={{ height: '350px' }}>
-      <Table {...args} />
-    </div>
-  </ThemeProvider>
+export const VirtualizedPerformance: ComponentStory<typeof Table> = args => (
+  <Table {...args} />
 );
 
-ManyColumns.args = {
+VirtualizedPerformance.args = {
   data: bigdata,
   columns: bigColumns,
   size: TableSize.SMALL,
   resizable: true,
   reorderable: true,
   height: 350,
+  virtualize: true,

Review Comment:
   👍 



##########
superset-frontend/src/components/Table/VirtualTable.tsx:
##########
@@ -0,0 +1,154 @@
+/**
+ * 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 { Table } from 'antd';
+import type { TableProps } from 'antd/es/table';
+import classNames from 'classnames';
+import ResizeObserver from 'rc-resize-observer';
+import React, { useEffect, useRef, useState } from 'react';
+import { VariableSizeGrid as Grid } from 'react-window';
+import styled from '@emotion/styled';
+
+// If a column definition has no width, react-window will use this as the default column width
+const DEFAULT_COL_WIDTH = 150;
+
+const StyledCell = styled.div`
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  padding-left: 8px;
+  padding-right: 4px;

Review Comment:
   thanks, Addressing use of theme.gridUnit in next commit



##########
superset-frontend/package.json:
##########
@@ -158,6 +158,7 @@
     "polished": "^3.7.2",
     "prop-types": "^15.7.2",
     "query-string": "^6.13.7",
+    "rc-resize-observer": "^1.2.0",

Review Comment:
   Verified this works well and excited to NOT add a new dependency - thanks for the suggestion!  will add changes in next commit



##########
superset-frontend/src/components/Table/index.tsx:
##########
@@ -167,6 +177,20 @@ const StyledTable: StyledComponent<any> = styled(AntTable)<any>`
   `}
 `;
 
+const StyledVirtualTable: StyledComponent<any> = styled(VirtualTable)<any>`
+  .virtual-table .ant-table-container:before,
+  .virtual-table .ant-table-container:after {
+    display: none;
+  }
+  .virtual-table-cell {
+    box-sizing: border-box;
+    padding: 16px;

Review Comment:
   I will update with use of theme.gridUnit, thx!



##########
superset-frontend/package.json:
##########
@@ -158,6 +158,7 @@
     "polished": "^3.7.2",
     "prop-types": "^15.7.2",
     "query-string": "^6.13.7",
+    "rc-resize-observer": "^1.2.0",

Review Comment:
   Great idea, happy to remove new dependency!



##########
superset-frontend/src/components/Table/Table.stories.tsx:
##########
@@ -35,6 +35,13 @@ export default {
   title: 'Design System/Components/Table/Examples',
   component: Table,
   argTypes: { onClick: { action: 'clicked' } },
+  decorators: [
+    Story => (
+      <ThemeProvider theme={supersetTheme}>
+        <Story />
+      </ThemeProvider>
+    ),
+  ],

Review Comment:
   great, nice catch!



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