Skip to content

Commit bd45399

Browse files
authored
Merge pull request #27 from mr-m-coetzee/DashTable
Add Dash table
2 parents ef98069 + 9f97643 commit bd45399

File tree

18 files changed

+2919
-35
lines changed

18 files changed

+2919
-35
lines changed

Diff for: src/Dash.NET.Giraffe/DashApp.fs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open Microsoft.Extensions.Logging
1515
open Microsoft.Extensions.DependencyInjection
1616
open System.Reflection
1717
open Dash.NET
18+
open Newtonsoft.Json
1819

1920
//Giraffe, Logging and ASP.NET specific
2021
type DashGiraffeConfig = {
@@ -241,6 +242,11 @@ type DashApp =
241242
services.AddCors() |> ignore
242243
services.AddGiraffe() |> ignore
243244

245+
Common.Json.mkSerializerSettings()
246+
|> NewtonsoftJson.Serializer
247+
|> services.AddSingleton<Json.ISerializer>
248+
|> ignore
249+
244250
let configureLogging (builder : ILoggingBuilder) =
245251
builder.AddFilter(fun l -> l.Equals config.LogLevel)
246252
.AddConsole()

Diff for: src/Dash.NET.Giraffe/Views.fs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Views =
3838
script [_type "application/javascript"; _crossorigin " "; _src "https://unpkg.com/[email protected]/dash_core_components/dash_core_components.min.js"] []
3939
script [_type "application/javascript"; _crossorigin " "; _src "https://cdn.jsdelivr.net/npm/[email protected]/dash_html_components/dash_html_components.min.js"] []
4040
script [_type "application/javascript"; _crossorigin " "; _src "https://cdn.plot.ly/plotly-latest.min.js"] []
41+
script [_type "application/javascript"; _crossorigin " "; _src DashTable.CdnLink ] []
4142
]
4243

4344
let createIndex metas appTitle faviconPath css appEntry config scripts renderer =

Diff for: src/Dash.NET.Suave/App.fs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ open Newtonsoft.Json
1313
open Newtonsoft.Json.Serialization
1414

1515
module Util =
16-
let settings = new JsonSerializerSettings()
17-
settings.ContractResolver <- CamelCasePropertyNamesContractResolver()
16+
let settings = Common.Json.mkSerializerSettings()
1817
let json o = JsonConvert.SerializeObject(o, settings)
1918
let unjson<'T> str = JsonConvert.DeserializeObject<'T>(str,settings)
2019

Diff for: src/Dash.NET.Suave/Views.fs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Views =
3535
script ["type", "application/javascript"; "crossorigin", " "; "src", "https://unpkg.com/[email protected]/dash_core_components/dash_core_components.min.js"] []
3636
script ["type", "application/javascript"; "crossorigin", " "; "src", "https://cdn.jsdelivr.net/npm/[email protected]/dash_html_components/dash_html_components.min.js"] []
3737
script ["type", "application/javascript"; "crossorigin", " "; "src", "https://cdn.plot.ly/plotly-latest.min.js"] []
38+
script ["type", "application/javascript"; "crossorigin", " "; "src", DashTable.CdnLink ] []
3839
]
3940

4041
let createIndex metas appTitle faviconPath css appEntry config scripts renderer =

Diff for: src/Dash.NET/Common.fs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Dash.NET.Common
2+
3+
[<RequireQualifiedAccess>]
4+
module Json =
5+
6+
open Newtonsoft.Json
7+
open Newtonsoft.Json.Serialization
8+
9+
let mkSerializerSettings () =
10+
JsonSerializerSettings(
11+
ContractResolver = DefaultContractResolver(NamingStrategy = new DefaultNamingStrategy())
12+
)
13+

Diff for: src/Dash.NET/Dash.NET.fsproj

+2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
<Compile Include="DashComponents\CoreComponents\Textarea.fs" />
5757
<Compile Include="DashComponents\CoreComponents\Upload.fs" />
5858
<Compile Include="DashComponents\CoreComponents\Slider.fs" />
59+
<Compile Include="DashComponents\DashTable.fs" />
5960
<Compile Include="DynamicInvoke.fs" />
6061
<Compile Include="Dependency.fs" />
6162
<Compile Include="CallbackBinding.fs" />
6263
<Compile Include="Callback.fs" />
6364
<Compile Include="CallbackBuilder.fs" />
6465
<Compile Include="DashConfig.fs" />
6566
<Compile Include="Operators.fs" />
67+
<Compile Include="Common.fs" />
6668
</ItemGroup>
6769

