Slightly more robust (but still not robust) UI
This commit is contained in:
@@ -2,7 +2,6 @@ namespace RaftFable
|
|||||||
|
|
||||||
open System
|
open System
|
||||||
open System.Collections.Generic
|
open System.Collections.Generic
|
||||||
open System.Security.Cryptography
|
|
||||||
open Fable.Core.JS
|
open Fable.Core.JS
|
||||||
open Raft
|
open Raft
|
||||||
open Browser.Dom
|
open Browser.Dom
|
||||||
@@ -66,8 +65,8 @@ module App =
|
|||||||
try
|
try
|
||||||
clients.Add (client, HashSet ())
|
clients.Add (client, HashSet ())
|
||||||
with :? ArgumentException ->
|
with :? ArgumentException ->
|
||||||
failwith "got a response a second time - need to handle this in the UI"
|
failwith "TODO: got a response a second time - need to handle this in the UI"
|
||||||
| RegisterClientResponse.NotLeader hint -> failwith "asked a non-leader, have to handle it"
|
| RegisterClientResponse.NotLeader hint -> failwith "TODO: asked a non-leader, have to handle it"
|
||||||
)
|
)
|
||||||
|
|
||||||
let handleClientResponse (response : ClientResponse) : unit =
|
let handleClientResponse (response : ClientResponse) : unit =
|
||||||
@@ -75,8 +74,8 @@ module App =
|
|||||||
clients
|
clients
|
||||||
(fun () ->
|
(fun () ->
|
||||||
match response with
|
match response with
|
||||||
| ClientResponse.SessionExpired -> failwith "session expired, have to handle it"
|
| ClientResponse.SessionExpired -> failwith "TODO: session expired, have to handle it"
|
||||||
| ClientResponse.NotLeader hint -> failwith "asked a non-leader, have to handle it"
|
| ClientResponse.NotLeader hint -> failwith "TODO: asked a non-leader, have to handle it"
|
||||||
| ClientResponse.Success (client, sequence) ->
|
| ClientResponse.Success (client, sequence) ->
|
||||||
match clients.TryGetValue client with
|
match clients.TryGetValue client with
|
||||||
| false, _ ->
|
| false, _ ->
|
||||||
@@ -140,15 +139,25 @@ module App =
|
|||||||
// TODO: what happens when we try and log client data on a node that doesn't know about the client?
|
// TODO: what happens when we try and log client data on a node that doesn't know about the client?
|
||||||
|
|
||||||
let reloadActions () =
|
let reloadActions () =
|
||||||
// TODO: fix this button, it doesn't work properly
|
// TODO: fix this button, it doesn't work properly in the failure case
|
||||||
|
match Ui.getUserPrefs parseByte handleRegisterClientResponse handleClientResponse clusterSize ui with
|
||||||
|
| Error error ->
|
||||||
|
let error = sprintf "Unable to parse actions: %s" error
|
||||||
|
window.alert error
|
||||||
|
promise { return () }
|
||||||
|
|
||||||
|
| Ok newPrefs ->
|
||||||
|
|
||||||
let newCluster, newNetwork = InMemoryCluster.make<byte> clusterSize
|
let newCluster, newNetwork = InMemoryCluster.make<byte> clusterSize
|
||||||
cluster <- newCluster
|
cluster <- newCluster
|
||||||
network <- newNetwork
|
network <- newNetwork
|
||||||
|
|
||||||
userPrefs.Value <- Ui.getUserPrefs parseByte handleRegisterClientResponse handleClientResponse clusterSize ui
|
userPrefs.Value <-
|
||||||
|
{ newPrefs with
|
||||||
|
ActionHistory = []
|
||||||
|
}
|
||||||
|
|
||||||
startupActions
|
(promise { return () }, userPrefs.Value.ActionHistory)
|
||||||
|> fun s -> (fullyRerender parseByte userPrefs cluster network, s)
|
|
||||||
||> List.fold (fun (inPromise : Promise<unit>) action ->
|
||> List.fold (fun (inPromise : Promise<unit>) action ->
|
||||||
promise {
|
promise {
|
||||||
let! _ = inPromise
|
let! _ = inPromise
|
||||||
@@ -218,7 +227,4 @@ module App =
|
|||||||
NetworkAction.ClientRequest (server, ClientRequest.RegisterClient handleRegisterClientResponse)
|
NetworkAction.ClientRequest (server, ClientRequest.RegisterClient handleRegisterClientResponse)
|
||||||
|> perform parseByte userPrefs cluster network
|
|> perform parseByte userPrefs cluster network
|
||||||
|
|
||||||
ui.ShowConsumedMessages.onchange <-
|
ui.ShowConsumedMessages.onchange <- fun _event -> fullyRerender parseByte userPrefs cluster network
|
||||||
fun _event ->
|
|
||||||
printfn "rerendering"
|
|
||||||
fullyRerender parseByte userPrefs cluster network
|
|
||||||
|
@@ -201,7 +201,7 @@ module Ui =
|
|||||||
let actionList =
|
let actionList =
|
||||||
prefs.ActionHistory |> Seq.map NetworkAction.toString |> String.concat "\n"
|
prefs.ActionHistory |> Seq.map NetworkAction.toString |> String.concat "\n"
|
||||||
|
|
||||||
ui.ActionHistoryList.textContent <- actionList
|
ui.ActionHistoryList.value <- actionList
|
||||||
|
|
||||||
let render<'a>
|
let render<'a>
|
||||||
(perform : NetworkAction<'a> -> Fable.Core.JS.Promise<unit>)
|
(perform : NetworkAction<'a> -> Fable.Core.JS.Promise<unit>)
|
||||||
@@ -399,25 +399,23 @@ module Ui =
|
|||||||
(handleClientDataResponse : ClientResponse -> unit)
|
(handleClientDataResponse : ClientResponse -> unit)
|
||||||
(clusterSize : int)
|
(clusterSize : int)
|
||||||
(ui : UiElements)
|
(ui : UiElements)
|
||||||
: UserPreferences<'a>
|
: Result<UserPreferences<'a>, string>
|
||||||
=
|
=
|
||||||
{
|
let actionHistory =
|
||||||
LeaderUnderConsideration = ui.SelectedLeaderId.valueAsNumber |> int |> (fun i -> i * 1<ServerId>)
|
ui.ActionHistoryList.value.Split "\n"
|
||||||
ShowConsumedMessages = ui.ShowConsumedMessages.``checked``
|
|> Seq.filter (not << System.String.IsNullOrEmpty)
|
||||||
ActionHistory =
|
|> Seq.map (
|
||||||
// TODO write these back out again, and give a button to Load
|
NetworkAction.tryParse<'a> parse None handleRegisterClientResponse handleClientDataResponse clusterSize
|
||||||
ui.ActionHistoryList.textContent.Split "\n"
|
)
|
||||||
|> Seq.filter (not << System.String.IsNullOrEmpty)
|
|> Result.allOkOrError
|
||||||
|> Seq.map (
|
|> Result.map List.ofSeq
|
||||||
NetworkAction.tryParse<'a>
|
|
||||||
parse
|
match actionHistory with
|
||||||
None
|
| Result.Ok actionHistory ->
|
||||||
handleRegisterClientResponse
|
{
|
||||||
handleClientDataResponse
|
LeaderUnderConsideration = ui.SelectedLeaderId.valueAsNumber |> int |> (fun i -> i * 1<ServerId>)
|
||||||
clusterSize
|
ShowConsumedMessages = ui.ShowConsumedMessages.``checked``
|
||||||
)
|
ActionHistory = actionHistory
|
||||||
|> Result.allOkOrError
|
}
|
||||||
// TODO handle this
|
|> Result.Ok
|
||||||
|> Result.get
|
| Result.Error e -> Result.Error (snd e |> String.concat "\n")
|
||||||
|> List.ofSeq
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user