Skip to content

Commit

Permalink
refactor: backported deployments from v23
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Feb 5, 2024
1 parent ea5185d commit c81f1ff
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
70 changes: 59 additions & 11 deletions src/elm/Pages/Org_/Repo_/Deployments.elm
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ view : Shared.Model -> Route { org : String, repo : String } -> Model -> View Ms
view shared route model =
{ title = "Deployments"
, body =
[ viewDeployments model route
[ viewDeployments shared model route
, Components.Pager.view model.pager Components.Pager.defaultLabels GotoPage
]
}


{-| viewDeployments : renders a list of deployments
-}
viewDeployments : Model -> Route { org : String, repo : String } -> Html Msg
viewDeployments model route =
viewDeployments : Shared.Model -> Model -> Route { org : String, repo : String } -> Html Msg
viewDeployments shared model route =
let
actions =
Just <|
Expand All @@ -263,7 +263,7 @@ viewDeployments model route =
case ( model.repo, model.deployments ) of
( RemoteData.Success r, RemoteData.Success d ) ->
( text "No deployments found for this repo"
, deploymentsToRows r d
, deploymentsToRows shared r d
)

( RemoteData.Failure error, _ ) ->
Expand Down Expand Up @@ -295,9 +295,9 @@ viewDeployments model route =

{-| deploymentsToRows : takes list of deployments and produces list of Table rows
-}
deploymentsToRows : Vela.Repository -> List Vela.Deployment -> Components.Table.Rows Vela.Deployment Msg
deploymentsToRows repo deployments =
List.map (\deployment -> Components.Table.Row deployment (viewDeployment repo)) deployments
deploymentsToRows : Shared.Model -> Vela.Repository -> List Vela.Deployment -> Components.Table.Rows Vela.Deployment Msg
deploymentsToRows shared repo deployments =
List.map (\deployment -> Components.Table.Row deployment (viewDeployment shared repo)) deployments


{-| tableHeaders : returns table headers for deployments table
Expand All @@ -310,14 +310,17 @@ tableHeaders =
, ( Nothing, "commit" )
, ( Nothing, "ref" )
, ( Nothing, "description" )
, ( Nothing, "builds" )
, ( Nothing, "created by" )
, ( Nothing, "created at" )
, ( Nothing, "" )
]


{-| viewDeployment : takes deployment and renders a table row
-}
viewDeployment : Vela.Repository -> Vela.Deployment -> Html Msg
viewDeployment repo deployment =
viewDeployment : Shared.Model -> Vela.Repository -> Vela.Deployment -> Html Msg
viewDeployment shared repo deployment =
tr [ Util.testAttribute <| "deployments-row", class "-success" ]
[ Components.Table.viewIconCell
{ dataLabel = "status"
Expand All @@ -329,11 +332,11 @@ viewDeployment repo deployment =
]
}
, Components.Table.viewItemCell
{ dataLabel = "id"
{ dataLabel = "number"
, parentClassList = []
, itemClassList = []
, children =
[ text <| String.fromInt deployment.id
[ text <| String.fromInt deployment.number
]
}
, Components.Table.viewItemCell
Expand Down Expand Up @@ -370,6 +373,30 @@ viewDeployment repo deployment =
[ text deployment.description
]
}
, Components.Table.viewItemCell
{ dataLabel = "builds"
, parentClassList = []
, itemClassList = []
, children =
[ viewDeploymentBuildsLinks deployment
]
}
, Components.Table.viewItemCell
{ dataLabel = "created by"
, parentClassList = []
, itemClassList = []
, children =
[ text <| deployment.created_by
]
}
, Components.Table.viewItemCell
{ dataLabel = "created at"
, parentClassList = []
, itemClassList = []
, children =
[ text <| Util.humanReadableDateTimeWithDefault shared.zone deployment.created_at
]
}
, Components.Table.viewItemCell
{ dataLabel = ""
, parentClassList = []
Expand Down Expand Up @@ -413,6 +440,27 @@ viewDeployment repo deployment =
]


viewDeploymentBuildsLinks : Vela.Deployment -> Html msg
viewDeploymentBuildsLinks deployment =
deployment.builds
|> List.map
(\build ->
a
[ href build.link ]
[ text
(build.link
|> String.split "/"
|> List.reverse
|> List.head
|> Maybe.withDefault ""
|> String.append "#"
)
]
)
|> List.intersperse (text ", ")
|> div []


viewError : Http.Error -> Html msg
viewError error =
span [ Util.testAttribute "repo-deployments-error" ]
Expand Down
10 changes: 8 additions & 2 deletions src/elm/Vela.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1450,31 +1450,37 @@ encodeSecretPayload secret =

type alias Deployment =
{ id : Int
, number : Int
, repo_id : Int
, url : String
, user : String
, created_by : String
, created_at : Int
, commit : String
, ref : String
, task : String
, target : String
, description : String
, payload : Maybe (List KeyValuePair)
, builds : List Build
}


decodeDeployment : Decoder Deployment
decodeDeployment =
Json.Decode.succeed Deployment
|> optional "id" int -1
|> optional "number" int -1
|> optional "repo_id" int -1
|> optional "url" string ""
|> optional "user" string ""
|> optional "created_by" string ""
|> optional "created_at" int 0
|> optional "commit" string ""
|> optional "ref" string ""
|> optional "task" string ""
|> optional "target" string ""
|> optional "description" string ""
|> optional "payload" decodeDeploymentParameters Nothing
|> optional "builds" decodeBuilds []


decodeDeployments : Decoder (List Deployment)
Expand Down

0 comments on commit c81f1ff

Please sign in to comment.