6870
<ItemGroup>

Diff for: src/Dash.NET/DashComponents/ComponentBase.fs

+36-5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ module ComponentPropTypes =
101101
ComponentName : string
102102
}
103103
static member create isLoading propName componentName = {IsLoading=isLoading; PropName=propName; ComponentName=componentName}
104+
static member convert this =
105+
box {|
106+
isLoading = this.IsLoading
107+
propName = this.PropName
108+
componentName = this.ComponentName
109+
|}
104110

105111
type PersistenceTypeOptions =
106112
| Local
@@ -120,6 +126,13 @@ module ComponentPropTypes =
120126
Title:string
121127
}
122128
static member create label value disabled title = {Label=label; Value=value; Disabled=disabled; Title=title}
129+
static member convert this =
130+
box {|
131+
label = this.Label
132+
value = this.Value
133+
disabled = this.Disabled
134+
title= this.Title
135+
|}
123136

124137
type RadioItemsOption =
125138
{
@@ -128,14 +141,26 @@ module ComponentPropTypes =
128141
Disabled:bool
129142
}
130143
static member create label value disabled = {Label=label; Value=value; Disabled=disabled}
131-
132-
type TabColors =
144+
static member convert this =
145+
box {|
146+
label = this.Label
147+
value = this.Value
148+
disabled = this.Disabled
149+
|}
150+
151+
type TabColors =
133152
{
134153
Border : string
135154
Primary : string
136155
Background : string
137156
}
138157
static member create border primary background = {Border=border; Primary=primary; Background=background}
158+
static member convert this =
159+
box {|
160+
border = this.Border
161+
primary = this.Primary
162+
background = this.Background
163+
|}
139164

140165
type ChecklistOption =
141166
{
@@ -145,10 +170,16 @@ module ComponentPropTypes =
145170
}
146171
static member create label value disabled =
147172
{
148-
Label=label
149-
Value=value
150-
Disabled=disabled
173+
Label = label
174+
Value = value
175+
Disabled = disabled
151176
}
177+
static member convert this =
178+
box {|
179+
label = this.Label
180+
value = this.Value
181+
disabled = this.Disabled
182+
|}
152183

153184
type ComponentProperty =
154185
| Children

Diff for: src/Dash.NET/DashComponents/CoreComponents/Checklist.fs

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ module Checklist =
6464
| PersistenceType of PersistenceTypeOptions
6565
static member toDynamicMemberDef(prop: Prop) =
6666
match prop with
67-
| Options p -> "options", box p
67+
| Options p -> "options", p |> Seq.map ChecklistOption.convert |> box
6868
| Value p -> "value", box p
6969
| ClassName p -> "className", box p
7070
| Style p -> "style", box p
7171
| InputStyle p -> "inputStyle", box p
7272
| InputClassName p -> "inputClassName", box p
7373
| LabelStyle p -> "labelStyle", box p
7474
| LabelClassName p -> "labelClassName", box p
75-
| LoadingState p -> "loading_state", box p
75+
| LoadingState p -> "loading_state", LoadingState.convert p
7676
| Persistence p -> "persistence", box p
7777
| PersistedProps p -> "persisted_props", box p
7878
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
@@ -201,15 +201,15 @@ module Checklist =
201201
let props = DashComponentProps()
202202
DynObj.setValue props "id" id
203203
DynObj.setValue props "children" children
204-
DynObj.setValueOpt props "options" (options |> Option.map box)
204+
DynObj.setValueOpt props "options" (options |> Option.map (Seq.map ChecklistOption.convert >> box))
205205
DynObj.setValueOpt props "value" (value |> Option.map box)
206206
DynObj.setValueOpt props "className" (className |> Option.map box)
207207
DynObj.setValueOpt props "style" (style |> Option.map box)
208208
DynObj.setValueOpt props "inputStyle" (inputStyle |> Option.map box)
209209
DynObj.setValueOpt props "inputClassName" (inputClassName |> Option.map box)
210210
DynObj.setValueOpt props "labelStyle" (labelStyle |> Option.map box)
211211
DynObj.setValueOpt props "labelClassName" (labelClassName |> Option.map box)
212-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
212+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
213213
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
214214
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
215215
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)

