Skip to content

Add Dash table #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions src/Dash.NET/DashComponents/ComponentBase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ module ComponentPropTypes =
ComponentName : string
}
static member create isLoading propName componentName = {IsLoading=isLoading; PropName=propName; ComponentName=componentName}
static member convert this =
box {|
isLoading = this.IsLoading
propName = this.PropName
componentName = this.ComponentName
|}

type PersistenceTypeOptions =
| Local
Expand All @@ -120,6 +126,13 @@ module ComponentPropTypes =
Title:string
}
static member create label value disabled title = {Label=label; Value=value; Disabled=disabled; Title=title}
static member convert this =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to stop using the camelCase serializer settings, we should add JsonProperty attributes (like here) to all records that will not get serialized correctly with the new settings. Another example (which is why we used camelCase serialization can be seen here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - that would be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure we're on the same page: The problem with the camel-case field names is with "external" data, i.e. when it is being used to pass data in, e.g.

DataTable.dataTable "memory-table" [
    DataTable.Attr.data [
        {| Country = "Canada" |}
        {| Country = "USA" |}
    ]
]

Country would be camel-cased and would fail to bind correctly to the header record "Country".

box {|
label = this.Label
value = this.Value
disabled = this.Disabled
title= this.Title
|}

type RadioItemsOption =
{
Expand All @@ -128,14 +141,26 @@ module ComponentPropTypes =
Disabled:bool
}
static member create label value disabled = {Label=label; Value=value; Disabled=disabled}

type TabColors =
static member convert this =
box {|
label = this.Label
value = this.Value
disabled = this.Disabled
|}

type TabColors =
{
Border : string
Primary : string
Background : string
}
static member create border primary background = {Border=border; Primary=primary; Background=background}
static member convert this =
box {|
border = this.Border
primary = this.Primary
background = this.Background
|}

type ChecklistOption =
{
Expand All @@ -145,10 +170,16 @@ module ComponentPropTypes =
}
static member create label value disabled =
{
Label=label
Value=value
Disabled=disabled
Label = label
Value = value
Disabled = disabled
}
static member convert this =
box {|
label = this.Label
value = this.Value
disabled = this.Disabled
|}

type ComponentProperty =
| Children
Expand Down
8 changes: 4 additions & 4 deletions src/Dash.NET/DashComponents/CoreComponents/Checklist.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ module Checklist =
| PersistenceType of PersistenceTypeOptions
static member toDynamicMemberDef(prop: Prop) =
match prop with
| Options p -> "options", box p
| Options p -> "options", p |> Seq.map ChecklistOption.convert |> box
| Value p -> "value", box p
| ClassName p -> "className", box p
| Style p -> "style", box p
| InputStyle p -> "inputStyle", box p
| InputClassName p -> "inputClassName", box p
| LabelStyle p -> "labelStyle", box p
| LabelClassName p -> "labelClassName", box p
| LoadingState p -> "loading_state", box p
| LoadingState p -> "loading_state", LoadingState.convert p
| Persistence p -> "persistence", box p
| PersistedProps p -> "persisted_props", box p
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -201,15 +201,15 @@ module Checklist =
let props = DashComponentProps()
DynObj.setValue props "id" id
DynObj.setValue props "children" children
DynObj.setValueOpt props "options" (options |> Option.map box)
DynObj.setValueOpt props "options" (options |> Option.map (Seq.map ChecklistOption.convert >> box))
DynObj.setValueOpt props "value" (value |> Option.map box)
DynObj.setValueOpt props "className" (className |> Option.map box)
DynObj.setValueOpt props "style" (style |> Option.map box)
DynObj.setValueOpt props "inputStyle" (inputStyle |> Option.map box)
DynObj.setValueOpt props "inputClassName" (inputClassName |> Option.map box)
DynObj.setValueOpt props "labelStyle" (labelStyle |> Option.map box)
DynObj.setValueOpt props "labelClassName" (labelClassName |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
6 changes: 3 additions & 3 deletions src/Dash.NET/DashComponents/CoreComponents/Dropdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module Dropdown =
static member toDynamicMemberDef (prop:Prop) =
match prop with
| ClassName p -> "className", box p
| Options p -> "options", box p
| Options p -> "options", p |> Seq.map DropdownOption.convert |> box
| Value p -> "value", p |> DropdownValue.convert
| OptionHeight p -> "optionHeight", box p
| Clearable p -> "clearable", box p
Expand All @@ -105,7 +105,7 @@ module Dropdown =
| Searchable p -> "searchable", box p
| SearchValue p -> "search_value", box p
| Style p -> "style", box p
| LoadingState p -> "loading_state", box p
| LoadingState p -> "loading_state", LoadingState.convert p
| Persistence p -> "persistence", box p
| PersistedProps p -> "persisted_props", box p
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -282,7 +282,7 @@ module Dropdown =
DynObj.setValueOpt props "searchable" (searchable |> Option.map box)
DynObj.setValueOpt props "searchValue" (searchValue |> Option.map box)
DynObj.setValueOpt props "style" (style |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
4 changes: 2 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Graph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module Graph =
| Animate p -> "animate" , box p
| AnimationOptions p -> "animation_options" , box p
| Config p -> "config" , box p
| LoadingState p -> "loading_state" , box p
| LoadingState p -> "loading_state" , LoadingState.convert p

///<summary>
///A list of children or a property for this dash component
Expand Down Expand Up @@ -320,7 +320,7 @@ module Graph =
DynObj.setValueOpt props "animate" (animate |> Option.map box)
DynObj.setValueOpt props "animationOptions" (animationOptions |> Option.map box)
DynObj.setValueOpt props "config" (config |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValue t "namespace" "dash_core_components"
DynObj.setValue t "props" props
DynObj.setValue t "type" "Graph"
Expand Down
4 changes: 2 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Input.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module Input =
| NBlur p -> "n_blur", box p
| NBlurTimestamp p -> "n_blur_timestamp", box p
| SetProps p -> "setProps", box p
| LoadingState p -> "loading_state", box p
| LoadingState p -> "loading_state", LoadingState.convert p
| Persistence p -> "persistence", box p
| PersistedProps p -> "persisted_props", box p
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -473,7 +473,7 @@ module Input =
DynObj.setValueOpt props "nBlur" (nBlur |> Option.map box)
DynObj.setValueOpt props "nBlurTimestamp" (nBlurTimestamp |> Option.map box)
DynObj.setValueOpt props "setProps" (setProps |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
4 changes: 2 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Markdown.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module Markdown =
| DangerouslyAllowHtml (p) -> "dangerously_allow_html", box p
| Dedent (p) -> "dedent", box p
| HighlightConfig (p) -> "highlight_config", HighlightConfig.convert p
| LoadingState (p) -> "loading_state", box p
| LoadingState (p) -> "loading_state", LoadingState.convert p
| Style (p) -> "style", box p

///<summary>
Expand Down Expand Up @@ -149,7 +149,7 @@ module Markdown =
DynObj.setValueOpt props "dangerouslyAllowHtml" (dangerouslyAllowHtml |> Option.map box)
DynObj.setValueOpt props "dedent" (dedent |> Option.map box)
DynObj.setValueOpt props "highlightConfig" (highlightConfig |> Option.map HighlightConfig.convert)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "style" (style |> Option.map box)
DynObj.setValue t "namespace" "dash_core_components"
DynObj.setValue t "props" props
Expand Down
8 changes: 4 additions & 4 deletions src/Dash.NET/DashComponents/CoreComponents/RadioItems.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ module RadioItems =
match prop with
| ClassName p -> "className" , box p
| Style p -> "style" , box p
| Options p -> "options" , box p
| Options p -> "options" , p |> Seq.map RadioItemsOption.convert |> box
| Value p -> "value" , box p
| InputClassName p -> "inputClassName" , box p
| InputStyle p -> "inputStyle" , box p
| LabelClassName p -> "labelClassName" , box p
| LabelStyle p -> "labelStyle" , box p
| LoadingState p -> "loading_state" , box p
| LoadingState p -> "loading_state" , LoadingState.convert p
| Persistence p -> "persistence" , box p
| PersistedProps p -> "persisted_props" , box p
| PersistenceType p -> "persistence_type" , PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -205,15 +205,15 @@ module RadioItems =
let props = DashComponentProps()
DynObj.setValue props "id" id
DynObj.setValue props "children" children
DynObj.setValueOpt props "options" (options |> Option.map box)
DynObj.setValueOpt props "options" (options |> Option.map (Seq.map RadioItemsOption.convert >> box))
DynObj.setValueOpt props "value" (value |> Option.map box)
DynObj.setValueOpt props "style" (style |> Option.map box)
DynObj.setValueOpt props "className" (className |> Option.map box)
DynObj.setValueOpt props "inputStyle" (inputStyle |> Option.map box)
DynObj.setValueOpt props "inputClassName" (inputClassName |> Option.map box)
DynObj.setValueOpt props "labelStyle" (labelStyle |> Option.map box)
DynObj.setValueOpt props "labelClassName" (labelClassName |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
8 changes: 6 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Slider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module Slider =
box
{| always_visible = this.AlwaysVisible
placement = this.Placement |}
static member convert2 this =
box
{| always_visible = this.AlwaysVisible
placement = this.Placement |> TooltipPlacement.convert |}

///<summary>
///record with the fields: 'label: string (optional)', 'style: record (optional)'
Expand Down Expand Up @@ -195,7 +199,7 @@ module Slider =
| Vertical (p) -> "vertical", box p
| VerticalHeight (p) -> "verticalHeight", box p
| UpdateMode (p) -> "updatemode", UpdateModeType.convert p
| LoadingState (p) -> "loading_state", box p
| LoadingState (p) -> "loading_state", LoadingState.convert p
| Persistence (p) -> "persistence", box p
| PersistedProps (p) -> "persisted_props", box p
| PersistenceType (p) -> "persistence_type", PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -380,7 +384,7 @@ module Slider =
DynObj.setValueOpt props "vertical" (vertical |> Option.map box)
DynObj.setValueOpt props "verticalHeight" (verticalHeight |> Option.map box)
DynObj.setValueOpt props "updatemode" (updatemode |> Option.map UpdateModeType.convert)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
4 changes: 2 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Tab.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Tab =
| DisabledClassName p -> "disabled_className", box p
| SelectedClassName p -> "selected_className", box p
| SelectedStyle p -> "selected_style", box p
| LoadingState p -> "loading_state", box p
| LoadingState p -> "loading_state", LoadingState.convert p

///<summary>
///A list of children or a property for this dash component
Expand Down Expand Up @@ -169,7 +169,7 @@ module Tab =
DynObj.setValueOpt props "selectedClassName" (selectedClassName |> Option.map box)
DynObj.setValueOpt props "style" (style |> Option.map box)
DynObj.setValueOpt props "selectedStyle" (selectedStyle |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValue t "namespace" "dash_core_components"
DynObj.setValue t "props" props
DynObj.setValue t "type" "Tab"
Expand Down
8 changes: 4 additions & 4 deletions src/Dash.NET/DashComponents/CoreComponents/Tabs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ module Tabs =
| ContentStyle p -> "content_style" , box p
| Vertical p -> "vertical" , box p
| MobileBreakpoint p -> "mobile_breakpoint" , box p
| Colors p -> "colors" , box p
| LoadingState p -> "loading_state", box p
| Colors p -> "colors" , TabColors.convert p
| LoadingState p -> "loading_state", LoadingState.convert p
| Persistence p -> "persistence", box p
| PersistedProps p -> "persisted_props", box p
| PersistenceType p -> "persistence_type", PersistenceTypeOptions.convert p
Expand Down Expand Up @@ -242,8 +242,8 @@ module Tabs =
DynObj.setValueOpt props "contentStyle" (contentStyle |> Option.map box)
DynObj.setValueOpt props "vertical" (vertical |> Option.map box)
DynObj.setValueOpt props "mobileBreakpoint" (mobileBreakpoint |> Option.map box)
DynObj.setValueOpt props "colors" (colors |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "colors" (colors |> Option.map TabColors.convert)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValueOpt props "persistence" (persistence |> Option.map box)
DynObj.setValueOpt props "persistedProps" (persistedProps |> Option.map box)
DynObj.setValueOpt props "persistenceType" (persistenceType |> Option.map PersistenceTypeOptions.convert)
Expand Down
4 changes: 2 additions & 2 deletions src/Dash.NET/DashComponents/CoreComponents/Upload.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module Upload =
| StyleActive p -> "style_active" , box p
| StyleReject p -> "style_reject" , box p
| StyleDisabled p -> "style_disabled" , box p
| LoadingState p -> "loading_state" , box p
| LoadingState p -> "loading_state" , LoadingState.convert p

///<summary>
///A list of children or a property for this dash component
Expand Down Expand Up @@ -297,7 +297,7 @@ module Upload =
DynObj.setValueOpt props "styleActive" (styleActive |> Option.map box)
DynObj.setValueOpt props "styleReject" (styleReject |> Option.map box)
DynObj.setValueOpt props "styleDisabled" (styleDisabled |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map box)
DynObj.setValueOpt props "loadingState" (loadingState |> Option.map LoadingState.convert)
DynObj.setValue t "namespace" "dash_core_components"
DynObj.setValue t "props" props
DynObj.setValue t "type" "Upload"
Expand Down