Merge pull request #7307 from concourse/groups-propagation

This commit is contained in:
Aidan Oldershaw 2021-07-29 19:33:33 -04:00 committed by GitHub
commit b047d257f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 272 additions and 47 deletions

View File

@ -125,6 +125,7 @@ buildView session model =
Routes.Build
{ id = buildId
, highlight = model.highlight
, groups = []
}
in
Html.div
@ -194,6 +195,7 @@ breadcrumbs session model =
Routes.Job
{ id = jobId
, page = Nothing
, groups = []
}
( _, JobBuildPage buildId ) ->
@ -201,6 +203,7 @@ breadcrumbs session model =
Routes.Build
{ id = buildId
, highlight = model.highlight
, groups = []
}
_ ->
@ -326,7 +329,7 @@ viewBuildHeader session model build =
Just jobId ->
let
jobRoute =
Routes.Job { id = jobId, page = Nothing }
Routes.Job { id = jobId, page = Nothing, groups = [] }
in
Html.a
[ href <| Routes.toString jobRoute ]

View File

@ -401,25 +401,36 @@ redirectToLoginIfNecessary err ( model, effects ) =
urlUpdate : Routes.Route -> Model -> ( Model, List Effect )
urlUpdate route model =
let
oldRoute =
model.session.route
newRoute =
case route of
Routes.Pipeline _ ->
route
_ ->
Routes.withGroups (Routes.getGroups oldRoute) route
( newSubmodel, subEffects ) =
if route == model.session.route then
if newRoute == oldRoute then
( model.subModel, [] )
else if routeMatchesModel route model then
else if routeMatchesModel newRoute model then
SubPage.urlUpdate
{ from = model.session.route
, to = route
{ from = oldRoute
, to = newRoute
}
( model.subModel, [] )
else
SubPage.init model.session route
SubPage.init model.session newRoute
oldSession =
model.session
newSession =
{ oldSession | route = route, hovered = HoverState.NoHover }
{ oldSession | route = newRoute, hovered = HoverState.NoHover }
in
( { model | subModel = newSubmodel, session = newSession }
, subEffects ++ [ SetFavIcon Nothing ]

View File

@ -683,6 +683,7 @@ view session model =
Routes.Build
{ id = buildId
, highlight = model.highlight
, groups = []
}
in
Html.div
@ -745,6 +746,7 @@ breadcrumbs session model =
Routes.Job
{ id = jobId
, page = Nothing
, groups = Routes.getGroups session.route
}
( _, JobBuildPage buildId ) ->
@ -752,6 +754,7 @@ breadcrumbs session model =
Routes.Build
{ id = buildId
, highlight = model.highlight
, groups = Routes.getGroups session.route
}
_ ->

View File

@ -379,7 +379,7 @@ viewTitle name jobID createdBy =
Html.a
[ href <|
Routes.toString <|
Routes.Job { id = jid, page = Nothing }
Routes.Job { id = jid, page = Nothing, groups = [] }
, onMouseEnter <| Hover <| Just Message.JobName
, onMouseLeave <| Hover Nothing
, id <| toHtmlID Message.JobName

View File

@ -1045,6 +1045,7 @@ viewVersion step pipelineId name =
}
, page = Nothing
, version = Just version
, groups = []
}
, onMouseLeave <| Hover Nothing
, onMouseEnter <| Hover (Just domId)

View File

@ -241,6 +241,7 @@ view session model =
{ id = model.versionId
, direction = model.direction
, version = Maybe.map .version model.fetchedVersionedResource
, groups = Routes.getGroups session.route
}
in
Html.div
@ -511,7 +512,7 @@ graphvizDotNotation model =
}
link =
Routes.Build { id = build, highlight = Routes.HighlightNothing }
Routes.Build { id = build, highlight = Routes.HighlightNothing, groups = [] }
|> Routes.toString
in
row (attributes [ ( "HREF", link ), ( "BGCOLOR", buildStatusColor True b.status ) ]) ("#" ++ b.name)

View File

@ -186,7 +186,7 @@ bodyView session section pipelines pipelineJobs jobs =
let
pipelinePage =
Routes.toString <|
Routes.pipelineRoute p
Routes.pipelineRoute p []
curPipelineJobs =
Dict.get p.id pipelineJobs

View File

