Skip to content

Commit

Permalink
refactor: pagination consistency, urlchanged with tab switch focus sk…
Browse files Browse the repository at this point in the history
…ipping, and layout improvements
  • Loading branch information
plyr4 committed Feb 2, 2024
1 parent 54f796e commit 2e36467
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 188 deletions.
49 changes: 40 additions & 9 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ getUserSourceRepos baseUrl session =
getRepo : String -> Session -> { a | org : String, repo : String } -> Request Vela.Repository
getRepo baseUrl session options =
get baseUrl
(Api.Endpoint.Repository options.org options.repo)
(Api.Endpoint.Repository
options.org
options.repo
)
Vela.decodeRepository
|> withAuth session

Expand All @@ -144,7 +147,10 @@ getRepo baseUrl session options =
enableRepo : String -> Session -> Http.Body -> Request Vela.Repository
enableRepo baseUrl session body =
post baseUrl
(Api.Endpoint.Repositories Nothing Nothing)
(Api.Endpoint.Repositories
Nothing
Nothing
)
body
Vela.decodeRepository
|> withAuth session
Expand All @@ -155,7 +161,10 @@ enableRepo baseUrl session body =
updateRepo : String -> Session -> { a | org : String, repo : String, body : Http.Body } -> Request Vela.Repository
updateRepo baseUrl session options =
put baseUrl
(Api.Endpoint.Repository options.org options.repo)
(Api.Endpoint.Repository
options.org
options.repo
)
options.body
Vela.decodeRepository
|> withAuth session
Expand All @@ -166,7 +175,10 @@ updateRepo baseUrl session options =
repairRepo : String -> Session -> { a | org : String, repo : String } -> Request String
repairRepo baseUrl session options =
patch baseUrl
(Api.Endpoint.RepositoryRepair options.org options.repo)
(Api.Endpoint.RepositoryRepair
options.org
options.repo
)
Json.Decode.string
|> withAuth session

Expand All @@ -176,7 +188,10 @@ repairRepo baseUrl session options =
chownRepo : String -> Session -> { a | org : String, repo : String } -> Request String
chownRepo baseUrl session options =
patch baseUrl
(Api.Endpoint.RepositoryChown options.org options.repo)
(Api.Endpoint.RepositoryChown
options.org
options.repo
)
Json.Decode.string
|> withAuth session

Expand All @@ -186,17 +201,33 @@ chownRepo baseUrl session options =
disableRepo : String -> Session -> { a | org : String, repo : String } -> Request String
disableRepo baseUrl session options =
delete baseUrl
(Api.Endpoint.Repository options.org options.repo)
(Api.Endpoint.Repository
options.org
options.repo
)
Json.Decode.string
|> withAuth session


{-| getOrgRepos : retrieves the repositories for an org
-}
getOrgRepos : String -> Session -> { a | org : String } -> Request (List Vela.Repository)
getOrgRepos baseUrl session { org } =
getOrgRepos :
String
-> Session
->
{ a
| org : String
, pageNumber : Maybe Int
, perPage : Maybe Int
}
-> Request (List Vela.Repository)
getOrgRepos baseUrl session options =
get baseUrl
(Api.Endpoint.OrgRepositories Nothing Nothing org)
(Api.Endpoint.OrgRepositories
options.pageNumber
options.perPage
options.org
)
Vela.decodeRepositories
|> withAuth session

Expand Down
4 changes: 2 additions & 2 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ view shared props =
builds

RemoteData.Loading ->
Util.largeLoader
Util.smallLoader

RemoteData.NotAsked ->
Util.largeLoader
Util.smallLoader

RemoteData.Failure _ ->
div [ Util.testAttribute "builds-error" ]
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Components/Pager.elm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ view links labels toMsg =
_ ->
1
in
div [ class "pager-actions" ]
div [ class "pager-actions", class "buttons" ]
[ button
[ disabled <| isFirst || (List.length links == 0)
, Util.testAttribute "pager-previous"
Expand Down
4 changes: 2 additions & 2 deletions src/elm/Components/RecentBuilds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ view shared props =
]

else
Util.smallLoader
text ""

_ ->
text ""
Util.smallLoader


{-| viewRecentBuild : takes recent build and renders status and link to build as a small icon widget
Expand Down
6 changes: 3 additions & 3 deletions src/elm/Components/Secrets.elm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ viewOrgSecrets shared props =
)

_ ->
( Util.largeLoader, [] )
( Util.smallLoader, [] )

cfg =
Components.Table.Config
Expand Down Expand Up @@ -119,7 +119,7 @@ viewRepoSecrets shared props =
)

_ ->
( Util.largeLoader, [] )
( Util.smallLoader, [] )

cfg =
Components.Table.Config
Expand Down Expand Up @@ -169,7 +169,7 @@ viewSharedSecrets shared props =
)

_ ->
( Util.largeLoader, [] )
( Util.smallLoader, [] )

cfg =
Components.Table.Config
Expand Down
71 changes: 40 additions & 31 deletions src/elm/Components/Tabs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ 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)
import RemoteData
import Route
import Route.Path
import Shared
import Url exposing (Url)
import Utils.Helpers as Util


