diff --git a/src/web/ui/src/Controls/Table.fs b/src/web/ui/src/Controls/Table.fs index 19b487e69..f48d2e830 100644 --- a/src/web/ui/src/Controls/Table.fs +++ b/src/web/ui/src/Controls/Table.fs @@ -116,17 +116,16 @@ let showFilter (content:ReactElement) (onApplyClick: MouseEvent -> Unit) (onClea div [ Class "modal-background clear-background"; OnClick onCloseClick ][ ] div [ Class "card filter-card"; Style [ Top top; Left left ] ] [ div [ Class "card-content" ] - [ button [ Class "delete"; OnClick onCloseClick ] [ ] - content + [ content ] footer [ Class "card-footer" ] - [ p [ Class "card-footer-item" ] + [ p [ Class "card-footer-item"; OnClick onApplyClick ] [ span [ ] - [ a [ OnClick onApplyClick ] + [ a [ ] [ str "Apply" ] ] ] - p [ Class "card-footer-item" ] + p [ Class "card-footer-item"; OnClick onClearClick ] [ span [ ] - [ a [ OnClick onClearClick ] + [ a [ ] [ str "Clear" ] ] ] ] ] ] diff --git a/src/web/ui/src/Reports/State.fs b/src/web/ui/src/Reports/State.fs index 5b3b8a2a1..6619e9bc6 100644 --- a/src/web/ui/src/Reports/State.fs +++ b/src/web/ui/src/Reports/State.fs @@ -260,6 +260,12 @@ let getValFromPNLUnit header (data:PNLUnit) (securityList: Map "", data.cashValue | _ -> "", 0.0 +let filterIsDefault filter = + match filter with + | StringSearch s -> s = "" + | NumberRange (min, max) -> min = Double.MinValue && max = Double.MaxValue + | Empty -> true + let update msg (model:Reports.Types.Model) : Model * Cmd = match msg with | UpdateAdminData adm -> @@ -337,24 +343,45 @@ let update msg (model:Reports.Types.Model) : Model * Cmd = {model with FilterOpen = (isOpen, loca); TempFilter = (header, newFilter)}, Cmd.ofMsg (SetPnLTempFilter (header, newFilter)) | SetPnLFilter (header, filter) -> - let newFilterValues = - match Map.containsKey header model.PnLFilterValues with - | true -> (Map.remove header model.PnLFilterValues).Add(header, filter) - | false -> model.PnLFilterValues.Add(header, filter) + match filterIsDefault filter with + | true -> + let newFilterValues = + match Map.containsKey header model.PnLFilterValues with + | true -> (Map.remove header model.PnLFilterValues) + | false -> model.PnLFilterValues - let newFilter = - match filter with - | StringSearch s -> - function pnl -> - let v = (getValFromPNLUnit header pnl (Some model.securityList)) |> fst - if s.Trim() = "" || v.ToLower().Contains (s.Trim().ToLower()) then Some pnl else None - | NumberRange (min, max) -> - function pnl -> - let curVal = (getValFromPNLUnit header pnl None) |> snd - if (min <= curVal && curVal <= max) then Some pnl else None - | Empty -> Some - let newMap = model.PnLFilter.Add (header, newFilter) - { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + let newMap = + match Map.containsKey header model.PnLFilter with + | true -> Map.remove header model.PnLFilter + | false -> model.PnLFilter + + { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + | false -> + let newFilterValues = + match Map.containsKey header model.PnLFilterValues with + | true -> (Map.remove header model.PnLFilterValues).Add(header, filter) + | false -> model.PnLFilterValues.Add(header, filter) + + let newFilter = + match filter with + | StringSearch s -> + function pnl -> + let v = (getValFromPNLUnit header pnl (Some model.securityList)) |> fst + if s.Trim() = "" || v.ToLower().Contains (s.Trim().ToLower()) then Some pnl else None + | NumberRange (min, max) -> + function pnl -> + let curVal = (getValFromPNLUnit header pnl None) |> snd + if (min <= curVal && curVal <= max) then Some pnl else None + | Empty -> Some + + let newMap = model.PnLFilter.Add (header, newFilter) + + { model with PnLFilter = newMap; PnLFilterValues = newFilterValues }, ("", false, Wherever) |> ShowFilterBox |> Cmd.ofMsg + + | ClearPnLFilter header -> + match Map.containsKey header model.PnLFilterValues with + | true -> model, Cmd.ofMsg (SetPnLFilter (header, Empty)) + | false -> model, Cmd.Empty | SetPnLSort header -> Browser.console.log header diff --git a/src/web/ui/src/Reports/Types.fs b/src/web/ui/src/Reports/Types.fs index 871ac907e..569421ac6 100644 --- a/src/web/ui/src/Reports/Types.fs +++ b/src/web/ui/src/Reports/Types.fs @@ -42,7 +42,7 @@ type Msg = | SetPnLSort of string | SetPnLTempFilter of string * ColFilter | SetPnLFilter of string * ColFilter - //| ClearPnLFilter of string + | ClearPnLFilter of string | ShowGridSettings of bool | ShowFilterBox of string * bool * Location diff --git a/src/web/ui/src/Reports/View.fs b/src/web/ui/src/Reports/View.fs index fcf564bf2..255a83588 100644 --- a/src/web/ui/src/Reports/View.fs +++ b/src/web/ui/src/Reports/View.fs @@ -62,7 +62,7 @@ let PnLTabView (model:Model) (dispatch:Msg->Unit) = Fields.text "Search:" (searchStr) [] (fun v -> (filterHeader, StringSearch v) |> SetPnLTempFilter |> dispatch) ]) (fun _ -> (filterHeader, filterType) |> SetPnLFilter |> dispatch) - (fun _ -> ("", false, Wherever) |> ShowFilterBox |> dispatch) + (fun _ -> filterHeader |> ClearPnLFilter |> dispatch) (fun _ -> ("", false, Wherever) |> ShowFilterBox |> dispatch) (sprintf "%fpx" (where |> snd)) (sprintf "%fpx" (where |> fst)) | NumberRange (min, max), true -> @@ -83,12 +83,12 @@ let PnLTabView (model:Model) (dispatch:Msg->Unit) = | _, _ -> i [ ClassName (sprintf "fa fa-sort header-icon-hidden")] [ ] let filterIcon header = - let clsStr = match Map.containsKey header model.PnLFilterValues || (fst model.TempFilter) = header with - | true -> "fa fa-filter header-filter-icon yellow" - | false -> "fa fa-filter header-filter-icon header-icon-hidden" + let classStr = match Map.containsKey header model.PnLFilterValues || (fst model.TempFilter) = header with + | true -> "fa fa-filter header-filter-icon yellow" + | false -> "fa fa-filter header-filter-icon header-icon-hidden" let mutable origin = Location (0.0, 0.0) i [ - ClassName (clsStr) + ClassName (classStr) Ref (fun me -> if me <> null then let r = me.getBoundingClientRect()