Skip to content

Commit

Permalink
refactor: moved clipboard copy alert to shared.msg
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 10, 2024
1 parent f7cc6de commit 2c88b43
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/elm/Alerts.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0
--}


module Alerts exposing (Alert(..), errorConfig, successConfig, view)
module Alerts exposing (Alert(..), errorConfig, successConfig, view, wrapAlertMessage)

import FeatherIcons
import Html exposing (Html, a, button, div, h1, p, text)
Expand Down Expand Up @@ -76,6 +76,15 @@ wrapAlert variantClass title message link copy =
]


wrapAlertMessage : String -> String
wrapAlertMessage message =
if not <| String.isEmpty message then
"`" ++ message ++ "` "

else
message


copyButton : String -> Maybe (Copy msg) -> Html msg
copyButton copyContent copy =
case copy of
Expand Down
7 changes: 6 additions & 1 deletion src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, getCurrentUser, gotoPage, logout, pushPath, toggleFavorites
, getCurrentUser, gotoPage, logout, pushPath, showCopyToClipboardAlert, toggleFavorites
)

{-|
Expand Down Expand Up @@ -226,3 +226,8 @@ toggleFavorites options =
gotoPage : { pageNumber : Int } -> Effect msg
gotoPage options =
SendSharedMsg <| Shared.Msg.GotoPage options


showCopyToClipboardAlert : { contentCopied : String } -> Effect msg
showCopyToClipboardAlert options =
SendSharedMsg <| Shared.Msg.ShowCopyToClipboardAlert options
83 changes: 71 additions & 12 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import Nav exposing (viewUtil)
import Page
import Pager
import Pages exposing (Page)
import Pages.Account.Login_
import Pages.Account.Settings_
import Pages.Build.Graph.Interop exposing (renderBuildGraph)
import Pages.Build.Logs
exposing
Expand All @@ -110,7 +112,6 @@ import Pages.Deployments.View
import Pages.Deployments_
import Pages.Home_
import Pages.Hooks
import Pages.Login_
import Pages.NotFound_
import Pages.Organization
import Pages.Pipeline.Model
Expand Down Expand Up @@ -379,9 +380,9 @@ initPageAndLayout model =
case Route.Path.fromUrl model.url of
Route.Path.Login_ ->
let
page : Page.Page Pages.Login_.Model Pages.Login_.Msg
page : Page.Page Pages.Account.Login_.Model Pages.Account.Login_.Msg
page =
Pages.Login_.page model.shared (Route.fromUrl () model.url)
Pages.Account.Login_.page model.shared (Route.fromUrl () model.url)

( pageModel, pageEffect ) =
Page.init page ()
Expand All @@ -397,6 +398,30 @@ initPageAndLayout model =
|> Maybe.map (initLayout model)
}

Route.Path.AccountSettings_ ->
runWhenAuthenticatedWithLayout
model
(\user ->
let
page : Page.Page Pages.Account.Settings_.Model Pages.Account.Settings_.Msg
page =
Pages.Account.Settings_.page user model.shared (Route.fromUrl () model.url)

( pageModel, pageEffect ) =
Page.init page ()
in
{ page =
Tuple.mapBoth
Main.Pages.Model.AccountSettings_
(Effect.map Main.Pages.Msg.AccountSettings_ >> fromPageEffect model)
( pageModel, pageEffect )
, layout =
Page.layout pageModel page
|> Maybe.map (Layouts.map (Main.Pages.Msg.AccountSettings_ >> Page))
|> Maybe.map (initLayout model)
}
)

