Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/feedback-dialog.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feedback is now a global dialog opened from the footer, so sending a note no longer leaves the page. The Settings form remains as the no-JavaScript fallback and keeps the feedback history, the duplicate feedback button in the About card is gone, and submitting returns to the page the note was written on.
2 changes: 2 additions & 0 deletions public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ a.list-row:hover strong { color: var(--accent); }
.repos-head { align-items: center; gap: 12px; margin-bottom: 12px; }
.repos-head h2 { margin: 0; }
.add-repo-dialog { width: min(680px, calc(100vw - 32px)); max-height: min(80vh, 720px); overflow: auto; border: 1px solid var(--line-strong); border-radius: var(--radius-md); padding: 22px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.feedback-dialog { width: min(560px, calc(100vw - 32px)); }
.feedback-dialog .dialog-head .link { font-size: 20px; line-height: 1; }
.add-repo-dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
.add-repo-dialog .dialog-head { position: sticky; top: 0; z-index: 1; align-items: center; background: var(--panel); padding-bottom: 8px; }
.add-repo-dialog .dialog-head h2 { margin: 0; }
Expand Down
5 changes: 4 additions & 1 deletion public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,12 @@
dialog.addEventListener('close', () => clearDialogHash(dialog))
})
document.querySelectorAll('[data-open-dialog]').forEach((button) => {
button.addEventListener('click', () => {
button.addEventListener('click', (event) => {
const dialog = document.getElementById(button.getAttribute('data-open-dialog') ?? '')
if (dialog === null || !openDialog(dialog)) return
// The trigger may be an <a href="/settings#feedback">: the href is the
// no-JavaScript fallback, so the enhancement must stop the navigation.
event.preventDefault()
if (location.hash !== `#${dialog.id}`) history.replaceState(null, '', `${location.pathname}${location.search}#${dialog.id}`)
})
})
Expand Down
11 changes: 8 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4482,7 +4482,12 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
const kind = body.kind === 'bug' || body.kind === 'other' ? body.kind : 'feedback'
const message = redact((body.message ?? '').trim()).slice(0, 2000)
const page = (body.page ?? '').trim().slice(0, 200)
if (message === '') return reply.redirect(`/settings?error=${encodeURIComponent('请填写反馈内容。')}#feedback`)
const returnTo = safeLocalPath(body.returnTo, '/settings')
const back = (key: 'notice' | 'error', text: string): string => {
const target = withMessageParam(returnTo, key, text)
return returnTo.startsWith('/settings') ? `${target}#feedback` : target
}
if (message === '') return reply.redirect(back('error', '请填写反馈内容。'))
const id = randomId('fb')
const createdAt = new Date().toISOString()
const publishConsent = body.publishConsent === '1'
Expand All @@ -4497,10 +4502,10 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
...feedbackMail({ id, login: viewer.user.login, kind, message, page, createdAt }),
...(replyTo === '' ? {} : { replyTo }),
})
return reply.redirect(`/settings?notice=${encodeURIComponent('反馈已发送,谢谢。')}#feedback`)
return reply.redirect(back('notice', '反馈已发送,谢谢。'))
} catch (error) {
log.error('feedback mail failed', { id, error: redact(String(error)) })
return reply.redirect(`/settings?error=${encodeURIComponent('反馈已保存,但通知邮件发送失败;请稍后再试。')}#feedback`)
return reply.redirect(back('error', '反馈已保存,但通知邮件发送失败;请稍后再试。'))
}
})

