Skip to content

Commit

Permalink
feat(deployment): dynamic deployment form (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Jan 10, 2025
1 parent c633f97 commit cb16332
Show file tree
Hide file tree
Showing 19 changed files with 851 additions and 122 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
ui:
build:
context: .
dockerfile: Dockerfile.local
dockerfile: ${VELA_UI_DOCKERFILE:-Dockerfile}
container_name: ui
image: ui:local
networks:
Expand All @@ -34,7 +34,7 @@ services:
# https://go-vela.github.io/docs/administration/server/
server:
container_name: server
image: target/vela-server:latest
image: server:local
networks:
- vela
environment:
Expand Down
9 changes: 9 additions & 0 deletions src/elm/Api/Endpoint.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Endpoint
| Dashboard String
| Dashboards
| Deployment Vela.Org Vela.Repo (Maybe String)
| DeploymentConfig Vela.Org Vela.Repo (Maybe Vela.Ref)
| Deployments (Maybe Pagination.Page) (Maybe Pagination.PerPage) Vela.Org Vela.Repo
| Token
| Repositories (Maybe Pagination.Page) (Maybe Pagination.PerPage)
Expand Down Expand Up @@ -162,6 +163,14 @@ toUrl api endpoint =
Nothing ->
url api [ "deployments", org, repo ] []

DeploymentConfig org repo maybeRef ->
case maybeRef of
Nothing ->
url api [ "deployments", org, repo, "config" ] []

Just ref ->
url api [ "deployments", org, repo, "config" ] [ UB.string "ref" ref ]

Deployments maybePage maybePerPage org repo ->
url api [ "deployments", org, repo ] <| Pagination.toQueryParams maybePage maybePerPage

Expand Down
24 changes: 24 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Api.Operations exposing
, getCurrentUser
, getDashboard
, getDashboards
, getDeploymentConfig
, getOrgBuilds
, getOrgRepos
, getOrgSecret
Expand Down Expand Up @@ -467,6 +468,29 @@ addDeployment baseUrl session options =
|> withAuth session


{-| getDeploymentConfig : retrieves deployment config for a repo and pipeline ref.
-}
getDeploymentConfig :
String
-> Session
->
{ a
| org : String
, repo : String
, ref : Maybe String
}
-> Request Vela.DeploymentConfig
getDeploymentConfig baseUrl session options =
get baseUrl
(Api.Endpoint.DeploymentConfig
options.org
options.repo
options.ref
)
Vela.decodeDeploymentConfig
|> withAuth session


{-| getRepoHooks : retrieves hooks for a repo.
-}
getRepoHooks :
Expand Down
50 changes: 45 additions & 5 deletions src/elm/Components/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module Components.Form exposing (EditableListForm, handleNumberInputString, view

import Components.Loading
import Dict exposing (Dict)
import Effect exposing (Effect)
import FeatherIcons
import Html exposing (Html, button, div, h3, input, label, li, section, span, strong, text, textarea, ul)
import Html.Attributes exposing (attribute, checked, class, classList, disabled, for, id, placeholder, rows, type_, value, wrap)
import Html.Events exposing (onCheck, onClick, onInput)
import Http
import Json.Decode
import Maybe.Extra
import RemoteData exposing (WebData)
import Shared
Expand All @@ -36,9 +38,12 @@ viewInputSection :
, wrap_ : Maybe String
, msg : String -> msg
, disabled_ : Bool
, min : Maybe String
, max : Maybe String
, required : Bool
}
-> Html msg
viewInputSection { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
viewInputSection { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_, min, max, required } =
let
target =
String.join "-" [ "input", id_ ]
Expand All @@ -62,6 +67,9 @@ viewInputSection { id_, title, subtitle, val, placeholder_, classList_, rows_, w
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Maybe.Extra.unwrap Util.attrNone Html.Attributes.min min
, Maybe.Extra.unwrap Util.attrNone Html.Attributes.max max
, Html.Attributes.required required
, Util.testAttribute target
]
[]
Expand All @@ -82,9 +90,12 @@ viewInput :
, wrap_ : Maybe String
, msg : String -> msg
, disabled_ : Bool
, min : Maybe String
, max : Maybe String
, required : Bool
}
-> Html msg
viewInput { id_, title, subtitle, val, placeholder_, classList_, wrapperClassList, rows_, wrap_, msg, disabled_ } =
viewInput { id_, title, subtitle, val, placeholder_, classList_, wrapperClassList, rows_, wrap_, msg, disabled_, min, max, required } =
let
target =
String.join "-" [ "input", id_ ]
Expand All @@ -102,6 +113,9 @@ viewInput { id_, title, subtitle, val, placeholder_, classList_, wrapperClassLis
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Maybe.Extra.unwrap Util.attrNone Html.Attributes.min min
, Maybe.Extra.unwrap Util.attrNone Html.Attributes.max max
, Html.Attributes.required required
, Util.testAttribute target
]
[]
Expand Down Expand Up @@ -140,9 +154,10 @@ viewNumberInput :
, disabled_ : Bool
, min : Maybe Int
, max : Maybe Int
, required : Bool
}
-> Html msg
viewNumberInput { id_, title, subtitle, val, placeholder_, wrapperClassList, classList_, rows_, wrap_, msg, disabled_, min, max } =
viewNumberInput { id_, title, subtitle, val, placeholder_, wrapperClassList, classList_, rows_, wrap_, msg, disabled_, min, max, required } =
let
target =
String.join "-" [ "input", id_ ]
Expand All @@ -163,6 +178,7 @@ viewNumberInput { id_, title, subtitle, val, placeholder_, wrapperClassList, cla
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Html.Attributes.required required
, Util.testAttribute target
]
[]
Expand All @@ -182,9 +198,10 @@ viewTextareaSection :
, wrap_ : Maybe String
, msg : String -> msg
, disabled_ : Bool
, focusOutFunc : Maybe msg
}
-> Html msg
viewTextareaSection { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_ } =
viewTextareaSection { id_, title, subtitle, val, placeholder_, classList_, rows_, wrap_, msg, disabled_, focusOutFunc } =
let
target =
String.join "-" [ "textarea", id_ ]
Expand All @@ -208,6 +225,7 @@ viewTextareaSection { id_, title, subtitle, val, placeholder_, classList_, rows_
, Maybe.Extra.unwrap Util.attrNone wrap wrap_
, onInput msg
, disabled disabled_
, Maybe.Extra.unwrap Util.attrNone (Html.Events.on "focusout" << Json.Decode.succeed) focusOutFunc
, Util.testAttribute target
]
[]
Expand Down Expand Up @@ -256,17 +274,19 @@ viewCheckbox :
, subtitle : Maybe (Html msg)
, field : String
, state : Bool
, wrapperClassList : List ( String, Bool )
, msg : Bool -> msg
, disabled_ : Bool
}
-> Html msg
viewCheckbox { id_, title, subtitle, field, state, msg, disabled_ } =
viewCheckbox { id_, title, subtitle, field, state, wrapperClassList, msg, disabled_ } =
let
target =
String.join "-" [ "checkbox", id_, field ]
in
div
[ class "form-control"
, classList wrapperClassList
, Util.testAttribute target
]
[ input
Expand Down Expand Up @@ -387,6 +407,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_push_branch"
, state = allowEvents.push.branch
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PushBranch }
, disabled_ = False
, id_ = "allow-events-push-branch"
Expand All @@ -396,6 +417,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_push_tag"
, state = allowEvents.push.tag
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PushTag }
, disabled_ = False
, id_ = "allow-events-push-tag"
Expand All @@ -408,6 +430,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_opened"
, state = allowEvents.pull.opened
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullOpened }
, disabled_ = False
, id_ = "allow-events-pull-opened"
Expand All @@ -417,6 +440,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_synchronize"
, state = allowEvents.pull.synchronize
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullSynchronize }
, disabled_ = False
, id_ = "allow-events-pull-synchronize"
Expand All @@ -426,6 +450,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_edited"
, state = allowEvents.pull.edited
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullEdited }
, disabled_ = False
, id_ = "allow-events-pull-edited"
Expand All @@ -435,6 +460,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_reopened"
, state = allowEvents.pull.reopened
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullReopened }
, disabled_ = False
, id_ = "allow-events-pull-reopened"
Expand All @@ -444,6 +470,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_labeled"
, state = allowEvents.pull.labeled
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullLabeled }
, disabled_ = False
, id_ = "allow-events-pull-labeled"
Expand All @@ -453,6 +480,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_pull_unlabeled"
, state = allowEvents.pull.unlabeled
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PullUnlabeled }
, disabled_ = False
, id_ = "allow-events-pull-unlabeled"
Expand All @@ -465,6 +493,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_deploy_created"
, state = allowEvents.deploy.created
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.DeployCreated }
, disabled_ = False
, id_ = "allow-events-deploy-created"
Expand All @@ -477,6 +506,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_comment_created"
, state = allowEvents.comment.created
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.CommentCreated }
, disabled_ = False
, id_ = "allow-events-comment-created"
Expand All @@ -486,6 +516,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_comment_edited"
, state = allowEvents.comment.edited
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.CommentEdited }
, disabled_ = False
, id_ = "allow-events-comment-edited"
Expand All @@ -498,6 +529,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_push_delete_branch"
, state = allowEvents.push.deleteBranch
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PushDeleteBranch }
, disabled_ = False
, id_ = "allow-events-push-delete-branch"
Expand All @@ -507,6 +539,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_push_delete_tag"
, state = allowEvents.push.deleteTag
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.PushDeleteTag }
, disabled_ = False
, id_ = "allow-events-push-delete-tag"
Expand All @@ -519,6 +552,7 @@ viewAllowEvents shared { msg, allowEvents } =
, subtitle = Nothing
, field = "allow_schedule_run"
, state = allowEvents.schedule.run
, wrapperClassList = []
, msg = msg { allowEvents = allowEvents, event = Vela.ScheduleRun }
, disabled_ = False
, id_ = "allow-events-schedule-run"
Expand Down Expand Up @@ -585,6 +619,9 @@ viewEditableList props =
, wrap_ = Nothing
, msg = addProps.addOnInputMsg
, disabled_ = False
, min = Nothing
, max = Nothing
, required = False
}
, viewButton
{ id_ = target ++ "-add"
Expand Down Expand Up @@ -665,6 +702,9 @@ viewEditableListItem props item =
, wrap_ = Nothing
, msg = props.itemEditOnInputMsg { id = itemId }
, disabled_ = False
, min = Nothing
, max = Nothing
, required = False
}