@ -93,7 +93,7 @@ hdPipelineView { pipelineRunningKeyframes } { pipeline, resourceError, existingJ
([ class "card"
, attribute "data-pipeline-name" pipeline.name
, attribute "data-team-name" pipeline.teamName
, href <| Routes.toString <| Routes.pipelineRoute pipeline
, href <| Routes.toString <| Routes.pipelineRoute pipeline []
]
++ Styles.pipelineCardHd (pipelineStatus existingJobs pipeline)
)
@ -291,7 +291,7 @@ headerView section pipeline resourceError headerHeight viewingInstanceGroups inI
[]
in
Html.a
[ href <| Routes.toString <| Routes.pipelineRoute pipeline, draggable "false" ]
[ href <| Routes.toString <| Routes.pipelineRoute pipeline [], draggable "false" ]
[ Html.div
(class "card-header" :: Styles.pipelineCardHeader headerHeight)
(rows ++ [ resourceErrorElem ])

View File

@ -183,6 +183,7 @@ handleCallback callback ( model, effects ) =
, buildName = build.name
}
, highlight = Routes.HighlightNothing
, groups = []
}
]
)
@ -396,6 +397,7 @@ handleJobBuildsFetched requestedPage paginatedBuilds ( model, effects ) =
Routes.Job
{ id = model.jobIdentifier
, page = Just startingPage
, groups = []
}
]
)
@ -421,24 +423,17 @@ documentTitle model =
view : Session -> Model -> Html Message
view session model =
let
route =
Routes.Job
{ id = model.jobIdentifier
, page = Just model.currentPage
}
in
Html.div
(id "page-including-top-bar" :: Views.Styles.pageIncludingTopBar)
[ Html.div
(id "top-bar-app" :: Views.Styles.topBar False)
[ SideBar.sideBarIcon session
, TopBar.concourseLogo
, TopBar.breadcrumbs session route
, TopBar.breadcrumbs session session.route
, Login.view session.userState model
]
, Html.div
(id "page-below-top-bar" :: Views.Styles.pageBelowTopBar route)
(id "page-below-top-bar" :: Views.Styles.pageBelowTopBar session.route)
[ SideBar.view session
(Just
{ pipelineName = model.jobIdentifier.pipelineName
@ -689,7 +684,7 @@ viewPaginationBar session model =
Just page ->
let
jobRoute =
Routes.Job { id = model.jobIdentifier, page = Just page }
Routes.Job { id = model.jobIdentifier, page = Just page, groups = [] }
in
Html.div
([ onMouseEnter <| Hover <| Just PreviousPageButton
@ -729,7 +724,7 @@ viewPaginationBar session model =
Just page ->
let
jobRoute =
Routes.Job { id = model.jobIdentifier, page = Just page }
Routes.Job { id = model.jobIdentifier, page = Just page, groups = [] }
in
Html.div
([ onMouseEnter <| Hover <| Just NextPageButton

View File

@ -216,6 +216,7 @@ pinMenu { hovered } model =
}
, page = Nothing
, version = Nothing
, groups = []
}
}
)

View File

@ -479,6 +479,7 @@ handleCallback callback session ( model, effects ) =
{ id = model.resourceIdentifier
, page = Just startingPage
, version = Nothing
, groups = []
}
]
@ -730,6 +731,7 @@ update msg ( model, effects ) =
{ id = model.resourceIdentifier
, page = Just page
, version = Nothing
, groups = []
}
]
)
@ -997,6 +999,7 @@ view session model =
{ id = model.resourceIdentifier
, page = Nothing
, version = Nothing
, groups = Routes.getGroups session.route
}
in
Html.div
@ -1322,6 +1325,7 @@ paginationMenu { hovered } model =
{ id = model.resourceIdentifier
, page = Just page
, version = Nothing
, groups = []
}
, attribute "aria-label" "Previous Page"
, id <| toHtmlID PreviousPageButton
@ -1361,6 +1365,7 @@ paginationMenu { hovered } model =
{ id = model.resourceIdentifier
, page = Just page
, version = Nothing
, groups = []
}
, attribute "aria-label" "Next Page"
, id <| toHtmlID NextPageButton
@ -1994,6 +1999,7 @@ viewCausalityButton enabled dir versionId =
{ id = versionId
, direction = dir
, version = Nothing
, groups = []
}
( domID, text ) =
@ -2140,6 +2146,7 @@ viewBuildsByJob buildDict jobName =
, buildName = build.name
}
, highlight = Routes.HighlightNothing
, groups = []
}
in
Html.li [ class <| Concourse.BuildStatus.show build.status ]

View File

