Desk: card contract at CultLib 3a51bbab: decider_count, answerer_count, nullable answerer; the counts show when the ids are withheld
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m30s
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m30s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
57f0ef8df2
commit
9e02536e02
7 changed files with 61 additions and 2 deletions
|
|
@ -151,6 +151,34 @@ describe("a question's age", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('counts when the ids are withheld', () => {
|
||||
const withheld = (): ForkList => {
|
||||
const entry = STATES.noAnswers.forks[0];
|
||||
return {
|
||||
...STATES.noAnswers,
|
||||
forks: [
|
||||
{
|
||||
...entry,
|
||||
card: { ...entry.card, deciders: [], decider_count: 3 },
|
||||
record: { ...entry.record, answerer_count: 2 },
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
it('shows how many deciders and answerers there are, naming none', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ScreenSizeProvider value={ScreenSize.Desktop}>
|
||||
<DeskView mind="void" label="Void" list={withheld()} />
|
||||
</ScreenSizeProvider>
|
||||
);
|
||||
expect(html).toContain('3 deciders · 2 answerers');
|
||||
});
|
||||
it('says the singular for one', () => {
|
||||
const html = view('noAnswers', ScreenSize.Desktop);
|
||||
expect(html).toContain('1 decider · 0 answerers');
|
||||
});
|
||||
});
|
||||
|
||||
describe('DeskEntry', () => {
|
||||
afterEach(() => setDeskSource(() => undefined));
|
||||
const entry = (mind: string) =>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import * as css from './DeskView.css';
|
|||
/** Slice 1 has no session: every viewer is signed out, and the note says why it cannot be used. */
|
||||
export const SIGN_IN_NOTE = 'Answering opens with sign-in. Until then you can read the questions.';
|
||||
|
||||
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
||||
|
||||
const date = (iso: string) => iso.slice(0, 10);
|
||||
|
||||
const OUTCOME: Record<AnswerRow['outcome'], string> = {
|
||||
|
|
@ -81,6 +83,9 @@ function Row({ row, now }: { row: DeskRow; now: number }) {
|
|||
{raisedAge(row.raisedAt, now) && (
|
||||
<p className={css.Quiet}>{raisedAge(row.raisedAt, now)}</p>
|
||||
)}
|
||||
<p className={css.Quiet}>
|
||||
{`${plural(row.deciderCount, 'decider')} · ${plural(row.answererCount, 'answerer')}`}
|
||||
</p>
|
||||
<p className={css.Body}>{row.context}</p>
|
||||
<ul className={css.Options}>
|
||||
{row.options.map((o) => (
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ export type DeskRow =
|
|||
depends: string[];
|
||||
/** When the question was first admitted, as served; absent when the card carries none. */
|
||||
raisedAt?: string;
|
||||
/** Counts as served: the same in the decider and the withheld view, so they show either way. */
|
||||
deciderCount: number;
|
||||
answererCount: number;
|
||||
/** In admission order, as served. */
|
||||
answers: AnswerRow[];
|
||||
};
|
||||
|
|
@ -86,6 +89,8 @@ export const buildDesk = (
|
|||
recommended: card.options.find((o) => o.id === card.recommendation)?.text,
|
||||
depends: card.depends,
|
||||
raisedAt: card.raised_at ?? undefined,
|
||||
deciderCount: card.decider_count,
|
||||
answererCount: record.answerer_count,
|
||||
answers: record.answers.map((a) => answerRow(a, entry)),
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export const card = (label: string, over: Partial<ForkCard> = {}): ForkCard => (
|
|||
raised_in: null,
|
||||
raised_at: null,
|
||||
deciders: ['d1'],
|
||||
decider_count: 1,
|
||||
status: 'open',
|
||||
ruling: null,
|
||||
ruled_from: [],
|
||||
|
|
@ -61,6 +62,7 @@ export const entry = (
|
|||
fork_id: c.fork_id,
|
||||
options_hash: c.options_hash,
|
||||
counted_answer_id: counted,
|
||||
answerer_count: new Set(answers.map((a) => a.answerer)).size,
|
||||
answers,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,7 +30,13 @@ export type ForkCard = {
|
|||
* the client's: now minus `raised_at`.
|
||||
*/
|
||||
raised_at: string | null;
|
||||
/**
|
||||
* Who may answer. Empty when this reader is not a decider (the ids are withheld); otherwise it holds exactly
|
||||
* `decider_count` ids.
|
||||
*/
|
||||
deciders: string[];
|
||||
/** How many deciders there are, 1..64: the same number in both reader views. */
|
||||
decider_count: number;
|
||||
status: 'open' | 'closed';
|
||||
/** The ruling id when a ruling closed the fork; nil when open, and nil on a closed card withdrawn with no ruling. */
|
||||
ruling: string | null;
|
||||
|
|
@ -64,7 +70,8 @@ export type DeskAnswer = {
|
|||
answered_at: string;
|
||||
received_at: string;
|
||||
claim_in_future: boolean;
|
||||
answerer: string;
|
||||
/** Who answered; nil when this reader is not a decider (withheld). */
|
||||
answerer: string | null;
|
||||
authority: string;
|
||||
request_id: string;
|
||||
};
|
||||
|
|
@ -75,6 +82,8 @@ export type ForkRecord = {
|
|||
options_hash: string;
|
||||
/** Derived by the receiver; the page renders it and never recomputes it. */
|
||||
counted_answer_id: string | null;
|
||||
/** Distinct answerers over every stored answer, refusals included, at least 0: the same number in both views. */
|
||||
answerer_count: number;
|
||||
/** In admission order. */
|
||||
answers: DeskAnswer[];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,13 +20,21 @@ const KEYS = {
|
|||
'raised_in',
|
||||
'raised_at',
|
||||
'deciders',
|
||||
'decider_count',
|
||||
'status',
|
||||
'ruling',
|
||||
'ruled_from',
|
||||
'order',
|
||||
'options_hash',
|
||||
],
|
||||
record: ['schemaVersion', 'fork_id', 'options_hash', 'counted_answer_id', 'answers'],
|
||||
record: [
|
||||
'schemaVersion',
|
||||
'fork_id',
|
||||
'options_hash',
|
||||
'counted_answer_id',
|
||||
'answerer_count',
|
||||
'answers',
|
||||
],
|
||||
answer: [
|
||||
'schemaVersion',
|
||||
'answer_id',
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ const card = (label: string, order: number, over: Partial<ForkCard>): ForkCard =
|
|||
raised_in: null,
|
||||
raised_at: null,
|
||||
deciders: ['demo-decider'],
|
||||
decider_count: 1,
|
||||
status: 'open',
|
||||
ruling: null,
|
||||
ruled_from: [],
|
||||
|
|
@ -75,6 +76,7 @@ const entry = (
|
|||
fork_id: c.fork_id,
|
||||
options_hash: c.options_hash,
|
||||
counted_answer_id: counted,
|
||||
answerer_count: new Set(answers.map((a) => a.answerer)).size,
|
||||
answers,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue