Skip to content

Commit

Permalink
refactor: add link to alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 14, 2024
1 parent 7dfcad2 commit 6178d88
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 57 deletions.
7 changes: 4 additions & 3 deletions src/elm/Components/Alerts.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ SPDX-License-Identifier: Apache-2.0
--}


module Components.Alerts exposing (Alert(..), errorConfig, successConfig, view)
module Components.Alerts exposing (Alert(..), Link, errorConfig, successConfig, view)

import FeatherIcons
import Html exposing (Html, a, button, div, h1, p, text)
import Html.Attributes exposing (attribute, class, href)
import Html.Events
import Route.Path
import Toasty as Alerting
import Toasty.Defaults as Alerts
import Utils.Helpers as Util
Expand All @@ -27,7 +28,7 @@ type alias Label =


type alias Destination =
String
Route.Path.Path


type Alert
Expand Down Expand Up @@ -139,4 +140,4 @@ errorConfig =
-}
toHyperlink : Link -> Html msg
toHyperlink ( label, destination ) =
a [ href destination, Util.testAttribute "alert-hyperlink" ] [ text label ]
a [ Route.Path.href destination, Util.testAttribute "alert-hyperlink" ] [ text label ]
8 changes: 4 additions & 4 deletions src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Api.Api as Api
import Api.Operations
import Auth.Session
import Browser.Navigation
import Components.Alerts exposing (Alert)
import Components.Alerts
import Dict exposing (Dict)
import Http
import Http.Detailed
Expand Down Expand Up @@ -1202,17 +1202,17 @@ handleHttpError options =
SendSharedMsg <| Shared.Msg.HandleHttpError options.httpError


addAlertSuccess : { content : String, addToastIfUnique : Bool } -> Effect msg
addAlertSuccess : { content : String, addToastIfUnique : Bool, link : Maybe Components.Alerts.Link } -> Effect msg
addAlertSuccess options =
SendSharedMsg <| Shared.Msg.AddAlertSuccess options


addAlertError : { content : String, addToastIfUnique : Bool } -> Effect msg
addAlertError : { content : String, addToastIfUnique : Bool, link : Maybe Components.Alerts.Link } -> Effect msg
addAlertError options =
SendSharedMsg <| Shared.Msg.AddAlertError options


alertsUpdate : { alert : Alerting.Msg Alert } -> Effect msg
alertsUpdate : { alert : Alerting.Msg Components.Alerts.Alert } -> Effect msg
alertsUpdate options =
SendSharedMsg <| Shared.Msg.AlertsUpdate options.alert

Expand Down
6 changes: 5 additions & 1 deletion src/elm/Layouts/Default.elm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ update msg model =

AddAlertCopiedToClipboard contentCopied ->
( model
, Effect.addAlertSuccess { content = "'" ++ contentCopied ++ "' copied to clipboard.", addToastIfUnique = False }
, Effect.addAlertSuccess
{ content = "'" ++ contentCopied ++ "' copied to clipboard."
, addToastIfUnique = False
, link = Nothing
}
)


Expand Down
35 changes: 25 additions & 10 deletions src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0

module Layouts.Default.Build exposing (Model, Msg, Props, layout, map)

import Components.Alerts
import Components.Build
import Components.Crumbs
import Components.Help
Expand Down Expand Up @@ -194,13 +195,15 @@ update props shared route msg model =
restartedBuild =
"Build " ++ String.join "/" [ options.org, options.repo, options.buildNumber ]

newBuildNumber =
String.fromInt <| build.number

newBuild =
String.join "/" [ "", options.org, options.repo, newBuildNumber ]

-- todo: create new build link, add to toastie, refresh builds
newBuildLink =
Just
( "View Build #" ++ String.fromInt build.number
, Route.Path.Org_Repo_Build_
{ org = options.org
, repo = options.repo
, buildNumber = String.fromInt build.number
}
)
in
( model
, Effect.batch
Expand All @@ -211,7 +214,11 @@ update props shared route msg model =
, org = props.org
, repo = props.repo
}
, Effect.addAlertSuccess { content = restartedBuild ++ " restarted.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = restartedBuild ++ " restarted."
, addToastIfUnique = True
, link = newBuildLink
}
]
)

Expand Down Expand Up @@ -249,7 +256,11 @@ update props shared route msg model =
, repo = props.repo
, buildNumber = props.buildNumber
}
, Effect.addAlertSuccess { content = canceledBuild ++ " canceled.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = canceledBuild ++ " canceled."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down Expand Up @@ -287,7 +298,11 @@ update props shared route msg model =
, repo = props.repo
, buildNumber = props.buildNumber
}
, Effect.addAlertSuccess { content = approvedBuild ++ " approved.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = approvedBuild ++ " approved."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down
6 changes: 5 additions & 1 deletion src/elm/Pages/Account/Settings.elm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ update msg model =
-- ALERTS
AddAlertCopiedToClipboard contentCopied ->
( model
, Effect.addAlertSuccess { content = "'" ++ contentCopied ++ "' copied to clipboard.", addToastIfUnique = False }
, Effect.addAlertSuccess
{ content = "'" ++ contentCopied ++ "' copied to clipboard."
, addToastIfUnique = False
, link = Nothing
}
)


Expand Down
6 changes: 5 additions & 1 deletion src/elm/Pages/Account/SourceRepos.elm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ update shared msg model =
}
, Effect.batch
[ Effect.addAlertSuccess
{ content = "Repo " ++ repo.full_name ++ " enabled.", addToastIfUnique = True }
{ content = "Repo " ++ repo.full_name ++ " enabled."
, addToastIfUnique = True
, link = Nothing
}
, Effect.updateFavorites { org = repo.org, maybeRepo = Just repo.name, updateType = Favorites.Add }
]
)
Expand All @@ -201,6 +204,7 @@ update shared msg model =
, Effect.addAlertSuccess
{ content = "Repo " ++ options.repo.full_name ++ " enabled."
, addToastIfUnique = False
, link = Nothing
}
)

