Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit cd967c2

Browse files
committed
webui: Rewrite visualise page
This commit rewrites the visualise page to use React instead of AngularJS. Besides the migration to React this simplified and cleans up a lot of the existing code. Additionally it includes a few layout changes on the page. These have two aims: 1) Make the page more pleasant to use for visitors of a database who are not interested in creating or modifying visualisations. They only want to see the preconfigured visualisations, select them, and see the plots. For them all the buttons should be mostly hidden. 2) Make creating, updating, and maintaining the publicly visible visualisations easier for the database owner. For this the owner needs more tools and a better overview for configuring visualisations.
1 parent 7270cff commit cd967c2

17 files changed

+1146
-3530
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ webui/js/db-header.js
6363
webui/js/discussion-comments.js
6464
webui/js/discussion-create-mr.js
6565
webui/js/discussion-list.js
66+
webui/js/export-data.js
6667
webui/js/format.js
6768
webui/js/markdown-editor.js
6869
webui/js/profile-page.js
6970
webui/js/sql-terminal.js
7071
webui/js/user-page.js
72+
webui/js/visualisation-editor.js
7173

7274
# Local secrets
7375
.env

common/postgresql.go

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,8 +2483,8 @@ func GetUsernameFromEmail(email string) (userName, avatarURL string, err error)
24832483
return
24842484
}
24852485

