From 6f9cf1dce1c1dfd365900402c7bc361e59fc7114 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Wed, 30 Aug 2023 10:33:23 -0400 Subject: [PATCH] [TypeScript] Add StaticDataTable type definition This adds a typescript module definition for StaticDataTable, so that it can be imported from typescript in strict mode without triggering errors. It also adds a new parameter to the "getFormattedColumn" callback to indicate the current index of the column. (This should technically be a different PR, but it's easier to do it at the same time rather than need to modify the definition after.) --- jsx/StaticDataTable.d.ts | 60 ++++++++++++++++++++++++++++++++++++++++ jsx/StaticDataTable.js | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 jsx/StaticDataTable.d.ts diff --git a/jsx/StaticDataTable.d.ts b/jsx/StaticDataTable.d.ts new file mode 100644 index 00000000000..5203cc84b54 --- /dev/null +++ b/jsx/StaticDataTable.d.ts @@ -0,0 +1,60 @@ +import {ReactNode} from 'react'; +/** + * This file contains a sufficient typescript definition of the StaticDataTable + * to allow it to be imported into TypeScript with "strict" mode and not trigger + * errors. + */ + +type TableRow = (string|null)[]; + +type StaticDataTableProps = { + Headers: string[], + Data: TableRow[], + RowNumLabel: string?, + getFormattedCell: ( + columnname: string, + celldata: string, + row: string[], + headers: string[], + fieldNo: number + ) => ReactNode, + onSort?: () => void +}; + +/** + * StaticDataTable class. See StaticDataTable.js + */ +class StaticDataTable { + props: StaticDataTableProps + state: any + context: object + refs: {[key: string]: ReactInstance} + + /** + * Create a StaticDataTable + * + * @param {StaticDataTableProps} props - React props + */ + constructor(props: StaticDataTableProps) + + /** + * React Lifecycle Method + * + * @returns {ReactNode} - the StaticDataTable + */ + render(): ReactNode + + /** + * React Lifecycle Method + * + * @param {object} newstate - the state to overwrite + */ + setState(newstate: object): void + + /** + * React Lifecycle Method + */ + forceUpdate(): void +} + +export default StaticDataTable; diff --git a/jsx/StaticDataTable.js b/jsx/StaticDataTable.js index 344821f0c18..50f3dae0448 100644 --- a/jsx/StaticDataTable.js +++ b/jsx/StaticDataTable.js @@ -527,7 +527,8 @@ class StaticDataTable extends Component { this.props.Headers[j], data, this.props.Data[index[i].RowIdx], - this.props.Headers + this.props.Headers, + j ); if (data !== null) { // Note: Can't currently pass a key, need to update columnFormatter