Expand Down
34 changes: 24 additions & 10 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ update shared route msg model =
restartedBuild =
"Build " ++ String.join "/" [ options.org, options.repo, options.buildNumber ]

newBuildNumber =
String.fromInt <| build.number

newBuild =
String.join "/" [ "", options.org, options.repo, newBuildNumber ]

-- todo: create new build link, add to toastie, refresh builds
newBuildLink =
Just
( "View Build #" ++ String.fromInt build.number
, Route.Path.Org_Repo_Build_
{ org = options.org
, repo = options.repo
, buildNumber = String.fromInt build.number
}
)
in
( model
, Effect.batch
Expand All @@ -209,7 +211,11 @@ update shared route msg model =
, maybeEvent = Dict.get "event" route.query
, org = route.params.org
}
, Effect.addAlertSuccess { content = restartedBuild ++ " restarted.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = restartedBuild ++ " restarted."
, addToastIfUnique = True
, link = newBuildLink
}
]
)

Expand Down Expand Up @@ -248,7 +254,11 @@ update shared route msg model =
, maybeEvent = Dict.get "event" route.query
, org = route.params.org
}
, Effect.addAlertSuccess { content = canceledBuild ++ " canceled.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = canceledBuild ++ " canceled."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down Expand Up @@ -287,7 +297,11 @@ update shared route msg model =
, maybeEvent = Dict.get "event" route.query
, org = route.params.org
}
, Effect.addAlertSuccess { content = approvedBuild ++ " approved.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = approvedBuild ++ " approved."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down
34 changes: 24 additions & 10 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,15 @@ update shared route msg model =
restartedBuild =
"Build " ++ String.join "/" [ options.org, options.repo, options.buildNumber ]

newBuildNumber =
String.fromInt <| build.number

newBuild =
String.join "/" [ "", options.org, options.repo, newBuildNumber ]

-- todo: create new build link, add to toastie, refresh builds
newBuildLink =
Just
( "View Build #" ++ String.fromInt build.number
, Route.Path.Org_Repo_Build_
{ org = options.org
, repo = options.repo
, buildNumber = String.fromInt build.number
}
)
in
( model
, Effect.batch
Expand All @@ -220,7 +222,11 @@ update shared route msg model =
, org = route.params.org
, repo = route.params.repo
}
, Effect.addAlertSuccess { content = restartedBuild ++ " restarted.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = restartedBuild ++ " restarted."
, addToastIfUnique = True
, link = newBuildLink
}
]
)

Expand Down Expand Up @@ -260,7 +266,11 @@ update shared route msg model =
, org = route.params.org
, repo = route.params.repo
}
, Effect.addAlertSuccess { content = canceledBuild ++ " canceled.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = canceledBuild ++ " canceled."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down Expand Up @@ -300,7 +310,11 @@ update shared route msg model =
, org = route.params.org
, repo = route.params.repo
}
, Effect.addAlertSuccess { content = approvedBuild ++ " approved.", addToastIfUnique = True }
, Effect.addAlertSuccess
{ content = approvedBuild ++ " approved."
, addToastIfUnique = True
, link = Nothing
}
]
)

Expand Down
1 change: 1 addition & 0 deletions src/elm/Pages/Org_/Repo_/Deployments/Add.elm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ update shared route msg model =
, Effect.addAlertSuccess
{ content = "Added deployment for commit " ++ deployment.commit ++ "."
, addToastIfUnique = True
, link = Nothing
}
)

Expand Down
6 changes: 5 additions & 1 deletion src/elm/Pages/Org_/Repo_/Hooks.elm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ update shared route msg model =
case response of
Ok ( _, result ) ->
( model
, Effect.addAlertSuccess { content = result, addToastIfUnique = False }
, Effect.addAlertSuccess
{ content = result
, addToastIfUnique = False
, link = Nothing
}
)

Err error ->
Expand Down
1 change: 1 addition & 0 deletions src/elm/Pages/Org_/Repo_/Schedules/Add.elm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ update shared route msg model =
, Effect.addAlertSuccess
{ content = schedule.name ++ " added to repo schedules."
, addToastIfUnique = True
, link = Nothing
}
)

Expand Down
2 changes: 2 additions & 0 deletions src/elm/Pages/Org_/Repo_/Schedules/Edit_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ update shared route msg model =
, Effect.addAlertSuccess
{ content = schedule.name ++ " updated in repo schedules."
, addToastIfUnique = True
, link = Nothing
}
)

Expand All @@ -158,6 +159,7 @@ update shared route msg model =
[ Effect.addAlertSuccess
{ content = result
, addToastIfUnique = True
, link = Nothing
}
, Effect.pushPath <|
Route.Path.Org_Repo_Schedules
Expand Down
Loading

0 comments on commit 6178d88

Please sign in to comment.