Skip to content

Commit

Permalink
enhance(schedule): add branch field to form (#714)
Browse files Browse the repository at this point in the history
Co-authored-by: Claire.Nicholas <[email protected]>
Co-authored-by: dave vader <[email protected]>
Co-authored-by: Easton Crupper <[email protected]>
  • Loading branch information
4 people authored Sep 7, 2023
1 parent 06baa58 commit 12240a3
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions cypress/fixtures/schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"updated_at": 1685037152,
"updated_by": "CookieCat",
"scheduled_at": 0,
"branch": "master",
"repo": {
"id": 1,
"user_id": 1,
Expand Down
32 changes: 32 additions & 0 deletions cypress/integration/schedule.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ context('Add Schedule', () => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('default branch placeholder should show', () => {
cy.get('[data-test=schedule-branch-name]')
.should('exist')
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('Branch Name');
});
});
it('add button should show', () => {
cy.get('[data-test=schedule-add-button]').should('exist');
});
Expand Down Expand Up @@ -68,6 +76,14 @@ context('Add Schedule', () => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('default branch placeholder should show', () => {
cy.get('[data-test=schedule-branch-name]')
.should('exist')
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('Branch Name');
});
});
it('add button should show', () => {
cy.get('[data-test=schedule-add-button]').should('exist');
});
Expand All @@ -87,6 +103,9 @@ context('Add Schedule', () => {
it('default entry value should not show', () => {
cy.get('[data-test=schedule-entry]').should('not.exist');
});
it('default branch value should not show', () => {
cy.get('[data-test=schedule-branch-name]').should('not.exist');
});
it('add button should not show', () => {
cy.get('[data-test=schedule-add-button]').should('not.exist');
});
Expand Down Expand Up @@ -130,6 +149,11 @@ context('View/Edit Schedule', () => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('default branch value should show', () => {
cy.get('[data-test=schedule-branch-name]')
.should('exist')
.should('have.value', 'master');
});
it('update button should show', () => {
cy.get('[data-test=schedule-update-button]').should('exist');
});
Expand Down Expand Up @@ -160,6 +184,11 @@ context('View/Edit Schedule', () => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('default branch value should show', () => {
cy.get('[data-test=schedule-branch-name]')
.should('exist')
.should('have.value', 'master');
});
it('update button should show', () => {
cy.get('[data-test=schedule-update-button]').should('exist');
});
Expand All @@ -182,6 +211,9 @@ context('View/Edit Schedule', () => {
it('default entry value should not show', () => {
cy.get('[data-test=schedule-entry]').should('not.exist');
});
it('default branch value should not show', () => {
cy.get('[data-test=schedule-branch-name]').should('not.exist');
});
it('update button should not show', () => {
cy.get('[data-test=schedule-update-button]').should('not.exist');
});
Expand Down
27 changes: 27 additions & 0 deletions src/elm/Pages/Schedules/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ viewAddForm model =
[ viewNameInput sm.form.name False
, viewValueInput sm.form.entry "0 0 * * * (runs at 12:00 AM in UTC)" (Util.toUtcString model.time)
, viewEnabledCheckbox sm.form
, viewBranchNameInput sm.form.branch False
, viewHelp
, viewAddButton
]
Expand All @@ -72,6 +73,7 @@ viewEditForm model =
[ viewNameInput sm.form.name True
, viewValueInput sm.form.entry "0 0 * * * (runs at 12:00 AM in UTC)" (Util.toUtcString model.time)
, viewEnabledCheckbox sm.form
, viewBranchNameInput sm.form.branch False
, viewHelp
, viewEditFormSubmitButtons sm
]
Expand Down Expand Up @@ -168,6 +170,31 @@ viewEnabledCheckbox enableUpdate =
]


{-| viewBranchNameInput : renders branch input box
-}
viewBranchNameInput : String -> Bool -> Html Msg
viewBranchNameInput val disable =
section [ class "form-control", class "-stack" ]
[ label [ class "form-label", for <| "schedule-branch-name" ]
[ strong [] [ text "Branch" ]
, span
[ class "field-description" ]
[ em [] [ text "(Leave blank to use default branch)" ]
]
]
, input
[ disabled disable
, value val
, onInput <|
OnChangeStringField "branch"
, placeholder "Branch Name"
, id "schedule-branch-name"
, Util.testAttribute "schedule-branch-name"
]
[]
]


{-| viewHelp : renders help msg pointing to Vela docs
-}
viewHelp : Html Msg
Expand Down
3 changes: 2 additions & 1 deletion src/elm/Pages/Schedules/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ type alias ScheduleForm =
{ name : String
, entry : String
, enabled : Bool
, branch : String
}


defaultScheduleUpdate : ScheduleForm
defaultScheduleUpdate =
ScheduleForm "" "" True
ScheduleForm "" "" True ""



Expand Down
7 changes: 6 additions & 1 deletion src/elm/Pages/Schedules/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ reinitializeScheduleUpdate scheduleModel schedule =

initScheduleUpdate : Schedule -> ScheduleForm
initScheduleUpdate schedule =
ScheduleForm schedule.name schedule.entry schedule.enabled
ScheduleForm schedule.name schedule.entry schedule.enabled schedule.branch


{-| updateScheduleModel : makes an update to the appropriate schedule update
Expand Down Expand Up @@ -118,6 +118,9 @@ updateScheduleField field value schedule =
"entry" ->
{ schedule | entry = value }

"branch" ->
{ schedule | branch = value }

_ ->
schedule

Expand Down Expand Up @@ -148,6 +151,7 @@ toAddSchedulePayload scheduleModel schedule =
(stringToMaybe schedule.name)
(stringToMaybe schedule.entry)
(Just schedule.enabled)
(stringToMaybe schedule.branch)


{-| toUpdateSchedulePayload : builds payload for updating schedule
Expand All @@ -160,6 +164,7 @@ toUpdateSchedulePayload schedule =
Nothing
(stringToMaybe schedule.entry)
(Just schedule.enabled)
(stringToMaybe schedule.branch)



Expand Down
7 changes: 7 additions & 0 deletions src/elm/Pages/Schedules/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ tableHeaders =
[ ( Nothing, "name" )
, ( Nothing, "entry" )
, ( Nothing, "enabled" )
, ( Nothing, "branch" )
, ( Nothing, "last scheduled at" )
, ( Nothing, "updated by" )
, ( Nothing, "updated at" )
Expand Down Expand Up @@ -168,6 +169,12 @@ renderSchedule zone org repo schedule =
, class "break-word"
]
[ text <| Util.boolToYesNo schedule.enabled ]
, td
[ attribute "data-label" "branch"
, scope "row"
, class "break-word"
]
[ text schedule.branch ]
, td
[ attribute "data-label" "scheduled at"
, scope "row"
Expand Down
10 changes: 8 additions & 2 deletions src/elm/Vela.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ type alias Schedule =
, scheduled_at : Int
, updated_at : Int
, updated_by : String
, branch : String
}


Expand All @@ -1734,6 +1735,7 @@ type alias AddSchedulePayload =
, name : String
, entry : String
, enabled : Bool
, branch : String
}


Expand All @@ -1743,6 +1745,7 @@ type alias UpdateSchedulePayload =
, name : Maybe Name
, entry : Maybe String
, enabled : Maybe Bool
, branch : Maybe String
}


Expand All @@ -1752,9 +1755,10 @@ buildUpdateSchedulePayload :
-> Maybe Name
-> Maybe String
-> Maybe Bool
-> Maybe String
-> UpdateSchedulePayload
buildUpdateSchedulePayload org repo name entry enabled =
UpdateSchedulePayload org repo name entry enabled
buildUpdateSchedulePayload org repo name entry enabled branch =
UpdateSchedulePayload org repo name entry enabled branch


decodeSchedule : Decoder Schedule
Expand All @@ -1771,6 +1775,7 @@ decodeSchedule =
|> optional "scheduled_at" int 0
|> optional "updated_at" int 0
|> optional "updated_by" string ""
|> optional "branch" string ""


decodeSchedules : Decoder Schedules
Expand All @@ -1784,6 +1789,7 @@ encodeUpdateSchedule schedule =
[ ( "name", encodeOptional Encode.string schedule.name )
, ( "entry", encodeOptional Encode.string schedule.entry )
, ( "active", encodeOptional Encode.bool schedule.enabled )
, ( "branch", encodeOptional Encode.string schedule.branch )
]


Expand Down

0 comments on commit 12240a3

Please sign in to comment.