diff --git a/src/elm/Api/Api.elm b/src/elm/Api/Api.elm index 5aebd3f6f..f9d811ffa 100644 --- a/src/elm/Api/Api.elm +++ b/src/elm/Api/Api.elm @@ -303,13 +303,11 @@ tryAll msg request_ = |> Task.attempt msg +{-| tryString : way to request information from an endpoint with a string response --- ENTRYPOINT - + example usage: + Api.tryString UserResponse <| Api.getUser model authParams -{-| try : default way to request information from an endpoint -example usage: -Api.try UserResponse <| Api.getUser model authParams -} tryString : (Result (Http.Detailed.Error String) ( Http.Metadata, String ) -> msg) -> Request String -> Cmd msg tryString msg request_ = diff --git a/src/elm/Components/Alerts.elm b/src/elm/Components/Alerts.elm index ca190d0ea..f3948987f 100644 --- a/src/elm/Components/Alerts.elm +++ b/src/elm/Components/Alerts.elm @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 --} -module Components.Alerts exposing (Alert(..), errorConfig, successConfig, view, wrapAlertMessage) +module Components.Alerts exposing (Alert(..), errorConfig, successConfig, view) import FeatherIcons import Html exposing (Html, a, button, div, h1, p, text) @@ -75,15 +75,6 @@ wrapAlert variantClass title message link copy = ] -wrapAlertMessage : String -> String -wrapAlertMessage message = - if not <| String.isEmpty message then - "`" ++ message ++ "` " - - else - message - - copyButton : String -> Maybe (String -> msg) -> Html msg copyButton copyContent copy = case copy of diff --git a/src/elm/Components/Build.elm b/src/elm/Components/Build.elm index 4e314051e..bdcc1d628 100644 --- a/src/elm/Components/Build.elm +++ b/src/elm/Components/Build.elm @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 --} -module Components.Build exposing (..) +module Components.Build exposing (view, viewActionsMenu) import Components.Svgs import DateFormat.Relative diff --git a/src/elm/Components/Builds.elm b/src/elm/Components/Builds.elm index 25a505139..ae93e49a4 100644 --- a/src/elm/Components/Builds.elm +++ b/src/elm/Components/Builds.elm @@ -148,7 +148,7 @@ viewHeader : } -> Html msg viewHeader props = - div [ class "build-bar" ] + div [ class "builds-header" ] [ viewFilter props.maybeEvent props.filterByEvent , viewTimeToggle props.showFullTimestamps props.showHideFullTimestamps ] @@ -164,17 +164,6 @@ viewFilter maybeEvent filterByEventMsg = _ -> Just event - - eventEnum = - [ "all" - , "push" - , "pull_request" - , "tag" - , "deployment" - , "schedule" - , "comment" - , "delete" - ] in div [ class "form-controls", class "build-filters", Util.testAttribute "build-filter" ] <| div [] [ text "Filter by Event:" ] @@ -198,7 +187,7 @@ viewFilter maybeEvent filterByEventMsg = [ text <| String.replace "_" " " e ] ] ) - eventEnum + Vela.allowEventsFilterQueryKeys viewTimeToggle : Bool -> msg -> Html msg diff --git a/src/elm/Components/Crumbs.elm b/src/elm/Components/Crumbs.elm index 2e187772d..c7febd177 100644 --- a/src/elm/Components/Crumbs.elm +++ b/src/elm/Components/Crumbs.elm @@ -25,7 +25,7 @@ type alias Crumb = -- VIEW -{-| crumbs : takes current page and returns Html breadcrumb that produce Msgs +{-| view : takes current path and returns Html breadcrumbs -} view : Route.Path.Path -> List Crumb -> Html msg view path crumbs = diff --git a/src/elm/Components/Favorites.elm b/src/elm/Components/Favorites.elm index 812ef7e83..f85200a63 100644 --- a/src/elm/Components/Favorites.elm +++ b/src/elm/Components/Favorites.elm @@ -15,6 +15,10 @@ import Utils.Helpers as Util import Vela + +-- VIEW + + viewStarToggle : { msg : Vela.Org -> Maybe Vela.Repo -> msg , user : WebData Vela.CurrentUser diff --git a/src/elm/Components/Form.elm b/src/elm/Components/Form.elm index a709eb37a..5945e5fa4 100644 --- a/src/elm/Components/Form.elm +++ b/src/elm/Components/Form.elm @@ -162,8 +162,6 @@ viewButton { msg, text_, classList_, disabled_ } = [ text text_ ] -{-| viewAllowEvents : takes model and repo and renders the settings category for updating repo webhook events --} viewAllowEvents : Shared.Model -> diff --git a/src/elm/Components/Header.elm b/src/elm/Components/Header.elm index cb99f7845..e6d8d63b7 100644 --- a/src/elm/Components/Header.elm +++ b/src/elm/Components/Header.elm @@ -20,6 +20,10 @@ import Utils.Helpers as Util import Utils.Theme as Theme + +-- TYPES + + type alias Props msg = { from : String , theme : Theme.Theme @@ -30,6 +34,10 @@ type alias Props msg = } + +-- VIEW + + view : Shared.Model -> Props msg -> Html msg view shared props = let diff --git a/src/elm/Components/Help.elm b/src/elm/Components/Help.elm index a292e55ba..5e2217d64 100644 --- a/src/elm/Components/Help.elm +++ b/src/elm/Components/Help.elm @@ -5,7 +5,6 @@ SPDX-License-Identifier: Apache-2.0 module Components.Help exposing (Command, Props, view) -import Components.Build exposing (Props) import Components.Svgs as SvgBuilder import FeatherIcons import Html exposing (Html, a, button, details, div, label, span, strong, summary, text) @@ -15,6 +14,10 @@ import Shared import Utils.Helpers as Util + +-- TYPES + + type alias Props msg = { show : Bool , showHide : Maybe Bool -> msg @@ -30,6 +33,10 @@ type alias Command = } + +-- VIEW + + view : Shared.Model -> Props msg -> Html msg view shared props = details diff --git a/src/elm/Components/Logs.elm b/src/elm/Components/Logs.elm index fcc021917..a609d9f82 100644 --- a/src/elm/Components/Logs.elm +++ b/src/elm/Components/Logs.elm @@ -18,6 +18,10 @@ import Utils.Logs as Logs import Vela + +-- TYPES + + type alias Msgs msg = { pushUrlHash : { hash : String } -> msg , focusOn : { target : String } -> msg @@ -45,6 +49,10 @@ type alias LogLine msg = } + +-- VIEW + + view : Shared.Model -> Props msg -> Html msg view shared props = case props.log of @@ -59,10 +67,6 @@ view shared props = [ Util.smallLoaderWithText "loading..." ] - --- LOGS - - {-| viewLogLines : takes number linefocus log and clickAction shiftDown and renders logs for a build resource -} viewLogLines : Props msg -> Vela.Log -> Html msg diff --git a/src/elm/Components/Nav.elm b/src/elm/Components/Nav.elm index 0c91bdc3f..83105b080 100644 --- a/src/elm/Components/Nav.elm +++ b/src/elm/Components/Nav.elm @@ -27,12 +27,20 @@ import Utils.Helpers as Util import Vela + +-- TYPES + + type alias Props msg = { buttons : List (Html msg) , crumbs : Html msg } + +-- VIEW + + view : Shared.Model -> Route () -> Props msg -> Html msg view shared route props = nav [ class "navigation", attribute "aria-label" "Navigation" ] diff --git a/src/elm/Components/Pager.elm b/src/elm/Components/Pager.elm index 42e1fa519..2a67c079b 100644 --- a/src/elm/Components/Pager.elm +++ b/src/elm/Components/Pager.elm @@ -15,6 +15,10 @@ import RemoteData exposing (WebData) import Utils.Helpers as Util + +-- TYPES + + type alias Labels = { previousLabel : String , nextLabel : String @@ -35,8 +39,10 @@ prevNextLabels = } -{-| view : renders pager controls --} + +-- VIEW + + view : List WebLink -> Labels -> (Pagination.Page -> msg) -> Html msg view links labels toMsg = let diff --git a/src/elm/Components/RecentBuilds.elm b/src/elm/Components/RecentBuilds.elm index 0ea017d78..31600e305 100644 --- a/src/elm/Components/RecentBuilds.elm +++ b/src/elm/Components/RecentBuilds.elm @@ -15,6 +15,10 @@ import Utils.Helpers as Util import Vela + +--TYPES + + type alias Props = { builds : WebData (List Vela.Build) , build : WebData Vela.Build @@ -23,6 +27,10 @@ type alias Props = } + +-- VIEW + + view : Shared.Model -> Props -> Html msg view shared props = case props.builds of diff --git a/src/elm/Components/Repo.elm b/src/elm/Components/Repo.elm index 2d9f71810..3f9b0043b 100644 --- a/src/elm/Components/Repo.elm +++ b/src/elm/Components/Repo.elm @@ -14,6 +14,10 @@ import Utils.Favorites as Favorites import Utils.Helpers as Util + +-- TYPES + + type alias Props msg = { toggleFavoriteMsg : Favorites.UpdateFavorites msg , org : String @@ -23,6 +27,10 @@ type alias Props msg = } + +-- VIEW + + view : Shared.Model -> Props msg -> Html msg view shared { toggleFavoriteMsg, org, repo, favorites, filtered } = let diff --git a/src/elm/Components/ScheduleForm.elm b/src/elm/Components/ScheduleForm.elm index 1ad0479c1..2d4320ff7 100644 --- a/src/elm/Components/ScheduleForm.elm +++ b/src/elm/Components/ScheduleForm.elm @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 --} -module Components.ScheduleForm exposing (..) +module Components.ScheduleForm exposing (viewCronHelp, viewEnabledInput, viewHelp, viewSubmitButton) import Components.Form import Html diff --git a/src/elm/Components/Search.elm b/src/elm/Components/Search.elm index d2daf00df..78e1b886c 100644 --- a/src/elm/Components/Search.elm +++ b/src/elm/Components/Search.elm @@ -7,13 +7,13 @@ module Components.Search exposing ( Search , SimpleSearch , filterRepo - , homeSearchBar - , repoSearchBarGlobal - , repoSearchBarLocal , searchFilterGlobal , searchFilterLocal , shouldSearch , toLowerContains + , viewHomeSearchBar + , viewRepoSearchBarGlobal + , viewRepoSearchBarLocal ) import Dict exposing (Dict) @@ -33,6 +33,10 @@ import Utils.Helpers as Util import Vela + +-- TYPES + + {-| Search : takes org and repo and searches/filters based on user input -} type alias Search msg = @@ -45,8 +49,12 @@ type alias SimpleSearch msg = String -> msg -homeSearchBar : String -> SimpleSearch msg -> Html msg -homeSearchBar filter search = + +-- VIEW + + +viewHomeSearchBar : String -> SimpleSearch msg -> Html msg +viewHomeSearchBar filter search = div [ class "form-control", class "-with-icon", class "-is-expanded", Util.testAttribute "home-search-bar" ] [ input [ Util.testAttribute "home-search-input" @@ -60,10 +68,10 @@ homeSearchBar filter search = ] -{-| repoSearchBarGlobal : renders a input bar for searching across all repos +{-| viewRepoSearchBarGlobal : renders a input bar for searching across all repos -} -repoSearchBarGlobal : Dict Vela.Org String -> Search msg -> Html msg -repoSearchBarGlobal searchFilters search = +viewRepoSearchBarGlobal : Dict Vela.Org String -> Search msg -> Html msg +viewRepoSearchBarGlobal searchFilters search = div [ class "form-control", class "-with-icon", class "-is-expanded", Util.testAttribute "global-search-bar" ] [ input [ Util.testAttribute "global-search-input" @@ -77,10 +85,10 @@ repoSearchBarGlobal searchFilters search = ] -{-| repoSearchBarLocal : takes an org and placeholder text and renders a search bar for local repo filtering +{-| viewRepoSearchBarLocal : takes an org and placeholder text and renders a search bar for local repo filtering -} -repoSearchBarLocal : Dict Vela.Org String -> Vela.Org -> Search msg -> Html msg -repoSearchBarLocal searchFilters org search = +viewRepoSearchBarLocal : Dict Vela.Org String -> Vela.Org -> Search msg -> Html msg +viewRepoSearchBarLocal searchFilters org search = div [ class "form-control", class "-with-icon", class "-is-expanded", Util.testAttribute "local-search-bar" ] [ input [ Util.testAttribute <| "local-search-input-" ++ org @@ -96,6 +104,10 @@ repoSearchBarLocal searchFilters org search = ] + +-- HELPERS + + {-| toLowerContains : takes user input and -} toLowerContains : String -> String -> Bool diff --git a/src/elm/Components/SecretForm.elm b/src/elm/Components/SecretForm.elm index e8b005d31..7e6c31d9e 100644 --- a/src/elm/Components/SecretForm.elm +++ b/src/elm/Components/SecretForm.elm @@ -41,41 +41,6 @@ import Vela -- VIEW -viewAllowEventsSelect : - Shared.Model - -> - { msg : { allowEvents : Vela.AllowEvents, event : String } -> Bool -> msg - , allowEvents : Vela.AllowEvents - , disabled_ : Bool - } - -> Html msg -viewAllowEventsSelect shared props = - section [] - [ div [ for "events-select" ] - ([ strong [] [ text "Limit to Events" ] - , span [ class "field-description" ] - [ text "( " - , em [] [ text "at least one event must be selected" ] - , text " )" - ] - , viewPullRequestWarning - ] - ++ Components.Form.viewAllowEvents - shared - props - ) - ] - - -viewPullRequestWarning : Html msg -viewPullRequestWarning = - p [ class "notice" ] - [ text "Disclaimer: Native secrets do NOT have the " - , strong [] [ text "pull_request" ] - , text " event enabled by default. This is intentional to help mitigate exposure via a pull request against the repo. You can override this behavior, at your own risk, for each secret." - ] - - viewImagesInput : { onInput_ : String -> msg , addImage : String -> msg @@ -205,3 +170,38 @@ viewHelp docsUrl = [ text "docs" ] , text "!" ] + + +viewAllowEventsSelect : + Shared.Model + -> + { msg : { allowEvents : Vela.AllowEvents, event : String } -> Bool -> msg + , allowEvents : Vela.AllowEvents + , disabled_ : Bool + } + -> Html msg +viewAllowEventsSelect shared props = + section [] + [ div [ for "events-select" ] + ([ strong [] [ text "Limit to Events" ] + , span [ class "field-description" ] + [ text "( " + , em [] [ text "at least one event must be selected" ] + , text " )" + ] + , viewPullRequestWarning + ] + ++ Components.Form.viewAllowEvents + shared + props + ) + ] + + +viewPullRequestWarning : Html msg +viewPullRequestWarning = + p [ class "notice" ] + [ text "Disclaimer: Native secrets do NOT have the " + , strong [] [ text "pull_request" ] + , text " event enabled by default. This is intentional to help mitigate exposure via a pull request against the repo. You can override this behavior, at your own risk, for each secret." + ] diff --git a/src/elm/Components/Secrets.elm b/src/elm/Components/Secrets.elm index 1c22e91fb..9dc944cc3 100644 --- a/src/elm/Components/Secrets.elm +++ b/src/elm/Components/Secrets.elm @@ -19,6 +19,10 @@ import Utils.Helpers as Util import Vela + +-- TYPES + + type alias Msgs msg = { showCopyAlert : String -> msg } @@ -33,6 +37,10 @@ type alias Props msg = } + +-- VIEW + + {-| viewOrgSecrets : takes secrets model and renders table for viewing org secrets -} viewOrgSecrets : Shared.Model -> Props msg -> Html msg @@ -350,6 +358,8 @@ editSecretHref engine type_ secret = } +{-| enabledAllowEventsToList : takes allow events struct and converts it to a list of vieweable strings based on which events are enabled +-} enabledAllowEventsToList : Vela.AllowEvents -> List String enabledAllowEventsToList allowEvents = allowEvents diff --git a/src/elm/Components/Svgs.elm b/src/elm/Components/Svgs.elm index 74717ece2..abb789672 100644 --- a/src/elm/Components/Svgs.elm +++ b/src/elm/Components/Svgs.elm @@ -43,6 +43,10 @@ import Utils.Helpers as Util import Vela + +-- VIEW + + {-| velaLogo: produces the svg for the Vela logo -} velaLogo : Int -> Html msg diff --git a/src/elm/Components/Table.elm b/src/elm/Components/Table.elm index a9d8ecd34..581d9a5e6 100644 --- a/src/elm/Components/Table.elm +++ b/src/elm/Components/Table.elm @@ -39,6 +39,10 @@ import String.Extra import Utils.Helpers as Util + +-- TYPES + + {-| Column : string alias for table column headers -} type alias Column = @@ -77,6 +81,10 @@ type alias Config data msg = } + +-- VIEW + + {-| view : renders data table -} view : Config data msg -> Html msg diff --git a/src/elm/Components/Tabs.elm b/src/elm/Components/Tabs.elm index b09d4cc3d..51cdcf4c3 100644 --- a/src/elm/Components/Tabs.elm +++ b/src/elm/Components/Tabs.elm @@ -5,7 +5,6 @@ SPDX-License-Identifier: Apache-2.0 module Components.Tabs exposing (Tab, view, viewBuildTabs, viewOrgTabs, viewRepoTabs) -import Api.Pagination as Pagination import Dict exposing (Dict) import Html exposing (Html, a, div, span, text) import Html.Attributes exposing (class, classList) @@ -17,6 +16,10 @@ import Url exposing (Url) import Utils.Helpers as Util + +-- TYPES + + {-| Tab : record to represent information used by page navigation tab -} type alias Tab = @@ -27,6 +30,10 @@ type alias Tab = } + +-- VIEW + + {-| view : takes list of tab records and renders them with spacers and horizontal filler -} view : Dict String Url -> Route.Path.Path -> List Tab -> String -> Html msg diff --git a/src/elm/Components/Util.elm b/src/elm/Components/Util.elm index a0e9ed867..0a4f5eecf 100644 --- a/src/elm/Components/Util.elm +++ b/src/elm/Components/Util.elm @@ -11,6 +11,10 @@ import Route exposing (Route) import Shared + +-- VIEW + + view : Shared.Model -> Route () -> List (Html msg) -> Html msg view shared route buttons = div [ class "util" ] diff --git a/src/elm/Pages/Account/SourceRepos.elm b/src/elm/Pages/Account/SourceRepos.elm index f4793949d..f4167f20a 100644 --- a/src/elm/Pages/Account/SourceRepos.elm +++ b/src/elm/Pages/Account/SourceRepos.elm @@ -10,15 +10,6 @@ import Api.Operations import Auth import Components.Favorites import Components.Search - exposing - ( Search - , filterRepo - , repoSearchBarGlobal - , repoSearchBarLocal - , searchFilterGlobal - , searchFilterLocal - , shouldSearch - ) import Dict exposing (Dict) import Effect exposing (Effect) import FeatherIcons @@ -277,7 +268,7 @@ view shared model = let body = div [ Util.testAttribute "source-repos" ] - [ repoSearchBarGlobal model.searchFilters UpdateSearchFilter + [ Components.Search.viewRepoSearchBarGlobal model.searchFilters UpdateSearchFilter , viewSourceRepos shared model ] in @@ -294,7 +285,7 @@ viewSourceRepos : Shared.Model -> Model -> Html Msg viewSourceRepos shared model = case model.sourceRepos of RemoteData.Success repos -> - if shouldSearch <| searchFilterGlobal model.searchFilters then + if Components.Search.shouldSearch <| Components.Search.searchFilterGlobal model.searchFilters then searchReposGlobal shared model repos EnableRepo ToggleFavorite else @@ -382,12 +373,10 @@ viewSourceOrg : viewSourceOrg user filters org repos = let ( repos_, filtered, content ) = - if shouldSearch <| searchFilterLocal org filters then - -- Search and render repos using the global filter + if Components.Search.shouldSearch <| Components.Search.searchFilterLocal org filters then searchReposLocal user org filters repos EnableRepo ToggleFavorite else - -- Render repos normally ( repos, False, List.map (viewSourceRepo user EnableRepo ToggleFavorite) repos ) in viewSourceOrgDetails filters org repos_ filtered content UpdateSearchFilter EnableRepos @@ -401,7 +390,7 @@ viewSourceOrgDetails : -> List Vela.Repository -> Bool -> List (Html msg) - -> Search msg + -> Components.Search.Search msg -> (List Vela.Repository -> msg) -> Html msg viewSourceOrgDetails filters org repos filtered content search enableRepos = @@ -417,7 +406,7 @@ viewSourceOrgSummary : -> List Vela.Repository -> Bool -> List (Html msg) - -> Search msg + -> Components.Search.Search msg -> (List Vela.Repository -> msg) -> List (Html msg) viewSourceOrgSummary filters org repos filtered content search enableRepos = @@ -427,7 +416,7 @@ viewSourceOrgSummary filters org repos filtered content search enableRepos = , FeatherIcons.chevronDown |> FeatherIcons.withSize 20 |> FeatherIcons.withClass "details-icon-expand" |> FeatherIcons.toHtml [] ] :: div [ class "form-controls", class "-no-x-pad" ] - [ repoSearchBarLocal filters org search + [ Components.Search.viewRepoSearchBarLocal filters org search , enableReposButton org repos filtered enableRepos ] :: content @@ -585,15 +574,13 @@ searchReposGlobal shared model repos enableRepo toggleFavorite = |> Dict.toList |> Util.filterEmptyLists |> List.concatMap (\( _, repos_ ) -> repos_) - |> List.filter (\repo -> filterRepo filters Nothing <| repo.org ++ "/" ++ repo.name) + |> List.filter (\repo -> Components.Search.filterRepo filters Nothing <| repo.org ++ "/" ++ repo.name) in div [ class "filtered-repos" ] <| - -- Render the found repositories if not <| List.isEmpty filteredRepos then filteredRepos |> List.map (\repo -> viewSearchedSourceRepo enableRepo toggleFavorite repo user) else - -- No repos matched the search [ div [ class "item" ] [ text "No results" ] ] @@ -608,10 +595,9 @@ searchReposLocal : -> Favorites.UpdateFavorites msg -> ( List Vela.Repository, Bool, List (Html msg) ) searchReposLocal user org filters repos enableRepo toggleFavorite = - -- Filter the repos if the user typed more than 2 characters let filteredRepos = - List.filter (\repo -> filterRepo filters (Just org) repo.name) repos + List.filter (\repo -> Components.Search.filterRepo filters (Just org) repo.name) repos in ( filteredRepos , True diff --git a/src/elm/Pages/Home.elm b/src/elm/Pages/Home.elm index 3d9fd3235..2844988fb 100644 --- a/src/elm/Pages/Home.elm +++ b/src/elm/Pages/Home.elm @@ -9,8 +9,8 @@ import Auth import Components.Repo import Components.Search exposing - ( homeSearchBar - , toLowerContains + ( toLowerContains + , viewHomeSearchBar ) import Components.Svgs as SvgBuilder import Dict exposing (Dict) @@ -159,7 +159,7 @@ view shared model = case shared.user of RemoteData.Success u -> if List.length u.favorites > 0 then - [ homeSearchBar model.favoritesFilter SearchFavorites + [ viewHomeSearchBar model.favoritesFilter SearchFavorites , viewFavorites shared u.favorites model.favoritesFilter ] @@ -177,7 +177,7 @@ view shared model = ] _ -> - [ homeSearchBar model.favoritesFilter SearchFavorites + [ viewHomeSearchBar model.favoritesFilter SearchFavorites , viewFavorites shared [] model.favoritesFilter ] ] diff --git a/src/elm/Vela.elm b/src/elm/Vela.elm index 7684234e4..b1d666e35 100644 --- a/src/elm/Vela.elm +++ b/src/elm/Vela.elm @@ -44,6 +44,7 @@ module Vela exposing , Template , Templates , Type + , allowEventsFilterQueryKeys , allowEventsToList , buildEnableRepoPayload , decodeBuild @@ -721,6 +722,19 @@ allowEventsToList events = ] +allowEventsFilterQueryKeys : List String +allowEventsFilterQueryKeys = + [ "all" + , "push" + , "pull_request" + , "tag" + , "deployment" + , "schedule" + , "comment" + , "delete" + ] + + -- PIPELINE diff --git a/src/scss/_main.scss b/src/scss/_main.scss index 40535c300..9c9ecd096 100644 --- a/src/scss/_main.scss +++ b/src/scss/_main.scss @@ -1481,7 +1481,7 @@ details.build-toggle { } // build filters -.build-bar { +.builds-header { display: flex; flex-direction: row; justify-content: space-between;