Route.Path.Logout_ ->
{ page =
( Main.Pages.Model.Redirecting_
Expand Down Expand Up @@ -572,7 +597,7 @@ type Msg
| Shared Shared.Msg
| Batch (List Msg)
-- END NEW WORLD
-- todo: do we HAVE to move this to Shared.Msg?
-- todo: determine if this should, and if it can, be moved to Shared.Msg
| TokenResponse (Result (Http.Detailed.Error String) ( Http.Metadata, JwtAccessToken ))
--
--
Expand Down Expand Up @@ -2846,7 +2871,17 @@ updateFromPage msg model =
Tuple.mapBoth
Main.Pages.Model.Login_
(Effect.map Main.Pages.Msg.Login_ >> fromPageEffect model)
(Page.update (Pages.Login_.page model.shared (Route.fromUrl () model.url)) pageMsg pageModel)
(Page.update (Pages.Account.Login_.page model.shared (Route.fromUrl () model.url)) pageMsg pageModel)

( Main.Pages.Msg.AccountSettings_ pageMsg, Main.Pages.Model.AccountSettings_ pageModel ) ->
runWhenAuthenticated
model
(\user ->
Tuple.mapBoth
Main.Pages.Model.AccountSettings_
(Effect.map Main.Pages.Msg.AccountSettings_ >> fromPageEffect model)
(Page.update (Pages.Account.Settings_.page user model.shared (Route.fromUrl () model.url)) pageMsg pageModel)
)

( Main.Pages.Msg.Home_ pageMsg, Main.Pages.Model.Home_ pageModel ) ->
runWhenAuthenticated
Expand All @@ -2859,10 +2894,6 @@ updateFromPage msg model =
)

( Main.Pages.Msg.Deployments_ pageMsg, Main.Pages.Model.Deployments_ pageModel ) ->
let
_ =
Debug.log "updateFromPage" "Deployments_"
in
runWhenAuthenticated
model
(\user ->
Expand Down Expand Up @@ -2904,10 +2935,16 @@ toLayoutFromPage model =
case model.page of
Main.Pages.Model.Login_ pageModel ->
Route.fromUrl () model.url
|> Pages.Login_.page model.shared
|> Pages.Account.Login_.page model.shared
|> Page.layout pageModel
|> Maybe.map (Layouts.map (Main.Pages.Msg.Login_ >> Page))

Main.Pages.Model.AccountSettings_ pageModel ->
Route.fromUrl () model.url
|> toAuthProtectedPage model Pages.Account.Settings_.page
|> Maybe.andThen (Page.layout pageModel)
|> Maybe.map (Layouts.map (Main.Pages.Msg.AccountSettings_ >> Page))

Main.Pages.Model.Home_ pageModel ->
Route.fromUrl () model.url
|> toAuthProtectedPage model Pages.Home_.page
Expand Down Expand Up @@ -3009,10 +3046,19 @@ viewPage : Model -> View Msg
viewPage model =
case model.page of
Main.Pages.Model.Login_ pageModel ->
Page.view (Pages.Login_.page model.shared (Route.fromUrl () model.url)) pageModel
Page.view (Pages.Account.Login_.page model.shared (Route.fromUrl () model.url)) pageModel
|> View.map Main.Pages.Msg.Login_
|> View.map Page

Main.Pages.Model.AccountSettings_ pageModel ->
Auth.Action.view
(\user ->
Page.view (Pages.Account.Settings_.page user model.shared (Route.fromUrl () model.url)) pageModel
|> View.map Main.Pages.Msg.AccountSettings_
|> View.map Page
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Home_ pageModel ->
Auth.Action.view
(\user ->
Expand Down Expand Up @@ -3123,11 +3169,21 @@ toPageUrlHookCmd model routes =
in
case model.page of
Main.Pages.Model.Login_ pageModel ->
Page.toUrlMessages routes (Pages.Login_.page model.shared (Route.fromUrl () model.url))
Page.toUrlMessages routes (Pages.Account.Login_.page model.shared (Route.fromUrl () model.url))
|> List.map Main.Pages.Msg.Login_
|> List.map Page
|> toCommands

Main.Pages.Model.AccountSettings_ pageModel ->
Auth.Action.command
(\user ->
Page.toUrlMessages routes (Pages.Account.Settings_.page user model.shared (Route.fromUrl () model.url))
|> List.map Main.Pages.Msg.AccountSettings_
|> List.map Page
|> toCommands
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Home_ pageModel ->
Auth.Action.command
(\user ->
Expand Down Expand Up @@ -3213,6 +3269,9 @@ isAuthProtected routePath =
Route.Path.Login_ ->
False

Route.Path.AccountSettings_ ->
True

Route.Path.Logout_ ->
True

Expand Down
7 changes: 4 additions & 3 deletions src/elm/Main/Pages/Model.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module Main.Pages.Model exposing (Model(..))

import Pages.Account.Login_
import Pages.Account.Settings_
import Pages.Deployments_
import Pages.Home_
import Pages.Login_
import Pages.NotFound_
import View exposing (View)


type Model
= Login_ Pages.Login_.Model
= Login_ Pages.Account.Login_.Model
| AccountSettings_ Pages.Account.Settings_.Model
| Home_ Pages.Home_.Model
| Deployments_ Pages.Deployments_.Model
| Redirecting_
Expand Down
6 changes: 4 additions & 2 deletions src/elm/Main/Pages/Msg.elm
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module Main.Pages.Msg exposing (Msg(..))

import Pages.Account.Login_
import Pages.Account.Settings_
import Pages.Deployments_
import Pages.Home_
import Pages.Login_
import Pages.NotFound_


type Msg
= Login_ Pages.Login_.Msg
= Login_ Pages.Account.Login_.Msg
| AccountSettings_ Pages.Account.Settings_.Msg
| Home_ Pages.Home_.Msg
| Deployments_ Pages.Deployments_.Msg
| NotFound_ Pages.NotFound_.Msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Pages.Login_ exposing (..)
module Pages.Account.Login_ exposing (..)

import Api.Endpoint
import Browser.Navigation
Expand Down
Loading

0 comments on commit 2c88b43

Please sign in to comment.