Skip to content
Open
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ Content lives in JSON files under [`src/data/`](src/data/):

To change content, edit the relevant file and open a pull request.

In `funding.json`, `category` is the funding programme, `ELIXIR` or
`Google Summer of Code`: it titles the grant's card, sets its logo and is
its filter. `funder` is the detailed grant type, e.g. `ELIXIR Strategic
Implementation Study`, shown under the title unless it equals the
programme; it starts with the programme's name. Dates are `YYYY-MM-DD`;
grants are listed by end date (newest first), then start date (oldest
first), then name. `formattedDuration` is
the period as shown on the card; keep it in step with the dates. A new
programme needs its logo in `public/` and an entry in `PROGRAMMES` in
[`src/lib/funding.ts`](src/lib/funding.ts).

The listings (Products, Funding, Contributors) share one filter behaviour
([`src/lib/filters.ts`](src/lib/filters.ts)): several filters can be selected,
and an item is listed if it matches any of them. The selection is kept in the
Expand Down
1 change: 1 addition & 0 deletions public/gsoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions src/app/funding/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { render, screen, within } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import funding from '@/data/funding.json';
import { grantType, sortGrants } from '@/lib/funding';
import FundingPage from './page';

// The grant cards, in display order
const cards = () => screen.getAllByRole('article');

describe('Funding page', () => {
it('shows the stats in order, capitalized like the rest of the site', () => {
render(<FundingPage />);
const labels = screen
.getAllByTestId('stat')
.map((stat) => stat.lastChild?.textContent);
expect(labels).toEqual(['Total grants', 'ELIXIR grants', 'GSoC projects']);
const count = (category: string) =>
funding.filter((grant) => grant.category === category).length;
const values = screen
.getAllByTestId('stat')
.map((stat) => stat.firstChild?.textContent);
expect(values).toEqual(
[funding.length, count('ELIXIR'), count('Google Summer of Code')].map(
String,
),
);
});

it('offers one filter per programme', () => {
render(<FundingPage />);
const filters = within(screen.getByRole('group', { name: 'Filter' }))
.getAllByRole('button')
.map((button) => button.firstChild?.textContent);
expect(filters).toEqual(['ELIXIR', 'Google Summer of Code']);
});

it('sorts grants by end date, start date and name', () => {
render(<FundingPage />);
const titles = cards().map(
(card) => within(card).getByRole('heading', { level: 3 }).textContent,
);
expect(titles).toEqual(sortGrants(funding).map((grant) => grant.project));
});

it('titles each card with its programme, logo and grant type', () => {
render(<FundingPage />);
const sorted = sortGrants(funding);
cards().forEach((card, index) => {
const grant = sorted[index];
const header = within(card);
expect(
header.getByRole('heading', { level: 4 }).textContent,
grant.project,
).toBe(grant.category);
expect(header.getByRole('img').getAttribute('alt')).toBe(
`${grant.category} logo`,
);
const type = card.querySelector('[data-testid="grant-type"]');
expect(type?.textContent ?? null).toBe(grantType(grant));
// The programme is in the title; no badge repeats it
expect(header.queryByText(/^(Grant|GSoC)$/)).toBeNull();
});
});
});
119 changes: 58 additions & 61 deletions src/app/funding/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use client';

import { useMemo, useState } from 'react';
import Image from 'next/image';
import {
Award,
Building2,
Calendar,
HeartHandshake,
Search,
Sparkles,
Users,
X,
} from 'lucide-react';
Expand All @@ -19,33 +18,29 @@ import { Card } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { AnimatedGridPattern } from '@/components/ui/animated-grid-pattern';
import { checkFilterIds, filterId, matchesAny } from '@/lib/filters';
import {
ELIXIR,
type Grant,
grants,
grantType,
GSOC,
PROGRAMMES,
} from '@/lib/funding';
import { useUrlFilters } from '@/lib/use-url-filters';
import { cn } from '@/lib/utils';

import fundingData from '@/data/funding.json';

type FundingItem = {
id: string;
funder: string;
project: string;
recipients: string[];
startDate: string;
endDate: string;
formattedDuration: string;
category: string;
};

const grants = fundingData as FundingItem[];
// The logo of each programme (`category`)
const LOGOS = Object.fromEntries(
PROGRAMMES.map(({ name, logo }) => [name, logo]),
);

// One filter per category, in the order the categories first appear
// One filter per programme, in the order of PROGRAMMES
const categoryOptions = checkFilterIds(
Array.from(new Set(grants.map((grant) => grant.category))).map(
(category) => ({
value: filterId(category),
label: category,
count: grants.filter((grant) => grant.category === category).length,
}),
),
PROGRAMMES.map(({ name }) => ({
value: filterId(name),
label: name,
count: grants.filter((grant) => grant.category === name).length,
})),
);
const categoryIds = categoryOptions.map((option) => option.value);