@ -8,6 +8,7 @@ module Routes exposing
, buildRoute
, extractPid
, extractQuery
, getGroups
, jobRoute
, parsePath
, pipelineRoute
@ -17,6 +18,7 @@ module Routes exposing
, toString
, tokenToFlyRoute
, versionQueryParams
, withGroups
)
import Api.Pagination
@ -47,15 +49,15 @@ import Url.Parser.Query as Query
type Route
= Build { id : Concourse.JobBuildIdentifier, highlight : Highlight }
| Resource { id : Concourse.ResourceIdentifier, page : Maybe Pagination.Page, version : Maybe Concourse.Version }
| Job { id : Concourse.JobIdentifier, page : Maybe Pagination.Page }
= Build { id : Concourse.JobBuildIdentifier, highlight : Highlight, groups : List String }
| Resource { id : Concourse.ResourceIdentifier, page : Maybe Pagination.Page, version : Maybe Concourse.Version, groups : List String }
| Job { id : Concourse.JobIdentifier, page : Maybe Pagination.Page, groups : List String }
| OneOffBuild { id : Concourse.BuildId, highlight : Highlight }
| Pipeline { id : Concourse.PipelineIdentifier, groups : List String }
| Dashboard { searchType : SearchType, dashboardView : DashboardView }
| FlySuccess Bool (Maybe Int)
-- the version field is really only used as a hack to populate the breadcrumbs, it's not actually used by anyhting else
| Causality { id : Concourse.VersionedResourceIdentifier, direction : Concourse.CausalityDirection, version : Maybe Concourse.Version }
| Causality { id : Concourse.VersionedResourceIdentifier, direction : Concourse.CausalityDirection, version : Maybe Concourse.Version, groups : List String }
type SearchType
@ -131,6 +133,7 @@ build =
, buildName = buildName
}
, highlight = h
, groups = []
}
in
map buildHelper
@ -183,6 +186,7 @@ resource =
}
, page = parsePage from to limit
, version = version
, groups = []
}
in
map resourceHelper
@ -233,6 +237,7 @@ job =
, jobName = jobName
}
, page = parsePage from to limit
, groups = []
}
in
map jobHelper
@ -316,6 +321,7 @@ causality =
}
, direction = direction
, version = Nothing
, groups = []
}
baseRoute dir =
@ -352,6 +358,7 @@ buildRoute id name jobId =
, buildName = name
}
, highlight = HighlightNothing
, groups = []
}
Nothing ->
@ -368,6 +375,7 @@ jobRoute j =
, jobName = j.name
}
, page = Nothing
, groups = []
}
@ -382,14 +390,15 @@ resourceRoute r v =
}
, page = Nothing
, version = v
, groups = []
}
pipelineRoute : { a | name : String, teamName : String, instanceVars : InstanceVars } -> Route
pipelineRoute p =
pipelineRoute : { a | name : String, teamName : String, instanceVars : InstanceVars } -> List String -> Route
pipelineRoute p groups =
Pipeline
{ id = Concourse.toPipelineId p
, groups = []
, groups = groups
}
@ -642,3 +651,59 @@ versionQueryParams version =
pipelineIdBuilder : { r | teamName : String, pipelineName : String, pipelineInstanceVars : Concourse.InstanceVars } -> RouteBuilder
pipelineIdBuilder =
RouteBuilder.pipeline
getGroups : Route -> List String
getGroups route =
case route of
Build { groups } ->
groups
Resource { groups } ->
groups
Job { groups } ->
groups
Pipeline { groups } ->
groups
Causality { groups } ->
groups
OneOffBuild _ ->
[]
Dashboard _ ->
[]
FlySuccess _ _ ->
[]
withGroups : List String -> Route -> Route
withGroups groups route =
case route of
Build params ->
Build { params | groups = groups }
Resource params ->
Resource { params | groups = groups }
Job params ->
Job { params | groups = groups }
Pipeline params ->
Pipeline { params | groups = groups }
Causality params ->
Causality { params | groups = groups }
OneOffBuild _ ->
route
Dashboard _ ->
route
FlySuccess _ _ ->
route

View File

