eric-briscoe commented on code in PR #21520: URL: https://github.com/apache/superset/pull/21520#discussion_r1017087752
########## superset-frontend/src/components/Table/Table.stories.tsx: ########## @@ -0,0 +1,471 @@ +/** + * 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 { ComponentStory, ComponentMeta } from '@storybook/react'; +import { supersetTheme, ThemeProvider } from '@superset-ui/core'; +import { ColumnsType } from 'antd/es/table'; +import { Table, TableSize, SUPERSET_TABLE_COLUMN } from './index'; +import { numericalSort, alphabeticalSort } from './sorters'; +import ButtonCell from './cell-renderers/ButtonCell'; +import ActionCell from './cell-renderers/ActionCell'; +import { exampleMenuOptions } from './cell-renderers/ActionCell/fixtures'; +import NumericCell, { + CurrencyCode, + LocaleCode, + Style, +} from './cell-renderers/NumericCell'; + +export default { + title: 'Design System/Components/Table/Examples', + component: Table, +} as ComponentMeta<typeof Table>; + +// eslint-disable-next-line no-alert +const handleClick = (data: object, index: number) => + alert(`I was Clicked: ${JSON.stringify(data)}, index: ${index}`); Review Comment: @lyndsiWilliams Great point, using storybook actions as suggested by @michael-s-molina ########## superset-frontend/src/components/Table/Table.stories.tsx: ########## @@ -0,0 +1,471 @@ +/** + * 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 { ComponentStory, ComponentMeta } from '@storybook/react'; +import { supersetTheme, ThemeProvider } from '@superset-ui/core'; +import { ColumnsType } from 'antd/es/table'; +import { Table, TableSize, SUPERSET_TABLE_COLUMN } from './index'; +import { numericalSort, alphabeticalSort } from './sorters'; +import ButtonCell from './cell-renderers/ButtonCell'; +import ActionCell from './cell-renderers/ActionCell'; +import { exampleMenuOptions } from './cell-renderers/ActionCell/fixtures'; +import NumericCell, { + CurrencyCode, + LocaleCode, + Style, +} from './cell-renderers/NumericCell'; + +export default { + title: 'Design System/Components/Table/Examples', + component: Table, +} as ComponentMeta<typeof Table>; + +// eslint-disable-next-line no-alert +const handleClick = (data: object, index: number) => + alert(`I was Clicked: ${JSON.stringify(data)}, index: ${index}`); + +export interface BasicData { + name: string; + category: string; + price: number; + description?: string; + key: number; +} + +export interface RendererData { + key: number; + buttonCell: string; + textCell: string; + euroCell: number; + dollarCell: number; +} + +export interface ExampleData { + title: string; + name: string; + age: number; + address: string; + tags?: string[]; + key: number; +} + +function generateValues(amount: number): object { + const cells = {}; + for (let i = 0; i < amount; i += 1) { + cells[`col-${i}`] = `Text ${i}`; + } + return cells; +} + +function generateColumns(amount: number): ColumnsType<ExampleData>[] { + const newCols: any[] = []; + for (let i = 0; i < amount; i += 1) { + newCols.push({ + title: `Column Header ${i}`, + dataIndex: `col-${i}`, + key: `col-${i}`, + }); + } + return newCols as ColumnsType<ExampleData>[]; +} +const recordCount = 200; +const columnCount = 12; +const randomCols: ColumnsType<ExampleData>[] = generateColumns(columnCount); + +const basicData: BasicData[] = [ + { + key: 1, + name: 'Floppy Disk 10 pack', + category: 'Disk Storage', + price: 9.99, + description: 'A real blast from the past', + }, + { + key: 2, + name: 'DVD 100 pack', + category: 'Optical Storage', + price: 27.99, + description: 'Still pretty ancient', + }, + { + key: 3, + name: '128 GB SSD', + category: 'Hardrive', + price: 49.99, + description: 'Reliable and fast data storage', + }, +]; + +const basicColumns: ColumnsType<BasicData> = [ + { + title: 'Name', + dataIndex: 'name', + key: 'name', + width: 150, + sorter: (a: BasicData, b: BasicData) => alphabeticalSort('name', a, b), + }, + { + title: 'Category', + dataIndex: 'category', + key: 'category', + sorter: (a: BasicData, b: BasicData) => alphabeticalSort('category', a, b), + }, + { + title: 'Price', + dataIndex: 'price', + key: 'price', + sorter: (a: BasicData, b: BasicData) => numericalSort('price', a, b), + }, + { + title: 'Description', + dataIndex: 'description', + key: 'description', + }, +]; + +const bigColumns: ColumnsType<ExampleData> = [ + { + title: 'Name', + dataIndex: 'name', + key: 'name', + render: (text: string, row: object, index: number) => ( + <ButtonCell label={text} onClick={handleClick} row={row} index={index} /> + ), + width: 150, + }, + { + title: 'Age', + dataIndex: 'age', + key: 'age', + }, + { + title: 'Address', + dataIndex: 'address', + key: 'address', + }, + ...(randomCols as ColumnsType<ExampleData>), +]; + +const rendererColumns: ColumnsType<RendererData> = [ + { + title: 'Button Cell', + dataIndex: 'buttonCell', + key: 'buttonCell', + width: 150, + render: (text: string, data: object, index: number) => ( + <ButtonCell + label={text} + row={data} + index={index} + onClick={(row: object, index: number) => + // eslint-disable-next-line no-alert + alert(`Cell was clicked: row ${index}, row: ${JSON.stringify(row)}`) Review Comment: using storybook actions as suggested by @michael-s-molina -- 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-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org