Diff for: src/Dash.NET/DashComponents/CoreComponents/Dropdown.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module Dropdown =
9595
static member toDynamicMemberDef (prop:Prop) =
9696
match prop with
9797
| ClassName p -> "className", box p
98-
| Options p -> "options", box p
98+
| Options p -> "options", p |> Seq.map DropdownOption.convert |> box
9999
| Value p -> "value", p |> DropdownValue.convert
100100
| OptionHeight p -> "optionHeight", box p
101101
| Clearable p -> "clearable", box p
@@ -105,7 +105,7 @@ module Dropdown =
105105
| Searchable p -> "searchable", box p
106106
| SearchValue p -> "search_value", box p
107107
| Style p -> "style", box p
108-
| LoadingState p -> "loading_state", box p
108+
| LoadingState p -> "loading_state", LoadingState.convert p
109109
| Persistence p -> "persistence", box p
110110
| PersistedProps p -> "persisted_props", box p
111111
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
@@ -282,7 +282,7 @@ module Dropdown =
282282
DynObj.setValueOpt props "searchable" (searchable |> Option.map box)
283283
DynObj.setValueOpt props "searchValue" (searchValue |> Option.map box)
284284
DynObj.setValueOpt props "style" (style |> Option.map box)
285-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
285+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
286286
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
287287
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
288288
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)

Diff for: src/Dash.NET/DashComponents/CoreComponents/Graph.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module Graph =
137137
| Animate p -> "animate" , box p
138138
| AnimationOptions p -> "animation_options" , box p
139139
| Config p -> "config" , box p
140-
| LoadingState p -> "loading_state" , box p
140+
| LoadingState p -> "loading_state" , LoadingState.convert p
141141

142142
///<summary>
143143
///A list of children or a property for this dash component
@@ -320,7 +320,7 @@ module Graph =
320320
DynObj.setValueOpt props "animate" (animate |> Option.map box)
321321
DynObj.setValueOpt props "animationOptions" (animationOptions |> Option.map box)
322322
DynObj.setValueOpt props "config" (config |> Option.map box)
323-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
323+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
324324
DynObj.setValue t "namespace" "dash_core_components"
325325
DynObj.setValue t "props" props
326326
DynObj.setValue t "type" "Graph"

Diff for: src/Dash.NET/DashComponents/CoreComponents/Input.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ module Input =
179179
| NBlur p -> "n_blur", box p
180180
| NBlurTimestamp p -> "n_blur_timestamp", box p
181181
| SetProps p -> "setProps", box p
182-
| LoadingState p -> "loading_state", box p
182+
| LoadingState p -> "loading_state", LoadingState.convert p
183183
| Persistence p -> "persistence", box p
184184
| PersistedProps p -> "persisted_props", box p
185185
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
@@ -473,7 +473,7 @@ module Input =
473473
DynObj.setValueOpt props "nBlur" (nBlur |> Option.map box)
474474
DynObj.setValueOpt props "nBlurTimestamp" (nBlurTimestamp |> Option.map box)
475475
DynObj.setValueOpt props "setProps" (setProps |> Option.map box)
476-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
476+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
477477
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
478478
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
479479
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)

Diff for: src/Dash.NET/DashComponents/CoreComponents/Markdown.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module Markdown =
6767
| DangerouslyAllowHtml (p) -> "dangerously_allow_html", box p
6868
| Dedent (p) -> "dedent", box p
6969
| HighlightConfig (p) -> "highlight_config", HighlightConfig.convert p
70-
| LoadingState (p) -> "loading_state", box p
70+
| LoadingState (p) -> "loading_state", LoadingState.convert p
7171
| Style (p) -> "style", box p
7272

7373
///<summary>
@@ -149,7 +149,7 @@ module Markdown =
149149
DynObj.setValueOpt props "dangerouslyAllowHtml" (dangerouslyAllowHtml |> Option.map box)
150150
DynObj.setValueOpt props "dedent" (dedent |> Option.map box)
151151
DynObj.setValueOpt props "highlightConfig" (highlightConfig |> Option.map HighlightConfig.convert)
152-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
152+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
153153
DynObj.setValueOpt props "style" (style |> Option.map box)
154154
DynObj.setValue t "namespace" "dash_core_components"
155155
DynObj.setValue t "props" props

