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.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ All notable changes to OpenSignup are documented here. Format follows [Keep a Ch
- A Number field with values in it can be changed to Text or a List (#783). The change was refused with "change would invalidate existing slot values", and the values couldn't be turned into text first because a Number field refuses text, so the only way through was to clear every slot's value and type them in again. The stored numbers now become text as written (`2.5` becomes "2.5"), in the same save as the type change; a change to a List still needs every number among its choices, and Text that's too short for a number is still refused. `field.updated` records how many slots it changed as `convertedSlotValues`. Text to Number is still refused when a slot holds words.
- A field change after a participant's reminder went out no longer sends them a second reminder saying their slot's time changed (#1041). Retyping a text field to Time, deleting a Time field or changing which date field reminders follow gives slots a new time to remind from without moving them, and the reminder job took that for a move. A reminder now goes out again only when the organizer moves the slot after it, and reads "Time changed" only when the slot's time is one the organizer moved it to, as the email about a moved slot already did.
- On the Build tab, hovering a slot row or tabbing into it no longer hides its "0 of 6 taken" count under the row's Edit, Duplicate and Delete buttons (#593). While the buttons show, the count moves left to sit beside them, and the row's other text gives up the room; a row at rest looks as before.
- The number beside a signup's **Build** tab now counts its slots (#597). It added slots and fields together, so 4 slots and 3 fields read "Build 7", and it changed only on a reload. Adding, duplicating or deleting a slot now changes it at once, and Responses and Settings show the new number too. A screen reader hears what it counts, "Build 4 slots", where it heard "Build 7".
- Building the Docker image works again. `pnpm build` stopped with "Invalid environment" while prerendering `/login`, because the sign-in layout and the page's title read the instance's language (`DEFAULT_LOCALE`) through the server settings, and an image build has only the `NEXT_PUBLIC_*` values. `/login` is now rendered for each request, as `/login/check` and `/login/confirm` already were, so `DEFAULT_LOCALE` is read when the app runs, as its documentation says, never baked in at build time. Builds that have the full server settings (CI, a local `.env.local`) never showed the problem.
- Clicking **Disconnect** on Settings → Connected apps for an app that was already disconnected, from another tab say, now says "That app is already disconnected." (#882), where it gave the "No longer available." every screen gives something that's gone. Any other failed disconnect now reads "Couldn’t disconnect. Try again." (was "Could not disconnect. Try again."). Both are in Swedish too.
- The organizer pages and the sign-in pages show the site's own name (#881). The breadcrumb's first link on every organizer page, the "Welcome to …" card for an organizer with no workspace, and the "Sign in to …" heading on `/login` and `/login/confirm` typed "OpenSignup"; they now show `NEXT_PUBLIC_INSTANCE_NAME`, as the site header, page titles and help already do. A self-hosted site with its own name no longer shows OpenSignup's. On a site named "OpenSignup" nothing changes. The sign-in email still says "OpenSignup" for now.
Expand Down
2 changes: 1 addition & 1 deletion budgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"/help/[slug]": 113,
"/app/signups/new": 119.8,
"/app/signups/[id]": 130,
"/app/signups/[id]/build": 151.8,
"/app/signups/[id]/build": 152,
"/app/signups/[id]/edit": 130,
"/app/signups/[id]/preview": 130.5,
"/app/signups/[id]/responses": 132,
Expand Down
14 changes: 8 additions & 6 deletions src/app/(organizer)/app/(chrome)/signups/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export default async function SignupDetailLayout({ children, params }: LayoutPro
const publicUrl = publicSignupUrl(sig.slug);
const status = sig.status as SignupStatus;
const aiDraft = getServerTranslator(locale, 'organizer.aiDraft');
const slots = {
count: sig.slots.length,
spoken: getServerTranslator(locale, 'organizer.build.sheet')('slotCount', {
count: sig.slots.length,
}),
};
// The words of the header's client components, the closed box and the
// tabs, passed to them as props.
const text = signupHeaderText(getServerTranslator(locale, 'organizer.signup'));
Expand All @@ -85,7 +91,7 @@ export default async function SignupDetailLayout({ children, params }: LayoutPro
return (
// The header reaches the Build tab through this: Publish saves its edits
// first, and a check's fix opens a slot there.
<BuildBridge buildHref={signupTabPath(id, 'build')}>
<BuildBridge buildHref={signupTabPath(id, 'build')} slots={slots}>
{/* On a phone, a draft's Publish and share or an open signup's Share is in
a bar fixed to the bottom of the screen; the page leaves room for it. */}
<div className={`space-y-6 ${hasPhoneBar(status) ? PHONE_BAR_ROOM : ''}`}>
Expand Down Expand Up @@ -132,11 +138,7 @@ export default async function SignupDetailLayout({ children, params }: LayoutPro
status === 'draft' ? messagesFor(locale, 'organizer.aiDraft.warnings') : null
}
/>
<TabsNav
signupId={id}
counts={{ build: sig.fields.length + sig.slots.length, responses: responsesCount }}
labels={text.tabs}
/>
<TabsNav signupId={id} counts={{ slots, responses: responsesCount }} labels={text.tabs} />
<div>{children}</div>
</div>
</BuildBridge>
Expand Down
4 changes: 2 additions & 2 deletions src/components/build-wysiwyg/BuildWysiwyg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ describe('BuildWysiwyg — opened by Publish’s check', () => {
takesFocus?: boolean;
}) {
return (
<BuildBridge buildHref="/app/signups/sig_t/build">
<BuildBridge buildHref="/app/signups/sig_t/build" slots={{ count: 0, spoken: '0 slots' }}>
<Header onReady={onReady} takesFocus={takesFocus} />
{build ? (
<BuildWysiwyg {...baseProps} initialFields={[what, where]} initialSlots={slots} />
Expand Down Expand Up @@ -964,7 +964,7 @@ describe('BuildWysiwyg — opened by Publish’s check', () => {
);
let bridge: ReturnType<typeof useBuildBridge> | null = null;
render(
<BuildBridge buildHref="/app/signups/sig_t/build">
<BuildBridge buildHref="/app/signups/sig_t/build" slots={{ count: 0, spoken: '0 slots' }}>
<Header onReady={(b) => (bridge = b)} />
<BuildWysiwyg
{...baseProps}
Expand Down
5 changes: 4 additions & 1 deletion src/components/build-wysiwyg/BuildWysiwyg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from 'react';
import { Plus } from 'lucide-react';
import { useTranslations } from 'next-intl';
import { useRegisterBuildTab } from '@/components/signup/BuildBridge';
import { useRegisterBuildTab, useReportSlotCount } from '@/components/signup/BuildBridge';
import {
useBuildState,
type BuildField,
Expand Down Expand Up @@ -277,6 +277,9 @@ function BuildSheet({
// The header's Publish saves what's pending here first, and a check's fix
// opens the slot it's about, here or once this tab has loaded.
const handBack = useRegisterBuildTab({ flushPendingSaves, openSlot });
// The count beside the Build tab, which follows slots as they come and go.
const slotCount = state.rows.length;
useReportSlotCount({ count: slotCount, spoken: t('slotCount', { count: slotCount }) });

// What a row asks for: its own editor, or null when Done or Escape closes
// the one that's open. An editor opened by Enter or Space takes the focus;
Expand Down
59 changes: 56 additions & 3 deletions src/components/signup/BuildBridge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { getTestTranslator } from '@/i18n/testing/translator';
import { BuildBridge, useBuildBridge, useRegisterBuildTab } from './BuildBridge';
import {
BuildBridge,
useBuildBridge,
useRegisterBuildTab,
useReportSlotCount,
} from './BuildBridge';
import { signupHeaderText } from './header-text';
import { TabsNav } from './TabsNav';

Expand All @@ -16,6 +21,9 @@ const BUILD = '/app/signups/sig_1/build';
/** The header's words in English, as the layout passes them. */
const TEXT = signupHeaderText(getTestTranslator('organizer.signup'));

/** Two slots, as the layout passes them. */
const SLOTS = { count: 2, spoken: '2 slots' };

type Bridge = ReturnType<typeof useBuildBridge>;
type Tab = Parameters<typeof useRegisterBuildTab>[0];

Expand All @@ -36,9 +44,9 @@ function BuildTab(tab: Tab) {
function renderBridge(tab: Tab | null) {
let bridge: Bridge | null = null;
const tree = (shown: Tab | null) => (
<BuildBridge buildHref="/app/signups/sig_1/build">
<BuildBridge buildHref="/app/signups/sig_1/build" slots={SLOTS}>
<Header onReady={(b) => (bridge = b)} />
<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={TEXT.tabs} />
<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={TEXT.tabs} />
{shown ? <BuildTab {...shown} /> : null}
</BuildBridge>
);
Expand Down Expand Up @@ -267,4 +275,49 @@ describe('BuildBridge', () => {
expect(handBack()).toBe(false);
expect(phone).toHaveBeenCalledOnce();
});

describe('the count beside Build', () => {
function Slots({ count }: { count: number }) {
useReportSlotCount({ count, spoken: `${count} slots` });
return null;
}

/** The bridge with the tabs, the layout's `slots`, and the Build tab's count while it shows. */
function tree(slots: typeof SLOTS, shown: number | null) {
return (
<BuildBridge buildHref={BUILD} slots={slots}>
<TabsNav signupId="sig_1" counts={{ slots, responses: 0 }} labels={TEXT.tabs} />
{shown === null ? null : <Slots count={shown} />}
</BuildBridge>
);
}

const build = () => screen.getByRole('tab', { name: /^Build/ });

it('counts slots, then follows the Build tab as slots come and go', () => {
const view = render(tree(SLOTS, null));
expect(build()).toHaveTextContent(/^Build22 slots$/);
view.rerender(tree(SLOTS, 2));
view.rerender(tree(SLOTS, 3));
expect(build()).toHaveTextContent(/^Build33 slots$/);
view.rerender(tree(SLOTS, 1));
expect(build()).toHaveAccessibleName(/^Build ?1 slots$/);
});

it('keeps the last count on another tab, which loads nothing again', () => {
const view = render(tree(SLOTS, 2));
view.rerender(tree(SLOTS, 5));
view.rerender(tree(SLOTS, null));
expect(build()).toHaveTextContent(/^Build55 slots$/);
});

it('takes a fresh load’s count over one the Build tab reported before it', () => {
const view = render(tree(SLOTS, 4));
view.rerender(tree(SLOTS, null));
// A Publish or a Settings save loads the layout again, with the
// server's count: a connected assistant may have added slots since.
view.rerender(tree({ count: 6, spoken: '6 slots' }, null));
expect(build()).toHaveTextContent(/^Build66 slots$/);
});
});
});
71 changes: 68 additions & 3 deletions src/components/signup/BuildBridge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use client';

import { createContext, useContext, useEffect, useMemo, useRef, type ReactNode } from 'react';
import {
createContext,
useContext,
useEffect,
useMemo,
useRef,
useState,
type ReactNode,
} from 'react';
import { usePathname, useRouter } from 'next/navigation';

/** What the Build tab lets the header do while it's showing. */
Expand Down Expand Up @@ -37,6 +45,15 @@ interface Bridge extends HeaderBridge {
handBack: () => boolean;
/** Forgets a slot a fix asked Build to open: the organizer went elsewhere. */
dropPending: () => void;
/** The Build tab: how many slots it has now, and those words for a screen reader. */
reportSlots: (slots: SlotCount) => void;
}

/** How many slots a signup has, and the words a screen reader hears for it. */
export interface SlotCount {
count: number;
/** The count in words, such as "4 slots", in the organizer's language. */
spoken: string;
}

const NO_BUILD_TAB: Bridge = {
Expand All @@ -46,10 +63,14 @@ const NO_BUILD_TAB: Bridge = {
openSlot: () => false,
onHandBack: () => () => {},
handBack: () => false,
reportSlots: () => {},
};

const BridgeContext = createContext<Bridge>(NO_BUILD_TAB);

/** The slots the tabs show, apart from the bridge so a change re-renders only them. */
const SlotsContext = createContext<SlotCount | null>(null);

const SAVED = Promise.resolve(true);

/**
Expand All @@ -74,14 +95,36 @@ const SAVED = Promise.resolve(true);
* what matter. And once the organizer has fixed the slot, Done hands focus
* back to Publish and share, through here.
*/
export function BuildBridge({ buildHref, children }: { buildHref: string; children: ReactNode }) {
export function BuildBridge({
buildHref,
slots,
children,
}: {
buildHref: string;
/**
* The slots when the layout loaded. The Build tab's own count replaces it
* once it reports one, and stays after the organizer goes to another tab,
* which doesn't load the layout again; a load that does (a Publish, a
* Settings save) brings a count of its own, which replaces it again.
*/
slots: SlotCount;
children: ReactNode;
}) {
const tab = useRef<BuildTab | null>(null);
// The slot a fix asked Build to open, in a box: null itself means "add one".
const pending = useRef<{ slotId: string | null } | null>(null);
const leaving = useRef(SAVED);
const focusPublish = useRef<(() => void) | null>(null);
const router = useRouter();
const pathname = usePathname();
// What the Build tab last reported, until the layout loads again and
// brings the server's count.
const [shownSlots, setShownSlots] = useState(slots);
const [loaded, setLoaded] = useState(slots);
if (loaded !== slots) {
setLoaded(slots);
setShownSlots(slots);
}
useEffect(() => {
if (pathname !== buildHref) pending.current = null;
}, [pathname, buildHref]);
Expand Down Expand Up @@ -136,17 +179,27 @@ export function BuildBridge({ buildHref, children }: { buildHref: string; childr
focus?.();
return focus !== null;
},
reportSlots: setShownSlots,
}),
[buildHref, router],
);
return <BridgeContext.Provider value={bridge}>{children}</BridgeContext.Provider>;
return (
<BridgeContext.Provider value={bridge}>
<SlotsContext.Provider value={shownSlots}>{children}</SlotsContext.Provider>
</BridgeContext.Provider>
);
}

/** The header's way to the Build tab; does nothing outside a `BuildBridge`. */
export function useBuildBridge(): HeaderBridge {
return useContext(BridgeContext);
}

/** The signup's slots, for the Build tab's count; null outside a `BuildBridge`. */
export function useSlotCount(): SlotCount | null {
return useContext(SlotsContext);
}

/** Forgets a pending fix, for a tab the organizer chooses that isn't Build. */
export function useDropPendingFix(): () => void {
return useContext(BridgeContext).dropPending;
Expand All @@ -173,3 +226,15 @@ export function useRegisterBuildTab(tab: BuildTab): () => boolean {
);
return handBack;
}

/**
* Tells the tabs how many slots the Build tab has, as that changes: adding,
* duplicating or deleting one changes the count beside Build at once.
*/
export function useReportSlotCount(slots: SlotCount): void {
const { reportSlots } = useContext(BridgeContext);
const { count, spoken } = slots;
useEffect(() => {
reportSlots({ count, spoken });
}, [reportSlots, count, spoken]);
}
2 changes: 1 addition & 1 deletion src/components/signup/PublishButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function Header({
page?: ReactNode;
}) {
return (
<BuildBridge buildHref="/app/signups/sig_1/build">
<BuildBridge buildHref="/app/signups/sig_1/build" slots={{ count: 0, spoken: '0 slots' }}>
<HeaderAnnouncer status="draft" announcements={TEXT.announcements}>
<ShareScope
text={SHARE_TEXT}
Expand Down
28 changes: 20 additions & 8 deletions src/components/signup/TabsNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { TabsNav } from './TabsNav';
/** The tabs' names in English, as the layout passes them. */
const LABELS = signupHeaderText(getTestTranslator('organizer.signup')).tabs;

/** Two slots, as the layout passes them. */
const SLOTS = { count: 2, spoken: '2 slots' };

const nav = vi.hoisted(() => ({ pathname: '/app/signups/sig_1/build' }));
vi.mock('next/navigation', () => ({ usePathname: () => nav.pathname }));

Expand All @@ -22,7 +25,7 @@ function layOut() {
this: HTMLElement,
) {
if (this.getAttribute('role') === 'tablist') return STRIP.offsetLeft;
return TAB_LEFT[this.textContent?.replace(/\d+$/, '') ?? ''] ?? 0;
return TAB_LEFT[this.textContent?.replace(/\d.*$/, '') ?? ''] ?? 0;
});
vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(TAB_WIDTH);
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(STRIP.clientWidth);
Expand All @@ -40,7 +43,7 @@ describe('TabsNav', () => {
const scrollIntoView = vi.fn();
Element.prototype.scrollIntoView = scrollIntoView;
layOut();
render(<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={LABELS} />);
render(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />);
expect(scrollIntoView).not.toHaveBeenCalled();
// @ts-expect-error -- jsdom has none; put back as it was.
delete Element.prototype.scrollIntoView;
Expand All @@ -49,7 +52,7 @@ describe('TabsNav', () => {
it('centres the current tab in the strip', () => {
nav.pathname = '/app/signups/sig_1/responses';
layOut();
render(<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={LABELS} />);
render(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />);
// Responses starts 120px into the strip; centring it in 300px leaves 90px
// either side.
expect(screen.getByRole('tablist').scrollLeft).toBe(136 - 16 - (300 - 120) / 2);
Expand All @@ -58,27 +61,36 @@ describe('TabsNav', () => {
it('scrolls again when the tab changes', () => {
layOut();
const { rerender } = render(
<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={LABELS} />,
<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />,
);
nav.pathname = '/app/signups/sig_1/settings';
rerender(<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={LABELS} />);
rerender(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />);
expect(screen.getByRole('tablist').scrollLeft).toBe(256 - 16 - (300 - 120) / 2);
});

it('names the strip and each tab with the words it is given', () => {
render(<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={LABELS} />);
render(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />);
const strip = screen.getByRole('tablist', { name: 'Signup sections' });
expect(strip).toBeInTheDocument();
expect(screen.getAllByRole('tab').map((tab) => tab.textContent)).toEqual([
'Build2',
'Build22 slots',
'Responses0',
'Settings',
]);
});

it("says what Build's number counts, in place of the bare number", () => {
render(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={LABELS} />);
const build = screen.getByRole('tab', { name: /^Build/ });
// jsdom lays nothing out; a browser puts a space before the hidden words.
expect(build).toHaveAccessibleName(/^Build ?2 slots$/);
// Responses keeps its plain number: "Responses, 2" says what it counts.
expect(screen.getByRole('tab', { name: /^Responses/ })).toHaveAccessibleName(/^Responses ?0$/);
});

it('shows the words of another language when given them', () => {
const labels = signupHeaderText(getStandInTranslator('sv', 'organizer.signup')).tabs;
render(<TabsNav signupId="sig_1" counts={{ build: 2, responses: 0 }} labels={labels} />);
render(<TabsNav signupId="sig_1" counts={{ slots: SLOTS, responses: 0 }} labels={labels} />);
expect(
screen.getByRole('tablist', { name: 'organizer.signup.tabs.label in sv' }),
).toBeVisible();
Expand Down
Loading