feat(web): open a repository from anywhere on its row
The cards on the repository page already opened as a whole, but the tables on the organisation and overview pages still only linked the name, so the same object behaved differently depending on where it was listed. A table row can now carry a destination. Controls inside it keep their own behaviour, the row is reachable with the keyboard, and only the empty space navigates. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+38
-8
No files matched your search
@@ -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;
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user