Skip to content

Commit

Permalink
[TypeScript] Add StaticDataTable type definition (#8878)
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
driusan authored Nov 13, 2023
1 parent db9ed84 commit 64ffdf4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
60 changes: 60 additions & 0 deletions jsx/StaticDataTable.d.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion jsx/StaticDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64ffdf4

Please sign in to comment.