Diff for: src/Dash.NET/DashComponents/CoreComponents/RadioItems.fs

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ module RadioItems =
6767
match prop with
6868
| ClassName p -> "className" , box p
6969
| Style p -> "style" , box p
70-
| Options p -> "options" , box p
70+
| Options p -> "options" , p |> Seq.map RadioItemsOption.convert |> box
7171
| Value p -> "value" , box p
7272
| InputClassName p -> "inputClassName" , box p
7373
| InputStyle p -> "inputStyle" , box p
7474
| LabelClassName p -> "labelClassName" , box p
7575
| LabelStyle p -> "labelStyle" , box p
76-
| LoadingState p -> "loading_state" , box p
76+
| LoadingState p -> "loading_state" , LoadingState.convert p
7777
| Persistence p -> "persistence" , box p
7878
| PersistedProps p -> "persisted_props" , box p
7979
| PersistenceType p -> "persistence_type" , PersistenceTypeOptions.convert p
@@ -205,15 +205,15 @@ module RadioItems =
205205
let props = DashComponentProps()
206206
DynObj.setValue props "id" id
207207
DynObj.setValue props "children" children
208-
DynObj.setValueOpt props "options" (options |> Option.map box)
208+
DynObj.setValueOpt props "options" (options |> Option.map (Seq.map RadioItemsOption.convert >> box))
209209
DynObj.setValueOpt props "value" (value |> Option.map box)
210210
DynObj.setValueOpt props "style" (style |> Option.map box)
211211
DynObj.setValueOpt props "className" (className |> Option.map box)
212212
DynObj.setValueOpt props "inputStyle" (inputStyle |> Option.map box)
213213
DynObj.setValueOpt props "inputClassName" (inputClassName |> Option.map box)
214214
DynObj.setValueOpt props "labelStyle" (labelStyle |> Option.map box)
215215
DynObj.setValueOpt props "labelClassName" (labelClassName |> Option.map box)
216-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
216+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
217217
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
218218
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
219219
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)

Diff for: src/Dash.NET/DashComponents/CoreComponents/Slider.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module Slider =
6161
static member convert this =
6262
box
6363
{| always_visible = this.AlwaysVisible
64-
placement = this.Placement |}
64+
placement = this.Placement |> TooltipPlacement.convert |}
6565

6666
///<summary>
6767
///record with the fields: 'label: string (optional)', 'style: record (optional)'
@@ -195,7 +195,7 @@ module Slider =
195195
| Vertical (p) -> "vertical", box p
196196
| VerticalHeight (p) -> "verticalHeight", box p
197197
| UpdateMode (p) -> "updatemode", UpdateModeType.convert p
198-
| LoadingState (p) -> "loading_state", box p
198+
| LoadingState (p) -> "loading_state", LoadingState.convert p
199199
| Persistence (p) -> "persistence", box p
200200
| PersistedProps (p) -> "persisted_props", box p
201201
| PersistenceType (p) -> "persistence_type", PersistenceTypeOptions.convert p
@@ -380,7 +380,7 @@ module Slider =
380380
DynObj.setValueOpt props "vertical" (vertical |> Option.map box)
381381
DynObj.setValueOpt props "verticalHeight" (verticalHeight |> Option.map box)
382382
DynObj.setValueOpt props "updatemode" (updatemode |> Option.map UpdateModeType.convert)
383-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
383+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
384384
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
385385
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
386386
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)

Diff for: src/Dash.NET/DashComponents/CoreComponents/Tab.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module Tab =
5858
| DisabledClassName p -> "disabled_className", box p
5959
| SelectedClassName p -> "selected_className", box p
6060
| SelectedStyle p -> "selected_style", box p
61-
| LoadingState p -> "loading_state", box p
61+
| LoadingState p -> "loading_state", LoadingState.convert p
6262

6363
///<summary>
6464
///A list of children or a property for this dash component
@@ -169,7 +169,7 @@ module Tab =
169169
DynObj.setValueOpt props "selectedClassName" (selectedClassName |> Option.map box)
170170
DynObj.setValueOpt props "style" (style |> Option.map box)
171171
DynObj.setValueOpt props "selectedStyle" (selectedStyle |> Option.map box)
172-
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
172+
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
173173
DynObj.setValue t "namespace" "dash_core_components"
174174
DynObj.setValue t "props" props
175175
DynObj.setValue t "type" "Tab"

0 commit comments

Comments
 (0)