Skip to content

Commit

Permalink
refactor: moved Tabs into Components
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 17, 2024
1 parent 42720a5 commit bc09a54
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 215 deletions.
49 changes: 5 additions & 44 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module Components.Builds exposing (view, viewPreview)

import Ansi
import Ansi.Log
import Array
import Components.Nav
import Components.Svgs as SvgBuilder exposing (buildStatusToIcon, stepStatusToIcon)
import Components.Svgs as SvgBuilder exposing (buildStatusToIcon)
import DateFormat.Relative exposing (relativeTime)
import FeatherIcons
import Html exposing (Html, a, br, button, code, details, div, em, h1, h2, h3, h4, h5, h6, li, ol, p, small, span, strong, summary, table, td, text, tr, ul)
import Html exposing (Html, a, br, code, details, div, em, h1, li, ol, p, span, strong, summary, table, td, text, tr, ul)
import Html.Attributes
exposing
( attribute
Expand All @@ -18,62 +16,25 @@ import Html.Attributes
, style
, title
)
import Html.Events exposing (onClick)
import List.Extra exposing (unique)
import Pages exposing (Page)
import Pages.Build.Graph.View
import Pages.Build.Logs
exposing
( bottomTrackerFocusId
, defaultAnsiLogModel
, downloadFileName
, getLog
, isEmpty
, topTrackerFocusId
)
import List.Extra
import Pages.Build.Model
exposing
( Download
, ExpandAll
, FocusLine
, FocusOn
, FollowResource
, LogLine
, LogsMsgs
, Msgs
, PartialModel
( Msgs
)
import RemoteData exposing (WebData)
import Routes
import Shared
import String
import Time exposing (Posix, Zone)
import Url
import Time
import Utils.Errors as Errors
import Utils.Focus as Focus
exposing
( ResourceID
, ResourceType
, lineFocusStyles
, lineRangeId
, resourceAndLineToFocusId
, resourceToFocusId
)
import Utils.Helpers as Util exposing (getNameFromRef)
import Vela
exposing
( Build
, BuildNumber
, Log
, LogFocus
, Org
, Repo
, RepoModel
, Service
, Status(..)
, Step
, Steps
, defaultStep
)


Expand Down
146 changes: 1 addition & 145 deletions src/elm/Components/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0
--}


module Components.Nav exposing (Msgs, Tab, view, viewOrgTabs, viewTabs)
module Components.Nav exposing (Msgs, view)

import Api.Pagination as Pagination
import Components.Crumbs
Expand Down Expand Up @@ -55,17 +55,6 @@ type alias Msgs msg =
}


{-| Tab : record to represent information used by page navigation tab
-}
type alias Tab =
{ name : String
, currentPage : Page
, toPage : Page
, isAlerting : Bool
, show : Bool
}


view : Shared.Model -> Route () -> List (Html msg) -> Html msg
view shared route buttons =
nav [ class "navigation", attribute "aria-label" "Navigation" ]
Expand All @@ -74,139 +63,6 @@ view shared route buttons =
)


{-| viewTabs : takes list of tab records and renders them with spacers and horizontal filler
-}
viewTabs : List Tab -> String -> Html msg
viewTabs tabs testLabel =
tabs
|> List.filterMap viewTab
|> List.intersperse viewSpacer
|> (\t -> t ++ [ viewFiller ])
|> div [ class "jump-bar", Util.testAttribute testLabel ]


{-| viewTab : takes single tab record and renders jump link, uses current page to display conditional style
-}
viewTab : Tab -> Maybe (Html msg)
viewTab { name, currentPage, toPage, isAlerting, show } =
if show then
Just <|
a
[ classList
[ ( "jump", True )
, ( "alerting", isAlerting )
]
, viewingTab currentPage toPage
, Routes.href <| Pages.toRoute toPage
, Util.testAttribute <| "jump-" ++ name
]
[ text name ]

else
Nothing


{-| viewSpacer : renders horizontal spacer between tabs
-}
viewSpacer : Html msg
viewSpacer =
span [ class "jump", class "spacer" ] []


{-| viewSpacer : renders horizontal filler to the right of tabs
-}
viewFiller : Html msg
viewFiller =
span [ class "jump", class "fill" ] []


{-| viewingTab : returns true if user is viewing this tab
-}
viewingTab : Page -> Page -> Html.Attribute msg
viewingTab p1 p2 =
if Pages.strip p1 == Pages.strip p2 then
class "current"

else
class ""



-- ORG


viewOrgTabs :
{ org : String
, currentPage : Page
, maybePage : Maybe Pagination.Page
, maybePerPage : Maybe Pagination.PerPage
, maybeEvent : Maybe String
}
-> Html msg
viewOrgTabs props =
let
tabs =
[ Tab "Repositories" props.currentPage (Pages.OrgRepositories props.org Nothing Nothing) False True
, Tab "Builds" props.currentPage (Pages.OrgBuilds props.org props.maybePage props.maybePerPage props.maybeEvent) False True
, Tab "Secrets" props.currentPage (Pages.OrgSecrets "native" props.org Nothing Nothing) False True
]
in
viewTabs tabs "jump-bar-repo"



-- REPO


{-| viewRepoTabs : takes RepoModel and current page and renders navigation tabs
-}
viewRepoTabs : RepoModel -> Org -> Repo -> Page -> List ( Org, Repo ) -> Html msg
viewRepoTabs rm org repo currentPage scheduleAllowlist =
let
lastHook =
case rm.hooks.hooks of
RemoteData.Success hooks ->
List.head hooks

_ ->
Nothing

lastBuild =
case rm.builds.builds of
RemoteData.Success builds ->
List.head builds

_ ->
Nothing

isAlerting =
case ( lastHook, lastBuild ) of
( Just hook, Just build ) ->
case hook.status of
"success" ->
False

_ ->
hook.created > build.created

_ ->
False

showSchedules =
Util.checkScheduleAllowlist org repo scheduleAllowlist

tabs =
[ Tab "Builds" currentPage (Pages.RepositoryBuilds org repo rm.builds.maybePage rm.builds.maybePerPage rm.builds.maybeEvent) False True
, Tab "Deployments" currentPage (Pages.RepositoryDeployments org repo rm.builds.maybePage rm.builds.maybePerPage) False True
, Tab "Secrets" currentPage (Pages.RepoSecrets "native" org repo Nothing Nothing) False True
, Tab "Schedules" currentPage (Pages.Schedules org repo Nothing Nothing) False showSchedules
, Tab "Audit" currentPage (Pages.Hooks org repo rm.hooks.maybePage rm.hooks.maybePerPage) isAlerting True
, Tab "Settings" currentPage (Pages.RepoSettings org repo) False True
]
in
viewTabs tabs "jump-bar-repo"



-- BUILD

Expand Down
Loading

0 comments on commit bc09a54

Please sign in to comment.