2486-
// GetVisualisationParams returns a saved set of visualisation parameters
2487-
func GetVisualisationParams(dbOwner, dbName, visName string) (params VisParamsV2, ok bool, err error) {
2486+
// GetVisualisations returns the saved visualisations for a given database
2487+
func GetVisualisations(dbOwner, dbName string) (visualisations map[string]VisParamsV2, err error) {
24882488
dbQuery := `
24892489
WITH u AS (
24902490
SELECT user_id
@@ -2496,44 +2496,7 @@ func GetVisualisationParams(dbOwner, dbName, visName string) (params VisParamsV2
24962496
WHERE db.user_id = u.user_id
24972497
AND db_name = $2
24982498
)
2499-
SELECT parameters
2500-
FROM vis_params as vis, u, d
2501-
WHERE vis.db_id = d.db_id
2502-
AND vis.user_id = u.user_id
2503-
AND vis.name = $3`
2504-
e := pdb.QueryRow(context.Background(), dbQuery, dbOwner, dbName, visName).Scan(&params)
2505-
if e != nil {
2506-
if errors.Is(e, pgx.ErrNoRows) {
2507-
// There weren't any saved parameters for this database visualisation
2508-
return
2509-
}
2510-
2511-
// A real database error occurred
2512-
err = e
2513-
log.Printf("Retrieving visualisation parameters for '%s/%s', visualisation '%s' failed: %v",
2514-
SanitiseLogString(dbOwner), SanitiseLogString(dbName), SanitiseLogString(visName), e)
2515-
return
2516-
}
2517-
2518-
// Parameters were successfully retrieved
2519-
ok = true
2520-
return
2521-
}
2522-
2523-
// GetVisualisations returns the list of saved visualisations for a given database
2524-
func GetVisualisations(dbOwner, dbName string) (visNames []string, err error) {
2525-
dbQuery := `
2526-
WITH u AS (
2527-
SELECT user_id
2528-
FROM users
2529-
WHERE lower(user_name) = lower($1)
2530-
), d AS (
2531-
SELECT db.db_id
2532-
FROM sqlite_databases AS db, u
2533-
WHERE db.user_id = u.user_id
2534-
AND db_name = $2
2535-
)
2536-
SELECT name
2499+
SELECT name, parameters
25372500
FROM vis_params as vis, u, d
25382501
WHERE vis.db_id = d.db_id
25392502
AND vis.user_id = u.user_id
@@ -2552,14 +2515,17 @@ func GetVisualisations(dbOwner, dbName string) (visNames []string, err error) {
25522515
}
25532516
defer rows.Close()
25542517

2555-
var s string
2518+
visualisations = make(map[string]VisParamsV2)
25562519
for rows.Next() {
2557-
err = rows.Scan(&s)
2520+
var n string
2521+
var p VisParamsV2
2522+
err = rows.Scan(&n, &p)
25582523
if err != nil {
25592524
log.Printf("Error retrieving visualisation list: %v", err.Error())
25602525
return
25612526
}
2562-
visNames = append(visNames, s)
2527+
2528+
visualisations[n] = p
25632529
}
25642530
return
25652531
}
@@ -5263,6 +5229,33 @@ func VisualisationDeleteParams(dbOwner, dbName, visName string) (err error) {
52635229
return
52645230
}
52655231

5232+
// VisualisationRename renames an existing saved visualisation
5233+
func VisualisationRename(dbOwner, dbName, visName, visNewName string) (err error) {
5234+
dbQuery := `
5235+
WITH u AS (
5236+
SELECT user_id
5237+
FROM users
5238+
WHERE lower(user_name) = lower($1)
5239+
), d AS (
5240+
SELECT db.db_id
5241+
FROM sqlite_databases AS db, u
5242+
WHERE db.user_id = u.user_id
5243+
AND db_name = $2
5244+
)
5245+
UPDATE vis_params SET name = $4 WHERE user_id = (SELECT user_id FROM u) AND db_id = (SELECT db_id FROM d) AND name = $3`
5246+
commandTag, err := pdb.Exec(context.Background(), dbQuery, dbOwner, dbName, visName, visNewName)
5247+
if err != nil {
5248+
log.Printf("Renaming visualisation '%s' for database '%s/%s' failed: %v", SanitiseLogString(visName),
5249+
SanitiseLogString(dbOwner), SanitiseLogString(dbName), err)
5250+
return err
5251+
}
5252+
if numRows := commandTag.RowsAffected(); numRows != 1 {
5253+
log.Printf("Wrong number of rows (%d) affected while renaming visualisation '%s' for database '%s/%s'",
5254+
numRows, SanitiseLogString(visName), SanitiseLogString(dbOwner), SanitiseLogString(dbName))
5255+
}
5256+
return
5257+
}
5258+
52665259
// VisualisationSaveData saves visualisation result data for later retrieval
52675260
func VisualisationSaveData(dbOwner, dbName, commitID, hash string, visData []VisRowV1) (err error) {
52685261
var commandTag pgconn.CommandTag

cypress/e2e/1-webui/auth0_dialog.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('ensure auth0 dialog is available on all pages', () => {
105105

106106
it('visualise page', () => {
107107
cy.visit('vis/default/Assembly Election 2017.sqlite')
108-
cy.get('[data-cy="usersqltext"]')
108+
cy.title().should('include', 'Visualisations')
109109
cy.get('[data-cy="loginlnk"]').click()
110110
cy.get('.auth0-lock-name').should('contain.text', 'Auth0')
111111
})

cypress/e2e/1-webui/bugs/002-visualisation-base64url-padding-bug.cy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ describe('002-visualisation-base64url-padding-bug', () => {
77
// Run a SQL visualisation which used to trigger a base64url encoding padding bug
88
it('run a visualisation query whose base64url encoding does not have a padding character', () => {
99
cy.visit('/vis/default/Assembly Election 2017 with view.sqlite')
10+
cy.get('[data-cy="newvisbtn"]').click()
1011
cy.get('[data-cy="sqltab"]').click()
11-
cy.get('[data-cy="usersqltext"]').type('{selectall}{backspace}').type(
12+
cy.get('[name="usersql"]').type('{selectall}{backspace}').type(
1213
'SELECT Constituency_Name, Constituency_Number\n' +
1314
'FROM Constituency_Turnout_Information\n' +
1415
'WHERE Constituency_Number > 0\n' +
1516
'ORDER BY Constituency_Name ASC\n' +
1617
'LIMIT 10')
1718
cy.get('[data-cy="runsqlbtn"]').click()
1819
cy.wait(150) // Needs a bit of a delay here, otherwise any error status message may be missed
19-
cy.get('[data-cy="statusmsg"]').should('contain.text', 'SQL query ran successfully')
20+
cy.get('[data-cy="statusmsg"]').should('contain.text', 'successfully')
2021
})
2122
})

0 commit comments

Comments
 (0)