diff --git a/src/web/ui/src/Controls/DataGrid.fs b/src/web/ui/src/Controls/DataGrid.fs new file mode 100644 index 000000000..b4042c067 --- /dev/null +++ b/src/web/ui/src/Controls/DataGrid.fs @@ -0,0 +1,32 @@ +module DataGrid +open Fable.Core.Exceptions +open Fable.Core + +type ColumnDefinition = ReactGrid.ColumnDefinition + +type GridProps = + | EnableCellSelect of bool + | Columns of ColumnDefinition[] + | MinHeight of int + +let private mapProp = function + | EnableCellSelect b -> ReactGrid.EnableCellSelect b + | Columns c -> ReactGrid.Columns c + | MinHeight m -> ReactGrid.MinHeight m + +[] +let merge<'a> (_:'a) (_:obj) : 'a = jsNative + +let private update<'a> dispatch (rows:'a[]) (update:ReactGrid.GridUpdate) = + let updatedRows = Array.map (fun i -> merge rows.[i] update.updated) update.rowIds + dispatch updatedRows + +let dataGrid<'a> props (rows:'a[]) dispatch = + let rgprops = + (List.map mapProp props) @ [ + ReactGrid.RowGetter (fun i -> rows.[i]) + ReactGrid.OnGridRowsUpdated (update dispatch rows) + ] + ReactGrid.reactGrid rgprops + + diff --git a/src/web/ui/src/Controls/ReactGrid.fs b/src/web/ui/src/Controls/ReactGrid.fs index 34011bc8a..16125f279 100644 --- a/src/web/ui/src/Controls/ReactGrid.fs +++ b/src/web/ui/src/Controls/ReactGrid.fs @@ -3,14 +3,6 @@ open Fable.Helpers.React open Fable.Core.JsInterop open Fable.Core -type Model<'a> = { - rows : 'a[] -} - -type Message<'a> = - | RowUpdate of 'a - - type ColumnDefinition = { key : string name : string @@ -18,21 +10,21 @@ type ColumnDefinition = { editable : bool } -type GridUpdate<'a> = { - cellKey : 'a +type GridUpdate = { + cellKey : string fromRow : int toRow : int rowIds: int[] updated: obj } -type GridProps<'a,'b> = +type GridProps<'a> = | EnableCellSelect of bool | Columns of ColumnDefinition[] - | RowGetter of (int->'b) | RowsCount of int | MinHeight of int - | OnGridRowsUpdated of (GridUpdate<'a>->unit) + | RowGetter of (int->'a) + | OnGridRowsUpdated of (GridUpdate->unit) let reactGrid props = ofImport "default" "react-data-grid" (keyValueList CaseRules.LowerFirst props) [] diff --git a/src/web/ui/src/ui.fsproj b/src/web/ui/src/ui.fsproj index cbf9fce01..c12bdf014 100644 --- a/src/web/ui/src/ui.fsproj +++ b/src/web/ui/src/ui.fsproj @@ -17,6 +17,7 @@ +