Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Improving typing on data prop and related manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Rivet committed Apr 21, 2020
1 parent e3d6fca commit 8350c64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/dash-table/components/Table/derivedPropsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QuerySyntaxTree from 'dash-table/syntax-tree/QuerySyntaxTree';

import {
ControlledTableProps,
IndexedData,
SanitizedAndDerivedProps,
SetProps,
TableAction
Expand Down Expand Up @@ -67,19 +68,19 @@ export default () => {
if (!virtualCached) {
newProps.derived_virtual_data = virtual.data;
newProps.derived_virtual_indices = virtual.indices;
newProps.derived_virtual_row_ids = R.pluck('id', virtual.data);
newProps.derived_virtual_row_ids = R.pluck('id', virtual.data as IndexedData);
}

if (!viewportCached) {
newProps.derived_viewport_data = viewport.data;
newProps.derived_viewport_indices = viewport.indices;
newProps.derived_viewport_row_ids = R.pluck('id', viewport.data);
newProps.derived_viewport_row_ids = R.pluck('id', viewport.data as IndexedData);
}

if (!virtualSelectedRowsCached) {
newProps.derived_virtual_selected_rows = virtual_selected_rows;
newProps.derived_virtual_selected_row_ids = R.map(
i => virtual.data[i].id,
i => (virtual.data as IndexedData)[i].id,
virtual_selected_rows
);
}
Expand All @@ -91,7 +92,7 @@ export default () => {
if (!viewportSelectedRowsCached) {
newProps.derived_viewport_selected_rows = viewport_selected_rows;
newProps.derived_viewport_selected_row_ids = R.map(
i => viewport.data[i].id,
i => (viewport.data as IndexedData)[i].id,
viewport_selected_rows
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/dash-table/components/Table/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export interface ICellCoordinates {
export type ColumnId = string;
export type Columns = IColumn[];
export type Data = Datum[];
export type IndexedData = IndexedDatum[];
export type Datum = IDatumObject;
export type IndexedDatum = Omit<Datum, 'id'> & { id: number | string; };
export type Indices = number[];
export type RowId = string | number;
export type SelectedCells = ICellCoordinates[];
Expand Down Expand Up @@ -199,7 +201,7 @@ export type IColumnType = INumberColumn | ITextColumn | IDatetimeColumn | IAnyCo
export type IColumn = IBaseColumn & IColumnType;

interface IDatumObject {
[key: string]: any;
[key: string]: boolean | number | string | null | undefined;
}

export interface IDropdownValue {
Expand Down
4 changes: 2 additions & 2 deletions src/dash-table/derived/cell/cellProps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { map, range, xprod } from 'ramda';
import { ICellCoordinates, Columns, IDerivedData } from 'dash-table/components/Table/props';
import { ICellCoordinates, Columns, IDerivedData, IndexedData } from 'dash-table/components/Table/props';

export function makeCell (
row: number,
Expand All @@ -12,7 +12,7 @@ export function makeCell (
column,
column_id: columns[column].id
};
const rowId = viewport.data[row].id;
const rowId = (viewport.data as IndexedData)[row].id;
if (rowId !== undefined) {
cell.row_id = rowId;
}
Expand Down

0 comments on commit 8350c64

Please sign in to comment.