Skip to content

Commit

Permalink
Merge branch 'fix-enter-autosubmit' into 'release-0.10'
Browse files Browse the repository at this point in the history
TriggerBuilder: Handle modal form auto-submit

See merge request Astarte-NG/astarte-dashboard!51
  • Loading branch information
rbino committed Dec 17, 2018
2 parents b3ef440 + 7f6ac76 commit bc89863
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.10.0-beta.3] - Unreleased
### Fixed
- Enter key press behavior: close confirm message instead of reloading page.
- Accept `/*` as a valid Data Trigger path.
- Do not show inconsistent data while showing an existing trigger.

Expand Down
49 changes: 17 additions & 32 deletions src/elm/Page/InterfaceBuilder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Page.InterfaceBuilder exposing (Model, Msg, init, update, view, subscript
import Dict exposing (Dict)
import Html exposing (Html, text, h5, p, br, b, i, small)
import Html.Attributes exposing (class, value, for, selected)
import Html.Events exposing (onSubmit)
import Navigation
import Task
import Time exposing (Time)
Expand Down Expand Up @@ -142,10 +143,8 @@ type ModalResult

type Msg
= GetInterfaceDone Interface
| AddInterface
| AddInterfaceDone String
| DeleteInterfaceDone String
| UpdateInterface
| UpdateInterfaceDone String
| RemoveMapping InterfaceMapping
| ShowDeleteModal
Expand Down Expand Up @@ -241,32 +240,12 @@ update session msg model =
, ExternalMsg.Noop
)

AddInterface ->
( model
, AstarteApi.addNewInterface model.interface
session
AddInterfaceDone
(ShowError "Cannot install interface.")
RedirectToLogin
, ExternalMsg.Noop
)

AddInterfaceDone response ->
( model
, Navigation.modifyUrl <| Route.toString (Route.Realm Route.ListInterfaces)
, ExternalMsg.AddFlashMessage FlashMessage.Notice "Interface succesfully installed."
)

UpdateInterface ->
( model
, AstarteApi.updateInterface model.interface
session
UpdateInterfaceDone
(ShowError "Cannot apply changes.")
RedirectToLogin
, ExternalMsg.Noop
)

UpdateInterfaceDone response ->
( { model
| minMinor = model.interface.minor
Expand Down Expand Up @@ -294,15 +273,21 @@ update session msg model =
CloseDeleteModal modalResult ->
case modalResult of
ModalOk ->
( { model | deleteModalVisibility = Modal.hidden }
, AstarteApi.deleteInterface model.interface.name
model.interface.major
session
DeleteInterfaceDone
(ShowError "")
RedirectToLogin
, ExternalMsg.Noop
)
if model.interface.name == model.confirmInterfaceName then
( { model | deleteModalVisibility = Modal.hidden }
, AstarteApi.deleteInterface model.interface.name
model.interface.major
session
DeleteInterfaceDone
(ShowError "")
RedirectToLogin
, ExternalMsg.Noop
)
else
( model
, Cmd.none
, ExternalMsg.Noop
)

ModalCancel ->
( { model | deleteModalVisibility = Modal.hidden }
Expand Down Expand Up @@ -1350,7 +1335,7 @@ renderDeleteInterfaceModal model =
|> Modal.large
|> Modal.h5 [] [ text "Confirmation Required" ]
|> Modal.body []
[ Form.form []
[ Form.form [ onSubmit (CloseDeleteModal ModalOk) ]
[ Form.row []
[ Form.col [ Col.sm12 ]
[ text "You are going to remove "
Expand Down
25 changes: 16 additions & 9 deletions src/elm/Page/TriggerBuilder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Page.TriggerBuilder exposing (Model, Msg, init, update, view, subscriptio
import Regex exposing (regex)
import Html exposing (Html, text, h5, b, i)
import Html.Attributes exposing (class, value, readonly, selected, for)
import Html.Events exposing (onSubmit)
import Navigation
import Task
import Time
Expand Down Expand Up @@ -734,14 +735,20 @@ update session msg model =
CloseDeleteModal result ->
case result of
ModalOk ->
( { model | deleteModalVisibility = Modal.hidden }
, AstarteApi.deleteTrigger model.trigger.name
session
DeleteTriggerDone
(ShowError "Cannot delete trigger.")
RedirectToLogin
, ExternalMsg.Noop
)
if (model.trigger.name == model.confirmTriggerName) then
( { model | deleteModalVisibility = Modal.hidden }
, AstarteApi.deleteTrigger model.trigger.name
session
DeleteTriggerDone
(ShowError "Cannot delete trigger.")
RedirectToLogin
, ExternalMsg.Noop
)
else
( model
, Cmd.none
, ExternalMsg.Noop
)

ModalCancel ->
( { model | deleteModalVisibility = Modal.hidden }
Expand Down Expand Up @@ -1259,7 +1266,7 @@ renderDeleteTriggerModal model =
|> Modal.large
|> Modal.h5 [] [ text "Confirmation Required" ]
|> Modal.body []
[ Form.form []
[ Form.form [ onSubmit (CloseDeleteModal ModalOk) ]
[ Form.row []
[ Form.col [ Col.sm12 ]
[ text "You are going to remove "
Expand Down

0 comments on commit bc89863

Please sign in to comment.