Nothing ->
Expand Down
3 changes: 3 additions & 0 deletions src/elm/Components/SecretForm.elm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ viewImagesInput { onInput_, addImage, removeImage, images, imageValue, disabled_
, wrap_ = Just "soft"
, msg = onInput_
, disabled_ = disabled_
, min = Nothing
, max = Nothing
, required = False
}
, button
[ class "button"
Expand Down
22 changes: 21 additions & 1 deletion src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getAllBuildServices, getAllBuildSteps, getAllBuilds, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getDashboards, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoHooksShared, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getAllBuildServices, getAllBuildSteps, getAllBuilds, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getDashboards, getDeploymentConfig, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoHooksShared, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
)

{-|
Expand Down Expand Up @@ -594,6 +594,26 @@ addDeployment options =
|> sendCmd


getDeploymentConfig :
{ baseUrl : String
, session : Auth.Session.Session
, onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, Vela.DeploymentConfig ) -> msg
, ref : Maybe String
, org : String
, repo : String
}
-> Effect msg
getDeploymentConfig options =
Api.try
options.onResponse
(Api.Operations.getDeploymentConfig
options.baseUrl
options.session
options
)
|> sendCmd


getRepoHooks :
{ baseUrl : String
, session : Auth.Session.Session
Expand Down
Loading

0 comments on commit cb16332

Please sign in to comment.