Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deployments): updating ui to show new changes to database #753

Merged
merged 8 commits into from
Jan 15, 2024
3 changes: 3 additions & 0 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,9 @@ loadRepoSubPage model org repo toPage =
Pages.RepoSettings o r ->
( model, getRepo model o r )

Pages.RepositoryDeployments o r maybePage maybePerPage ->
( model, getDeployments model o r maybePage maybePerPage )

Pages.PromoteDeployment o r deploymentNumber ->
( model, getDeployment model o r deploymentNumber )

Expand Down
56 changes: 53 additions & 3 deletions src/elm/Pages/Deployments/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ deploymentsToRows repo_ deployments =
tableHeaders : Table.Columns
tableHeaders =
[ ( Just "-icon", "" )
, ( Nothing, "id" )
, ( Nothing, "number" )
, ( Nothing, "target" )
, ( Nothing, "commit" )
, ( Nothing, "ref" )
, ( Nothing, "description" )
, ( Nothing, "user" )
, ( Nothing, "builds" )
, ( Nothing, "created by" )
, ( Nothing, "" )
]

Expand All @@ -200,6 +202,13 @@ renderDeployment repo_ deployment =
, Util.testAttribute <| "deployments-row-id"
]
[ text <| String.fromInt deployment.id ]
, td
[ attribute "data-label" "number"
, scope "row"
, class "break-word"
, Util.testAttribute <| "deployments-row-number"
]
[ text <| String.fromInt deployment.number ]
, td
[ attribute "data-label" "target"
, scope "row"
Expand Down Expand Up @@ -232,11 +241,18 @@ renderDeployment repo_ deployment =
]
[ text deployment.description ]
, td
[ attribute "data-label" "user"
[ attribute "data-label" "builds"
, scope "row"
, class "break-word"
, class "build"
]
[ text deployment.user ]
[ linksView (pullBuildLinks deployment) ]
, td
[ attribute "data-label" "created by"
, scope "row"
, class "break-word"
]
[ text deployment.created_by ]
, td
[ attribute "data-label" ""
, scope "row"
Expand All @@ -258,3 +274,37 @@ redeployLink org repo deployment =
]
[ text "Redeploy"
]


{-| pullBuildLinks : takes deployment and creates a list of links to every build in the builds field
-}
pullBuildLinks : Deployment -> List String
pullBuildLinks deployment =
case deployment.builds of
Nothing ->
[]

Just builds ->
List.map (String.dropRight 1) (List.map (String.dropLeft 1) (List.map Debug.toString (List.map .link builds)))
claire1618 marked this conversation as resolved.
Show resolved Hide resolved


{-| linksView : takes list of links and creates an HTML msg that displays as a list of links
-}
linksView : List String -> Html msg
linksView links =
links
|> List.map (\link -> a [ href link ] [ text (String.append "#" (getHead (List.head (List.reverse (String.split "/" link))))) ])
wass3rw3rk marked this conversation as resolved.
Show resolved Hide resolved
|> List.intersperse (text ", ")
|> div []


{-| getHead : takes Maybe String and returns either Nothing or the value to help with the linksView function
-}
getHead : Maybe String -> String
getHead link =
case link of
Nothing ->
""

Just val ->
val
24 changes: 22 additions & 2 deletions src/elm/Vela.elm
Original file line number Diff line number Diff line change
Expand Up @@ -907,15 +907,17 @@ type alias KeyValuePair =

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


Expand Down Expand Up @@ -1591,6 +1593,7 @@ type alias Build =
, started : Int
, finished : Int
, deploy : String
, deploy_number : Int
, clone : String
, source : String
, title : String
Expand Down Expand Up @@ -1626,6 +1629,7 @@ decodeBuild =
|> optional "started" int -1
|> optional "finished" int -1
|> optional "deploy" string ""
|> optional "deploy_number" int -1
|> optional "clone" string ""
|> optional "source" string ""
|> optional "title" string ""
Expand Down Expand Up @@ -2535,15 +2539,17 @@ decodeDeployment : Decoder Deployment
decodeDeployment =
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 "commit" string ""
|> optional "ref" string ""
|> optional "task" string ""
|> optional "target" string ""
|> optional "description" string ""
|> optional "payload" decodeDeploymentParameters Nothing
|> optional "builds" decodeDeploymentBuilds Nothing


decodeDeployments : Decoder (List Deployment)
Expand Down Expand Up @@ -2589,6 +2595,20 @@ decodeDeploymentParameters =
Decode.map decodeKeyValuePairs <| Decode.keyValuePairs Decode.string


decodeDeployPairs : List Build -> Maybe (List Build)
decodeDeployPairs o =
if List.isEmpty o then
Nothing

else
Just o


decodeDeploymentBuilds : Decoder (Maybe (List Build))
decodeDeploymentBuilds =
Decode.map decodeDeployPairs <| Decode.list decodeBuild


type alias DeploymentPayload =
{ org : Maybe String
, repo : Maybe String
Expand Down
Loading