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

enhance(dashboards): show user's dashboards #819

Merged
merged 15 commits into from
Sep 19, 2024
Merged
63 changes: 63 additions & 0 deletions cypress/fixtures/user_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[
{
"dashboard": {
"id": "6e26a6d0-2fc3-4531-a04d-678a58135288",
"name": "demo dashboard",
"created_at": 1726757028,
"created_by": "CookieCat",
"updated_at": 1726757028,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": [
{
"id": 1,
"name": "github/repo1"
}
]
},
"repos": [
{
"org": "github",
"name": "repo1",
"counter": 1,
"active": true,
"builds": [
{
"number": 1,
"started": 1726757097,
"sender": "CookieCat",
"ref": "refs/heads/main",
"status": "running",
"event": "push",
"branch": "master",
"link": "http://vela.example.com/github/repo1/1"
}
]
}
]
},
{
"dashboard": {
"id": "c4e8f563-4784-4b4b-9534-3007d579dc2a",
"name": "another demo dashboard",
"created_at": 1726757636,
"created_by": "CookieCat",
"updated_at": 1726757636,
"updated_by": "CookieCat",
"admins": [
{
"id": 1,
"name": "CookieCat",
"active": true
}
],
"repos": []
}
}
]
61 changes: 50 additions & 11 deletions cypress/integration/dashboards.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,56 @@
*/

context('Dashboards', () => {
context('main dashboards page', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/user/dashboards',
'fixture:user_dashboards.json',
);
cy.login('/dashboards');
});

it('shows the list of dashboards', () => {
cy.get('[data-test=dashboard-item]').should('have.length', 2);
});

it('shows the repos within a dashboard', () => {
cy.get('[data-test=dashboard-repos]').first().contains('github/repo1');
});

it('shows a message when there are no repos', () => {
cy.get('[data-test=dashboard-repos]')
.eq(1)
.contains('No repositories in this dashboard');
});

it('clicking dashoard name navigates to dashboard page', () => {
cy.get('[data-test=dashboard-item]')
.first()
.within(() => {
cy.get('a').first().click();
cy.location('pathname').should(
'eq',
'/dashboards/6e26a6d0-2fc3-4531-a04d-678a58135288',
);
});
});
});

context('main dashboards page shows message', () => {
beforeEach(() => {
cy.server();
cy.route(
'GET',
'*api/v1/user/dashboards',
'fixture:user_dashboards.json',
);
cy.login('/dashboards');
});
});

context('server returns dashboard with 3 cards, one without builds', () => {
beforeEach(() => {
cy.server();
Expand Down Expand Up @@ -112,15 +162,4 @@ context('Dashboards', () => {
);
});
});

context('main dashboards page shows message', () => {
beforeEach(() => {
cy.server();
cy.login('/dashboards');
});

it('shows the welcome message', () => {
cy.get('[data-test=dashboards]').contains('Welcome to dashboards!');
});
});
});
4 changes: 4 additions & 0 deletions src/elm/Api/Endpoint.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Endpoint
| Logout
| CurrentUser
| Dashboard String
| Dashboards
| Deployment Vela.Org Vela.Repo (Maybe String)
| Deployments (Maybe Pagination.Page) (Maybe Pagination.PerPage) Vela.Org Vela.Repo
| Token
Expand Down Expand Up @@ -164,6 +165,9 @@ toUrl api endpoint =
Deployments maybePage maybePerPage org repo ->
url api [ "deployments", org, repo ] <| Pagination.toQueryParams maybePage maybePerPage

Dashboards ->
url api [ "user", "dashboards" ] []

Dashboard dashboard ->
url api [ "dashboards", dashboard ] []

Expand Down
14 changes: 14 additions & 0 deletions src/elm/Api/Operations.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Api.Operations exposing
, getBuildSteps
, getCurrentUser
, getDashboard
, getDashboards
, getOrgBuilds
, getOrgRepos
, getOrgSecret
Expand Down Expand Up @@ -1316,3 +1317,16 @@ getDashboard baseUrl session options =
)
Vela.decodeDashboard
|> withAuth session


{-| getDashboards : retrieves the dashboards for the current user.
-}
getDashboards :
String
-> Session
-> Request (List Vela.Dashboard)
getDashboards baseUrl session =
get baseUrl
Api.Endpoint.Dashboards
Vela.decodeDashboards
|> withAuth session
18 changes: 17 additions & 1 deletion src/elm/Effect.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Effect exposing
, sendCmd, sendMsg
, pushRoute, replaceRoute, loadExternalUrl
, map, toCmd
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getAllBuildServices, getAllBuildSteps, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoHooksShared, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
, addAlertError, addAlertSuccess, addDeployment, addFavorites, addOrgSecret, addRepoSchedule, addRepoSecret, addSharedSecret, alertsUpdate, approveBuild, cancelBuild, chownRepo, clearRedirect, deleteOrgSecret, deleteRepoSchedule, deleteRepoSecret, deleteSharedSecret, disableRepo, downloadFile, enableRepo, expandPipelineConfig, finishAuthentication, focusOn, getAllBuildServices, getAllBuildSteps, getBuild, getBuildGraph, getBuildServiceLog, getBuildServices, getBuildStepLog, getBuildSteps, getCurrentUser, getCurrentUserShared, getDashboard, getDashboards, getOrgBuilds, getOrgRepos, getOrgSecret, getOrgSecrets, getPipelineConfig, getPipelineTemplates, getRepo, getRepoBuilds, getRepoBuildsShared, getRepoDeployments, getRepoHooks, getRepoHooksShared, getRepoSchedule, getRepoSchedules, getRepoSecret, getRepoSecrets, getSettings, getSharedSecret, getSharedSecrets, getWorkers, handleHttpError, logout, pushPath, redeliverHook, repairRepo, replacePath, replaceRouteRemoveTabHistorySkipDomFocus, restartBuild, setRedirect, setTheme, updateFavicon, updateFavorite, updateOrgSecret, updateRepo, updateRepoHooksShared, updateRepoSchedule, updateRepoSecret, updateSettings, updateSharedSecret, updateSourceReposShared
)

{-|
Expand Down Expand Up @@ -1384,3 +1384,19 @@ getDashboard options =
options
)
|> sendCmd


getDashboards :
{ baseUrl : String
, session : Auth.Session.Session
, onResponse : Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Dashboard ) -> msg
}
-> Effect msg
getDashboards options =
Api.try
options.onResponse
(Api.Operations.getDashboards
options.baseUrl
options.session
)
|> sendCmd
7 changes: 7 additions & 0 deletions src/elm/Layouts/Default/Org.elm
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ view props shared route { toContentMsg, model, content } =
{ buttons =
props.navButtons
++ [ a
[ class "button"
, class "-outline"
, Util.testAttribute "dashboards-button"
, Route.Path.href Route.Path.Dashboards
]
[ text "Dashboards" ]
, a
[ class "button"
, class "-outline"
, Util.testAttribute "source-repos"
Expand Down
Loading
Loading