Expand Down
35 changes: 34 additions & 1 deletion src/views/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,45 @@ export function layout(options: LayoutOptions): string {
<form method="post" action="/auth/logout"><input type="hidden" name="csrf" value="${escapeHtml(viewer.csrfToken)}" /><button class="link account-exit" type="submit">${escapeHtml(t('退出', 'Sign out'))}</button></form>
</div>`
const brandSmall = locale === 'zh' ? '<small>羽巢</small>' : ''
// Feedback is a global action, not a Settings section. The dialog uses the
// existing [data-open-dialog] pattern; the footer link keeps /settings#feedback
// as the no-JavaScript fallback and the inline form remains on Settings.
const onSettings = cleanPath === '/settings' || cleanPath.startsWith('/settings/')
const feedbackViewer = viewer !== undefined && viewer !== null && viewer.user.status === 'approved' && !onSettings ? viewer : null
const feedbackHref = onSettings ? '#feedback' : '/settings#feedback'
const feedbackAttrs = feedbackViewer === null ? '' : ' data-open-dialog="feedback-dialog" aria-haspopup="dialog" aria-controls="feedback-dialog"'
const feedbackDialog = feedbackViewer === null ? '' : `<dialog id="feedback-dialog" class="add-repo-dialog feedback-dialog" aria-labelledby="feedback-dialog-title">
<div class="row between dialog-head">
<h2 id="feedback-dialog-title">${escapeHtml(t('反馈给开发者', 'Send feedback'))}</h2>
<button class="link" type="button" data-close-dialog aria-label="${escapeHtml(t('关闭', 'Close'))}">×</button>
</div>
<p class="muted">${escapeHtml(t('遇到问题、想要一个功能,或者发现异常?这里会保存一条记录并邮件通知开发者。', 'Found a problem, want a feature, or saw something unexpected? This stores a record and mails the maintainer.'))}</p>
<form method="post" action="/feedback" class="form">
${csrfField(feedbackViewer)}
<input type="hidden" name="returnTo" value="${escapeHtml(path)}" />
<div class="row">
<label>${escapeHtml(t('类型', 'Kind'))}
<select name="kind">
<option value="feedback">${escapeHtml(t('建议 / 一般反馈', 'Suggestion / feedback'))}</option>
<option value="bug">${escapeHtml(t('Bug', 'Bug'))}</option>
<option value="other">${escapeHtml(t('其他', 'Other'))}</option>
</select>
</label>
<label class="grow">${escapeHtml(t('相关页面(可选)', 'Related page (optional)'))} <input name="page" maxlength="200" value="${escapeHtml(path)}" placeholder="/settings 或 /dashboard" /></label>
</div>
<label>${escapeHtml(t('内容', 'Message'))}<textarea name="message" rows="4" maxlength="2000" required placeholder="${escapeHtml(t('发生了什么?你期望什么?', 'What happened, and what did you expect?'))}"></textarea></label>
<label class="check"><input type="checkbox" name="publishConsent" value="1" /> ${escapeHtml(t('我同意 Fledge 在公开 GitHub issue 中 @ 我的账号,并引用脱敏后的反馈摘要。', 'I agree Fledge may @ my GitHub account in a public issue, citing a sanitized summary of this feedback.'))}</label>
<p class="fine">${escapeHtml(t('不要粘贴 token、密码或他人的隐私信息。反馈会保存并邮件通知开发者。', 'Do not paste tokens, passwords or another person’s private data. The note is stored and mailed to the maintainer.'))}</p>
<button class="btn" type="submit">${escapeHtml(t('发送反馈', 'Send feedback'))}</button>
</form>
</dialog>`
const footer = `<footer class="foot">
<div>${escapeHtml(t('Fledge · 让托管的仓库自己长大 · 由 FlyBot 驱动', 'Fledge · hosted repositories that grow themselves · powered by FlyBot'))}${release.version === null ? '' : ` · <span class="foot-release">v${escapeHtml(release.version)}</span>`}</div>
<nav class="foot-links" aria-label="${escapeHtml(t('页脚导航', 'Footer navigation'))}">
<a href="${escapeHtml(withSlash(config.services.docs))}" target="_blank" rel="noreferrer">${escapeHtml(t('文档', 'Docs'))}</a>
<a href="${escapeHtml(config.services.portal)}" target="_blank" rel="noreferrer">Portal</a>
<a href="${escapeHtml(withSlash(config.services.status))}" target="_blank" rel="noreferrer">${escapeHtml(t('平台状态', 'Status'))}</a>
<a href="/settings#feedback">${escapeHtml(t('反馈', 'Feedback'))}</a>
<a href="${feedbackHref}"${feedbackAttrs}>${escapeHtml(t('反馈', 'Feedback'))}</a>
<a class="star-link" href="${FLEDGE_GITHUB_URL}" target="_blank" rel="noreferrer" title="${escapeHtml(t('在 GitHub 上加星', 'Star Fledge on GitHub'))}" aria-label="${escapeHtml(t('在 GitHub 上加星', 'Star Fledge on GitHub'))}">${starIcon()}<span>${escapeHtml(t('加星', 'Star'))}</span></a>
</nav>
</footer>`
Expand Down Expand Up @@ -310,6 +342,7 @@ export function layout(options: LayoutOptions): string {
${body}
</main>
${footer}
${feedbackDialog}
<script src="${assetUrl('/assets/section-nav.js')}" defer></script>
<dialog id="confirm-dialog" class="confirm-dialog" aria-labelledby="confirm-dialog-title">
<form method="dialog">
Expand Down
4 changes: 2 additions & 2 deletions src/views/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ export function settingsPage(input: {
<option value="jobs:read">${escapeHtml(t('任务读取:只读 /api/v1/jobs', 'Jobs: read /api/v1/jobs only'))}</option>
</select>
</label>
<label>${escapeHtml(t('有效期', 'Expires'))}{infoTip(t('个人 token 必须有期限;到期后网关直接拒绝。永不过期只对管理员创建的运维 token 开放。', 'A personal token must expire; the gateway refuses it afterwards. A token without an expiry is only for an operator token created by an admin.'))}
<label>${escapeHtml(t('有效期', 'Expires'))}${infoTip(t('个人 token 必须有期限;到期后网关直接拒绝。永不过期只对管理员创建的运维 token 开放。', 'A personal token must expire; the gateway refuses it afterwards. A token without an expiry is only for an operator token created by an admin.'))}
<select name="expiryDays">
${PAT_EXPIRY_CHOICES.map((days) => `<option value="${days}"${days === config.tokens.patExpiryDays ? ' selected' : ''}>${escapeHtml(t(`${days} 天`, `${days} days`))}</option>`).join('')}
${viewer.user.role === 'admin' || viewer.user.role === 'superadmin' ? `<option value="never">${escapeHtml(t('永不过期(运维)', 'Never (operator)'))}</option>` : ''}
Expand All @@ -2335,6 +2335,7 @@ export function settingsPage(input: {
<p class="muted">${escapeHtml(t('遇到问题、想要一个功能,或者发现异常?这里会保存一条记录并邮件通知开发者。', 'Found a problem, want a feature, or saw something unexpected? This stores a record and mails the maintainer.'))}</p>
<form method="post" action="/feedback" class="form">
${csrf(viewer)}
<input type="hidden" name="returnTo" value="/settings" />
<div class="row">
<label>${escapeHtml(t('类型', 'Kind'))}
<select name="kind">
Expand Down Expand Up @@ -2368,7 +2369,6 @@ export function settingsPage(input: {
<p class="muted">${escapeHtml(t('Fledge 是开源的自托管平台;如果它对你的仓库有帮助,可以在 GitHub 上加星支持。', 'Fledge is an open-source, self-hosted platform. If it helps your repositories, a star on GitHub supports it.'))}</p>
<div class="actions">
<a class="btn star-btn" href="${FLEDGE_GITHUB_URL}" target="_blank" rel="noreferrer">${starIcon()}${escapeHtml(t('在 GitHub 上加星', 'Star Fledge on GitHub'))}</a>
<a class="btn btn-ghost" href="#feedback">${escapeHtml(t('反馈', 'Feedback'))}</a>
</div>
</section>`
return layout({ title: t('设置', 'Settings'), viewer, body, config, locale, path: '/settings', active: 'settings', notice, error })
Expand Down
28 changes: 28 additions & 0 deletions test/feedback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ test('the settings page offers feedback and a Star link', async () => {
assert.match(response.body, /class="star-icon"/)
assert.doesNotMatch(response.body, /★/, 'the text glyph is replaced by the drawn star')
assert.match(response.body, /About Fledge/)
assert.doesNotMatch(response.body, /\{infoTip\(/, 'the infoTip helper is interpolated, not printed as source')
assert.match(response.body, /name="returnTo" value="\/settings"/)
assert.doesNotMatch(response.body, /class="btn btn-ghost" href="#feedback"/, 'the About card no longer duplicates the feedback form')
} finally {
await f.built.close()
}
})

test('the feedback dialog is available on a normal page and returns there', async () => {
const f = await fixture()
try {
const page = await f.built.app.inject({ method: 'GET', url: '/dashboard', headers: { cookie: f.cookie } })
assert.equal(page.statusCode, 200)
assert.match(page.body, /<dialog id="feedback-dialog"/)
assert.match(page.body, /data-open-dialog="feedback-dialog"/)
assert.match(page.body, /name="returnTo" value="\/dashboard"/)
assert.match(page.body, /name="publishConsent"/)
assert.match(page.body, /action="\/feedback"/)

const posted = await f.built.app.inject({
method: 'POST',
url: '/feedback',
headers: { 'content-type': 'application/x-www-form-urlencoded', cookie: f.cookie },
payload: formBody({ csrf: f.session.csrf, kind: 'bug', message: 'The dialog should keep me here.', page: '/dashboard', returnTo: '/dashboard' }),
})
assert.equal(posted.statusCode, 302)
assert.equal(String(posted.headers.location), '/dashboard')
assert.equal(flashOf(posted)?.notice?.text, '反馈已发送,谢谢。')
} finally {
await f.built.close()
}
Expand Down
2 changes: 2 additions & 0 deletions test/repoTabs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const KEPT_IDS = ['inbox', 'chief', 'chief-thread', 'board', 'jobs', 'repo-setti

const FORM_ACTIONS = [
'/auth/logout',
// The global feedback dialog lives in the layout, so every page carries it.
'/feedback',
'/repos/:id/delete',
'/repos/:id/delivery/merge-clean',
'/repos/:id/disable',
Expand Down
Loading