Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pagination): handle new pagination cases from server changes #843

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 38 additions & 25 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type alias Props msg =
, viewActionsMenu : { build : Vela.Build } -> Html msg
, showRepoLink : Bool
, linkBuildNumber : Bool
, pageNumber : Int
}


Expand Down Expand Up @@ -100,34 +101,46 @@ view shared props =
none =
case props.maybeEvent of
Nothing ->
div []
[ h2 [] [ noBuildsHeaderText ]
, p [] [ text "Builds will show up here once you have:" ]
, ol [ class "list" ]
[ li []
[ text "A "
, code [] [ text ".vela.yml" ]
, text " file that describes your build pipeline in the root of your repository."
, br [] []
, a [ href <| shared.velaDocsURL ++ "/usage/" ] [ text "Review the documentation" ]
, text " for help or "
, a [ href <| shared.velaDocsURL ++ "/usage/examples/" ] [ text "check some of the pipeline examples" ]
, text "."
case props.pageNumber of
1 ->
div []
[ h2 [] [ noBuildsHeaderText ]
, p [] [ text "Builds will show up here once you have:" ]
, ol [ class "list" ]
[ li []
[ text "A "
, code [] [ text ".vela.yml" ]
, text " file that describes your build pipeline in the root of your repository."
, br [] []
, a [ href <| shared.velaDocsURL ++ "/usage/" ] [ text "Review the documentation" ]
, text " for help or "
, a [ href <| shared.velaDocsURL ++ "/usage/examples/" ] [ text "check some of the pipeline examples" ]
, text "."
]
, li []
[ text "Trigger one of the "
, webhooks
, text " by performing the respective action via "
, em [] [ text "Git" ]
, text "."
]
]
, p [] [ text "Happy building!" ]
]
, li []
[ text "Trigger one of the "
, webhooks
, text " by performing the respective action via "
, em [] [ text "Git" ]
, text "."
]
]
, p [] [ text "Happy building!" ]
]

_ ->
div []
[ h2 [] [ text <| "End of build results." ] ]

Just event ->
div []
[ h3 [] [ text <| "No builds for \"" ++ event ++ "\" event found." ] ]
case props.pageNumber of
1 ->
div []
[ h3 [] [ text <| "No builds for \"" ++ event ++ "\" event found." ] ]

_ ->
div []
[ h2 [] [ text <| "End of build results." ] ]
in
case props.builds of
RemoteData.Success builds ->
Expand Down
6 changes: 5 additions & 1 deletion src/elm/Components/Secrets.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type alias Props msg =
, key : String
, secrets : WebData (List Vela.Secret)
, tableButtons : Maybe (List (Html msg))
, pageNumber : Int
}


Expand All @@ -59,7 +60,7 @@ viewOrgSecrets shared props =
( noRowsView, rows ) =
case props.secrets of
RemoteData.Success s ->
( text <| "No secrets found for the org (" ++ props.key ++ ")"
( text <| "No secrets found for the repo: (" ++ props.key ++ ")"
, secretsToRows props.engine Vela.OrgSecret props.msgs.showCopyAlert s
)

Expand Down Expand Up @@ -92,6 +93,7 @@ viewOrgSecrets shared props =
tableHeaders
rows
actions
props.pageNumber
in
div [] [ Components.Table.view cfg ]

Expand Down Expand Up @@ -142,6 +144,7 @@ viewRepoSecrets shared props =
tableHeaders
rows
actions
props.pageNumber
in
div [] [ Components.Table.view cfg ]

Expand Down Expand Up @@ -192,6 +195,7 @@ viewSharedSecrets shared props =
tableHeaders
rows
actions
props.pageNumber
in
div [ class "shared-secrets-container" ] [ Components.Table.view cfg ]

Expand Down
16 changes: 11 additions & 5 deletions src/elm/Components/Table.elm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type alias Config data msg =
, columns : Columns
, rows : Rows data msg
, headerElement : Maybe (Html msg)
, pageNumber : Int
}


Expand All @@ -91,7 +92,7 @@ type alias Config data msg =
{-| view : renders data table.
-}
view : Config data msg -> Html msg
view { label, testLabel, noRows, columns, rows, headerElement } =
view { label, testLabel, noRows, columns, rows, headerElement, pageNumber } =
let
numRows =
List.length rows
Expand All @@ -118,17 +119,22 @@ view { label, testLabel, noRows, columns, rows, headerElement } =
)
columns
]
, viewFooter noRows numRows numColumns
, viewFooter noRows numRows numColumns pageNumber
, tbody [] <| List.map (\row_ -> row_.display row_.data) rows
]


{-| viewFooter : renders data table footer.
-}
viewFooter : Html msg -> Int -> Int -> Html msg
viewFooter noRows numRows numColumns =
viewFooter : Html msg -> Int -> Int -> Int -> Html msg
viewFooter noRows numRows numColumns pageNum =
if numRows == 0 then
tfoot [ class "no-rows" ] [ tr [] [ td [ attribute "colspan" <| String.fromInt numColumns ] [ noRows ] ] ]
case pageNum of
1 ->
tfoot [ class "no-rows" ] [ tr [] [ td [ attribute "colspan" <| String.fromInt numColumns ] [ noRows ] ] ]

