// One app card per product, across studios and store accounts. The pairing rules live in cli/lib/identity.ts (shared // with the CLI workspace, `storebound ws`); this file adds the desktop's types and the portfolio list helpers. import type { Project } from '../api'; import type { UnifiedApp as CoreApp } from '../../../../cli/lib/identity'; export { buildApps, type BuildInput, NO_OVERRIDES, normId, normName, type Overrides, type Pair, pairCandidates, type Pairing, refKey, type StoreRef, storeTarget, withIgnored, withLink, withPair, withStudio, withUnpair, } from '../../../../cli/lib/identity'; export type UnifiedApp = CoreApp; // ---- Portfolio list: filter, search, sort, group ---- export type SortBy = 'attention' | 'recent' | 'name'; export interface ListRow { app: UnifiedApp; attention: number; blockers: number; updated: string | null } export function filterSort(rows: ListRow[], o: { studio: string | 'all' | 'none'; query: string; sort: SortBy }): ListRow[] { const q = o.query.trim().toLowerCase(); const hit = (r: ListRow) => !q || [r.app.name, r.app.ios?.app.bundleId, r.app.android?.app.id, r.app.project?.path.split(/[\\/]/).pop()] .some(s => s && s.toLowerCase().includes(q)); const inStudio = (r: ListRow) => o.studio === 'all' || (o.studio === 'none' ? !r.app.studio : r.app.studio === o.studio); const by = { attention: (a: ListRow, b: ListRow) => b.blockers - a.blockers || b.attention - a.attention || a.app.name.localeCompare(b.app.name), recent: (a: ListRow, b: ListRow) => (b.updated ?? '').localeCompare(a.updated ?? '') || a.app.name.localeCompare(b.app.name), name: (a: ListRow, b: ListRow) => a.app.name.localeCompare(b.app.name), }[o.sort]; return rows.filter(r => !r.app.ignored && inStudio(r) && hit(r)).sort(by); } /** Groups by studio in the studios' order, apps without a studio last. */ export function groupByStudio(rows: T[], studios: { id: string }[]): { studio: string | null; rows: T[] }[] { const order = [...studios.map(s => s.id as string | null), null]; const known = new Set(studios.map(s => s.id)); return order.map(id => ({ studio: id, rows: rows.filter(r => (id === null ? !r.app.studio || !known.has(r.app.studio) : r.app.studio === id)) })).filter(g => g.rows.length); } /** Per studio: visible apps (not ignored). */ export function studioCounts(apps: UnifiedApp[]): Record { const m: Record = {}; for (const a of apps) if (!a.ignored) m[a.studio ?? ''] = (m[a.studio ?? ''] ?? 0) + 1; return m; }