{-| Tab : record to represent information used by page navigation tab
-}
type alias Tab =
{ currentPath : Route.Path.Path
, toPath : Route.Path.Path
{ toPath : Route.Path.Path
, name : String
, isAlerting : Bool
, show : Bool
Expand All @@ -27,19 +29,36 @@ type alias Tab =

{-| view : takes list of tab records and renders them with spacers and horizontal filler
-}
view : List Tab -> String -> Html msg
view tabs testLabel =
view : Dict String Url -> Route.Path.Path -> List Tab -> String -> Html msg
view tabHistory currentPath tabs testLabel =
tabs
|> List.filterMap viewTab
|> List.filterMap (viewTab tabHistory currentPath)
|> 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, currentPath, toPath, isAlerting, show } =
viewTab : Dict String Url -> Route.Path.Path -> Tab -> Maybe (Html msg)
viewTab tabHistory currentPath { name, toPath, isAlerting, show } =
let
toRoute =
Dict.get (Route.Path.toString toPath) tabHistory
|> Maybe.map (Route.fromUrl ())
|> Maybe.map
(\r ->
{ path = r.path
, query = r.query |> Dict.insert "tab_switch" "true"
, hash = r.hash
}
)
|> Maybe.withDefault
{ path = toPath
, query = Dict.empty
, hash = Nothing
}
in
if show then
Just <|
a
Expand All @@ -48,7 +67,7 @@ viewTab { name, currentPath, toPath, isAlerting, show } =
, ( "alerting", isAlerting )
]
, currentPathClass currentPath toPath
, Route.Path.href toPath
, Route.href toRoute
, Util.testAttribute <| "jump-" ++ name
]
[ text name ]
Expand Down Expand Up @@ -87,37 +106,34 @@ currentPathClass p1 p2 =


viewOrgTabs :
{ currentPath : Route.Path.Path
, org : String
, maybePage : Maybe Pagination.Page
, maybePerPage : Maybe Pagination.PerPage
, maybeEvent : Maybe String
}
Shared.Model
->
{ currentPath : Route.Path.Path
, org : String
, tabHistory : Dict String Url
}
-> Html msg
viewOrgTabs props =
viewOrgTabs shared props =
let
tabs =
[ { name = "Repositories"
, currentPath = props.currentPath
, toPath = Route.Path.Org_ { org = props.org }
, isAlerting = False
, show = True
}
, { name = "Builds"
, currentPath = props.currentPath
, toPath = Route.Path.Org_Builds { org = props.org }
, isAlerting = False
, show = True
}
, { name = "Secrets"
, currentPath = props.currentPath
, toPath = Route.Path.SecretsEngine_OrgOrg_ { org = props.org, engine = "native" }
, isAlerting = False
, show = True
}
]
in
view tabs "jump-bar-repo"
view props.tabHistory props.currentPath tabs "jump-bar-repo"



Expand All @@ -130,6 +146,7 @@ viewRepoTabs :
{ currentPath : Route.Path.Path
, org : String
, repo : String
, tabHistory : Dict String Url
}
-> Html msg
viewRepoTabs shared props =
Expand Down Expand Up @@ -168,7 +185,6 @@ viewRepoTabs shared props =

tabs =
[ { name = "Builds"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_
{ org = props.org
Expand All @@ -178,7 +194,6 @@ viewRepoTabs shared props =
, show = True
}
, { name = "Deployments"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_Deployments
{ org = props.org
Expand All @@ -188,7 +203,6 @@ viewRepoTabs shared props =
, show = True
}
, { name = "Secrets"
, currentPath = props.currentPath
, toPath =
Route.Path.SecretsEngine_RepoOrg_Repo_
{ org = props.org
Expand All @@ -199,30 +213,28 @@ viewRepoTabs shared props =
, show = True
}
, { name = "Schedules"
, currentPath = props.currentPath
, toPath = Route.Path.Org_Repo_Schedules { org = props.org, repo = props.repo }
, isAlerting = False
, show = showSchedules
}
, { name = "Audit"
, currentPath = props.currentPath
, toPath = Route.Path.Org_Repo_Audit { org = props.org, repo = props.repo }
, isAlerting = auditAlerting
, show = True
}
, { name = "Settings"
, currentPath = props.currentPath
, toPath = Route.Path.Org_Repo_Settings { org = props.org, repo = props.repo }
, isAlerting = False
, show = True
}
]
in
view tabs "jump-bar-repo"
view props.tabHistory props.currentPath tabs "jump-bar-repo"



-- BUILD
-- fromHistory : Dict String Url -> String -> Route.Path.Path


viewBuildTabs :
Expand All @@ -232,13 +244,13 @@ viewBuildTabs :
, repo : String
, buildNumber : String
, currentPath : Route.Path.Path
, tabHistory : Dict String Url
}
-> Html msg
viewBuildTabs shared props =
let
tabs =
[ { name = "Build"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_Build_
{ org = props.org
Expand All @@ -249,7 +261,6 @@ viewBuildTabs shared props =
, show = True
}
, { name = "Services"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_Build_Services
{ org = props.org
Expand All @@ -260,7 +271,6 @@ viewBuildTabs shared props =
, show = True
}
, { name = "Pipeline"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_Build_Pipeline
{ org = props.org
Expand All @@ -271,7 +281,6 @@ viewBuildTabs shared props =
, show = True
}
, { name = "Visualize"
, currentPath = props.currentPath
, toPath =
Route.Path.Org_Repo_Build_Graph
{ org = props.org
Expand All @@ -283,4 +292,4 @@ viewBuildTabs shared props =
}
]
in
view tabs "jump-bar-build"
view props.tabHistory props.currentPath tabs "jump-bar-build"
Loading

0 comments on commit 2e36467

Please sign in to comment.