Skip to content

Commit

Permalink
feat(test reports): add scaffolding and basic styling
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Jan 2, 2025
1 parent 2557666 commit 8f34f21
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/elm/Components/Tabs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ viewBuildTabs shared props =
, isAlerting = False
, show = True
}
, { name = "Reports"
, toPath =
Route.Path.Org__Repo__Build__Reports
{ org = props.org
, repo = props.repo
, build = props.build
}
, isAlerting = False
, show = True
}
]
in
view props.tabHistory props.currentPath tabs "jump-bar-build"
Expand Down
72 changes: 72 additions & 0 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Pages.Org_.Repo_
import Pages.Org_.Repo_.Build_
import Pages.Org_.Repo_.Build_.Graph
import Pages.Org_.Repo_.Build_.Pipeline
import Pages.Org_.Repo_.Build_.Reports
import Pages.Org_.Repo_.Build_.Services
import Pages.Org_.Repo_.Deployments
import Pages.Org_.Repo_.Deployments.Add
Expand Down Expand Up @@ -1344,6 +1345,30 @@ initPageAndLayout model =
}
)

Route.Path.Org__Repo__Build__Reports params ->
runWhenAuthenticatedWithLayout
model
(\user ->
let
page : Page.Page Pages.Org_.Repo_.Build_.Reports.Model Pages.Org_.Repo_.Build_.Reports.Msg
page =
Pages.Org_.Repo_.Build_.Reports.page user model.shared (Route.fromUrl params model.url)

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

Route.Path.Org__Repo__Build__Services params ->
runWhenAuthenticatedWithLayout
model
Expand Down Expand Up @@ -1932,6 +1957,16 @@ updateFromPage msg model =
(Page.update (Pages.Org_.Repo_.Build_.Pipeline.page user model.shared (Route.fromUrl params model.url)) pageMsg pageModel)
)

( Main.Pages.Msg.Org__Repo__Build__Reports pageMsg, Main.Pages.Model.Org__Repo__Build__Reports params pageModel ) ->
runWhenAuthenticated
model
(\user ->
Tuple.mapBoth
(Main.Pages.Model.Org__Repo__Build__Reports params)
(Effect.map Main.Pages.Msg.Org__Repo__Build__Reports >> fromPageEffect model)
(Page.update (Pages.Org_.Repo_.Build_.Reports.page user model.shared (Route.fromUrl params model.url)) pageMsg pageModel)
)

( Main.Pages.Msg.Org__Repo__Build__Services pageMsg, Main.Pages.Model.Org__Repo__Build__Services params pageModel ) ->
runWhenAuthenticated
model
Expand Down Expand Up @@ -2249,6 +2284,12 @@ toLayoutFromPage model =
|> Maybe.andThen (Page.layout pageModel)
|> Maybe.map (Layouts.map (Main.Pages.Msg.Org__Repo__Build__Pipeline >> Page))

Main.Pages.Model.Org__Repo__Build__Reports params pageModel ->
Route.fromUrl params model.url
|> toAuthProtectedPage model Pages.Org_.Repo_.Build_.Reports.page
|> Maybe.andThen (Page.layout pageModel)
|> Maybe.map (Layouts.map (Main.Pages.Msg.Org__Repo__Build__Reports >> Page))