@ -99,37 +99,37 @@ breadcrumbs session route =
[]
Just pipeline ->
pipelineBreadcrumbs session pipeline
pipelineBreadcrumbs session pipeline []
Routes.Build { id } ->
Routes.Build { id, groups } ->
case lookupPipeline (byPipelineId id) session of
Nothing ->
[]
Just pipeline ->
pipelineBreadcrumbs session pipeline
pipelineBreadcrumbs session pipeline groups
++ [ breadcrumbSeparator
, jobBreadcrumb id.jobName
]
Routes.Resource { id } ->
Routes.Resource { id, groups } ->
case lookupPipeline (byPipelineId id) session of
Nothing ->
[]
Just pipeline ->
pipelineBreadcrumbs session pipeline
pipelineBreadcrumbs session pipeline groups
++ [ breadcrumbSeparator
, resourceBreadcrumb id
]
Routes.Job { id } ->
Routes.Job { id, groups } ->
case lookupPipeline (byPipelineId id) session of
Nothing ->
[]
Just pipeline ->
pipelineBreadcrumbs session pipeline
pipelineBreadcrumbs session pipeline groups
++ [ breadcrumbSeparator
, jobBreadcrumb id.jobName
]
@ -137,13 +137,13 @@ breadcrumbs session route =
Routes.Dashboard _ ->
[ clusterNameBreadcrumb session ]
Routes.Causality { id, direction, version } ->
Routes.Causality { id, direction, version, groups } ->
case lookupPipeline (byPipelineId id) session of
Nothing ->
[]
Just pipeline ->
pipelineBreadcrumbs session pipeline
pipelineBreadcrumbs session pipeline groups
++ [ breadcrumbSeparator
, resourceBreadcrumb <| Concourse.resourceIdFromVersionedResourceId id
, breadcrumbSeparator
@ -193,8 +193,8 @@ clusterNameBreadcrumb session _ =
[ Html.text session.clusterName ]
pipelineBreadcrumbs : Session -> Concourse.Pipeline -> List (Bool -> Html Message)
pipelineBreadcrumbs session pipeline =
pipelineBreadcrumbs : Session -> Concourse.Pipeline -> List String -> List (Bool -> Html Message)
pipelineBreadcrumbs session pipeline groups =
let
pipelineGroup =
session.pipelines
@ -229,11 +229,11 @@ pipelineBreadcrumbs session pipeline =
else
[]
)
++ [ pipelineBreadcrumb inInstanceGroup pipeline ]
++ [ pipelineBreadcrumb inInstanceGroup pipeline groups ]
pipelineBreadcrumb : Bool -> Concourse.Pipeline -> Bool -> Html Message
pipelineBreadcrumb inInstanceGroup pipeline isLastBreadcrumb =
pipelineBreadcrumb : Bool -> Concourse.Pipeline -> List String -> Bool -> Html Message
pipelineBreadcrumb inInstanceGroup pipeline groups isLastBreadcrumb =
let
text =
if inInstanceGroup then
@ -246,7 +246,7 @@ pipelineBreadcrumb inInstanceGroup pipeline isLastBreadcrumb =
([ id "breadcrumb-pipeline"
, href <|
Routes.toString <|
Routes.pipelineRoute pipeline
Routes.pipelineRoute pipeline groups
]
++ Styles.breadcrumbItem True isLastBreadcrumb
)

View File

@ -3,8 +3,12 @@ module ApplicationTests exposing (all)
import Application.Application as Application
import Browser
import Common exposing (queryView)
import Concourse
import Data
import Dict
import Expect
import HoverState
import Message.Callback as Callback
import Message.Effects as Effects
import Message.Message exposing (DomID(..), Message(..))
import Message.Subscription as Subscription exposing (Delivery(..))
@ -142,4 +146,122 @@ all =
|> .session
|> .hovered
|> Expect.equal HoverState.NoHover
, describe "pipeline groups propagation"
[ test "navigating through sub routes of a pipeline persists the groups" <|
\_ ->
Common.initRoute
(Routes.Pipeline
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
}
, groups = [ "test-group" ]
}
)
|> Application.handleCallback
(Callback.AllPipelinesFetched <| Ok [ Data.pipeline "t" 1 |> Data.withName "p" ])
|> Tuple.first
|> Application.handleDelivery
(RouteChanged <|
Routes.Job
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
, jobName = "j"
}
, page = Nothing
, groups = []
}
)
|> Tuple.first
|> Application.handleDelivery
(RouteChanged <|
Routes.Build
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
, jobName = "j"
, buildName = "b"
}
, highlight = Routes.HighlightNothing
, groups = []
}
)
|> Tuple.first
|> Application.handleDelivery
(RouteChanged <|
Routes.Resource
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
, resourceName = "r"
}
, page = Nothing
, version = Nothing
, groups = []
}
)
|> Tuple.first
|> Application.handleDelivery
(RouteChanged <|
Routes.Causality
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
, resourceName = "r"
, versionID = 1
}
, direction = Concourse.Downstream
, version = Nothing
, groups = []
}
)
|> Tuple.first
|> Common.queryView
|> Query.find [ id "top-bar-app" ]
|> Query.has
[ Common.routeHref <|
Routes.Pipeline
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
}
, groups = [ "test-group" ]
}
]
, test "navigating to no groups pipeline page does not propagate the groups" <|
\_ ->
Common.initRoute
(Routes.Pipeline
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
}
, groups = [ "test-group" ]
}
)
|> Application.handleDelivery
(RouteChanged <|
Routes.Pipeline
{ id =
{ teamName = "t"
, pipelineName = "p"
, pipelineInstanceVars = Dict.empty
}
, groups = []
}
)
|> Tuple.first
|> .session
|> .route
|> Routes.getGroups
|> Expect.equal []
]
]

