feat(web): make deploying reachable from where it is looked for
The « Déployer » button only existed on the row of an already created target, so an empty list was a dead end whose only way out sat in the page header. The empty state now carries the action that fills it. A release also gains its own deploy button: wanting to ship a given version is the moment people look for it, and sending them to another page to retype the tag was needless. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
3 files changed
+91
-6
No files matched your search
@@ -81,7 +81,13 @@ export function toggle(checked, onChange, label) {
|
|||||||
* `render` returns a Node or a string.
|
* `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.' } = {}) {
|
||||||
if (!rows || rows.length === 0) return h('p', { class: 'empty', text: empty });
|
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.
|
||||||
|
return empty instanceof Node
|
||||||
|
? h('div', { class: 'empty' }, empty)
|
||||||
|
: h('p', { class: 'empty', text: empty });
|
||||||
|
}
|
||||||
|
|
||||||
return h(
|
return h(
|
||||||
'div',
|
'div',
|
||||||
|
|||||||
@@ -342,7 +342,24 @@ export function render(host, { state }) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
data.targets,
|
data.targets,
|
||||||
{ empty: 'Aucune cible pour l’instant. Crée-en une pour déployer depuis ce site.' },
|
{
|
||||||
|
// The action that fills the table belongs in the table, not only
|
||||||
|
// in the page header where nobody looks for it.
|
||||||
|
empty: h(
|
||||||
|
'div',
|
||||||
|
{ class: 'stack', style: { alignItems: 'center' } },
|
||||||
|
h('p', {
|
||||||
|
text: 'Aucune cible pour l’instant. Une cible dit où livrer un dépôt ; le bouton « Déployer » apparaît ensuite sur sa ligne.',
|
||||||
|
}),
|
||||||
|
level >= LEVELS.DEV
|
||||||
|
? button(
|
||||||
|
'Créer une première cible',
|
||||||
|
() => editTarget(null, data.repositories, data.commandDeploysAllowed, level, reload),
|
||||||
|
{ tone: 'primary' },
|
||||||
|
)
|
||||||
|
: h('p', { class: 'muted', text: 'Le niveau Dev est requis pour en créer une.' }),
|
||||||
|
),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,51 @@ async function publishRelease(base, repository, releases, branches, reload) {
|
|||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
function releaseRow(base, level, reload) {
|
/** Runs one of the repository's targets on a given version. */
|
||||||
|
async function deployRelease(release, targets, reload) {
|
||||||
|
const runnable = targets.filter((target) => target.enabled);
|
||||||
|
if (runnable.length === 0) {
|
||||||
|
toast('Aucune cible active pour ce dépôt. Crée-en une depuis la page Déploiements.', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const picker = select(
|
||||||
|
runnable.map((target) => ({
|
||||||
|
value: String(target.id),
|
||||||
|
label: `${target.name} — ${target.environment}`,
|
||||||
|
})),
|
||||||
|
{ value: String(runnable[0].id) },
|
||||||
|
);
|
||||||
|
const summary = h('p', { class: 'muted', text: runnable[0].summary });
|
||||||
|
picker.addEventListener('change', () => {
|
||||||
|
summary.textContent = runnable.find((target) => String(target.id) === picker.value)?.summary ?? '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const confirmed = await modal(
|
||||||
|
`Déployer ${release.tag}`,
|
||||||
|
() => ({
|
||||||
|
node: h('div', { class: 'stack' }, field('Cible', picker), summary),
|
||||||
|
submit: () => true,
|
||||||
|
}),
|
||||||
|
{ confirmLabel: 'Déployer', tone: 'primary' },
|
||||||
|
);
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
toast('Déploiement lancé…', 'info');
|
||||||
|
const result = await api.post(`/api/deploy/targets/${picker.value}/run`, {
|
||||||
|
releaseTag: release.tag,
|
||||||
|
ref: release.target || undefined,
|
||||||
|
});
|
||||||
|
toast(
|
||||||
|
result.status === 'success'
|
||||||
|
? `${release.tag} déployé.`
|
||||||
|
: `Déploiement en échec : ${result.error ?? 'raison inconnue'}`,
|
||||||
|
result.status === 'success' ? 'success' : 'error',
|
||||||
|
);
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function releaseRow(base, level, reload, targets) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: 'Version',
|
label: 'Version',
|
||||||
@@ -129,6 +173,9 @@ function releaseRow(base, level, reload) {
|
|||||||
'div',
|
'div',
|
||||||
{ class: 'row' },
|
{ class: 'row' },
|
||||||
button('Notes', () => showNotes(release), { tone: 'ghost' }),
|
button('Notes', () => showNotes(release), { tone: 'ghost' }),
|
||||||
|
level >= LEVELS.DEV &&
|
||||||
|
!release.draft &&
|
||||||
|
button('Déployer', () => deployRelease(release, targets, reload), { tone: 'primary' }),
|
||||||
level >= LEVELS.DEV &&
|
level >= LEVELS.DEV &&
|
||||||
release.draft &&
|
release.draft &&
|
||||||
button(
|
button(
|
||||||
@@ -197,12 +244,18 @@ export async function render(host, { state }) {
|
|||||||
renderAsync(
|
renderAsync(
|
||||||
body,
|
body,
|
||||||
async () => {
|
async () => {
|
||||||
const [detail, releases, deployments] = await Promise.all([
|
const [detail, releases, deployments, targets] = await Promise.all([
|
||||||
api.get(base),
|
api.get(base),
|
||||||
api.get(`${base}/releases`, { limit: 30 }),
|
api.get(`${base}/releases`, { limit: 30 }),
|
||||||
api.get('/api/deployments', { repository: current.fullName, limit: 15 }),
|
api.get('/api/deployments', { repository: current.fullName, limit: 15 }),
|
||||||
|
api.get('/api/deploy/targets', { repository: current.fullName }).catch(() => ({ targets: [] })),
|
||||||
]);
|
]);
|
||||||
return { detail, releases: releases.releases, deployments: deployments.deployments };
|
return {
|
||||||
|
detail,
|
||||||
|
releases: releases.releases,
|
||||||
|
deployments: deployments.deployments,
|
||||||
|
targets: targets.targets ?? [],
|
||||||
|
};
|
||||||
},
|
},
|
||||||
(data) =>
|
(data) =>
|
||||||
h(
|
h(
|
||||||
@@ -220,7 +273,16 @@ export async function render(host, { state }) {
|
|||||||
{ tone: 'primary' },
|
{ tone: 'primary' },
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
table(releaseRow(base, level, draw), data.releases, { empty: 'Aucune release publiée.' }),
|
table(releaseRow(base, level, draw, data.targets), data.releases, {
|
||||||
|
empty: 'Aucune release publiée.',
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
|
level >= LEVELS.DEV &&
|
||||||
|
data.targets.length === 0 &&
|
||||||
|
notice(
|
||||||
|
'Aucune cible de déploiement pour ce dépôt : le bouton « Déployer » apparaîtra une fois une cible créée depuis la page Déploiements.',
|
||||||
|
'info',
|
||||||
),
|
),
|
||||||
|
|
||||||
card(
|
card(
|
||||||
|
|||||||
Reference in new issue
Block a user