Repository navigation
Club: let a member edit their report, and send one already decided back for review #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
487fff2
Club: let a member edit their report, and send one already decided ba…
openipc-ai 6c53ce8
Address review: no decision on what the reviewer did not see, no edit…
openipc-ai aa3bb1e
Merge remote-tracking branch 'origin/master' into club-report-edit
openipc-ai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
frontend/apps/site/src/components/club/EditReport.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // @vitest-environment jsdom | ||
| /** | ||
| * A member's edit to a report, as /club sends it: only what changed, files | ||
| * to take out by position, files to add as their kind; and before a decided | ||
| * report is saved, the warning that it goes back for review. | ||
| */ | ||
| import { afterEach, expect, test, vi } from 'vitest'; | ||
| import { cleanup, fireEvent, render, waitFor } from '@testing-library/preact'; | ||
| import { useBoardsTranslations } from '../../lib/boards-i18n'; | ||
| import type { MemberReport } from '../../lib/club'; | ||
| import EditReport from './EditReport.tsx'; | ||
|
|
||
| const t = useBoardsTranslations('en'); | ||
| afterEach(() => { cleanup(); vi.unstubAllGlobals(); }); | ||
|
|
||
| const report = (over: Partial<MemberReport>): MemberReport => ({ | ||
| id: 'r-abcd2345', received_at: '2026-10-08T10:00:00Z', status: 'pending', note: 'from a market', | ||
| proposal: { maker: 'Jooan', board: 'Q9' }, stars: 0, pending: 2, | ||
| files: [ | ||
| { position: 1, kind: 'photo', name: 'front.jpg', bytes: 100, url: '', points: 1 }, | ||
| { position: 2, kind: 'photo', name: 'back.jpg', bytes: 100, url: '', points: 1 }, | ||
| ], | ||
| ...over, | ||
| }); | ||
|
|
||
| function capture() { | ||
| const sent: { url: string; form: FormData }[] = []; | ||
| vi.stubGlobal('fetch', vi.fn(async (url: string, init?: RequestInit) => { | ||
| sent.push({ url, form: init?.body as FormData }); | ||
| return new Response(JSON.stringify({ id: 'r-abcd2345', status: 'pending', rereview: false })); | ||
| })); | ||
| return sent; | ||
| } | ||
|
|
||
| test('an edit sends what changed: the note, a photo out, a boot log in', async () => { | ||
| const sent = capture(); | ||
| const saved = vi.fn(); | ||
| const { container, getByText, getByLabelText } = render(<EditReport report={report({})} t={t} onSaved={saved} onCancel={() => {}} />); | ||
| expect(container.textContent).not.toContain('goes back to them'); | ||
| fireEvent.input(getByLabelText('Your note'), { target: { value: 'bought on Ozon as Q9 Pro' } }); | ||
| fireEvent.click(getByText(/back\.jpg/)); | ||
| fireEvent.change(container.querySelector('select')!, { target: { value: 'boot_log' } }); | ||
| fireEvent.change(getByLabelText('Add', { selector: 'input' }), { target: { files: [new File(['U-Boot\n'], 'boot.log')] } }); | ||
| fireEvent.click(getByText('Save')); | ||
| await waitFor(() => expect(saved).toHaveBeenCalled()); | ||
| const f = sent[0].form; | ||
| expect(sent[0].url).toBe('/api/v1/club/reports/r-abcd2345/edit'); | ||
| expect(f.get('note')).toBe('bought on Ozon as Q9 Pro'); | ||
| expect(f.getAll('remove')).toEqual(['2']); | ||
| expect((f.get('boot_log') as File).name).toBe('boot.log'); | ||
| // The camera was not touched, so it is not sent. | ||
| expect(f.get('maker')).toBeNull(); | ||
| }); | ||
|
|
||
| test('a decided report says it goes back for review before it is saved', () => { | ||
| capture(); | ||
| const { getByRole, getByText } = render(<EditReport report={report({ status: 'published' })} t={t} onSaved={() => {}} onCancel={() => {}} />); | ||
| expect(getByRole('note').textContent).toContain('goes back to them'); | ||
| expect(getByText('Save and send for review again')).toBeTruthy(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * A member changing a report of theirs from /club | ||
| * (POST /api/v1/club/reports/{id}/edit): the note, the camera they proposed, | ||
| * files taken out, photos and text added. ipctool's output and a backup stay | ||
| * as sent. A report a maintainer has decided goes back to them: the form says | ||
| * so before it is saved. | ||
| */ | ||
| import { useState } from 'preact/hooks'; | ||
| import type { BoardsT } from '../../lib/boards-i18n'; | ||
| import { editReport, type MemberReport } from '../../lib/club'; | ||
|
|
||
| type AddKind = 'photo' | 'boot_log' | 'uboot_env'; | ||
| const ADD_KINDS: AddKind[] = ['photo', 'boot_log', 'uboot_env']; | ||
| const field = 'rounded-md border border-hairline px-2.5 py-1.5 text-sm text-body'; | ||
|
|
||
| export default function EditReport({ report, t, onSaved, onCancel }: { | ||
| report: MemberReport; t: BoardsT; onSaved: () => void; onCancel: () => void; | ||
| }) { | ||
| const [note, setNote] = useState(report.note ?? ''); | ||
| const [maker, setMaker] = useState(report.proposal?.maker ?? ''); | ||
| const [board, setBoard] = useState(report.proposal?.board ?? ''); | ||
| const [soc, setSoc] = useState(report.proposal?.soc ?? ''); | ||
| const [remove, setRemove] = useState<Set<number>>(new Set()); | ||
| const [kind, setKind] = useState<AddKind>('photo'); | ||
| const [add, setAdd] = useState<File[]>([]); | ||
| const [busy, setBusy] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const decided = report.status === 'published' || report.status === 'rejected'; | ||
|
|
||
| const toggle = (pos: number) => { | ||
| const next = new Set(remove); | ||
| if (next.has(pos)) next.delete(pos); else next.add(pos); | ||
| setRemove(next); | ||
| }; | ||
| const save = (e: Event) => { | ||
| e.preventDefault(); | ||
| const form = new FormData(); | ||
| if (note.trim() !== (report.note ?? '')) form.set('note', note.trim()); | ||
| if (report.proposal && (maker.trim() !== report.proposal.maker || board.trim() !== report.proposal.board || soc.trim() !== (report.proposal.soc ?? ''))) { | ||
| form.set('maker', maker.trim()); | ||
| form.set('board', board.trim()); | ||
| form.set('soc', soc.trim()); | ||
| } | ||
| for (const pos of remove) form.append('remove', String(pos)); | ||
| for (const f of add) form.append(kind, f, f.name); | ||
| setBusy(true); | ||
| setError(null); | ||
| editReport(report.id, form) | ||
| .then(onSaved) | ||
| .catch((err: Error) => setError(t('club.send_failed', { error: err.message }))) | ||
| .finally(() => setBusy(false)); | ||
| }; | ||
|
|
||
| return ( | ||
| <form class="grid gap-2.5 rounded-md border border-hairline bg-surface-alt p-3 text-[13px]" onSubmit={save}> | ||
| {decided && <p class="m-0 rounded-md bg-[#fff4e2] px-3 py-2 text-[#8a4b00]" role="note">{t('club.edit_rereview')}</p>} | ||
| {report.proposal && ( | ||
| <div class="grid gap-2 sm:grid-cols-[1fr_1fr_8rem]"> | ||
| <label class="grid gap-1 text-body-secondary">{t('club.new_maker')} | ||
| <input value={maker} maxLength={80} onInput={(e) => setMaker((e.target as HTMLInputElement).value)} class={field} /> | ||
| </label> | ||
| <label class="grid gap-1 text-body-secondary">{t('club.new_board')} | ||
| <input value={board} maxLength={80} onInput={(e) => setBoard((e.target as HTMLInputElement).value)} class={field} /> | ||
| </label> | ||
| <label class="grid gap-1 text-body-secondary">{t('club.new_soc')} | ||
| <input value={soc} maxLength={40} onInput={(e) => setSoc((e.target as HTMLInputElement).value)} class={field} /> | ||
| </label> | ||
| </div> | ||
| )} | ||
| <label class="grid gap-1 text-body-secondary">{t('club.your_note')} | ||
| <textarea value={note} maxLength={4000} onInput={(e) => setNote((e.target as HTMLTextAreaElement).value)} | ||
| class={`${field} min-h-[56px] resize-y`} /> | ||
| </label> | ||
| {report.files.some((f) => f.kind !== 'backup') && ( | ||
| <fieldset class="m-0 grid gap-1 border-0 p-0"> | ||
| <legend class="mb-1 p-0 text-body-secondary">{t('club.edit_remove')}</legend> | ||
| {report.files.filter((f) => f.kind !== 'backup').map((f) => ( | ||
| <label key={f.position} class="flex items-center gap-2"> | ||
| <input type="checkbox" checked={remove.has(f.position)} onChange={() => toggle(f.position)} /> | ||
| <span class={remove.has(f.position) ? 'line-through text-body-secondary' : ''}>{t(`club.kind_${f.kind}`)} · {f.name}</span> | ||
| </label> | ||
| ))} | ||
| </fieldset> | ||
| )} | ||
| <div class="grid gap-1"> | ||
| <span class="text-body-secondary">{t('club.edit_add')}</span> | ||
| <div class="flex flex-wrap items-center gap-2"> | ||
| <select value={kind} onChange={(e) => { setKind((e.target as HTMLSelectElement).value as AddKind); setAdd([]); }} class={field}> | ||
| {ADD_KINDS.map((k) => <option key={k} value={k}>{t(`club.kind_${k}`)}</option>)} | ||
| </select> | ||
| {/* keyed on the kind: switching it clears what was picked, input and all */} | ||
| <input key={kind} type="file" multiple aria-label={t('club.edit_add')} accept={kind === 'photo' ? 'image/jpeg,image/png,image/webp' : '.txt,.log,text/plain'} | ||
| onChange={(e) => setAdd([...((e.target as HTMLInputElement).files ?? [])])} class="text-sm text-body" /> | ||
| </div> | ||
| </div> | ||
| <div class="flex flex-wrap items-center gap-2"> | ||
| <button type="submit" class="site-btn site-btn-primary site-btn-sm" disabled={busy}>{t(decided ? 'club.edit_save_rereview' : 'club.edit_save')}</button> | ||
| <button type="button" class="site-btn site-btn-outline-secondary site-btn-sm" onClick={onCancel}>{t('club.edit_cancel')}</button> | ||
| {error && <span class="text-[#a3262e]" role="alert">{error}</span>} | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.