_ ->
tfoot [ class "no-rows" ] [ tr [] [ td [ attribute "colspan" <| String.fromInt numColumns ] [ text "End of results." ] ] ]

else
text ""
Expand Down
14 changes: 14 additions & 0 deletions src/elm/Pages/Dash/Secrets/Engine_/Org/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ subscriptions model =
-}
view : Shared.Model -> Route { engine : String, org : String } -> Model -> View Msg
view shared route model =
let
pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
{ title = "Secrets" ++ Util.pageToString (Dict.get "page" route.query)
, body =
[ Components.Secrets.viewOrgSecrets shared
Expand Down Expand Up @@ -272,6 +284,7 @@ view shared route model =
, msg = GotoPage
}
]
, pageNumber = pageNum
}
, Components.Pager.view
{ show = True
Expand Down Expand Up @@ -306,6 +319,7 @@ view shared route model =
|> FeatherIcons.toHtml [ Svg.Attributes.class "button-icon" ]
]
]
, pageNumber = 1
}
]
}
14 changes: 14 additions & 0 deletions src/elm/Pages/Dash/Secrets/Engine_/Repo/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ subscriptions model =

view : Shared.Model -> Route { engine : String, org : String, repo : String } -> Model -> View Msg
view shared route model =
let
pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
{ title = "Secrets" ++ Util.pageToString (Dict.get "page" route.query)
, body =
[ Components.Secrets.viewRepoSecrets shared
Expand Down Expand Up @@ -257,6 +269,7 @@ view shared route model =
, msg = GotoPage
}
]
, pageNumber = pageNum
}
, Components.Secrets.viewOrgSecrets shared
{ msgs =
Expand All @@ -279,6 +292,7 @@ view shared route model =
]
[ text "Manage Org Secrets" ]
]
, pageNumber = 1
}
]
}
12 changes: 12 additions & 0 deletions src/elm/Pages/Dash/Secrets/Engine_/Shared/Org_/Team_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ view shared route model =
, ( route.params.team, Nothing )
, ( "Secrets", Nothing )
]

pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
{ title = "Secrets" ++ Util.pageToString (Dict.get "page" route.query)
, body =
Expand Down Expand Up @@ -244,6 +255,7 @@ view shared route model =
, msg = GotoPage
}
]
, pageNumber = pageNum
}
]
]
Expand Down
12 changes: 12 additions & 0 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,17 @@ view shared route model =
, cancelBuild = CancelBuild
, showHideActionsMenus = ShowHideActionsMenus
}

pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
{ title = "Builds" ++ Util.pageToString (Dict.get "page" route.query)
, body =
Expand Down Expand Up @@ -475,6 +486,7 @@ view shared route model =
}
, showRepoLink = True
, linkBuildNumber = True
, pageNumber = pageNum
}
, Components.Pager.view
{ show = RemoteData.unwrap False (\builds -> List.length builds > 0) model.builds
Expand Down
28 changes: 26 additions & 2 deletions src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,22 @@ update shared route msg model =
GetRepoBuildsResponse response ->
case response of
Ok ( meta, builds ) ->
let
pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
( { model
| builds = RemoteData.succeed builds
, pager = Api.Pagination.get meta.headers
, showFilter = List.length builds > 0 || Dict.get "event" route.query /= Nothing
, showFilter = List.length builds > 0 || Dict.get "event" route.query /= Nothing || pageNum > 1
}
, Effect.none
)
Expand Down Expand Up @@ -454,6 +466,17 @@ view shared route model =
, cancelBuild = CancelBuild
, showHideActionsMenus = ShowHideActionsMenus
}

pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1
in
{ title = "Builds" ++ Util.pageToString (Dict.get "page" route.query)
, body =
Expand All @@ -469,7 +492,7 @@ view shared route model =
]
[ span [] []
, Components.Pager.view
{ show = RemoteData.unwrap False (\builds -> List.length builds > 0) model.builds
{ show = RemoteData.unwrap False (\builds -> List.length builds > 0 || pageNum > 1) model.builds
, links = model.pager
, labels = Components.Pager.defaultLabels
, msg = GotoPage
Expand All @@ -495,6 +518,7 @@ view shared route model =
}
, showRepoLink = False
, linkBuildNumber = True
, pageNumber = pageNum
}
, Components.Pager.view
{ show = RemoteData.unwrap False (\builds -> List.length builds > 0) model.builds
Expand Down
12 changes: 12 additions & 0 deletions src/elm/Pages/Org_/Repo_/Deployments.elm
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ viewDeployments shared model route =
}
]

pageNumQuery =
Dict.get "page" route.query |> Maybe.andThen String.toInt

pageNum =
case pageNumQuery of
Just n ->
n

Nothing ->
1

( noRowsView, rows ) =
let
viewHttpError e =
Expand Down Expand Up @@ -344,6 +355,7 @@ viewDeployments shared model route =
tableHeaders
rows
actions
pageNum
in
div []
[ Components.Table.view cfg
Expand Down
Loading
Loading