Skip to content

Commit

Permalink
enhance(schedules): add utc warning (#699)
Browse files Browse the repository at this point in the history
Co-authored-by: Easton Crupper <[email protected]>
  • Loading branch information
plyr4 and ecrupper authored Jul 12, 2023
1 parent dc526c2 commit fc1d1e9
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 102 deletions.
20 changes: 16 additions & 4 deletions cypress/integration/schedule.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ context('Add Schedule', () => {
it('default entry value should show', () => {
cy.get('[data-test=schedule-entry]')
.should('exist')
.should('have.value', '0 0 * * *');
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('add button should show', () => {
cy.get('[data-test=schedule-add-button]').should('exist');
Expand All @@ -60,7 +63,10 @@ context('Add Schedule', () => {
it('default entry value should show', () => {
cy.get('[data-test=schedule-entry]')
.should('exist')
.should('have.value', '0 0 * * *');
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('add button should show', () => {
cy.get('[data-test=schedule-add-button]').should('exist');
Expand Down Expand Up @@ -119,7 +125,10 @@ context('View/Edit Schedule', () => {
it('default entry value should show', () => {
cy.get('[data-test=schedule-entry]')
.should('exist')
.should('have.value', '0 0 * * *');
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('update button should show', () => {
cy.get('[data-test=schedule-update-button]').should('exist');
Expand All @@ -146,7 +155,10 @@ context('View/Edit Schedule', () => {
it('default entry value should show', () => {
cy.get('[data-test=schedule-entry]')
.should('exist')
.should('have.value', '0 0 * * *');
.and('have.attr', 'placeholder')
.then(placeholder => {
expect(placeholder).to.include('0 0 * * *');
});
});
it('update button should show', () => {
cy.get('[data-test=schedule-update-button]').should('exist');
Expand Down
4 changes: 2 additions & 2 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2693,12 +2693,12 @@ viewContent model =

Pages.AddSchedule org repo ->
( String.join "/" [ org, repo, "add schedule" ]
, Html.map AddScheduleUpdate <| lazy Pages.Schedules.View.addSchedule model
, Html.map AddScheduleUpdate <| lazy Pages.Schedules.View.viewAddSchedule model
)

Pages.Schedule org repo name ->
( String.join "/" [ org, repo, name ]
, Html.map AddScheduleUpdate <| lazy Pages.Schedules.View.editSchedule model
, Html.map AddScheduleUpdate <| lazy Pages.Schedules.View.viewEditSchedule model
)

Pages.Schedules org repo maybePage _ ->
Expand Down
98 changes: 83 additions & 15 deletions src/elm/Pages/Schedules/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ Use of this source code is governed by the LICENSE file in this repository.


module Pages.Schedules.Form exposing
( viewEnabledCheckbox
, viewHelp
, viewNameInput
, viewSubmitButtons
, viewValueInput
( viewAddForm
, viewEditForm
)

import Html
Expand Down Expand Up @@ -41,16 +38,43 @@ import Html.Attributes
, value
)
import Html.Events exposing (onClick, onInput)
import Pages.Schedules.Model exposing (DeleteScheduleState(..), Model, Msg(..), ScheduleForm)
import Pages.Schedules.Model exposing (DeleteScheduleState(..), Model, Msg(..), PartialModel, ScheduleForm)
import Util
import Vela exposing (Field)


{-| viewHelp : renders help msg pointing to Vela docs
{-| viewAddForm : renders schedule update form for adding a new schedule
-}
viewHelp : Html Msg
viewHelp =
div [ class "help" ] [ text "Need help? Visit our ", a [ href schedulesDocsURL, target "_blank" ] [ text "docs" ], text "!" ]
viewAddForm : PartialModel a msg -> Html Msg
viewAddForm model =
let
sm =
model.schedulesModel
in
div [ class "schedule-form" ]
[ 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
, viewHelp
, viewAddButton
]


{-| viewEditForm : renders schedule update form for updating a preexisting schedule
-}
viewEditForm : PartialModel a msg -> Html Msg
viewEditForm model =
let
sm =
model.schedulesModel
in
div [ class "schedule-form", class "edit-form" ]
[ 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
, viewHelp
, viewEditFormSubmitButtons sm
]


{-| viewNameInput : renders name input box
Expand All @@ -74,12 +98,17 @@ viewNameInput val disable =

{-| viewValueInput : renders value input box
-}
viewValueInput : String -> String -> Html Msg
viewValueInput val placeholder_ =
viewValueInput : String -> String -> String -> Html Msg
viewValueInput val placeholder_ time =
section [ class "form-control", class "-stack" ]
[ label [ class "form-label", for <| "schedule-entry" ]
[ strong [] [ text "Cron Expression " ]
, a [ href "https://crontab.guru/", target "_blank" ] [ text "(help)" ]
, viewCronHelpLink
, span [ class "field-description" ]
[ text "( "
, em [] [ text <| "Expressions are evaluated in UTC, time now is " ++ time ]
, text " )"
]
]
, textarea
[ value val
Expand All @@ -93,6 +122,13 @@ viewValueInput val placeholder_ =
]


{-| viewCronHelpLink : renders cron help link
-}
viewCronHelpLink : Html msg
viewCronHelpLink =
a [ class "field-help-link", href "https://crontab.guru/", target "_blank" ] [ text "help" ]


{-| radio : takes current value, field id, title for label, and click action and renders an input radio.
-}
radio : String -> String -> Field -> msg -> Html msg
Expand Down Expand Up @@ -132,15 +168,41 @@ viewEnabledCheckbox enableUpdate =
]


viewSubmitButtons : Model msg -> Html Msg
viewSubmitButtons schedulesModel =
{-| viewHelp : renders help msg pointing to Vela docs
-}
viewHelp : Html Msg
viewHelp =
div [ class "help" ] [ text "Need help? Visit our ", a [ href schedulesDocsURL, target "_blank" ] [ text "docs" ], text "!" ]


{-| viewAddButton : renders submit button for adding a schedule
-}
viewAddButton : Html Msg
viewAddButton =
div [ class "form-action" ]
[ button
[ class "button"
, class "-outline"
, onClick <| Pages.Schedules.Model.AddSchedule
, Util.testAttribute "schedule-add-button"
]
[ text "Add" ]
]


{-| viewEditFormSubmitButtons : renders all submit buttons for view/edit schedule
-}
viewEditFormSubmitButtons : Model msg -> Html Msg
viewEditFormSubmitButtons schedulesModel =
div [ class "buttons" ]
[ viewUpdateButton
, viewCancelButton schedulesModel
, viewDeleteButton schedulesModel
]


{-| viewUpdateButton : renders submit button for updating a schedule
-}
viewUpdateButton : Html Msg
viewUpdateButton =
button
Expand All @@ -151,6 +213,8 @@ viewUpdateButton =
[ text "Update" ]


{-| viewDeleteButton : renders submit button for deleting a schedule
-}
viewDeleteButton : Model msg -> Html Msg
viewDeleteButton schedulesModel =
let
Expand Down Expand Up @@ -181,6 +245,8 @@ viewDeleteButton schedulesModel =
[ text deleteButtonText ]


{-| viewCancelButton : renders submit button for canceling a schedule deletion
-}
viewCancelButton : Model msg -> Html Msg
viewCancelButton schedulesModel =
case schedulesModel.deleteState of
Expand All @@ -204,6 +270,8 @@ viewCancelButton schedulesModel =
-- HELPERS


{-| schedulesDocsURL : returns the Vela docs URL for schedules
-}
schedulesDocsURL : String
schedulesDocsURL =
"https://go-vela.github.io/docs/usage/schedules/"
5 changes: 3 additions & 2 deletions src/elm/Pages/Schedules/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Http.Detailed
import LinkHeader exposing (WebLink)
import Pages exposing (Page)
import RemoteData exposing (WebData)
import Time exposing (Zone)
import Time exposing (Posix, Zone)
import Vela exposing (Org, Repo, Schedule, Schedules)


Expand All @@ -41,6 +41,7 @@ type alias PartialModel a msg =
, velaScheduleAllowlist : List ( Org, Repo )
, session : Session
, page : Page
, time : Posix
, zone : Zone
, schedulesModel : Model msg
}
Expand Down Expand Up @@ -76,7 +77,7 @@ type alias ScheduleForm =

defaultScheduleUpdate : ScheduleForm
defaultScheduleUpdate =
ScheduleForm "" "0 0 * * *" True
ScheduleForm "" "" True



Expand Down
Loading

0 comments on commit fc1d1e9

Please sign in to comment.