Main.Pages.Model.Org__Repo__Build__Services params pageModel ->
Route.fromUrl params model.url
|> toAuthProtectedPage model Pages.Org_.Repo_.Build_.Services.page
Expand Down Expand Up @@ -2592,6 +2633,15 @@ subscriptions model =
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Reports params pageModel ->
Auth.Action.subscriptions
(\user ->
Page.subscriptions (Pages.Org_.Repo_.Build_.Reports.page user model.shared (Route.fromUrl params model.url)) pageModel
|> Sub.map Main.Pages.Msg.Org__Repo__Build__Reports
|> Sub.map Page
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Services params pageModel ->
Auth.Action.subscriptions
(\user ->
Expand Down Expand Up @@ -3102,6 +3152,15 @@ viewPage model =
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Reports params pageModel ->
Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url)))
(\user ->
Page.view (Pages.Org_.Repo_.Build_.Reports.page user model.shared (Route.fromUrl params model.url)) pageModel
|> View.map Main.Pages.Msg.Org__Repo__Build__Reports
|> View.map Page
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Services params pageModel ->
Auth.Action.view (View.map never (Auth.viewCustomPage model.shared (Route.fromUrl () model.url)))
(\user ->
Expand Down Expand Up @@ -3500,6 +3559,16 @@ toPageUrlHookCmd model routes =
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Reports params pageModel ->
Auth.Action.command
(\user ->
Page.toUrlMessages routes (Pages.Org_.Repo_.Build_.Reports.page user model.shared (Route.fromUrl params model.url))
|> List.map Main.Pages.Msg.Org__Repo__Build__Reports
|> List.map Page
|> toCommands
)
(Auth.onPageLoad model.shared (Route.fromUrl () model.url))

Main.Pages.Model.Org__Repo__Build__Services params pageModel ->
Auth.Action.command
(\user ->
Expand Down Expand Up @@ -3769,6 +3838,9 @@ isAuthProtected routePath =
Route.Path.Org__Repo__Build__Pipeline _ ->
True

Route.Path.Org__Repo__Build__Reports _ ->
True

Route.Path.Org__Repo__Build__Services _ ->
True

Expand Down
2 changes: 2 additions & 0 deletions src/elm/Main/Pages/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Pages.Org_.Repo_
import Pages.Org_.Repo_.Build_
import Pages.Org_.Repo_.Build_.Graph
import Pages.Org_.Repo_.Build_.Pipeline
import Pages.Org_.Repo_.Build_.Reports
import Pages.Org_.Repo_.Build_.Services
import Pages.Org_.Repo_.Deployments
import Pages.Org_.Repo_.Deployments.Add
Expand Down Expand Up @@ -79,6 +80,7 @@ type Model
| Org__Repo__Build_ { org : String, repo : String, build : String } Pages.Org_.Repo_.Build_.Model
| Org__Repo__Build__Graph { org : String, repo : String, build : String } Pages.Org_.Repo_.Build_.Graph.Model
| Org__Repo__Build__Pipeline { org : String, repo : String, build : String } Pages.Org_.Repo_.Build_.Pipeline.Model
| Org__Repo__Build__Reports { org : String, repo : String, build : String } Pages.Org_.Repo_.Build_.Reports.Model
| Org__Repo__Build__Services { org : String, repo : String, build : String } Pages.Org_.Repo_.Build_.Services.Model
| NotFound_ Pages.NotFound_.Model
| Redirecting_
Expand Down
2 changes: 2 additions & 0 deletions src/elm/Main/Pages/Msg.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Pages.Org_.Repo_
import Pages.Org_.Repo_.Build_
import Pages.Org_.Repo_.Build_.Graph
import Pages.Org_.Repo_.Build_.Pipeline
import Pages.Org_.Repo_.Build_.Reports
import Pages.Org_.Repo_.Build_.Services
import Pages.Org_.Repo_.Deployments
import Pages.Org_.Repo_.Deployments.Add
Expand Down Expand Up @@ -78,5 +79,6 @@ type Msg
| Org__Repo__Build_ Pages.Org_.Repo_.Build_.Msg
| Org__Repo__Build__Graph Pages.Org_.Repo_.Build_.Graph.Msg
| Org__Repo__Build__Pipeline Pages.Org_.Repo_.Build_.Pipeline.Msg
| Org__Repo__Build__Reports Pages.Org_.Repo_.Build_.Reports.Msg
| Org__Repo__Build__Services Pages.Org_.Repo_.Build_.Services.Msg
| NotFound_ Pages.NotFound_.Msg
198 changes: 198 additions & 0 deletions src/elm/Pages/Org_/Repo_/Build_/Reports.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{--
SPDX-License-Identifier: Apache-2.0
--}


module Pages.Org_.Repo_.Build_.Reports exposing (..)

import Auth
import Effect exposing (Effect)
import Html exposing (a, button, div, li, text, ul)
import Html.Attributes exposing (class, download, href)
import Layouts
import Page exposing (Page)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Route.Path
import Shared
import Vela
import View exposing (View)


{-| page : takes user, shared model, route, and returns a build's reports page.
-}
page : Auth.User -> Shared.Model -> Route { org : String, repo : String, build : String } -> Page Model Msg
page user shared route =
Page.new
{ init = init shared route
, update = update shared route
, subscriptions = subscriptions
, view = view shared route
}
|> Page.withLayout (toLayout user route)



-- LAYOUT


{-| toLayout : takes user, route, model, and passes a build's pipeline page info to Layouts.
-}
toLayout : Auth.User -> Route { org : String, repo : String, build : String } -> Model -> Layouts.Layout Msg
toLayout user route model =
Layouts.Default_Build
{ navButtons = []
, utilButtons = []
, helpCommands =
[ { name = "View Build"
, content =
"vela view build --org "
++ route.params.org
++ " --repo "
++ route.params.repo
++ " --build "
++ route.params.build
, docs = Just "build/view"
}
, { name = "Approve Build"
, content =
"vela approve build --org "
++ route.params.org
++ " --repo "
++ route.params.repo
++ " --build "
++ route.params.build
, docs = Just "build/approve"
}
, { name = "Restart Build"
, content =
"vela restart build --org "
++ route.params.org
++ " --repo "
++ route.params.repo
++ " --build "
++ route.params.build
, docs = Just "build/restart"
}
, { name = "Cancel Build"
, content =
"vela cancel build --org "
++ route.params.org
++ " --repo "
++ route.params.repo
++ " --build "
++ route.params.build
, docs = Just "build/cancel"
}
]
, crumbs =
[ ( "Overview", Just Route.Path.Home_ )
, ( route.params.org, Just <| Route.Path.Org_ { org = route.params.org } )
, ( route.params.repo, Just <| Route.Path.Org__Repo_ { org = route.params.org, repo = route.params.repo } )
, ( "#" ++ route.params.build, Nothing )
]
, org = route.params.org
, repo = route.params.repo
, build = route.params.build
, toBuildPath =
\build ->
Route.Path.Org__Repo__Build__Reports
{ org = route.params.org
, repo = route.params.repo
, build = build
}
}



-- INIT


type alias Model =
{ build : WebData Vela.Build
}


init : Shared.Model -> Route { org : String, repo : String, build : String } -> () -> ( Model, Effect Msg )
init shared route () =
( { build = RemoteData.Loading
}
, Effect.none
)



-- UPDATE


type Msg
= NoOp
| DownloadTextArtifact { filename : String, content : String, map : String -> String }


{-| update : takes current models, route, message, and returns an updated model and effect.
-}
update : Shared.Model -> Route { org : String, repo : String, build : String } -> Msg -> Model -> ( Model, Effect Msg )
update shared route msg model =
case msg of
NoOp ->
( model
, Effect.none
)

DownloadTextArtifact options ->
( model
, Effect.downloadFile options
)


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none



-- VIEW


view : Shared.Model -> Route { org : String, repo : String, build : String } -> Model -> View Msg
view shared route model =
let
downloadLinks =
a
[ class "report-output"
, href ""
, download ""
]
[ text "an artifact" ]
in
{ title = "Reports"
, body =
[ div [ class "reports-container" ]
[ div []
[ ul [ class "reports-buttons" ]
[ li []
[ button
[ class "reports-button"
]
[ text "artifacts" ]
]
, li []
[ button
[ class "reports-button"
]
[ text "test results" ]
]
]
]
, downloadLinks
]
]
}



-- TODO:
-- - default artifacts button to active
-- - allow any other buttons to replace active button
-- - each button will provide a different view
Loading

0 comments on commit 8f34f21

Please sign in to comment.