SearchAndFilter
Encontrar una cosa entre cientos: palabras para buscar, filtros que se ven como chips, un orden, y un conteo que dice cuántos coinciden. Si nada coincide, se dice qué se pidió y hay un camino de vuelta.
import { SearchInput, FilterBar, SortMenu } from '@sypnia/ui/react'
En un computador
Busca «refunds», filtra por estado, cambia el orden. El conteo lo sigue.
Despliegues
Cada versión de northwind-shop que se construyó, la más nueva primero.
| Despliegue | Estado | Entorno | Cuándo | Construcción |
|---|---|---|---|---|
Fix rounding in refunds9f3a2c1…9f3a2c1a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | En línea | Vista previa · Ana Ruiz | ahora | 38 s |
Move images to the new bucket9f3c1b0…9f3c1b0a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Kenji Mori | hace 5 horas | 1 min |
Speed up the product search9f3e09f…9f3e09fa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Marta Gil | hace 11 horas | 2 min |
Bump dependencies9f3ff8e…9f3ff8ea3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Vista previa · Luis Ortega | hace 16 horas | 59 s |
Retry webhooks on 5029f41e7d…9f41e7da3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Falló | Producción · Ana Ruiz | hace 21 horas | 2 min |
Add the refunds table9f43d6c…9f43d6ca3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Kenji Mori | ayer | 43 s |
Show stock on the product page9f45c5b…9f45c5ba3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Vista previa · Marta Gil | ayer | 1 min |
Update the checkout copy9f47b4a…9f47b4aa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Luis Ortega | anteayer | 2 min |
Fix rounding in refunds9f49a39…9f49a39a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Ana Ruiz | anteayer | 1 min |
Move images to the new bucket9f4b928…9f4b928a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Cancelado | Vista previa · Kenji Mori | anteayer | 2 min |
Speed up the product search9f4d817…9f4d817a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Marta Gil | anteayer | 48 s |
Bump dependencies9f4f706…9f4f706a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Luis Ortega | anteayer | 1 min |
Retry webhooks on 5029f515f5…9f515f5a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Vista previa · Ana Ruiz | hace 3 días | 2 min |
Add the refunds table9f534e4…9f534e4a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Kenji Mori | hace 3 días | 1 min |
Show stock on the product page9f553d3…9f553d3a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Marta Gil | hace 3 días | 2 min |
Update the checkout copy9f572c2…9f572c2a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Falló | Vista previa · Luis Ortega | hace 3 días | 53 s |
Fix rounding in refunds9f591b1…9f591b1a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Ana Ruiz | hace 4 días | 2 min |
Move images to the new bucket9f5b0a0…9f5b0a0a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Kenji Mori | hace 4 días | 2 min |
Speed up the product search9f5cf8f…9f5cf8fa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Vista previa · Marta Gil | hace 4 días | 1 min |
Bump dependencies9f5ee7e…9f5ee7ea3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a | Listo | Producción · Luis Ortega | hace 4 días | 2 min |
Código
import { useMemo, useState } from 'react';
import {
Badge, Button, EmptyState, FilterBar, Hash, LiveRegion, Page, PageHeader, SearchInput, SkeletonOf, SkeletonWords, SortMenu, Table, TableToolbar,
useSypnia, type DataFilters, type DataSort,
} from '@sypnia/ui/react';
// Finding one thing among hundreds: words to search, filters that show as chips, an order, and a count that says how
// many match. Nothing matching is said with what was asked and a way back. The table paginates and says which rows
// are on screen.
type Deploy = { id: string; commit: string; message: string; env: 'production' | 'preview'; status: 'live' | 'ready' | 'failed' | 'cancelled'; author: string; at: number; secs: number };
const en = {
title: 'Deploys', lead: 'Every version of northwind-shop that was built, newest first.', search: 'Search deploys', searchHint: 'Commit message or hash',
filters: 'Filter deploys', env: 'Environment', status: 'Status', author: 'Author', authorHint: 'Name', sort: 'Order', newest: 'Date', duration: 'Build time',
deploy: 'Deploy', when: 'When', time: 'Build time', count: (n: number, all: number) => (n === all ? `${all} deploys` : `${n} of ${all} deploys match`),
envs: { production: 'Production', preview: 'Preview' }, statuses: { live: 'Live', ready: 'Ready', failed: 'Failed', cancelled: 'Cancelled' },
none: (q: string) => (q ? `No deploy matches «${q}» with these filters` : 'No deploy matches these filters'), noneBody: 'Try fewer words, or clear the filters to see every deploy.', clear: 'Clear search and filters',
failed: 'The deploys could not be loaded. Nothing changed in your project.',
};
const es: typeof en = {
title: 'Despliegues', lead: 'Cada versión de northwind-shop que se construyó, la más nueva primero.', search: 'Buscar despliegues', searchHint: 'Mensaje o hash del commit',
filters: 'Filtrar despliegues', env: 'Entorno', status: 'Estado', author: 'Autor', authorHint: 'Nombre', sort: 'Orden', newest: 'Fecha', duration: 'Tiempo de construcción',
deploy: 'Despliegue', when: 'Cuándo', time: 'Construcción', count: (n: number, all: number) => (n === all ? `${all} despliegues` : `${n} de ${all} despliegues coinciden`),
envs: { production: 'Producción', preview: 'Vista previa' }, statuses: { live: 'En línea', ready: 'Listo', failed: 'Falló', cancelled: 'Cancelado' },
none: (q: string) => (q ? `Ningún despliegue coincide con «${q}» y estos filtros` : 'Ningún despliegue coincide con estos filtros'), noneBody: 'Prueba con menos palabras, o borra los filtros para ver todos los despliegues.', clear: 'Borrar búsqueda y filtros',
failed: 'No se pudieron cargar los despliegues. Nada cambió en tu proyecto.',
};
const messages = ['Fix rounding in refunds', 'Add the refunds table', 'Speed up the product search', 'Update the checkout copy', 'Retry webhooks on 502', 'Move images to the new bucket', 'Show stock on the product page', 'Bump dependencies'];
const people = ['Ana Ruiz', 'Luis Ortega', 'Marta Gil', 'Kenji Mori'];
const now = Date.UTC(2026, 10, 17, 15);
const all: Deploy[] = Array.from({ length: 132 }, (_, i) => ({
id: `dpl_${(9137 - i).toString(36)}`, commit: (0x9f3a2c1 + i * 7919).toString(16).padEnd(40, 'a3c9'), message: messages[(i * 5) % messages.length],
env: i % 3 === 0 ? 'preview' : 'production', status: i === 0 ? 'live' : i % 11 === 4 ? 'failed' : i % 17 === 9 ? 'cancelled' : 'ready',
author: people[(i * 3) % 4], at: now - i * 5.3 * 3600e3, secs: 38 + ((i * 37) % 90),
}));
const tone = { live: 'light', ready: 'ok', failed: 'fail', cancelled: 'neutral' } as const;
export default function SearchAndFilter({ state = 'ready' }: { state?: 'ready' | 'loading' | 'none' | 'error' }) {
const { locale, format } = useSypnia();
const c = locale.startsWith('es') ? es : en;
const [query, setQuery] = useState(state === 'none' ? 'invoice pdf' : '');
const [filters, setFilters] = useState<DataFilters>(state === 'none' ? { env: 'production' } : {});
const [sort, setSort] = useState<DataSort | null>({ id: 'at', dir: 'descending' });
const [failed, setFailed] = useState(state === 'error');
const shown = useMemo(() => {
const q = query.trim().toLowerCase();
const out = all.filter((d) => (!q || `${d.message} ${d.commit}`.toLowerCase().includes(q))
&& (!filters.env || d.env === filters.env) && (!filters.status || d.status === filters.status)
&& (!filters.author || d.author.toLowerCase().includes(filters.author.toLowerCase())));
if (sort) out.sort((a, b) => (sort.id === 'secs' ? a.secs - b.secs : a.at - b.at) * (sort.dir === 'ascending' ? 1 : -1));
return out;
}, [query, filters, sort]);
// Loading: the real page. The search, order and filters are the person's, so they are there; the deploys are a page
// of rows (and the pagination bar: there were more than a page last time), each value as long as a real one.
const loading = state === 'loading';
const was = (i: number) => all[i % all.length];
const fields = [
{ id: 'env', label: c.env, type: 'select' as const, options: (['production', 'preview'] as const).map((v) => ({ value: v, label: c.envs[v] })) },
{ id: 'status', label: c.status, type: 'select' as const, options: (['live', 'ready', 'failed', 'cancelled'] as const).map((v) => ({ value: v, label: c.statuses[v] })) },
{ id: 'author', label: c.author, placeholder: c.authorHint },
];
const clear = () => { setQuery(''); setFilters({}); };
return (
<Page>
<PageHeader title={c.title} lead={c.lead} />
<form role="search" aria-label={c.search} onSubmit={(e) => e.preventDefault()}>
<TableToolbar label={c.search} actions={<SortMenu value={sort} onChange={setSort} options={[{ id: 'at', label: c.newest }, { id: 'secs', label: c.duration }]} />}>
<SearchInput aria-label={c.search} placeholder={c.searchHint} value={query} onChange={(e) => setQuery(e.target.value)} />
</TableToolbar>
</form>
<FilterBar label={c.filters} fields={fields} values={filters} onChange={setFilters} />
<LiveRegion visible={false}>{c.count(shown.length, all.length)}</LiveRegion>
<Table label={c.title} rows={failed || loading ? undefined : shown} rowKey={(d) => d.id} pageSize={20} loading={loading} loadingRows={all.length}
error={failed ? c.failed : undefined} onRetry={() => setFailed(false)}
toolbar={loading ? <SkeletonOf><Badge tone="neutral">{c.count(all.length, all.length)}</Badge></SkeletonOf> : <Badge tone="neutral">{c.count(shown.length, all.length)}</Badge>}
empty={<EmptyState icon="search" compact title={c.none(query.trim())} actions={<Button onClick={clear}>{c.clear}</Button>}>{c.noneBody}</EmptyState>}
columns={[
{ id: 'deploy', header: c.deploy, cell: (d) => <span><b>{d.message}</b><br /><Hash value={d.commit} label="commit" /></span>,
skeleton: (i) => <span><b><SkeletonWords>{was(i).message}</SkeletonWords></b><br /><SkeletonOf><Hash value={was(i).commit} label="commit" /></SkeletonOf></span> },
{ id: 'status', header: c.status, cell: (d) => <Badge tone={tone[d.status]} dot>{c.statuses[d.status]}</Badge>, skeleton: (i) => <SkeletonOf><Badge dot>{c.statuses[was(i).status]}</Badge></SkeletonOf> },
{ id: 'env', header: c.env, cell: (d) => `${c.envs[d.env]} · ${d.author}`, skeleton: (i) => <SkeletonWords>{`${c.envs[was(i).env]} · ${was(i).author}`}</SkeletonWords> },
{ id: 'at', header: c.when, cell: (d) => format.relative(new Date(d.at), now), skeleton: (i) => <SkeletonWords>{format.relative(new Date(was(i).at), now)}</SkeletonWords> },
{ id: 'secs', header: c.time, numeric: true, cell: (d) => format.duration(d.secs * 1000), skeleton: (i) => <SkeletonWords>{format.duration(was(i).secs * 1000)}</SkeletonWords> },
]} />
</Page>
);
} En un celular
En un celular los filtros van de a dos y cada despliegue es una tarjeta.
Nada coincide
Las palabras y los filtros se quedan, y un botón los borra.
Despliegues
Cada versión de northwind-shop que se construyó, la más nueva primero.
Ningún despliegue coincide con «invoice pdf» y estos filtros
Skeleton
La búsqueda, el orden y los filtros se quedan (son de la persona); la tabla dibuja una página de filas del tamaño de despliegues reales, y la barra de paginación.
Despliegues
Cada versión de northwind-shop que se construyó, la más nueva primero.
| Despliegue | Estado | Entorno | Cuándo | Construcción |
|---|---|---|---|---|