diff --git a/src/web/public/core/ui.js b/src/web/public/core/ui.js index 20121e7..a7de773 100644 --- a/src/web/public/core/ui.js +++ b/src/web/public/core/ui.js @@ -80,7 +80,7 @@ export function toggle(checked, onChange, label) { * Renders a table. Each column is `{ key, label, render?, className? }`; * `render` returns a Node or a string. */ -export function table(columns, rows, { empty = 'Rien à afficher pour le moment.' } = {}) { +export function table(columns, rows, { empty = 'Rien à afficher pour le moment.', rowHref = null } = {}) { if (!rows || rows.length === 0) { // An empty state is where people look for the action that fills it, so it // accepts a node and not only a sentence. @@ -107,10 +107,11 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment. h( 'tbody', {}, - rows.map((row) => - h( + rows.map((row) => { + const target = rowHref?.(row) ?? null; + const line = h( 'tr', - {}, + target ? { class: 'row-link', tabindex: '0', role: 'link' } : {}, columns.map((column) => { const cell = h('td', { class: column.className ?? '' }); const value = column.render ? column.render(row) : row[column.key]; @@ -118,8 +119,25 @@ export function table(columns, rows, { empty = 'Rien à afficher pour le moment. else cell.textContent = value === null || value === undefined ? '—' : String(value); return cell; }), - ), - ), + ); + + if (target) { + // A control inside the row keeps its own behaviour; only the empty + // space navigates. + const open = (event) => { + if (event.target.closest('a, button, input, select, textarea, label')) return; + window.location.hash = target.replace(/^#/, ''); + }; + line.addEventListener('click', open); + line.addEventListener('keydown', (event) => { + if (event.key === 'Enter' || event.key === ' ') { + event.preventDefault(); + open(event); + } + }); + } + return line; + }), ), ), ); diff --git a/src/web/public/styles.css b/src/web/public/styles.css index 0b0dbdd..bcf9719 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -535,6 +535,14 @@ pre code { .table tbody tr:hover { background: color-mix(in srgb, var(--blue) 6%, transparent); } +.table tbody tr.row-link { + cursor: pointer; +} +.table tbody tr.row-link:focus-visible { + outline: 2px solid var(--blue); + outline-offset: -2px; +} + .num { text-align: right; font-variant-numeric: tabular-nums; diff --git a/src/web/public/views/organization.js b/src/web/public/views/organization.js index c770d93..4df1e59 100644 --- a/src/web/public/views/organization.js +++ b/src/web/public/views/organization.js @@ -164,7 +164,7 @@ export function render(host, { state }) { card( 'Dépôts', - { subtitle: 'Clique sur un dépôt pour le gérer en détail.' }, + { subtitle: 'Clique sur une ligne pour gérer le dépôt en détail.' }, table( [ { @@ -207,7 +207,10 @@ export function render(host, { state }) { }, ], data.repositories, - { empty: 'Aucun dépôt dans cette organisation.' }, + { + empty: 'Aucun dépôt dans cette organisation.', + rowHref: (repository) => `#/repos/${repository.fullName}`, + }, ), ), diff --git a/src/web/public/views/overview.js b/src/web/public/views/overview.js index 7f46edb..a1b9396 100644 --- a/src/web/public/views/overview.js +++ b/src/web/public/views/overview.js @@ -96,6 +96,7 @@ function giteaCard(gitea) { }, ], gitea.repositories, + { rowHref: (repository) => `#/repos/${repository.fullName}` }, ), ); }