View File

@ -465,7 +465,7 @@ session =
, timeZone = Time.utc
, favoritedPipelines = Set.empty
, favoritedInstanceGroups = Set.empty
, route = Routes.Build { id = Data.jobBuildId, highlight = Routes.HighlightNothing }
, route = Routes.Build { id = Data.jobBuildId, highlight = Routes.HighlightNothing, groups = [] }
}

View File

@ -1306,6 +1306,7 @@ all =
buildParams =
{ id = Data.jobBuildId
, highlight = Routes.HighlightNothing
, groups = []
}
in
Common.init "/"
@ -1826,6 +1827,7 @@ all =
Routes.Build
{ id = Data.jobBuildId |> Data.withBuildName "2"
, highlight = Routes.HighlightNothing
, groups = []
}
)
>> Tuple.first

View File

@ -154,6 +154,7 @@ all =
{ id = Data.resourceId |> Data.withResourceName "test"
, page = Nothing
, version = Nothing
, groups = []
}
}
]
@ -202,6 +203,7 @@ all =
{ id = Data.resourceId |> Data.withResourceName "test"
, page = Nothing
, version = Nothing
, groups = []
}
}
]

View File

@ -317,6 +317,7 @@ all =
{ id = versionID
, direction = Concourse.Downstream
, version = Nothing
, groups = []
}
]
, test "'Outputs Of' links to causality page" <|
@ -330,6 +331,7 @@ all =
{ id = versionID
, direction = Concourse.Upstream
, version = Nothing
, groups = []
}
]
]
@ -357,6 +359,7 @@ all =
{ id = versionID
, direction = Concourse.Downstream
, version = Nothing
, groups = []
}
]
, test "'Outputs Of' links to causality page" <|
@ -370,6 +373,7 @@ all =
{ id = versionID
, direction = Concourse.Upstream
, version = Nothing
, groups = []
}
]
]
@ -4090,5 +4094,5 @@ session =
, favoritedInstanceGroups = Set.empty
, screenSize = ScreenSize.Desktop
, timeZone = Time.utc
, route = Routes.Resource { id = Data.resourceId, page = Nothing, version = Nothing }
, route = Routes.Resource { id = Data.resourceId, page = Nothing, version = Nothing, groups = [] }
}

View File

@ -293,6 +293,7 @@ all =
}
, page = Nothing
, version = Just <| Dict.fromList [ ( "version", "sha:123abc" ) ]
, groups = []
}
)
]

View File

@ -34,6 +34,7 @@ all =
(Routes.Job
{ id = Data.shortJobId
, page = Nothing
, groups = []
}
)
)
@ -51,6 +52,7 @@ all =
{ id = Data.shortResourceId
, page = Nothing
, version = Nothing
, groups = []
}
)
)

View File

@ -304,6 +304,7 @@ all =
{ id = Data.shortResourceId
, page = Nothing
, version = Nothing
, groups = []
}
)
)
@ -315,6 +316,7 @@ all =
{ id = Data.shortResourceId
, page = Nothing
, version = Nothing
, groups = []
}
]
, context "when pipeline is paused"
@ -673,6 +675,7 @@ all =
, buildName = "1"
}
, highlight = Routes.HighlightNothing
, groups = []
}
)
|> Application.handleCallback
@ -770,6 +773,7 @@ all =
}
, page = Nothing
, version = Nothing
, groups = []
}
)
|> Application.handleCallback
@ -894,6 +898,7 @@ all =
, jobName = "job"
}
, page = Nothing
, groups = []
}
)
|> Application.handleCallback