Web: Add react grid and higher level wrapper

This commit is contained in:
Eric Harding committed 2018-05-03 16:54:05 -04:00
1 parent 2290c955ef
commit 3bb527247d
3 files changed
+38 -13

No files matched your search

+32
View File
@@ -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
[<Emit("{... $0, ... $1}")>]
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
+5 -13
View File
@@ -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) []
+1
View File
@@ -17,6 +17,7 @@
<Compile Include="../../../../build/web/api/fable/AdminService.fable.fs" />
<!-- Global to the app -->
<Compile Include="Controls/ReactGrid.fs" />
<Compile Include="Controls/DataGrid.fs" />
<Compile Include="Global.fs" />
<!-- Login -->
<Compile Include="Login/Login.fs" />