Expand All @@ -69,10 +64,8 @@ export default function FundingPage() {
}, [query, selected]);

// Stat metrics
const gsocCount = grants.filter((g) =>
g.funder.includes('Google Summer of Code'),
).length;
const elixirCount = grants.filter((g) => g.funder.includes('ELIXIR')).length;
const gsocCount = grants.filter((g) => g.category === GSOC).length;
const elixirCount = grants.filter((g) => g.category === ELIXIR).length;

return (
<main className="relative min-h-screen overflow-hidden bg-background">
Expand Down Expand Up @@ -116,9 +109,9 @@ export default function FundingPage() {

{/* Stats Bar */}
<div className="mx-auto mt-12 grid max-w-3xl grid-cols-3 divide-x rounded-2xl border bg-card/70 p-1 shadow-sm">
<Stat label="Total Grants" value={grants.length} />
<Stat label="GSoC Projects" value={gsocCount} />
<Stat label="ELIXIR Grants" value={elixirCount} />
<Stat label="Total grants" value={grants.length} />
<Stat label="ELIXIR grants" value={elixirCount} />
<Stat label="GSoC projects" value={gsocCount} />
</div>
</div>
</section>
Expand Down Expand Up @@ -205,42 +198,46 @@ export default function FundingPage() {

/* Helper Components */

function FundingCard({ item }: { item: FundingItem }) {
const isGSoC = item.funder.includes('Google Summer of Code');
function FundingCard({ item }: { item: Grant }) {
const logo = LOGOS[item.category];
const type = grantType(item);

return (
<Card className="group relative flex h-full flex-col justify-between overflow-hidden rounded-2xl border bg-card p-5 transition-all duration-300 hover:-translate-y-1 hover:border-primary/30 hover:shadow-xl hover:shadow-primary/5">
<Card
className="group relative flex h-full flex-col justify-between overflow-hidden rounded-2xl border bg-card p-5 transition-all duration-300 hover:-translate-y-1 hover:border-primary/30 hover:shadow-xl hover:shadow-primary/5"
role="article"
>
{/* Background Hover Effect */}
<div className="pointer-events-none absolute -right-10 -top-10 h-32 w-32 rounded-full bg-primary/10 blur-2xl transition-opacity duration-300 opacity-0 group-hover:opacity-100" />

<div className="relative flex-1 space-y-4">
{/* Funder Header Row */}
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-2.5">
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border bg-muted/50 text-primary">
{isGSoC ? (
<Sparkles className="h-4 w-4 text-amber-500" />
) : (
<Building2 className="h-4 w-4 text-blue-500" />
)}
</div>
<div className="min-w-0">
<h4 className="truncate text-xs font-semibold uppercase tracking-wider text-muted-foreground">
{item.funder}
</h4>
</div>
{/* Programme: logo, title and detailed grant type. The logo tile
stays white, as the logos are made for light backgrounds. */}
<div className="flex items-center gap-2.5">
<div className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border bg-white p-1.5">
{logo && (
<Image
alt={`${item.category} logo`}
className="h-full w-full object-contain"
height={24}
src={logo}
width={24}
/>
)}
</div>
<div className="min-w-0">
<h4 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
{item.category}
</h4>
{type && (
<p
className="mt-0.5 text-xs text-muted-foreground"
data-testid="grant-type"
>
{type}
</p>
)}
</div>

<Badge
className={`shrink-0 rounded-full px-2.5 py-0.5 text-[10px] font-medium ${
isGSoC
? 'bg-amber-500/10 text-amber-600 dark:text-amber-400'
: 'bg-blue-500/10 text-blue-600 dark:text-blue-400'
}`}
variant="secondary"
>
{isGSoC ? 'GSoC' : 'Grant'}
</Badge>
</div>

{/* Project Title */}
Expand Down Expand Up @@ -273,7 +270,7 @@ function FundingCard({ item }: { item: FundingItem }) {

function Stat({ value, label }: { value: number; label: string }) {
return (
<div className="px-3 py-4 text-center sm:px-6">
<div className="px-3 py-4 text-center sm:px-6" data-testid="stat">
<div className="text-xl font-bold tracking-tight sm:text-2xl">
{value}
</div>
Expand Down
30 changes: 15 additions & 15 deletions src/app/listing-filters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event';
import { afterEach, describe, expect, it, vi } from 'vitest';
import contributors from '@/data/contributor.json';
import funding from '@/data/funding.json';
import { sortGrants } from '@/lib/funding';
import ContributorsPage from './contributors/page';
import FundingPage from './funding/page';

Expand All @@ -28,32 +29,34 @@ const removeFilters = () =>
screen.queryByRole('button', { name: 'Remove filters' });

describe('Funding page filters', () => {
// Grants in display order
const sorted = sortGrants(funding);
const inCategories = (...categories: string[]) =>
funding
sorted
.filter((grant) => categories.includes(grant.category))
.map((grant) => grant.project);
const count = (...categories: string[]) => inCategories(...categories).length;
const listedGrants = () => listed(funding.map((grant) => grant.project));
const shown = () =>
screen.getByText(/^Showing \d+ of \d+ project grants\.$/).textContent;

it('lists grants of any selected category', async () => {
it('lists grants of any selected programme', async () => {
const user = userEvent.setup();
render(<FundingPage />);
expect(removeFilters()).toBeNull();

await user.click(filterButton(/^ELIXIR Services/));
await user.click(filterButton(/^ELIXIR/));
expect(shown()).toBe(
`Showing ${count('ELIXIR Services')} of ${funding.length} project grants.`,
`Showing ${count('ELIXIR')} of ${funding.length} project grants.`,
);
expect(listedGrants()).toEqual(inCategories('ELIXIR Services'));
expect(listedGrants()).toEqual(inCategories('ELIXIR'));

await user.click(filterButton(/^ELIXIR Platform Tasks/));
await user.click(filterButton(/^Google Summer of Code/));
expect(shown()).toBe(
`Showing ${count('ELIXIR Services', 'ELIXIR Platform Tasks')} of ${funding.length} project grants.`,
`Showing ${funding.length} of ${funding.length} project grants.`,
);
expect(listedGrants()).toEqual(
inCategories('ELIXIR Services', 'ELIXIR Platform Tasks'),
inCategories('ELIXIR', 'Google Summer of Code'),
);

await user.click(removeFilters()!);
Expand All @@ -63,16 +66,13 @@ describe('Funding page filters', () => {
});

it('starts with the filters given in the URL', () => {
window.history.replaceState(null, '', '/funding?filter=elixir-services');
window.history.replaceState(null, '', '/funding?filter=elixir');
render(<FundingPage />);
expect(shown()).toBe(
`Showing ${count('ELIXIR Services')} of ${funding.length} project grants.`,
);
expect(listedGrants()).toEqual(inCategories('ELIXIR Services'));
expect(filterButton(/^ELIXIR Services/)).toHaveAttribute(
'aria-pressed',
'true',
`Showing ${count('ELIXIR')} of ${funding.length} project grants.`,
);
expect(listedGrants()).toEqual(inCategories('ELIXIR'));
expect(filterButton(/^ELIXIR/)).toHaveAttribute('aria-pressed', 'true');
});
});

Expand Down
35 changes: 35 additions & 0 deletions src/data/data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
Service,
} from '@/components/catalog/types';
import contributors from './contributor.json';
import { PROGRAMMES } from '@/lib/funding';
import funding from './funding.json';
import nodesData from './nodes.json';
import productsData from './product.json';
import { GA4GH_DRIVER_PROJECT_URL } from '@/lib/site';
Expand Down Expand Up @@ -116,6 +118,39 @@ describe('nodes.json', () => {
);
});

describe('funding.json', () => {
it.each(PROGRAMMES.map(({ name, logo }) => [name, logo]))(
'has the logo of %s',
(_, logo) => {
expect(publicFile(logo), logo).toBe(true);
},
);

it.each(PROGRAMMES.map(({ name }) => [name]))('has grants of %s', (name) => {
expect(funding.some((grant) => grant.category === name)).toBe(true);
});

it('has unique ids', () => {
expect(duplicates(funding.map((grant) => grant.id))).toEqual([]);
});

it.each(funding.map((grant) => [grant.project, grant] as const))(
'%s names its programme and dates',
(_, grant) => {
// The programme is the card's title, filter and logo
expect(PROGRAMMES.map(({ name }) => name)).toContain(grant.category);
expect(grant.funder.startsWith(grant.category)).toBe(true);
// ISO dates, as the listing sorts them as text
expect(grant.startDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
expect(grant.endDate).toMatch(/^\d{4}-\d{2}-\d{2}$/);
expect(grant.startDate <= grant.endDate).toBe(true);
expect(grant.project).toBeTruthy();
expect(grant.recipients.length).toBeGreaterThan(0);
expect(grant.formattedDuration).toBeTruthy();
},
);
});

describe('contributor.json', () => {
it('only references images that exist', () => {
const missing = contributors
Expand Down
Loading