better-supabase 0.63.2 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-base-DXF0tNJJ.js → adapter-base-BWp_GpBq.js} +1 -1
- package/dist/{api-DhCLHpIU.js → api-TwaJ4nS8.js} +1 -1
- package/dist/astro/index.js +3 -3
- package/dist/{build-Vd4JkaqJ.js → build-CF_wE706.js} +1 -1
- package/dist/cli/{add-B8H-eHVK.js → add-CAEF20DB.js} +9 -9
- package/dist/cli/{add-DzsB2EMd.js → add-DAbzG8-C.js} +2 -2
- package/dist/cli/add-bP1hqEPB.js +1 -0
- package/dist/cli/{app-table-files-BNbkk4mU.js → app-table-files-BNnw-4C9.js} +3 -3
- package/dist/cli/{app-tables-B9xoTgSg.js → app-tables-D2TRhx62.js} +2 -2
- package/dist/cli/{backfill-DxGGF0tw.js → backfill-DgqbUamk.js} +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-zWXWOGcv.js → blocks-CWVG1w3P.js} +1 -1
- package/dist/cli/{blocks-xgk0tdfI.js → blocks-DykCgrRb.js} +1 -1
- package/dist/cli/{cache-DGTzqvsc.js → cache-JroD4zCO.js} +1 -1
- package/dist/cli/{codemod-C63P8ybN.js → codemod-CAz5XmH0.js} +4 -4
- package/dist/cli/{codemod-naming-wb0ni9VH.js → codemod-naming-DtzMgEs7.js} +1 -1
- package/dist/cli/{column-renames-Cw-VJmbc.js → column-renames-DcEFMXX4.js} +2 -2
- package/dist/cli/{content-mapper-DXjq7Wfl.js → content-mapper-DQczPByw.js} +1 -1
- package/dist/cli/{dev-r1oRNl1e.js → dev-Bwy7jmxv.js} +3 -3
- package/dist/cli/{doctor-BHIIEqOU.js → doctor-BjwgIEEk.js} +17 -17
- package/dist/cli/{emit-C6S__22g.js → emit-D1NL_ewe.js} +2 -2
- package/dist/cli/{gen-DWNQMbqr.js → gen-5GahcSRz.js} +3 -3
- package/dist/cli/{gen-tasks-D0_qerE6.js → gen-tasks-BNqtXDSZ.js} +9 -9
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +7 -7
- package/dist/cli/{init-DiYhhVtO.js → init-DwJ-fzKE.js} +8 -8
- package/dist/cli/{live-C7AMtQsQ.js → live-hA0NkWeP.js} +2 -2
- package/dist/cli/{mcp-DaymIFzT.js → mcp-BpU-r3at.js} +2 -2
- package/dist/cli/{memo-backend-DaO-IuUk.js → memo-backend-jPoQR64l.js} +1 -1
- package/dist/cli/{metadata-CsSZ8mZc.js → metadata-DsItgHac.js} +4 -4
- package/dist/cli/{migrate-Ceai0fte.js → migrate-bs8m1S4X.js} +1 -1
- package/dist/cli/{migration-safety-BXKmX5ar.js → migration-safety-CYnC7qr0.js} +1 -1
- package/dist/cli/{module-migration-ueN8AWpK.js → module-migration-DI1bC407.js} +1 -1
- package/dist/cli/{partition-DMv3-JOr.js → partition-B_o9eCEl.js} +1 -1
- package/dist/cli/powersync-BeiG2uAK.js +1 -0
- package/dist/cli/{powersync-QpdoYTM1.js → powersync-CYzLue5S.js} +3 -3
- package/dist/cli/{print-CQe9SQD_.js → print-CX3mfrR4.js} +2 -2
- package/dist/cli/{providers-DocDgHot.js → providers-C_0X8CZ5.js} +1 -1
- package/dist/cli/{prune-workflows-w_4KdMR9.js → prune-workflows-BRymSktV.js} +1 -1
- package/dist/cli/{remove-DvnCBCVe.js → remove-Ddd7JMeU.js} +6 -6
- package/dist/cli/{render-X1jNuye8.js → render-D0JOrrdH.js} +4 -4
- package/dist/cli/{render-cache-Be5Sm_Eu.js → render-cache-B6_cW4jQ.js} +1 -1
- package/dist/cli/{run-BoLLvybx.js → run-CRbd_qI2.js} +30 -30
- package/dist/cli/{run-72NxM1zM.js → run-CivaFfvS.js} +101 -21
- package/dist/cli/{shared-BR48oJN4.js → shared-77CYy2Ff.js} +1 -1
- package/dist/cli/{source-aefKuXMY.js → source-H6tArdAg.js} +1 -1
- package/dist/cli/{spec-Dvz-C4MP.js → spec-Bn4ArkKk.js} +2 -2
- package/dist/cli/{spec-CxtMMgXM.js → spec-CKr1A_Oo.js} +1 -1
- package/dist/cli/{sql-layout-B2fda2KP.js → sql-layout--Tblsahr.js} +2 -2
- package/dist/cli/{squash-D7KwCZHj.js → squash-BdHHGvSy.js} +1 -1
- package/dist/cli/{sync-DvD3jbb4.js → sync-koAHC0Xq.js} +4 -4
- package/dist/cli/{upgrade-hDU5DI6_.js → upgrade-B6MOyby0.js} +5 -5
- package/dist/cli/{upgrade-C6Pw49Jc.js → upgrade-D9dPPfIy.js} +5 -5
- package/dist/cli/{version-CiDgdPUD.js → version-3_JBFBjw.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/native/index.js +2 -2
- package/dist/{composite-C13UCNgm.js → composite-RorL_F8I.js} +1 -1
- package/dist/config/index.js +4 -4
- package/dist/{config-1kAVpZc_.js → config-BuZW7wNr.js} +3 -3
- package/dist/{config-L5_4kg24.js → config-ocvgjLWV.js} +1 -1
- package/dist/create/index.js +3 -3
- package/dist/create/lite/index.js +4 -4
- package/dist/{define-runtime-BbNPkt-5.js → define-runtime-DQC2Gjdr.js} +4 -0
- package/dist/{define-runtime-full-gpz09qAj.js → define-runtime-full-BIrEQWJR.js} +1 -1
- package/dist/edge/index.js +4 -4
- package/dist/{executor-DABWqMfV.js → executor-D7avvqx3.js} +1 -1
- package/dist/expo/index.js +3 -3
- package/dist/{former-permission-keys-FPrqQHXf.js → former-permission-keys-DVwR65bj.js} +1 -1
- package/dist/{framework-BQgHM3zD.js → framework-DxCx0pmS.js} +1 -1
- package/dist/generators/factories/index.js +1 -1
- package/dist/generators/json-schema/index.js +1 -1
- package/dist/generators/nuqs/index.js +1 -1
- package/dist/generators/standard-schema/index.js +1 -1
- package/dist/generators/valibot/index.js +1 -1
- package/dist/generators/zod/index.js +1 -1
- package/dist/hono/index.js +3 -3
- package/dist/{index-B2NJNoRd.d.ts → index-CwvF-r09.d.ts} +8 -0
- package/dist/{instances-PZAWgQEX.js → instances-B9oCgEOH.js} +76 -0
- package/dist/{json-schema-BwfI_jJ2.js → json-schema-BuzopJOK.js} +1 -1
- package/dist/mapper/bin.js +5 -5
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/sdk/index.js +1 -1
- package/dist/{mcp-Cif2SnK4.js → mcp-BCP-kBjf.js} +3 -3
- package/dist/next/index.js +2 -2
- package/dist/orpc/index.js +2 -2
- package/dist/otel/index.js +5 -5
- package/dist/{ports-ClJbgoyt.js → ports-BfHdHz1e.js} +1 -1
- package/dist/powersync/index.js +1 -1
- package/dist/preset/index.js +3 -3
- package/dist/{preset-BcwGsW_B.js → preset-DrfMF0Hv.js} +2 -2
- package/dist/{project-DYyr_iyu.js → project-BdZTXDVG.js} +5 -5
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/server.d.ts +1 -1
- package/dist/react/server.js +1 -1
- package/dist/{react-hb2gg5UV.js → react-BkLf1aNc.js} +14 -1
- package/dist/react-router/index.js +3 -3
- package/dist/server/index.js +4 -4
- package/dist/{server-B0T944J9.js → server-DpcMKAt_.js} +1 -1
- package/dist/solid-start/index.js +3 -3
- package/dist/spec/index.js +2 -2
- package/dist/sql/index.js +2 -2
- package/dist/{sql-DPpcMNUF.js → sql-B3e0Ji-Q.js} +79 -3
- package/dist/sqlite/index.js +1 -1
- package/dist/sveltekit/index.js +3 -3
- package/dist/tanstack-start/index.js +3 -3
- package/dist/testing/index.js +3 -3
- package/dist/{version-B9H4YoiS.js → version-Adj2H6dY.js} +1 -1
- package/dist/webmcp/index.js +1 -1
- package/package.json +1 -1
- package/skills/better-supabase/references/ui-recipes.md +1174 -532
- package/dist/cli/add-BpikP7u5.js +0 -1
- package/dist/cli/powersync-CEhwfawV.js +0 -1
|
@@ -378,124 +378,447 @@ A search dialog over the search index, with favorites and recents before the use
|
|
|
378
378
|
Web, with shadcn components:
|
|
379
379
|
|
|
380
380
|
```bash
|
|
381
|
-
npx shadcn add button dialog
|
|
381
|
+
npx shadcn add button command dialog kbd
|
|
382
382
|
```
|
|
383
383
|
|
|
384
384
|
```bash
|
|
385
385
|
npx shadcn add @better-supabase/use-search
|
|
386
386
|
```
|
|
387
387
|
|
|
388
|
-
```tsx title="apps/examples/nextjs/src/features/search/components/command-
|
|
388
|
+
```tsx title="apps/examples/nextjs/src/features/search/components/command-center.tsx"
|
|
389
389
|
"use client";
|
|
390
390
|
|
|
391
|
-
import {
|
|
392
|
-
import { useExtracted } from "next-intl";
|
|
391
|
+
import type { LucideIcon } from "lucide-react";
|
|
393
392
|
|
|
393
|
+
import { useTheme } from "@wrksz/themes/client";
|
|
394
|
+
import {
|
|
395
|
+
ArrowRightIcon,
|
|
396
|
+
BotIcon,
|
|
397
|
+
ClockIcon,
|
|
398
|
+
CompassIcon,
|
|
399
|
+
LanguagesIcon,
|
|
400
|
+
MonitorIcon,
|
|
401
|
+
MoonIcon,
|
|
402
|
+
PlusIcon,
|
|
403
|
+
RotateCwIcon,
|
|
404
|
+
SearchIcon,
|
|
405
|
+
StarIcon,
|
|
406
|
+
SunIcon,
|
|
407
|
+
UserPlusIcon,
|
|
408
|
+
} from "lucide-react";
|
|
409
|
+
import { hasLocale, useExtracted, useLocale } from "next-intl";
|
|
410
|
+
import { useState } from "react";
|
|
411
|
+
|
|
412
|
+
import type { CommandSearchItem } from "@/hooks/use-search";
|
|
413
|
+
|
|
414
|
+
import { Alert, AlertDescription, AlertTitle } from "@/components/reui/alert";
|
|
394
415
|
import { Button } from "@/components/ui/button";
|
|
395
416
|
import {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
417
|
+
CommandDialog,
|
|
418
|
+
Command,
|
|
419
|
+
CommandGroup,
|
|
420
|
+
CommandInput,
|
|
421
|
+
CommandItem,
|
|
422
|
+
CommandList,
|
|
423
|
+
CommandSeparator,
|
|
424
|
+
} from "@/components/ui/command";
|
|
425
|
+
import { Kbd, KbdGroup } from "@/components/ui/kbd";
|
|
426
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
427
|
+
import { CreateOrganizationDialog } from "@/features/organization/components/create-organization-dialog";
|
|
403
428
|
import { useCommandSearch } from "@/hooks/use-search";
|
|
404
|
-
import {
|
|
429
|
+
import { usePathname, useRouter, toAppHref } from "@/i18n/navigation";
|
|
430
|
+
import { routing } from "@/i18n/routing";
|
|
405
431
|
import { searchConfig } from "@/lib/supabase/blocks/slices";
|
|
406
432
|
|
|
433
|
+
import { useSubjectTypeLabel } from "../use-subject-type-label";
|
|
434
|
+
import { CommandSearchTrigger } from "./command-search-trigger";
|
|
435
|
+
import { OrganizationCommands } from "./organization-commands";
|
|
436
|
+
|
|
437
|
+
/** A page of the side menu the caller may open. */
|
|
438
|
+
export interface CommandPage {
|
|
439
|
+
readonly id: string;
|
|
440
|
+
/** Without the locale prefix. */
|
|
441
|
+
readonly href: string;
|
|
442
|
+
readonly label: string;
|
|
443
|
+
}
|
|
444
|
+
|
|
407
445
|
/** The API schema `gen` wrote for the search block. */
|
|
408
446
|
const API_SCHEMA = searchConfig.api;
|
|
409
447
|
|
|
410
|
-
/**
|
|
411
|
-
|
|
412
|
-
const t = useExtracted("search");
|
|
413
|
-
const search = useCommandSearch({ schema: API_SCHEMA });
|
|
448
|
+
/** Pages listed before the user types; typing searches all of them. */
|
|
449
|
+
const PAGES_WHEN_EMPTY = 6;
|
|
414
450
|
|
|
415
|
-
|
|
416
|
-
if (key === "favorites") {
|
|
417
|
-
return t("Favorites");
|
|
418
|
-
}
|
|
451
|
+
const LOCALE_NAMES = { en: "English", nl: "Nederlands" } as const;
|
|
419
452
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
453
|
+
/** Every word of `query` appears in one of the texts. */
|
|
454
|
+
function matches(query: string, ...texts: readonly string[]): boolean {
|
|
455
|
+
const haystack = texts.join(" ").toLowerCase();
|
|
456
|
+
|
|
457
|
+
return query
|
|
458
|
+
.toLowerCase()
|
|
459
|
+
.split(/\s+/)
|
|
460
|
+
.filter((word) => word !== "")
|
|
461
|
+
.every((word) => haystack.includes(word));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
interface CommandAction {
|
|
465
|
+
readonly id: string;
|
|
466
|
+
readonly label: string;
|
|
467
|
+
readonly keywords: string;
|
|
468
|
+
readonly icon: LucideIcon;
|
|
469
|
+
readonly run: () => void;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Cmd+K over the app: records from every subject the search block indexes (one
|
|
474
|
+
* call to `search(q)` per typing burst, answered by Postgres under the caller's
|
|
475
|
+
* access), recents and favorites, actions, and the pages of the menu. The code
|
|
476
|
+
* loads on the first intent (ADR 0483), so it stays out of every route's first
|
|
477
|
+
* load.
|
|
478
|
+
*/
|
|
479
|
+
export function CommandCenter({
|
|
480
|
+
pages,
|
|
481
|
+
canCreateCustomer,
|
|
482
|
+
}: {
|
|
483
|
+
pages: readonly CommandPage[];
|
|
484
|
+
canCreateCustomer: boolean;
|
|
485
|
+
}) {
|
|
486
|
+
const t = useExtracted("search");
|
|
487
|
+
const typeLabel = useSubjectTypeLabel();
|
|
488
|
+
const router = useRouter();
|
|
489
|
+
const pathname = usePathname();
|
|
490
|
+
const locale = useLocale();
|
|
491
|
+
const { setTheme } = useTheme();
|
|
492
|
+
const [creatingOrganization, setCreatingOrganization] = useState(false);
|
|
493
|
+
const search = useCommandSearch({ schema: API_SCHEMA, limit: 30 });
|
|
494
|
+
const query = search.query.trim();
|
|
495
|
+
|
|
496
|
+
const go = (href: string) => {
|
|
497
|
+
search.setOpen(false);
|
|
498
|
+
router.push(toAppHref(href));
|
|
499
|
+
};
|
|
423
500
|
|
|
424
|
-
|
|
425
|
-
|
|
501
|
+
const open = (item: CommandSearchItem) => {
|
|
502
|
+
if (item.url === null) {
|
|
503
|
+
return;
|
|
426
504
|
}
|
|
427
505
|
|
|
428
|
-
|
|
506
|
+
const href = item.url;
|
|
507
|
+
void search.select(item);
|
|
508
|
+
router.push(toAppHref(href));
|
|
429
509
|
};
|
|
430
510
|
|
|
511
|
+
const actions: readonly CommandAction[] = [
|
|
512
|
+
...(canCreateCustomer
|
|
513
|
+
? [
|
|
514
|
+
{
|
|
515
|
+
id: "new-customer",
|
|
516
|
+
label: t("New customer"),
|
|
517
|
+
keywords: t("create add customer"),
|
|
518
|
+
icon: UserPlusIcon,
|
|
519
|
+
run: () => {
|
|
520
|
+
go("/customers?new=1");
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
]
|
|
524
|
+
: []),
|
|
525
|
+
{
|
|
526
|
+
id: "new-organization",
|
|
527
|
+
label: t("Create organization"),
|
|
528
|
+
keywords: t("new organization workspace"),
|
|
529
|
+
icon: PlusIcon,
|
|
530
|
+
run: () => {
|
|
531
|
+
search.setOpen(false);
|
|
532
|
+
setCreatingOrganization(true);
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
id: "theme-light",
|
|
537
|
+
label: t("Light theme"),
|
|
538
|
+
keywords: t("theme appearance light"),
|
|
539
|
+
icon: SunIcon,
|
|
540
|
+
run: () => {
|
|
541
|
+
setTheme("light");
|
|
542
|
+
search.setOpen(false);
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
id: "theme-dark",
|
|
547
|
+
label: t("Dark theme"),
|
|
548
|
+
keywords: t("theme appearance dark"),
|
|
549
|
+
icon: MoonIcon,
|
|
550
|
+
run: () => {
|
|
551
|
+
setTheme("dark");
|
|
552
|
+
search.setOpen(false);
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
id: "theme-system",
|
|
557
|
+
label: t("System theme"),
|
|
558
|
+
keywords: t("theme appearance system"),
|
|
559
|
+
icon: MonitorIcon,
|
|
560
|
+
run: () => {
|
|
561
|
+
setTheme("system");
|
|
562
|
+
search.setOpen(false);
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
...routing.locales
|
|
566
|
+
.filter((option) => option !== locale)
|
|
567
|
+
.map((option) => ({
|
|
568
|
+
id: `locale-${option}`,
|
|
569
|
+
label: t("Switch language to {language}", {
|
|
570
|
+
language: LOCALE_NAMES[option],
|
|
571
|
+
}),
|
|
572
|
+
keywords: t("language locale"),
|
|
573
|
+
icon: LanguagesIcon,
|
|
574
|
+
run: () => {
|
|
575
|
+
search.setOpen(false);
|
|
576
|
+
|
|
577
|
+
if (hasLocale(routing.locales, option)) {
|
|
578
|
+
router.replace(pathname, { locale: option });
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
})),
|
|
582
|
+
];
|
|
583
|
+
|
|
584
|
+
const shownActions =
|
|
585
|
+
query === ""
|
|
586
|
+
? actions
|
|
587
|
+
: actions.filter((action) =>
|
|
588
|
+
matches(query, action.label, action.keywords),
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
const shownPages =
|
|
592
|
+
query === ""
|
|
593
|
+
? pages.slice(0, PAGES_WHEN_EMPTY)
|
|
594
|
+
: pages.filter((page) => matches(query, page.label, page.href));
|
|
595
|
+
|
|
596
|
+
const waiting = search.loading && search.results.length === 0;
|
|
597
|
+
const noMatches = query !== "" && !search.loading;
|
|
598
|
+
|
|
431
599
|
return (
|
|
432
600
|
<>
|
|
433
|
-
<
|
|
434
|
-
variant="ghost"
|
|
435
|
-
size="sm"
|
|
436
|
-
aria-label={t("Search")}
|
|
437
|
-
aria-keyshortcuts="Meta+K Control+K"
|
|
601
|
+
<CommandSearchTrigger
|
|
438
602
|
onClick={() => {
|
|
439
603
|
search.setOpen(true);
|
|
440
604
|
}}
|
|
605
|
+
/>
|
|
606
|
+
<CommandDialog
|
|
607
|
+
open={search.open}
|
|
608
|
+
onOpenChange={search.setOpen}
|
|
609
|
+
title={t("Search")}
|
|
610
|
+
description={t(
|
|
611
|
+
"Find records, run an action or open a page. Press Escape to close.",
|
|
612
|
+
)}
|
|
613
|
+
className="sm:max-w-xl"
|
|
441
614
|
>
|
|
442
|
-
<
|
|
443
|
-
|
|
444
|
-
<kbd className="hidden text-xs text-muted-foreground sm:inline">⌘K</kbd>
|
|
445
|
-
</Button>
|
|
446
|
-
<Dialog open={search.open} onOpenChange={search.setOpen}>
|
|
447
|
-
<DialogContent className="gap-4 sm:max-w-lg">
|
|
448
|
-
<DialogHeader>
|
|
449
|
-
<DialogTitle>{t("Search")}</DialogTitle>
|
|
450
|
-
<DialogDescription>
|
|
451
|
-
{t("Find a customer by name, even with a typo.")}
|
|
452
|
-
</DialogDescription>
|
|
453
|
-
</DialogHeader>
|
|
454
|
-
<Input
|
|
455
|
-
type="search"
|
|
615
|
+
<Command shouldFilter={false} loop>
|
|
616
|
+
<CommandInput
|
|
456
617
|
value={search.query}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
placeholder={t("Search customers")}
|
|
461
|
-
aria-label={t("Search customers")}
|
|
618
|
+
onValueChange={search.setQuery}
|
|
619
|
+
placeholder={t("Search records, actions and pages")}
|
|
620
|
+
aria-label={t("Search records, actions and pages")}
|
|
462
621
|
/>
|
|
463
|
-
<
|
|
622
|
+
<CommandList aria-live="polite">
|
|
464
623
|
{search.error === undefined ? null : (
|
|
465
|
-
<
|
|
466
|
-
|
|
467
|
-
|
|
624
|
+
<div className="p-1">
|
|
625
|
+
<Alert variant="destructive">
|
|
626
|
+
<AlertTitle>{t("Search failed")}</AlertTitle>
|
|
627
|
+
<AlertDescription className="flex items-center justify-between gap-2">
|
|
628
|
+
{t("Records could not load. Actions and pages still work.")}
|
|
629
|
+
<Button
|
|
630
|
+
size="sm"
|
|
631
|
+
variant="outline"
|
|
632
|
+
onClick={() => {
|
|
633
|
+
// The controller queries again only when the trimmed text changes.
|
|
634
|
+
const again = search.query;
|
|
635
|
+
search.setQuery("");
|
|
636
|
+
search.setQuery(again);
|
|
637
|
+
}}
|
|
638
|
+
>
|
|
639
|
+
<RotateCwIcon />
|
|
640
|
+
{t("Retry")}
|
|
641
|
+
</Button>
|
|
642
|
+
</AlertDescription>
|
|
643
|
+
</Alert>
|
|
644
|
+
</div>
|
|
468
645
|
)}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
className="block rounded-md px-2 py-1.5 outline-none hover:bg-muted focus-visible:bg-muted"
|
|
646
|
+
|
|
647
|
+
{query === "" ? (
|
|
648
|
+
<>
|
|
649
|
+
{search.groups.map((group) => (
|
|
650
|
+
<CommandGroup
|
|
651
|
+
key={group.key}
|
|
652
|
+
heading={
|
|
653
|
+
group.key === "favorites" ? t("Favorites") : t("Recent")
|
|
654
|
+
}
|
|
655
|
+
>
|
|
656
|
+
{group.items.map((item) => (
|
|
657
|
+
<CommandItem
|
|
658
|
+
key={`${group.key}:${item.subjectType}:${item.subjectId}`}
|
|
659
|
+
value={`${group.key}:${item.subjectType}:${item.subjectId}`}
|
|
660
|
+
disabled={item.url === null}
|
|
661
|
+
onSelect={() => {
|
|
662
|
+
open(item);
|
|
663
|
+
}}
|
|
488
664
|
>
|
|
489
|
-
{
|
|
490
|
-
|
|
491
|
-
|
|
665
|
+
{group.key === "favorites" ? (
|
|
666
|
+
<StarIcon />
|
|
667
|
+
) : (
|
|
668
|
+
<ClockIcon />
|
|
669
|
+
)}
|
|
670
|
+
<span className="truncate">
|
|
671
|
+
{item.title ?? item.subjectId}
|
|
672
|
+
</span>
|
|
673
|
+
<span className="ml-auto text-xs text-muted-foreground">
|
|
674
|
+
{typeLabel(item.subjectType)}
|
|
675
|
+
</span>
|
|
676
|
+
</CommandItem>
|
|
677
|
+
))}
|
|
678
|
+
</CommandGroup>
|
|
679
|
+
))}
|
|
680
|
+
</>
|
|
681
|
+
) : (
|
|
682
|
+
<>
|
|
683
|
+
{search.groups.map((group) => (
|
|
684
|
+
<CommandGroup key={group.key} heading={typeLabel(group.key)}>
|
|
685
|
+
{group.items.map((item) => (
|
|
686
|
+
<CommandItem
|
|
687
|
+
key={`${item.subjectType}:${item.subjectId}`}
|
|
688
|
+
value={`${item.subjectType}:${item.subjectId}`}
|
|
689
|
+
disabled={item.url === null}
|
|
690
|
+
onSelect={() => {
|
|
691
|
+
open(item);
|
|
692
|
+
}}
|
|
693
|
+
>
|
|
694
|
+
<span className="truncate">
|
|
695
|
+
{item.title ?? item.subjectId}
|
|
696
|
+
</span>
|
|
697
|
+
</CommandItem>
|
|
698
|
+
))}
|
|
699
|
+
</CommandGroup>
|
|
700
|
+
))}
|
|
701
|
+
{waiting ? (
|
|
702
|
+
<CommandGroup heading={t("Records")}>
|
|
703
|
+
<div className="flex flex-col gap-2 p-2" aria-busy="true">
|
|
704
|
+
<Skeleton className="h-5 w-3/4" />
|
|
705
|
+
<Skeleton className="h-5 w-1/2" />
|
|
706
|
+
<Skeleton className="h-5 w-2/3" />
|
|
707
|
+
</div>
|
|
708
|
+
</CommandGroup>
|
|
709
|
+
) : null}
|
|
710
|
+
<CommandGroup>
|
|
711
|
+
<CommandItem
|
|
712
|
+
value={`all:${query}`}
|
|
713
|
+
onSelect={() => {
|
|
714
|
+
go(`/search?q=${encodeURIComponent(query)}`);
|
|
715
|
+
}}
|
|
716
|
+
>
|
|
717
|
+
<SearchIcon />
|
|
718
|
+
{t("See all results for {query}", { query })}
|
|
719
|
+
</CommandItem>
|
|
720
|
+
</CommandGroup>
|
|
721
|
+
</>
|
|
722
|
+
)}
|
|
723
|
+
|
|
724
|
+
{shownActions.length === 0 ? null : (
|
|
725
|
+
<>
|
|
726
|
+
<CommandSeparator />
|
|
727
|
+
<CommandGroup heading={t("Actions")}>
|
|
728
|
+
{shownActions.map((action) => (
|
|
729
|
+
<CommandItem
|
|
730
|
+
key={action.id}
|
|
731
|
+
value={`action:${action.id}`}
|
|
732
|
+
onSelect={action.run}
|
|
733
|
+
>
|
|
734
|
+
<action.icon />
|
|
735
|
+
{action.label}
|
|
736
|
+
</CommandItem>
|
|
492
737
|
))}
|
|
493
|
-
</
|
|
494
|
-
|
|
495
|
-
)
|
|
738
|
+
</CommandGroup>
|
|
739
|
+
</>
|
|
740
|
+
)}
|
|
741
|
+
|
|
742
|
+
<OrganizationCommands
|
|
743
|
+
query={query}
|
|
744
|
+
onSwitched={() => {
|
|
745
|
+
search.setOpen(false);
|
|
746
|
+
}}
|
|
747
|
+
/>
|
|
748
|
+
|
|
749
|
+
{shownPages.length === 0 ? null : (
|
|
750
|
+
<>
|
|
751
|
+
<CommandSeparator />
|
|
752
|
+
<CommandGroup heading={t("Go to")}>
|
|
753
|
+
{shownPages.map((page) => (
|
|
754
|
+
<CommandItem
|
|
755
|
+
key={page.id}
|
|
756
|
+
value={`page:${page.id}`}
|
|
757
|
+
onPointerEnter={() => {
|
|
758
|
+
router.prefetch(toAppHref(page.href));
|
|
759
|
+
}}
|
|
760
|
+
onSelect={() => {
|
|
761
|
+
go(page.href);
|
|
762
|
+
}}
|
|
763
|
+
>
|
|
764
|
+
<CompassIcon />
|
|
765
|
+
{page.label}
|
|
766
|
+
<ArrowRightIcon className="ml-auto opacity-50" />
|
|
767
|
+
</CommandItem>
|
|
768
|
+
))}
|
|
769
|
+
</CommandGroup>
|
|
770
|
+
</>
|
|
771
|
+
)}
|
|
772
|
+
|
|
773
|
+
{query === "" ? null : (
|
|
774
|
+
<>
|
|
775
|
+
<CommandSeparator />
|
|
776
|
+
<CommandGroup heading={t("Assistant")}>
|
|
777
|
+
<CommandItem
|
|
778
|
+
value="ask-assistant"
|
|
779
|
+
onSelect={() => {
|
|
780
|
+
go(`/assistant?ask=${encodeURIComponent(query)}`);
|
|
781
|
+
}}
|
|
782
|
+
>
|
|
783
|
+
<BotIcon />
|
|
784
|
+
{t("Ask the assistant: {query}", { query })}
|
|
785
|
+
</CommandItem>
|
|
786
|
+
</CommandGroup>
|
|
787
|
+
</>
|
|
788
|
+
)}
|
|
789
|
+
|
|
790
|
+
{noMatches &&
|
|
791
|
+
search.results.length === 0 &&
|
|
792
|
+
shownActions.length === 0 &&
|
|
793
|
+
shownPages.length === 0 ? (
|
|
794
|
+
<p className="px-3 py-4 text-center text-sm text-muted-foreground">
|
|
795
|
+
{t("No records match. Ask the assistant or see all results.")}
|
|
796
|
+
</p>
|
|
797
|
+
) : null}
|
|
798
|
+
</CommandList>
|
|
799
|
+
<div className="flex items-center justify-between gap-2 border-t px-3 py-2 text-xs text-muted-foreground">
|
|
800
|
+
<span className="flex items-center gap-1">
|
|
801
|
+
<KbdGroup>
|
|
802
|
+
<Kbd>↑</Kbd>
|
|
803
|
+
<Kbd>↓</Kbd>
|
|
804
|
+
</KbdGroup>
|
|
805
|
+
{t("to move")}
|
|
806
|
+
</span>
|
|
807
|
+
<span className="flex items-center gap-1">
|
|
808
|
+
<Kbd>↵</Kbd>
|
|
809
|
+
{t("to open")}
|
|
810
|
+
</span>
|
|
811
|
+
<span className="flex items-center gap-1">
|
|
812
|
+
<Kbd>Esc</Kbd>
|
|
813
|
+
{t("to close")}
|
|
814
|
+
</span>
|
|
496
815
|
</div>
|
|
497
|
-
</
|
|
498
|
-
</
|
|
816
|
+
</Command>
|
|
817
|
+
</CommandDialog>
|
|
818
|
+
<CreateOrganizationDialog
|
|
819
|
+
open={creatingOrganization}
|
|
820
|
+
onOpenChange={setCreatingOrganization}
|
|
821
|
+
/>
|
|
499
822
|
</>
|
|
500
823
|
);
|
|
501
824
|
}
|
|
@@ -2272,6 +2595,7 @@ import { DataGridTable } from "@/components/reui/data-grid/data-grid-table";
|
|
|
2272
2595
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
2273
2596
|
import { Badge } from "@/components/ui/badge";
|
|
2274
2597
|
import { Button } from "@/components/ui/button";
|
|
2598
|
+
import { Checkbox } from "@/components/ui/checkbox";
|
|
2275
2599
|
import {
|
|
2276
2600
|
Empty,
|
|
2277
2601
|
EmptyContent,
|
|
@@ -2400,6 +2724,8 @@ function JoinedCell({ row }: MemberCell) {
|
|
|
2400
2724
|
interface MemberActions {
|
|
2401
2725
|
readonly changeRole: (member: Member, role: Role) => Promise<void>;
|
|
2402
2726
|
readonly removeMember: (member: Member) => Promise<void>;
|
|
2727
|
+
readonly selected: ReadonlySet<string>;
|
|
2728
|
+
readonly toggle: (userId: string, on: boolean) => void;
|
|
2403
2729
|
}
|
|
2404
2730
|
|
|
2405
2731
|
const MemberActionsContext = createContext<MemberActions | null>(null);
|
|
@@ -2414,6 +2740,29 @@ function useMemberActions(): MemberActions {
|
|
|
2414
2740
|
return actions;
|
|
2415
2741
|
}
|
|
2416
2742
|
|
|
2743
|
+
function SelectCell({ row }: MemberCell) {
|
|
2744
|
+
const t = useExtracted("members");
|
|
2745
|
+
const { selected, toggle } = useMemberActions();
|
|
2746
|
+
const member = row.original;
|
|
2747
|
+
|
|
2748
|
+
if (member.roleChoices.length === 0) {
|
|
2749
|
+
return null;
|
|
2750
|
+
}
|
|
2751
|
+
|
|
2752
|
+
return (
|
|
2753
|
+
<Checkbox
|
|
2754
|
+
checked={selected.has(member.userId)}
|
|
2755
|
+
disabled={member.busy}
|
|
2756
|
+
aria-label={t("Select {name}", {
|
|
2757
|
+
name: member.name ?? member.email ?? "",
|
|
2758
|
+
})}
|
|
2759
|
+
onCheckedChange={(checked) => {
|
|
2760
|
+
toggle(member.userId, checked);
|
|
2761
|
+
}}
|
|
2762
|
+
/>
|
|
2763
|
+
);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2417
2766
|
function RoleCell({ row }: MemberCell) {
|
|
2418
2767
|
const t = useExtracted("members");
|
|
2419
2768
|
const roleLabel = useRoleLabel();
|
|
@@ -2558,12 +2907,33 @@ export function MemberTable({
|
|
|
2558
2907
|
[remove, t, errorMessage],
|
|
2559
2908
|
);
|
|
2560
2909
|
|
|
2910
|
+
const [selected, setSelected] = useState<ReadonlySet<string>>(new Set());
|
|
2911
|
+
const [bulkRole, setBulkRole] = useState<Role | null>(null);
|
|
2912
|
+
const [applying, setApplying] = useState(false);
|
|
2913
|
+
|
|
2914
|
+
const toggle = useCallback((userId: string, on: boolean) => {
|
|
2915
|
+
setSelected((current) => {
|
|
2916
|
+
const next = new Set(current);
|
|
2917
|
+
|
|
2918
|
+
if (on) {
|
|
2919
|
+
next.add(userId);
|
|
2920
|
+
} else {
|
|
2921
|
+
next.delete(userId);
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
return next;
|
|
2925
|
+
});
|
|
2926
|
+
}, []);
|
|
2927
|
+
|
|
2561
2928
|
const actions = useMemo(
|
|
2562
|
-
() => ({ changeRole, removeMember }),
|
|
2563
|
-
[changeRole, removeMember],
|
|
2929
|
+
() => ({ changeRole, removeMember, selected, toggle }),
|
|
2930
|
+
[changeRole, removeMember, selected, toggle],
|
|
2564
2931
|
);
|
|
2565
2932
|
|
|
2566
2933
|
const columns: ColumnDef<ReadOnlyGridFeatures, MemberRow>[] = [
|
|
2934
|
+
...(canUpdateRole
|
|
2935
|
+
? [{ id: "select", header: "", cell: SelectCell, size: 40 }]
|
|
2936
|
+
: []),
|
|
2567
2937
|
{ id: "member", header: t("Member"), cell: MemberCellView, size: 280 },
|
|
2568
2938
|
{ accessorKey: "role", header: t("Role"), cell: RoleCell, size: 150 },
|
|
2569
2939
|
{ id: "teams", header: t("Teams"), cell: TeamsCell, size: 200 },
|
|
@@ -2604,6 +2974,36 @@ export function MemberTable({
|
|
|
2604
2974
|
getRowId: (row) => row.userId,
|
|
2605
2975
|
});
|
|
2606
2976
|
|
|
2977
|
+
const applyBulkRole = async () => {
|
|
2978
|
+
if (!bulkRole) {
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
setApplying(true);
|
|
2983
|
+
let changed = 0;
|
|
2984
|
+
|
|
2985
|
+
for (const userId of selected) {
|
|
2986
|
+
const result = await setRole({ userId, role: bulkRole });
|
|
2987
|
+
|
|
2988
|
+
if (result.ok) {
|
|
2989
|
+
changed += 1;
|
|
2990
|
+
} else {
|
|
2991
|
+
toast.error(errorMessage(result.error));
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
setApplying(false);
|
|
2996
|
+
setSelected(new Set());
|
|
2997
|
+
|
|
2998
|
+
if (changed > 0) {
|
|
2999
|
+
toast.success(
|
|
3000
|
+
t("{count, plural, one {# role updated} other {# roles updated}}", {
|
|
3001
|
+
count: changed,
|
|
3002
|
+
}),
|
|
3003
|
+
);
|
|
3004
|
+
}
|
|
3005
|
+
};
|
|
3006
|
+
|
|
2607
3007
|
const clearFilters = () => {
|
|
2608
3008
|
setSearch("");
|
|
2609
3009
|
setRoleFilter(ALL_ROLES);
|
|
@@ -2642,6 +3042,60 @@ export function MemberTable({
|
|
|
2642
3042
|
</SelectContent>
|
|
2643
3043
|
</Select>
|
|
2644
3044
|
</div>
|
|
3045
|
+
{selected.size > 0 ? (
|
|
3046
|
+
<div
|
|
3047
|
+
className="flex flex-wrap items-center gap-2 rounded-lg border bg-muted/40 p-2"
|
|
3048
|
+
data-testid="members-bulk-bar"
|
|
3049
|
+
>
|
|
3050
|
+
<span className="text-sm">
|
|
3051
|
+
{t("{count, number} selected", { count: selected.size })}
|
|
3052
|
+
</span>
|
|
3053
|
+
<Select
|
|
3054
|
+
value={bulkRole}
|
|
3055
|
+
items={assignable.map((role) => ({
|
|
3056
|
+
value: role,
|
|
3057
|
+
label: roleLabel(role),
|
|
3058
|
+
}))}
|
|
3059
|
+
onValueChange={(value) => {
|
|
3060
|
+
setBulkRole(v.is(Role, value) ? value : null);
|
|
3061
|
+
}}
|
|
3062
|
+
>
|
|
3063
|
+
<SelectTrigger
|
|
3064
|
+
size="sm"
|
|
3065
|
+
className="w-40"
|
|
3066
|
+
aria-label={t("New role")}
|
|
3067
|
+
>
|
|
3068
|
+
<SelectValue placeholder={t("Change role to")} />
|
|
3069
|
+
</SelectTrigger>
|
|
3070
|
+
<SelectContent>
|
|
3071
|
+
{assignable.map((role) => (
|
|
3072
|
+
<SelectItem key={role} value={role}>
|
|
3073
|
+
{roleLabel(role)}
|
|
3074
|
+
</SelectItem>
|
|
3075
|
+
))}
|
|
3076
|
+
</SelectContent>
|
|
3077
|
+
</Select>
|
|
3078
|
+
<Button
|
|
3079
|
+
size="sm"
|
|
3080
|
+
disabled={!bulkRole || applying}
|
|
3081
|
+
onClick={() => {
|
|
3082
|
+
void applyBulkRole();
|
|
3083
|
+
}}
|
|
3084
|
+
>
|
|
3085
|
+
{t("Apply")}
|
|
3086
|
+
</Button>
|
|
3087
|
+
<Button
|
|
3088
|
+
size="sm"
|
|
3089
|
+
variant="ghost"
|
|
3090
|
+
disabled={applying}
|
|
3091
|
+
onClick={() => {
|
|
3092
|
+
setSelected(new Set());
|
|
3093
|
+
}}
|
|
3094
|
+
>
|
|
3095
|
+
{t("Clear selection")}
|
|
3096
|
+
</Button>
|
|
3097
|
+
</div>
|
|
3098
|
+
) : null}
|
|
2645
3099
|
<div data-testid="members">
|
|
2646
3100
|
<DataGrid
|
|
2647
3101
|
table={table}
|
|
@@ -4351,34 +4805,44 @@ export function TwoFactorCard({
|
|
|
4351
4805
|
|
|
4352
4806
|
## Inbox with threads
|
|
4353
4807
|
|
|
4354
|
-
A shared inbox
|
|
4808
|
+
A shared inbox queue with search and status, assignee and channel filters in the URL; each row opens its thread beside the list. It calls `useInbox` from `@/hooks/use-inbox`; the [inbox block](https://bettersupabase.com/blocks/inbox) must be installed (`npx better-supabase add inbox`). Page: https://bettersupabase.com/recipes/inbox-threads.
|
|
4355
4809
|
|
|
4356
4810
|
Web, with shadcn components:
|
|
4357
4811
|
|
|
4358
4812
|
```bash
|
|
4359
|
-
npx shadcn add badge empty select
|
|
4813
|
+
npx shadcn add badge button empty input select skeleton
|
|
4360
4814
|
```
|
|
4361
4815
|
|
|
4362
4816
|
```bash
|
|
4363
4817
|
npx shadcn add @better-supabase/use-inbox
|
|
4364
4818
|
```
|
|
4365
4819
|
|
|
4366
|
-
```tsx title="apps/examples/nextjs/src/features/inbox/components/
|
|
4820
|
+
```tsx title="apps/examples/nextjs/src/features/inbox/components/conversation-queue.tsx"
|
|
4367
4821
|
"use client";
|
|
4368
4822
|
|
|
4369
|
-
import {
|
|
4370
|
-
import {
|
|
4371
|
-
import {
|
|
4372
|
-
import
|
|
4823
|
+
import { useAction } from "better-supabase/react";
|
|
4824
|
+
import { InboxIcon, SearchIcon } from "lucide-react";
|
|
4825
|
+
import { useExtracted, useFormatter, useNow } from "next-intl";
|
|
4826
|
+
import { useParams } from "next/navigation";
|
|
4827
|
+
import {
|
|
4828
|
+
debounce,
|
|
4829
|
+
parseAsString,
|
|
4830
|
+
parseAsStringLiteral,
|
|
4831
|
+
useQueryStates,
|
|
4832
|
+
} from "nuqs";
|
|
4833
|
+
import { useEffect, useEffectEvent, useState } from "react";
|
|
4373
4834
|
|
|
4374
|
-
import { Badge } from "@/components/
|
|
4835
|
+
import { Badge } from "@/components/reui/badge";
|
|
4836
|
+
import { Button } from "@/components/ui/button";
|
|
4375
4837
|
import {
|
|
4376
4838
|
Empty,
|
|
4839
|
+
EmptyContent,
|
|
4377
4840
|
EmptyDescription,
|
|
4378
4841
|
EmptyHeader,
|
|
4379
4842
|
EmptyMedia,
|
|
4380
4843
|
EmptyTitle,
|
|
4381
4844
|
} from "@/components/ui/empty";
|
|
4845
|
+
import { Input } from "@/components/ui/input";
|
|
4382
4846
|
import {
|
|
4383
4847
|
Select,
|
|
4384
4848
|
SelectContent,
|
|
@@ -4386,18 +4850,34 @@ import {
|
|
|
4386
4850
|
SelectTrigger,
|
|
4387
4851
|
SelectValue,
|
|
4388
4852
|
} from "@/components/ui/select";
|
|
4389
|
-
import {
|
|
4853
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
4390
4854
|
import { useInbox } from "@/hooks/use-inbox";
|
|
4855
|
+
import { Link, toAppHref } from "@/i18n/navigation";
|
|
4391
4856
|
import { cn } from "@/lib/utils";
|
|
4392
4857
|
|
|
4393
|
-
import type { ConversationRow } from "../inbox-types";
|
|
4858
|
+
import type { ConversationRow, InboxSummary } from "../inbox-types";
|
|
4394
4859
|
|
|
4395
|
-
import { loadConversations } from "../inbox-actions";
|
|
4860
|
+
import { loadConversations, loadInboxes } from "../inbox-actions";
|
|
4396
4861
|
import { unwrap } from "../inbox-load";
|
|
4397
|
-
import {
|
|
4398
|
-
import {
|
|
4862
|
+
import { QUEUE_ASSIGNEES, QUEUE_STATUSES, slaStateOf } from "../inbox-types";
|
|
4863
|
+
import { ChannelBadge, SlaBadge } from "./conversation-badges";
|
|
4399
4864
|
|
|
4400
|
-
|
|
4865
|
+
const ALL_CHANNELS = "all";
|
|
4866
|
+
|
|
4867
|
+
const queueParsers = {
|
|
4868
|
+
q: parseAsString.withDefault(""),
|
|
4869
|
+
status: parseAsStringLiteral(QUEUE_STATUSES).withDefault("open"),
|
|
4870
|
+
assignee: parseAsStringLiteral(QUEUE_ASSIGNEES).withDefault("anyone"),
|
|
4871
|
+
channel: parseAsString.withDefault(""),
|
|
4872
|
+
};
|
|
4873
|
+
|
|
4874
|
+
/**
|
|
4875
|
+
* The conversation queue: search, status, assignee and channel run in the
|
|
4876
|
+
* database (`loadConversations`), the filters live in the URL, and Realtime
|
|
4877
|
+
* pings reload the list without refetching the page. A row links to
|
|
4878
|
+
* `/inbox/<id>` and keeps the filters, so the thread opens beside the queue.
|
|
4879
|
+
*/
|
|
4880
|
+
export function ConversationQueue({
|
|
4401
4881
|
organizationId,
|
|
4402
4882
|
initial,
|
|
4403
4883
|
}: {
|
|
@@ -4405,187 +4885,372 @@ export function InboxView({
|
|
|
4405
4885
|
initial: readonly ConversationRow[];
|
|
4406
4886
|
}) {
|
|
4407
4887
|
const t = useExtracted("inbox");
|
|
4408
|
-
|
|
4409
|
-
const [
|
|
4410
|
-
|
|
4888
|
+
|
|
4889
|
+
const [filters, setFilters] = useQueryStates(queueParsers, {
|
|
4890
|
+
limitUrlUpdates: debounce(300),
|
|
4891
|
+
});
|
|
4892
|
+
|
|
4893
|
+
const inboxes = useAction(loadInboxes);
|
|
4894
|
+
|
|
4895
|
+
const loadChannels = useEffectEvent(() => {
|
|
4896
|
+
void inboxes.run(undefined);
|
|
4897
|
+
});
|
|
4898
|
+
|
|
4899
|
+
useEffect(() => {
|
|
4900
|
+
loadChannels();
|
|
4901
|
+
}, []);
|
|
4902
|
+
|
|
4903
|
+
const channelItems = [
|
|
4904
|
+
{ value: ALL_CHANNELS, label: t("All channels") },
|
|
4905
|
+
...(inboxes.data ?? []).map((inbox: InboxSummary) => ({
|
|
4906
|
+
value: inbox.id,
|
|
4907
|
+
label: inbox.name,
|
|
4908
|
+
})),
|
|
4909
|
+
];
|
|
4910
|
+
|
|
4911
|
+
const statusItems = [
|
|
4912
|
+
{ value: "open", label: t("Open") },
|
|
4913
|
+
{ value: "pending", label: t("Pending") },
|
|
4914
|
+
{ value: "snoozed", label: t("Snoozed") },
|
|
4915
|
+
{ value: "resolved", label: t("Resolved") },
|
|
4916
|
+
{ value: "all", label: t("All statuses") },
|
|
4917
|
+
];
|
|
4411
4918
|
|
|
4412
4919
|
const assigneeItems = [
|
|
4413
4920
|
{ value: "anyone", label: t("Anyone") },
|
|
4414
4921
|
{ value: "me", label: t("Mine") },
|
|
4415
4922
|
{ value: "unassigned", label: t("Unassigned") },
|
|
4416
|
-
]
|
|
4923
|
+
];
|
|
4924
|
+
|
|
4925
|
+
const isDefault =
|
|
4926
|
+
filters.status === "open" &&
|
|
4927
|
+
filters.assignee === "anyone" &&
|
|
4928
|
+
filters.channel === "" &&
|
|
4929
|
+
filters.q === "";
|
|
4417
4930
|
|
|
4418
4931
|
return (
|
|
4419
|
-
<
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4932
|
+
<section
|
|
4933
|
+
aria-label={t("Conversations")}
|
|
4934
|
+
className="flex h-full min-h-0 flex-col gap-3 p-3"
|
|
4935
|
+
>
|
|
4936
|
+
<div className="relative">
|
|
4937
|
+
<SearchIcon
|
|
4938
|
+
aria-hidden
|
|
4939
|
+
className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground"
|
|
4940
|
+
/>
|
|
4941
|
+
<Input
|
|
4942
|
+
type="search"
|
|
4943
|
+
value={filters.q}
|
|
4944
|
+
placeholder={t("Search conversations")}
|
|
4945
|
+
aria-label={t("Search conversations")}
|
|
4946
|
+
className="pl-8"
|
|
4947
|
+
onChange={(event) => {
|
|
4948
|
+
void setFilters({ q: event.target.value });
|
|
4949
|
+
}}
|
|
4950
|
+
/>
|
|
4951
|
+
</div>
|
|
4952
|
+
<div className="grid grid-cols-2 gap-2">
|
|
4953
|
+
<Select
|
|
4954
|
+
value={filters.status}
|
|
4955
|
+
items={statusItems}
|
|
4956
|
+
onValueChange={(value) => {
|
|
4957
|
+
const status = QUEUE_STATUSES.find((item) => item === value);
|
|
4428
4958
|
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4959
|
+
if (status !== undefined) {
|
|
4960
|
+
void setFilters({ status });
|
|
4961
|
+
}
|
|
4962
|
+
}}
|
|
4963
|
+
>
|
|
4964
|
+
<SelectTrigger size="sm" className="w-full" aria-label={t("Status")}>
|
|
4965
|
+
<SelectValue />
|
|
4966
|
+
</SelectTrigger>
|
|
4967
|
+
<SelectContent>
|
|
4968
|
+
{statusItems.map((item) => (
|
|
4969
|
+
<SelectItem key={item.value} value={item.value}>
|
|
4970
|
+
{item.label}
|
|
4971
|
+
</SelectItem>
|
|
4972
|
+
))}
|
|
4973
|
+
</SelectContent>
|
|
4974
|
+
</Select>
|
|
4975
|
+
<Select
|
|
4976
|
+
value={filters.assignee}
|
|
4977
|
+
items={assigneeItems}
|
|
4978
|
+
onValueChange={(value) => {
|
|
4979
|
+
const assignee = QUEUE_ASSIGNEES.find((item) => item === value);
|
|
4446
4980
|
|
|
4447
|
-
|
|
4448
|
-
|
|
4981
|
+
if (assignee !== undefined) {
|
|
4982
|
+
void setFilters({ assignee });
|
|
4983
|
+
}
|
|
4984
|
+
}}
|
|
4985
|
+
>
|
|
4986
|
+
<SelectTrigger
|
|
4987
|
+
size="sm"
|
|
4988
|
+
className="flex-1"
|
|
4989
|
+
aria-label={t("Assignee")}
|
|
4449
4990
|
>
|
|
4450
|
-
<
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4991
|
+
<SelectValue />
|
|
4992
|
+
</SelectTrigger>
|
|
4993
|
+
<SelectContent>
|
|
4994
|
+
{assigneeItems.map((item) => (
|
|
4995
|
+
<SelectItem key={item.value} value={item.value}>
|
|
4996
|
+
{item.label}
|
|
4997
|
+
</SelectItem>
|
|
4998
|
+
))}
|
|
4999
|
+
</SelectContent>
|
|
5000
|
+
</Select>
|
|
5001
|
+
<Select
|
|
5002
|
+
value={filters.channel === "" ? ALL_CHANNELS : filters.channel}
|
|
5003
|
+
items={channelItems}
|
|
5004
|
+
onValueChange={(value) => {
|
|
5005
|
+
void setFilters({
|
|
5006
|
+
channel: value === null || value === ALL_CHANNELS ? "" : value,
|
|
5007
|
+
});
|
|
5008
|
+
}}
|
|
5009
|
+
>
|
|
5010
|
+
<SelectTrigger
|
|
5011
|
+
size="sm"
|
|
5012
|
+
className="col-span-2 w-full"
|
|
5013
|
+
aria-label={t("Channel")}
|
|
5014
|
+
>
|
|
5015
|
+
<SelectValue />
|
|
5016
|
+
</SelectTrigger>
|
|
5017
|
+
<SelectContent>
|
|
5018
|
+
{channelItems.map((item) => (
|
|
5019
|
+
<SelectItem key={item.value} value={item.value}>
|
|
5020
|
+
{item.label}
|
|
5021
|
+
</SelectItem>
|
|
5022
|
+
))}
|
|
5023
|
+
</SelectContent>
|
|
5024
|
+
</Select>
|
|
5025
|
+
</div>
|
|
5026
|
+
<QueueRows
|
|
5027
|
+
key={`${filters.status}:${filters.assignee}:${filters.channel}:${filters.q}`}
|
|
5028
|
+
organizationId={organizationId}
|
|
5029
|
+
status={filters.status}
|
|
5030
|
+
assignee={filters.assignee}
|
|
5031
|
+
channel={filters.channel}
|
|
5032
|
+
q={filters.q}
|
|
5033
|
+
initial={isDefault ? initial : null}
|
|
5034
|
+
onClear={() => {
|
|
5035
|
+
void setFilters({
|
|
5036
|
+
q: "",
|
|
5037
|
+
status: "open",
|
|
5038
|
+
assignee: "anyone",
|
|
5039
|
+
channel: "",
|
|
5040
|
+
});
|
|
5041
|
+
}}
|
|
5042
|
+
/>
|
|
5043
|
+
</section>
|
|
4491
5044
|
);
|
|
4492
5045
|
}
|
|
4493
5046
|
|
|
4494
|
-
|
|
5047
|
+
const PAGE_SIZE = 40;
|
|
5048
|
+
|
|
5049
|
+
function QueueRows({
|
|
4495
5050
|
organizationId,
|
|
4496
5051
|
status,
|
|
4497
5052
|
assignee,
|
|
5053
|
+
channel,
|
|
5054
|
+
q,
|
|
4498
5055
|
initial,
|
|
4499
|
-
|
|
4500
|
-
onSelect,
|
|
5056
|
+
onClear,
|
|
4501
5057
|
}: {
|
|
4502
5058
|
organizationId: string;
|
|
4503
|
-
status:
|
|
4504
|
-
assignee:
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
5059
|
+
status: ConversationRow["status"] | "all";
|
|
5060
|
+
assignee: (typeof QUEUE_ASSIGNEES)[number];
|
|
5061
|
+
channel: string;
|
|
5062
|
+
q: string;
|
|
5063
|
+
initial: readonly ConversationRow[] | null;
|
|
5064
|
+
onClear: () => void;
|
|
4508
5065
|
}) {
|
|
4509
5066
|
const t = useExtracted("inbox");
|
|
4510
5067
|
const format = useFormatter();
|
|
5068
|
+
const selected = useParams<{ conversation?: string }>().conversation;
|
|
5069
|
+
const [search] = useQueryStates(queueParsers);
|
|
5070
|
+
const [more, setMore] = useState<readonly ConversationRow[]>([]);
|
|
5071
|
+
const nowDate = useNow({ updateInterval: 60_000 });
|
|
5072
|
+
const now = nowDate.getTime();
|
|
4511
5073
|
|
|
4512
5074
|
const inbox = useInbox({
|
|
4513
5075
|
organizationId,
|
|
4514
|
-
load: async () =>
|
|
5076
|
+
load: async () =>
|
|
5077
|
+
unwrap(await loadConversations({ status, assignee, channel, q })),
|
|
4515
5078
|
});
|
|
4516
5079
|
|
|
4517
|
-
const
|
|
5080
|
+
const next = useAction(loadConversations);
|
|
4518
5081
|
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
5082
|
+
const first = inbox.items ?? initial;
|
|
5083
|
+
|
|
5084
|
+
if (first === null) {
|
|
5085
|
+
return inbox.error === undefined || inbox.error === null ? (
|
|
5086
|
+
<QueueSkeleton />
|
|
5087
|
+
) : (
|
|
5088
|
+
<Empty className="border">
|
|
5089
|
+
<EmptyHeader>
|
|
5090
|
+
<EmptyTitle>{t("The queue did not load")}</EmptyTitle>
|
|
5091
|
+
<EmptyDescription>
|
|
5092
|
+
{inbox.error instanceof Error
|
|
5093
|
+
? inbox.error.message
|
|
5094
|
+
: t("Check your connection and try again.")}
|
|
5095
|
+
</EmptyDescription>
|
|
5096
|
+
</EmptyHeader>
|
|
5097
|
+
<EmptyContent>
|
|
5098
|
+
<Button
|
|
5099
|
+
variant="outline"
|
|
5100
|
+
size="sm"
|
|
5101
|
+
onClick={() => {
|
|
5102
|
+
void inbox.refresh();
|
|
5103
|
+
}}
|
|
5104
|
+
>
|
|
5105
|
+
{t("Retry")}
|
|
5106
|
+
</Button>
|
|
5107
|
+
</EmptyContent>
|
|
5108
|
+
</Empty>
|
|
5109
|
+
);
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
const rows = [...first, ...more];
|
|
5113
|
+
const last = rows.at(-1);
|
|
5114
|
+
const hasMore = first.length >= PAGE_SIZE && more.length % PAGE_SIZE === 0;
|
|
5115
|
+
|
|
5116
|
+
const query = new URLSearchParams();
|
|
4523
5117
|
|
|
4524
|
-
|
|
4525
|
-
|
|
5118
|
+
if (search.q !== "") {
|
|
5119
|
+
query.set("q", search.q);
|
|
5120
|
+
}
|
|
5121
|
+
|
|
5122
|
+
if (search.status !== "open") {
|
|
5123
|
+
query.set("status", search.status);
|
|
5124
|
+
}
|
|
4526
5125
|
|
|
5126
|
+
if (search.assignee !== "anyone") {
|
|
5127
|
+
query.set("assignee", search.assignee);
|
|
5128
|
+
}
|
|
5129
|
+
|
|
5130
|
+
if (search.channel !== "") {
|
|
5131
|
+
query.set("channel", search.channel);
|
|
5132
|
+
}
|
|
5133
|
+
|
|
5134
|
+
const suffix = query.size === 0 ? "" : `?${query.toString()}`;
|
|
5135
|
+
|
|
5136
|
+
if (rows.length === 0) {
|
|
4527
5137
|
return (
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
5138
|
+
<Empty className="border">
|
|
5139
|
+
<EmptyHeader>
|
|
5140
|
+
<EmptyMedia variant="icon">
|
|
5141
|
+
<InboxIcon />
|
|
5142
|
+
</EmptyMedia>
|
|
5143
|
+
<EmptyTitle>{t("No conversations")}</EmptyTitle>
|
|
5144
|
+
<EmptyDescription>
|
|
5145
|
+
{t(
|
|
5146
|
+
"Nothing matches these filters. Clear them, or use the simulator to receive a message.",
|
|
5147
|
+
)}
|
|
5148
|
+
</EmptyDescription>
|
|
5149
|
+
</EmptyHeader>
|
|
5150
|
+
<EmptyContent>
|
|
5151
|
+
<Button variant="outline" size="sm" onClick={onClear}>
|
|
5152
|
+
{t("Clear filters")}
|
|
5153
|
+
</Button>
|
|
5154
|
+
</EmptyContent>
|
|
5155
|
+
</Empty>
|
|
4532
5156
|
);
|
|
4533
|
-
}
|
|
5157
|
+
}
|
|
4534
5158
|
|
|
4535
|
-
return
|
|
4536
|
-
<
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
5159
|
+
return (
|
|
5160
|
+
<ul className="-mx-3 min-h-0 flex-1 divide-y overflow-y-auto border-y">
|
|
5161
|
+
{rows.map((conversation) => {
|
|
5162
|
+
const sla = slaStateOf(conversation, now);
|
|
5163
|
+
|
|
5164
|
+
return (
|
|
5165
|
+
<li key={conversation.id}>
|
|
5166
|
+
<Link
|
|
5167
|
+
href={toAppHref(`/inbox/${conversation.id}${suffix}`)}
|
|
5168
|
+
aria-current={selected === conversation.id ? "page" : undefined}
|
|
5169
|
+
prefetch={false}
|
|
5170
|
+
className={cn(
|
|
5171
|
+
"flex flex-col gap-1 px-3 py-3 text-sm transition-colors hover:bg-muted/50",
|
|
5172
|
+
selected === conversation.id && "bg-muted",
|
|
5173
|
+
)}
|
|
5174
|
+
>
|
|
5175
|
+
<span className="flex items-center gap-2">
|
|
5176
|
+
<span
|
|
5177
|
+
className={cn(
|
|
5178
|
+
"flex-1 truncate",
|
|
5179
|
+
conversation.unread ? "font-semibold" : "font-medium",
|
|
5180
|
+
)}
|
|
5181
|
+
>
|
|
5182
|
+
{conversation.contactName || t("Visitor")}
|
|
5183
|
+
</span>
|
|
5184
|
+
{conversation.unread ? (
|
|
5185
|
+
<Badge variant="primary-light">{t("New")}</Badge>
|
|
5186
|
+
) : null}
|
|
5187
|
+
{conversation.lastMessageAt ? (
|
|
5188
|
+
<span className="text-xs text-muted-foreground tabular-nums">
|
|
5189
|
+
{format.relativeTime(
|
|
5190
|
+
new Date(conversation.lastMessageAt),
|
|
5191
|
+
now,
|
|
5192
|
+
)}
|
|
5193
|
+
</span>
|
|
5194
|
+
) : null}
|
|
5195
|
+
</span>
|
|
5196
|
+
<span className="truncate">
|
|
5197
|
+
{conversation.subject ?? t("No subject")}
|
|
5198
|
+
</span>
|
|
5199
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
5200
|
+
{conversation.preview}
|
|
5201
|
+
</span>
|
|
5202
|
+
<span className="flex flex-wrap items-center gap-1">
|
|
5203
|
+
<ChannelBadge channel={conversation.channel} />
|
|
5204
|
+
<SlaBadge state={sla} />
|
|
5205
|
+
{conversation.assigneeId === null ? (
|
|
5206
|
+
<Badge variant="secondary">{t("Unassigned")}</Badge>
|
|
5207
|
+
) : null}
|
|
5208
|
+
{conversation.botMode === "bot" ? (
|
|
5209
|
+
<Badge variant="secondary">{t("Bot")}</Badge>
|
|
5210
|
+
) : null}
|
|
5211
|
+
</span>
|
|
5212
|
+
</Link>
|
|
5213
|
+
</li>
|
|
5214
|
+
);
|
|
5215
|
+
})}
|
|
5216
|
+
{hasMore && last ? (
|
|
5217
|
+
<li className="p-3">
|
|
5218
|
+
<Button
|
|
5219
|
+
variant="outline"
|
|
5220
|
+
size="sm"
|
|
5221
|
+
className="w-full"
|
|
5222
|
+
disabled={next.pending}
|
|
4558
5223
|
onClick={() => {
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
5224
|
+
void next
|
|
5225
|
+
.run({
|
|
5226
|
+
status,
|
|
5227
|
+
assignee,
|
|
5228
|
+
channel,
|
|
5229
|
+
q,
|
|
5230
|
+
cursor: { id: last.id, lastMessageAt: last.lastMessageAt },
|
|
5231
|
+
})
|
|
5232
|
+
.then((result) => {
|
|
5233
|
+
if (result.ok) {
|
|
5234
|
+
setMore((current) => [...current, ...result.data]);
|
|
5235
|
+
}
|
|
5236
|
+
});
|
|
4563
5237
|
}}
|
|
4564
5238
|
>
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
{conversation.contactName || t("Visitor")}
|
|
4568
|
-
</span>
|
|
4569
|
-
{unread(conversation) ? <Badge>{t("New")}</Badge> : null}
|
|
4570
|
-
</span>
|
|
4571
|
-
<span className="truncate">
|
|
4572
|
-
{conversation.subject ?? t("No subject")}
|
|
4573
|
-
</span>
|
|
4574
|
-
<span className="flex gap-2 text-xs text-muted-foreground">
|
|
4575
|
-
<span className="flex-1 truncate">{conversation.preview}</span>
|
|
4576
|
-
{conversation.lastMessageAt ? (
|
|
4577
|
-
<span className="tabular-nums">
|
|
4578
|
-
{format.dateTime(new Date(conversation.lastMessageAt), {
|
|
4579
|
-
dateStyle: "short",
|
|
4580
|
-
timeStyle: "short",
|
|
4581
|
-
})}
|
|
4582
|
-
</span>
|
|
4583
|
-
) : null}
|
|
4584
|
-
</span>
|
|
4585
|
-
</button>
|
|
5239
|
+
{t("Load more")}
|
|
5240
|
+
</Button>
|
|
4586
5241
|
</li>
|
|
5242
|
+
) : null}
|
|
5243
|
+
</ul>
|
|
5244
|
+
);
|
|
5245
|
+
}
|
|
5246
|
+
|
|
5247
|
+
export function QueueSkeleton() {
|
|
5248
|
+
return (
|
|
5249
|
+
<div className="flex flex-col gap-2" aria-busy="true">
|
|
5250
|
+
{Array.from({ length: 6 }, (_, index) => (
|
|
5251
|
+
<Skeleton key={index} className="h-20 w-full" />
|
|
4587
5252
|
))}
|
|
4588
|
-
</
|
|
5253
|
+
</div>
|
|
4589
5254
|
);
|
|
4590
5255
|
}
|
|
4591
5256
|
```
|
|
@@ -5877,32 +6542,66 @@ import { useState } from "react";
|
|
|
5877
6542
|
|
|
5878
6543
|
import { Button } from "@/components/ui/button";
|
|
5879
6544
|
|
|
6545
|
+
import type { MessageBranch, ModelOption } from "../assistant-queries";
|
|
6546
|
+
|
|
6547
|
+
import { switchChatBranch } from "../assistant-actions";
|
|
5880
6548
|
import { ChatView } from "./chat-view";
|
|
5881
6549
|
|
|
6550
|
+
const NO_MODELS: readonly ModelOption[] = [];
|
|
6551
|
+
const NO_BRANCHES: readonly MessageBranch[] = [];
|
|
6552
|
+
|
|
5882
6553
|
export type ChatMode = "standard" | "durable" | "research";
|
|
5883
6554
|
|
|
5884
6555
|
interface PanelProps {
|
|
5885
6556
|
readonly id: string;
|
|
5886
6557
|
readonly messages: UIMessage[];
|
|
5887
6558
|
readonly streaming: boolean;
|
|
6559
|
+
readonly models: readonly ModelOption[];
|
|
6560
|
+
readonly model: string | undefined;
|
|
6561
|
+
readonly onModelChange: (model: string) => void;
|
|
6562
|
+
readonly branches: readonly MessageBranch[];
|
|
5888
6563
|
}
|
|
5889
6564
|
|
|
5890
6565
|
/**
|
|
5891
6566
|
* The answer streams from the request; a reload picks it up from the stream
|
|
5892
6567
|
* store.
|
|
5893
6568
|
*/
|
|
5894
|
-
function StandardPanel({
|
|
6569
|
+
function StandardPanel({
|
|
6570
|
+
id,
|
|
6571
|
+
messages,
|
|
6572
|
+
models,
|
|
6573
|
+
model,
|
|
6574
|
+
onModelChange,
|
|
6575
|
+
branches,
|
|
6576
|
+
}: PanelProps) {
|
|
5895
6577
|
const router = useRouter();
|
|
5896
6578
|
|
|
5897
6579
|
const chat = useAssistant({
|
|
5898
6580
|
id,
|
|
5899
6581
|
messages,
|
|
6582
|
+
...(model === undefined ? {} : { model }),
|
|
5900
6583
|
onFinish: () => {
|
|
5901
6584
|
router.refresh();
|
|
5902
6585
|
},
|
|
5903
6586
|
});
|
|
5904
6587
|
|
|
5905
|
-
return
|
|
6588
|
+
return (
|
|
6589
|
+
<ChatView
|
|
6590
|
+
id={id}
|
|
6591
|
+
chat={chat}
|
|
6592
|
+
models={models}
|
|
6593
|
+
{...(model === undefined ? {} : { model })}
|
|
6594
|
+
onModelChange={onModelChange}
|
|
6595
|
+
branches={branches}
|
|
6596
|
+
onSwitchBranch={(messageId) => {
|
|
6597
|
+
void switchChatBranch({ chatId: id, messageId }).then(() => {
|
|
6598
|
+
router.refresh();
|
|
6599
|
+
});
|
|
6600
|
+
}}
|
|
6601
|
+
uploads
|
|
6602
|
+
rating
|
|
6603
|
+
/>
|
|
6604
|
+
);
|
|
5906
6605
|
}
|
|
5907
6606
|
|
|
5908
6607
|
/**
|
|
@@ -5928,7 +6627,7 @@ function DurablePanel({
|
|
|
5928
6627
|
},
|
|
5929
6628
|
});
|
|
5930
6629
|
|
|
5931
|
-
return <ChatView id={id} chat={chat} />;
|
|
6630
|
+
return <ChatView id={id} chat={chat} uploads rating />;
|
|
5932
6631
|
}
|
|
5933
6632
|
|
|
5934
6633
|
/**
|
|
@@ -5941,12 +6640,18 @@ export function AssistantChat({
|
|
|
5941
6640
|
streaming = false,
|
|
5942
6641
|
initialMode = "standard",
|
|
5943
6642
|
durableAvailable,
|
|
6643
|
+
models = NO_MODELS,
|
|
6644
|
+
initialModel,
|
|
6645
|
+
branches = NO_BRANCHES,
|
|
5944
6646
|
}: {
|
|
5945
6647
|
id: string;
|
|
5946
6648
|
messages: UIMessage[];
|
|
5947
6649
|
streaming?: boolean;
|
|
5948
6650
|
initialMode?: ChatMode;
|
|
5949
6651
|
durableAvailable: boolean;
|
|
6652
|
+
models?: readonly ModelOption[];
|
|
6653
|
+
initialModel?: string | undefined;
|
|
6654
|
+
branches?: readonly MessageBranch[];
|
|
5950
6655
|
}) {
|
|
5951
6656
|
const t = useExtracted("assistant");
|
|
5952
6657
|
|
|
@@ -5960,7 +6665,19 @@ export function AssistantChat({
|
|
|
5960
6665
|
{ mode: "research", label: t("Research") },
|
|
5961
6666
|
];
|
|
5962
6667
|
|
|
5963
|
-
const
|
|
6668
|
+
const [model, setModel] = useState<string | undefined>(
|
|
6669
|
+
initialModel ?? models[0]?.id,
|
|
6670
|
+
);
|
|
6671
|
+
|
|
6672
|
+
const panel = {
|
|
6673
|
+
id,
|
|
6674
|
+
messages,
|
|
6675
|
+
streaming,
|
|
6676
|
+
models,
|
|
6677
|
+
model,
|
|
6678
|
+
onModelChange: setModel,
|
|
6679
|
+
branches,
|
|
6680
|
+
};
|
|
5964
6681
|
|
|
5965
6682
|
return (
|
|
5966
6683
|
<div className="flex flex-col gap-3">
|
|
@@ -6752,7 +7469,7 @@ export function WorkflowRuns({ tenant }: { tenant: string | null }) {
|
|
|
6752
7469
|
<TableRow key={run.id}>
|
|
6753
7470
|
<TableCell>
|
|
6754
7471
|
<Link
|
|
6755
|
-
href={`/workflows/${run.id}`}
|
|
7472
|
+
href={`/workflows/runs/${run.id}`}
|
|
6756
7473
|
prefetch
|
|
6757
7474
|
className="font-medium"
|
|
6758
7475
|
>
|
|
@@ -12159,7 +12876,16 @@ export async function ContactDetail({ id }: { id: string }) {
|
|
|
12159
12876
|
</CardContent>
|
|
12160
12877
|
</Card>
|
|
12161
12878
|
<Suspense fallback={<ActivityTimelineSkeleton />}>
|
|
12162
|
-
<
|
|
12879
|
+
<AfterNavigation>
|
|
12880
|
+
<ActivityTimeline
|
|
12881
|
+
subject={{ type: contact.kind, id: contact.id }}
|
|
12882
|
+
/>
|
|
12883
|
+
</AfterNavigation>
|
|
12884
|
+
</Suspense>
|
|
12885
|
+
<Suspense fallback={<ContactSalesPanelSkeleton />}>
|
|
12886
|
+
<AfterNavigation>
|
|
12887
|
+
<ContactSalesPanel type={contact.kind} id={contact.id} />
|
|
12888
|
+
</AfterNavigation>
|
|
12163
12889
|
</Suspense>
|
|
12164
12890
|
</div>
|
|
12165
12891
|
{contact.kind === "company" ? (
|
|
@@ -13435,7 +14161,57 @@ export function WorkItemGrid({
|
|
|
13435
14161
|
const sortLabel = useSortLabel();
|
|
13436
14162
|
const [navigating, startTransition] = useTransition();
|
|
13437
14163
|
const [search, setSearch] = useState(query.q);
|
|
13438
|
-
|
|
14164
|
+
// The controller outlives renders, so it reads the latest message formatter.
|
|
14165
|
+
const latestErrorMessage = useLatest(errorMessage);
|
|
14166
|
+
|
|
14167
|
+
const { view: bulk } = useController(
|
|
14168
|
+
() =>
|
|
14169
|
+
createBulkSelectionController({
|
|
14170
|
+
run: async ({ rows: ids, action, args }) => {
|
|
14171
|
+
const to = WORK_ITEM_STATES.find((state) => state === args?.["to"]);
|
|
14172
|
+
|
|
14173
|
+
const result = await runWorkBulkAction(
|
|
14174
|
+
action === "state" && to !== undefined
|
|
14175
|
+
? { action: "state", ids: [...ids], to }
|
|
14176
|
+
: { action: "delete", ids: [...ids] },
|
|
14177
|
+
);
|
|
14178
|
+
|
|
14179
|
+
if (!result.ok) {
|
|
14180
|
+
toast.error(latestErrorMessage.current(result.error));
|
|
14181
|
+
throw new Error(result.error.message);
|
|
14182
|
+
}
|
|
14183
|
+
|
|
14184
|
+
const failed = new Map(
|
|
14185
|
+
result.data.failed.map((row) => [row.id, row]),
|
|
14186
|
+
);
|
|
14187
|
+
|
|
14188
|
+
return {
|
|
14189
|
+
mode: "now",
|
|
14190
|
+
total: result.data.total,
|
|
14191
|
+
succeeded: result.data.succeeded,
|
|
14192
|
+
failed: failed.size,
|
|
14193
|
+
results: ids.map((id) => {
|
|
14194
|
+
const row = failed.get(id);
|
|
14195
|
+
|
|
14196
|
+
return {
|
|
14197
|
+
id,
|
|
14198
|
+
ok: row === undefined,
|
|
14199
|
+
error: row
|
|
14200
|
+
? {
|
|
14201
|
+
code: row.code ?? undefined,
|
|
14202
|
+
message: row.message,
|
|
14203
|
+
sqlstate: undefined,
|
|
14204
|
+
}
|
|
14205
|
+
: null,
|
|
14206
|
+
};
|
|
14207
|
+
}),
|
|
14208
|
+
};
|
|
14209
|
+
},
|
|
14210
|
+
}),
|
|
14211
|
+
[latestErrorMessage],
|
|
14212
|
+
);
|
|
14213
|
+
|
|
14214
|
+
const selected = new Set(bulk.selected);
|
|
13439
14215
|
|
|
13440
14216
|
const onEditError = (error: DbError) => {
|
|
13441
14217
|
toast.error(workErrorHint(error.hint) ?? errorMessage(error));
|
|
@@ -13607,14 +14383,7 @@ export function WorkItemGrid({
|
|
|
13607
14383
|
)}
|
|
13608
14384
|
</div>
|
|
13609
14385
|
</div>
|
|
13610
|
-
{canBulk ?
|
|
13611
|
-
<BulkActionBar
|
|
13612
|
-
selected={selectedRows}
|
|
13613
|
-
onSettled={(failedIds) => {
|
|
13614
|
-
setSelected(new Set(failedIds));
|
|
13615
|
-
}}
|
|
13616
|
-
/>
|
|
13617
|
-
) : null}
|
|
14386
|
+
{canBulk ? <BulkActionBar selected={selectedRows} bulk={bulk} /> : null}
|
|
13618
14387
|
<Table>
|
|
13619
14388
|
<TableHeader>
|
|
13620
14389
|
<TableRow>
|
|
@@ -13625,9 +14394,11 @@ export function WorkItemGrid({
|
|
|
13625
14394
|
indeterminate={selection.length > 0 && !allSelected}
|
|
13626
14395
|
aria-label={t("Select all")}
|
|
13627
14396
|
onCheckedChange={(checked) => {
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
14397
|
+
if (checked) {
|
|
14398
|
+
bulk.selectMany(rows.map((row) => row.id));
|
|
14399
|
+
} else {
|
|
14400
|
+
bulk.clear();
|
|
14401
|
+
}
|
|
13631
14402
|
}}
|
|
13632
14403
|
/>
|
|
13633
14404
|
</TableHead>
|
|
@@ -13666,17 +14437,11 @@ export function WorkItemGrid({
|
|
|
13666
14437
|
identifier: row.identifier,
|
|
13667
14438
|
})}
|
|
13668
14439
|
onCheckedChange={(checked) => {
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
} else {
|
|
13675
|
-
next.delete(row.id);
|
|
13676
|
-
}
|
|
13677
|
-
|
|
13678
|
-
return next;
|
|
13679
|
-
});
|
|
14440
|
+
if (checked) {
|
|
14441
|
+
bulk.select(row.id);
|
|
14442
|
+
} else {
|
|
14443
|
+
bulk.deselect(row.id);
|
|
14444
|
+
}
|
|
13680
14445
|
}}
|
|
13681
14446
|
/>
|
|
13682
14447
|
</TableCell>
|
|
@@ -14498,59 +15263,60 @@ npx shadcn add alert alert-dialog button select
|
|
|
14498
15263
|
*/
|
|
14499
15264
|
export function BulkActionBar({
|
|
14500
15265
|
selected,
|
|
14501
|
-
|
|
15266
|
+
bulk,
|
|
14502
15267
|
}: {
|
|
14503
15268
|
selected: readonly Pick<WorkItemRow, "id" | "identifier">[];
|
|
14504
|
-
|
|
15269
|
+
bulk: BulkSelectionSnapshot & BulkSelectionActions;
|
|
14505
15270
|
}) {
|
|
14506
15271
|
const t = useExtracted("work");
|
|
14507
|
-
const errorMessage = useErrorMessage();
|
|
14508
15272
|
const stateLabel = useStateLabel();
|
|
14509
15273
|
const [to, setTo] = useState<TaskState | null>(null);
|
|
14510
15274
|
const [confirming, setConfirming] = useState(false);
|
|
14511
15275
|
const [failures, setFailures] = useState<readonly BulkFailure[]>([]);
|
|
14512
|
-
const bulk = useAction(runWorkBulkAction);
|
|
14513
15276
|
|
|
14514
15277
|
const identifiers = new Map(selected.map((row) => [row.id, row.identifier]));
|
|
14515
15278
|
|
|
14516
15279
|
const run = async (
|
|
14517
15280
|
input: { action: "state"; to: TaskState } | { action: "delete" },
|
|
14518
15281
|
): Promise<void> => {
|
|
14519
|
-
const
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
15282
|
+
const outcome = await bulk.run(
|
|
15283
|
+
input.action === "state"
|
|
15284
|
+
? { action: "state", args: { to: input.to } }
|
|
15285
|
+
: { action: "delete" },
|
|
15286
|
+
);
|
|
14524
15287
|
|
|
15288
|
+
// The grid's `run` already showed the error of a call that threw.
|
|
15289
|
+
if (outcome?.mode !== "now") {
|
|
14525
15290
|
return;
|
|
14526
15291
|
}
|
|
14527
15292
|
|
|
14528
|
-
const
|
|
15293
|
+
const failed = outcome.results.flatMap((row) =>
|
|
15294
|
+
row.ok || row.error === null ? [] : [{ id: row.id, error: row.error }],
|
|
15295
|
+
);
|
|
14529
15296
|
|
|
14530
15297
|
setFailures(
|
|
14531
15298
|
failed.map((row) => ({
|
|
14532
15299
|
id: row.id,
|
|
14533
15300
|
identifier: identifiers.get(row.id) ?? row.id,
|
|
14534
|
-
message:
|
|
15301
|
+
message:
|
|
15302
|
+
row.error.message === "" ? t("No reason given.") : row.error.message,
|
|
14535
15303
|
})),
|
|
14536
15304
|
);
|
|
14537
15305
|
|
|
14538
15306
|
if (failed.length === 0) {
|
|
14539
15307
|
toast.success(
|
|
14540
15308
|
t("{count, plural, one {# item updated} other {# items updated}}", {
|
|
14541
|
-
count: succeeded,
|
|
15309
|
+
count: outcome.succeeded,
|
|
14542
15310
|
}),
|
|
14543
15311
|
);
|
|
14544
15312
|
} else {
|
|
14545
15313
|
toast.warning(
|
|
14546
15314
|
t("{failed, number} of {total, number} items failed", {
|
|
14547
15315
|
failed: failed.length,
|
|
14548
|
-
total:
|
|
15316
|
+
total: outcome.total,
|
|
14549
15317
|
}),
|
|
14550
15318
|
);
|
|
14551
15319
|
}
|
|
14552
|
-
|
|
14553
|
-
onSettled(failed.map((row) => row.id));
|
|
14554
15320
|
};
|
|
14555
15321
|
|
|
14556
15322
|
const stateItems = WORK_ITEM_STATES.map((state) => ({
|
|
@@ -14670,7 +15436,7 @@ export function BulkActionBar({
|
|
|
14670
15436
|
variant="ghost"
|
|
14671
15437
|
disabled={bulk.pending}
|
|
14672
15438
|
onClick={() => {
|
|
14673
|
-
|
|
15439
|
+
bulk.clear();
|
|
14674
15440
|
}}
|
|
14675
15441
|
>
|
|
14676
15442
|
<XIcon />
|
|
@@ -15012,21 +15778,16 @@ export function RelatedItemsPanelSkeleton() {
|
|
|
15012
15778
|
|
|
15013
15779
|
## Employee directory
|
|
15014
15780
|
|
|
15015
|
-
A
|
|
15016
|
-
|
|
15017
|
-
Web, with shadcn components:
|
|
15781
|
+
A list of employees with server-side search, a status filter and a link to each record. It loads its data on the server through the block's client; the [employees block](https://bettersupabase.com/blocks/employees) must be installed (`npx better-supabase add employees`). Page: https://bettersupabase.com/recipes/employee-directory.
|
|
15018
15782
|
|
|
15019
|
-
|
|
15020
|
-
npx shadcn add card empty skeleton
|
|
15021
|
-
```
|
|
15783
|
+
Web, with no shadcn components.
|
|
15022
15784
|
|
|
15023
|
-
```tsx title="apps/examples/nextjs/src/features/people/components/employee-
|
|
15785
|
+
```tsx title="apps/examples/nextjs/src/features/people/components/employee-overview.tsx"
|
|
15024
15786
|
/**
|
|
15025
|
-
* Render inside `<Suspense>`:
|
|
15026
|
-
*
|
|
15027
|
-
* with `employees.read_sensitive`.
|
|
15787
|
+
* Render inside `<Suspense>`: every employee on the list kit, with the add
|
|
15788
|
+
* action for callers who can write.
|
|
15028
15789
|
*/
|
|
15029
|
-
export async function
|
|
15790
|
+
export async function EmployeeOverview() {
|
|
15030
15791
|
const [t, permissions] = await Promise.all([
|
|
15031
15792
|
getExtracted("people"),
|
|
15032
15793
|
getPermissions(),
|
|
@@ -15042,61 +15803,34 @@ export async function EmployeeDirectory() {
|
|
|
15042
15803
|
return null;
|
|
15043
15804
|
}
|
|
15044
15805
|
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
const managers =
|
|
15049
|
-
directory.kind === "ok"
|
|
15050
|
-
? directory.data.map((employee) => ({
|
|
15051
|
-
value: employee.id,
|
|
15052
|
-
label: employee.name,
|
|
15053
|
-
}))
|
|
15054
|
-
: [];
|
|
15806
|
+
if (directory.kind === "error") {
|
|
15807
|
+
return <PeopleLoadError title={t("The directory didn't load")} />;
|
|
15808
|
+
}
|
|
15055
15809
|
|
|
15056
|
-
const
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
/>
|
|
15061
|
-
) : null;
|
|
15810
|
+
const managers = directory.data.map((employee) => ({
|
|
15811
|
+
value: employee.id,
|
|
15812
|
+
label: employee.name,
|
|
15813
|
+
}));
|
|
15062
15814
|
|
|
15063
15815
|
return (
|
|
15064
|
-
<
|
|
15065
|
-
|
|
15066
|
-
<
|
|
15067
|
-
|
|
15068
|
-
|
|
15069
|
-
|
|
15070
|
-
{addEmployee && managers.length > 0 ? (
|
|
15071
|
-
<CardAction>{addEmployee}</CardAction>
|
|
15072
|
-
) : null}
|
|
15073
|
-
</CardHeader>
|
|
15074
|
-
<CardContent>
|
|
15075
|
-
{directory.kind === "error" ? (
|
|
15076
|
-
<PeopleLoadError title={t("The directory didn't load")} />
|
|
15077
|
-
) : directory.data.length === 0 ? (
|
|
15078
|
-
<Empty className="border">
|
|
15079
|
-
<EmptyHeader>
|
|
15080
|
-
<EmptyMedia variant="icon">
|
|
15081
|
-
<UsersIcon />
|
|
15082
|
-
</EmptyMedia>
|
|
15083
|
-
<EmptyTitle>{t("No employees yet")}</EmptyTitle>
|
|
15084
|
-
<EmptyDescription>
|
|
15085
|
-
{canWrite
|
|
15086
|
-
? t("Add the first employee to start the org chart.")
|
|
15087
|
-
: t("Ask an admin to add employees.")}
|
|
15088
|
-
</EmptyDescription>
|
|
15089
|
-
</EmptyHeader>
|
|
15090
|
-
{addEmployee ? <EmptyContent>{addEmployee}</EmptyContent> : null}
|
|
15091
|
-
</Empty>
|
|
15092
|
-
) : (
|
|
15093
|
-
<EmployeeTable
|
|
15094
|
-
employees={directory.data}
|
|
15095
|
-
canViewSensitive={canViewSensitive}
|
|
15816
|
+
<div className="flex flex-col gap-4">
|
|
15817
|
+
{can(permissions, "employees.write") ? (
|
|
15818
|
+
<div className="flex justify-end">
|
|
15819
|
+
<AddEmployeeDialog
|
|
15820
|
+
managers={managers}
|
|
15821
|
+
canViewSensitive={can(permissions, "employees.read_sensitive")}
|
|
15096
15822
|
/>
|
|
15823
|
+
</div>
|
|
15824
|
+
) : null}
|
|
15825
|
+
<EmployeeRecordList
|
|
15826
|
+
initial={pageBlockRows(
|
|
15827
|
+
employeeList,
|
|
15828
|
+
employeeSpec,
|
|
15829
|
+
directory.data,
|
|
15830
|
+
employeeList.defaults,
|
|
15097
15831
|
)}
|
|
15098
|
-
|
|
15099
|
-
</
|
|
15832
|
+
/>
|
|
15833
|
+
</div>
|
|
15100
15834
|
);
|
|
15101
15835
|
}
|
|
15102
15836
|
```
|
|
@@ -15563,9 +16297,10 @@ export async function RosterBoard() {
|
|
|
15563
16297
|
{shifts
|
|
15564
16298
|
.filter((shift) => shift.day === day)
|
|
15565
16299
|
.map((shift) => (
|
|
15566
|
-
<
|
|
16300
|
+
<Link
|
|
15567
16301
|
key={shift.id}
|
|
15568
|
-
|
|
16302
|
+
href={`/shifts/${shift.id}?on=${shift.day}`}
|
|
16303
|
+
className="flex flex-col gap-2 rounded-md border p-2 transition-colors hover:bg-muted/50"
|
|
15569
16304
|
>
|
|
15570
16305
|
<span className="text-sm">
|
|
15571
16306
|
{time(shift.startsAt)} – {time(shift.endsAt)}
|
|
@@ -15594,7 +16329,7 @@ export async function RosterBoard() {
|
|
|
15594
16329
|
})}
|
|
15595
16330
|
</span>
|
|
15596
16331
|
) : null}
|
|
15597
|
-
</
|
|
16332
|
+
</Link>
|
|
15598
16333
|
))}
|
|
15599
16334
|
</div>
|
|
15600
16335
|
))}
|
|
@@ -18647,6 +19382,8 @@ export async function CalendarView({
|
|
|
18647
19382
|
}: {
|
|
18648
19383
|
query: Record<string, string | string[] | undefined>;
|
|
18649
19384
|
}) {
|
|
19385
|
+
// The current month is read from the clock, which a prerender may not do.
|
|
19386
|
+
await io();
|
|
18650
19387
|
const first = firstOfMonth(query["month"], "UTC");
|
|
18651
19388
|
const weeks = weeksOf(first);
|
|
18652
19389
|
const from = weeks[0]?.[0] ?? first;
|
|
@@ -18659,7 +19396,6 @@ export async function CalendarView({
|
|
|
18659
19396
|
getExtracted("calendar"),
|
|
18660
19397
|
getFormatter(),
|
|
18661
19398
|
settle(() => loadCalendarMonth(from.toString(), until.toString())),
|
|
18662
|
-
io(),
|
|
18663
19399
|
]);
|
|
18664
19400
|
|
|
18665
19401
|
if (!can(permissions, "calendar.read")) {
|
|
@@ -27122,62 +27858,46 @@ The organization's risks in a data grid with their residual band, status and nex
|
|
|
27122
27858
|
Web, with shadcn components:
|
|
27123
27859
|
|
|
27124
27860
|
```bash
|
|
27125
|
-
npx shadcn add
|
|
27861
|
+
npx shadcn add badge @reui/data-grid
|
|
27126
27862
|
```
|
|
27127
27863
|
|
|
27128
|
-
```tsx title="apps/examples/nextjs/src/features/risks/components/risk-
|
|
27864
|
+
```tsx title="apps/examples/nextjs/src/features/risks/components/risk-record-list.tsx"
|
|
27129
27865
|
"use client";
|
|
27130
27866
|
|
|
27131
|
-
import type { CellContext
|
|
27132
|
-
import type { RiskStatus } from "better-supabase/blocks/risks";
|
|
27867
|
+
import type { CellContext } from "@tanstack/react-table";
|
|
27133
27868
|
|
|
27134
|
-
import {
|
|
27135
|
-
import { ShieldAlertIcon, TriangleAlertIcon } from "lucide-react";
|
|
27869
|
+
import { ShieldAlertIcon } from "lucide-react";
|
|
27136
27870
|
import { useExtracted, useFormatter } from "next-intl";
|
|
27137
|
-
import { useRouter } from "next/navigation";
|
|
27138
|
-
import { useTransition } from "react";
|
|
27139
27871
|
|
|
27872
|
+
import type { RecordListColumns } from "@/components/record-list/record-list-grid";
|
|
27873
|
+
import type { RecordListPage } from "@/components/record-list/record-list-types";
|
|
27140
27874
|
import type { ReadOnlyGridFeatures } from "@/components/reui/data-grid/data-grid";
|
|
27141
27875
|
|
|
27142
|
-
import {
|
|
27143
|
-
|
|
27144
|
-
AlertAction,
|
|
27145
|
-
AlertDescription,
|
|
27146
|
-
AlertTitle,
|
|
27147
|
-
} from "@/components/reui/alert";
|
|
27148
|
-
import { Badge } from "@/components/reui/badge";
|
|
27149
|
-
import {
|
|
27150
|
-
DataGrid,
|
|
27151
|
-
DataGridContainer,
|
|
27152
|
-
} from "@/components/reui/data-grid/data-grid";
|
|
27153
|
-
import { readOnlyGridFeatures } from "@/components/reui/data-grid/data-grid-features-read-only";
|
|
27154
|
-
import { DataGridScrollArea } from "@/components/reui/data-grid/data-grid-scroll-area";
|
|
27155
|
-
import { DataGridTable } from "@/components/reui/data-grid/data-grid-table";
|
|
27156
|
-
import {
|
|
27157
|
-
Frame,
|
|
27158
|
-
FrameDescription,
|
|
27159
|
-
FrameHeader,
|
|
27160
|
-
FramePanel,
|
|
27161
|
-
FrameTitle,
|
|
27162
|
-
} from "@/components/reui/frame";
|
|
27163
|
-
import { Button } from "@/components/ui/button";
|
|
27164
|
-
import {
|
|
27165
|
-
Empty,
|
|
27166
|
-
EmptyContent,
|
|
27167
|
-
EmptyDescription,
|
|
27168
|
-
EmptyHeader,
|
|
27169
|
-
EmptyMedia,
|
|
27170
|
-
EmptyTitle,
|
|
27171
|
-
} from "@/components/ui/empty";
|
|
27876
|
+
import { RecordListView } from "@/components/record-list/record-list-view";
|
|
27877
|
+
import { Link } from "@/i18n/navigation";
|
|
27172
27878
|
|
|
27173
|
-
import type {
|
|
27879
|
+
import type { RiskRow } from "../risk-rows";
|
|
27174
27880
|
|
|
27175
|
-
|
|
27176
|
-
|
|
27177
|
-
|
|
27178
|
-
|
|
27179
|
-
|
|
27180
|
-
|
|
27881
|
+
import { useRiskListState } from "../use-risk-list-state";
|
|
27882
|
+
import { RiskBandBadge } from "./risk-band-badge";
|
|
27883
|
+
import { RiskStatusBadge, useRiskStatusLabel } from "./risk-status-badge";
|
|
27884
|
+
|
|
27885
|
+
const STATUSES = ["identified", "assessed", "treating", "accepted", "closed"];
|
|
27886
|
+
const BANDS = ["low", "medium", "high", "critical"];
|
|
27887
|
+
|
|
27888
|
+
const CATEGORIES = [
|
|
27889
|
+
"quality",
|
|
27890
|
+
"safety",
|
|
27891
|
+
"environment",
|
|
27892
|
+
"security",
|
|
27893
|
+
"compliance",
|
|
27894
|
+
"operational",
|
|
27895
|
+
"financial",
|
|
27896
|
+
"strategic",
|
|
27897
|
+
];
|
|
27898
|
+
|
|
27899
|
+
const capitalized = (value: string): string =>
|
|
27900
|
+
value.charAt(0).toUpperCase() + value.slice(1);
|
|
27181
27901
|
|
|
27182
27902
|
type RiskCell = CellContext<ReadOnlyGridFeatures, RiskRow>;
|
|
27183
27903
|
|
|
@@ -27190,53 +27910,23 @@ function NumberCell({ row }: RiskCell) {
|
|
|
27190
27910
|
}
|
|
27191
27911
|
|
|
27192
27912
|
function TitleCell({ row }: RiskCell) {
|
|
27193
|
-
return
|
|
27913
|
+
return (
|
|
27914
|
+
<Link
|
|
27915
|
+
href={`/risks/${row.original.id}`}
|
|
27916
|
+
prefetch
|
|
27917
|
+
className="font-medium hover:underline"
|
|
27918
|
+
>
|
|
27919
|
+
{row.original.title}
|
|
27920
|
+
</Link>
|
|
27921
|
+
);
|
|
27194
27922
|
}
|
|
27195
27923
|
|
|
27196
27924
|
function BandCell({ row }: RiskCell) {
|
|
27197
|
-
|
|
27198
|
-
const { band, tone, score } = row.original;
|
|
27199
|
-
|
|
27200
|
-
return band === null || tone === null ? (
|
|
27201
|
-
<span className="text-muted-foreground">{t("Not assessed")}</span>
|
|
27202
|
-
) : (
|
|
27203
|
-
<Badge variant={TONE_VARIANT[tone]}>
|
|
27204
|
-
{t("{band} · {score, number}", { band, score: score ?? 0 })}
|
|
27205
|
-
</Badge>
|
|
27206
|
-
);
|
|
27925
|
+
return <RiskBandBadge {...row.original} />;
|
|
27207
27926
|
}
|
|
27208
27927
|
|
|
27209
27928
|
function StatusCell({ row }: RiskCell) {
|
|
27210
|
-
|
|
27211
|
-
const status: RiskStatus = row.original.status;
|
|
27212
|
-
|
|
27213
|
-
switch (status) {
|
|
27214
|
-
case "identified": {
|
|
27215
|
-
return <Badge variant="secondary">{t("Identified")}</Badge>;
|
|
27216
|
-
}
|
|
27217
|
-
|
|
27218
|
-
case "assessed": {
|
|
27219
|
-
return <Badge variant="info-light">{t("Assessed")}</Badge>;
|
|
27220
|
-
}
|
|
27221
|
-
|
|
27222
|
-
case "treating": {
|
|
27223
|
-
return <Badge variant="warning-light">{t("Treating")}</Badge>;
|
|
27224
|
-
}
|
|
27225
|
-
|
|
27226
|
-
case "accepted": {
|
|
27227
|
-
return <Badge variant="success-light">{t("Accepted")}</Badge>;
|
|
27228
|
-
}
|
|
27229
|
-
|
|
27230
|
-
case "closed": {
|
|
27231
|
-
return <Badge variant="secondary">{t("Closed")}</Badge>;
|
|
27232
|
-
}
|
|
27233
|
-
|
|
27234
|
-
default: {
|
|
27235
|
-
const unknown: never = status;
|
|
27236
|
-
|
|
27237
|
-
return unknown;
|
|
27238
|
-
}
|
|
27239
|
-
}
|
|
27929
|
+
return <RiskStatusBadge status={row.original.status} />;
|
|
27240
27930
|
}
|
|
27241
27931
|
|
|
27242
27932
|
function ReviewCell({ row }: RiskCell) {
|
|
@@ -27255,12 +27945,24 @@ function ReviewCell({ row }: RiskCell) {
|
|
|
27255
27945
|
);
|
|
27256
27946
|
}
|
|
27257
27947
|
|
|
27258
|
-
|
|
27948
|
+
/**
|
|
27949
|
+
* The risk register on the list kit: the URL holds the search, the status,
|
|
27950
|
+
* category and band filters and the keyset cursor; the list route serves every
|
|
27951
|
+
* state but the default first page, which the server renders. The block orders
|
|
27952
|
+
* by residual score, so there is no sort control.
|
|
27953
|
+
*/
|
|
27954
|
+
export function RiskRecordList({
|
|
27955
|
+
initial,
|
|
27956
|
+
}: {
|
|
27957
|
+
initial: RecordListPage<RiskRow>;
|
|
27958
|
+
}) {
|
|
27259
27959
|
const t = useExtracted("risks");
|
|
27960
|
+
const statusLabel = useRiskStatusLabel();
|
|
27961
|
+
const list = useRiskListState();
|
|
27260
27962
|
|
|
27261
|
-
const columns:
|
|
27963
|
+
const columns: RecordListColumns<RiskRow> = [
|
|
27262
27964
|
{ accessorKey: "number", header: t("Number"), cell: NumberCell, size: 100 },
|
|
27263
|
-
{ accessorKey: "title", header: t("Risk"), cell: TitleCell, size:
|
|
27965
|
+
{ accessorKey: "title", header: t("Risk"), cell: TitleCell, size: 280 },
|
|
27264
27966
|
{ accessorKey: "category", header: t("Category"), size: 140 },
|
|
27265
27967
|
{ accessorKey: "band", header: t("Residual"), cell: BandCell, size: 150 },
|
|
27266
27968
|
{ accessorKey: "status", header: t("Status"), cell: StatusCell, size: 120 },
|
|
@@ -27272,100 +27974,40 @@ function RiskGrid({ risks }: { risks: readonly RiskRow[] }) {
|
|
|
27272
27974
|
},
|
|
27273
27975
|
];
|
|
27274
27976
|
|
|
27275
|
-
const table = useTable({
|
|
27276
|
-
features: readOnlyGridFeatures,
|
|
27277
|
-
columns,
|
|
27278
|
-
data: [...risks],
|
|
27279
|
-
getRowId: (row) => row.id,
|
|
27280
|
-
});
|
|
27281
|
-
|
|
27282
|
-
return (
|
|
27283
|
-
<DataGrid
|
|
27284
|
-
table={table}
|
|
27285
|
-
recordCount={risks.length}
|
|
27286
|
-
tableLayout={{ dense: true }}
|
|
27287
|
-
>
|
|
27288
|
-
<DataGridContainer>
|
|
27289
|
-
<DataGridScrollArea>
|
|
27290
|
-
<DataGridTable />
|
|
27291
|
-
</DataGridScrollArea>
|
|
27292
|
-
</DataGridContainer>
|
|
27293
|
-
</DataGrid>
|
|
27294
|
-
);
|
|
27295
|
-
}
|
|
27296
|
-
|
|
27297
|
-
/**
|
|
27298
|
-
* The organization's risk register: each risk with its residual band and the
|
|
27299
|
-
* date of its next review, the highest residual score first.
|
|
27300
|
-
*/
|
|
27301
|
-
export function RiskRegister({ state }: { state: Loaded<readonly RiskRow[]> }) {
|
|
27302
|
-
const t = useExtracted("risks");
|
|
27303
|
-
const router = useRouter();
|
|
27304
|
-
const [retrying, startRetry] = useTransition();
|
|
27305
|
-
|
|
27306
|
-
if (state.kind === "no-organization") {
|
|
27307
|
-
return null;
|
|
27308
|
-
}
|
|
27309
|
-
|
|
27310
27977
|
return (
|
|
27311
|
-
<
|
|
27312
|
-
|
|
27313
|
-
|
|
27314
|
-
|
|
27315
|
-
|
|
27316
|
-
|
|
27317
|
-
|
|
27318
|
-
|
|
27319
|
-
|
|
27320
|
-
|
|
27321
|
-
|
|
27322
|
-
|
|
27323
|
-
|
|
27324
|
-
|
|
27325
|
-
|
|
27326
|
-
|
|
27327
|
-
|
|
27328
|
-
|
|
27329
|
-
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
<EmptyHeader>
|
|
27345
|
-
<EmptyMedia variant="icon">
|
|
27346
|
-
<ShieldAlertIcon />
|
|
27347
|
-
</EmptyMedia>
|
|
27348
|
-
<EmptyTitle>{t("No risks yet")}</EmptyTitle>
|
|
27349
|
-
<EmptyDescription>
|
|
27350
|
-
{t(
|
|
27351
|
-
"Register a risk with its cause and consequence, then assess it against the organization's matrix.",
|
|
27352
|
-
)}
|
|
27353
|
-
</EmptyDescription>
|
|
27354
|
-
</EmptyHeader>
|
|
27355
|
-
<EmptyContent>
|
|
27356
|
-
<a
|
|
27357
|
-
className="text-sm underline underline-offset-4"
|
|
27358
|
-
href="https://bettersupabase.com/docs/blocks/risks"
|
|
27359
|
-
>
|
|
27360
|
-
{t("Read the risks guide")}
|
|
27361
|
-
</a>
|
|
27362
|
-
</EmptyContent>
|
|
27363
|
-
</Empty>
|
|
27364
|
-
) : (
|
|
27365
|
-
<RiskGrid risks={state.data} />
|
|
27366
|
-
)}
|
|
27367
|
-
</FramePanel>
|
|
27368
|
-
</Frame>
|
|
27978
|
+
<RecordListView
|
|
27979
|
+
list={list}
|
|
27980
|
+
endpoint="/api/risks/list"
|
|
27981
|
+
initial={initial}
|
|
27982
|
+
columns={columns}
|
|
27983
|
+
facets={[
|
|
27984
|
+
{
|
|
27985
|
+
key: "status",
|
|
27986
|
+
label: t("Status"),
|
|
27987
|
+
values: STATUSES,
|
|
27988
|
+
valueLabel: statusLabel,
|
|
27989
|
+
},
|
|
27990
|
+
{
|
|
27991
|
+
key: "category",
|
|
27992
|
+
label: t("Category"),
|
|
27993
|
+
values: CATEGORIES,
|
|
27994
|
+
valueLabel: capitalized,
|
|
27995
|
+
},
|
|
27996
|
+
{
|
|
27997
|
+
key: "band",
|
|
27998
|
+
label: t("Residual"),
|
|
27999
|
+
values: BANDS,
|
|
28000
|
+
valueLabel: capitalized,
|
|
28001
|
+
},
|
|
28002
|
+
]}
|
|
28003
|
+
sorts={[]}
|
|
28004
|
+
searchLabel={t("Search risks")}
|
|
28005
|
+
emptyIcon={<ShieldAlertIcon />}
|
|
28006
|
+
emptyTitle={t("No risks found")}
|
|
28007
|
+
emptyDescription={t(
|
|
28008
|
+
"Register a risk with its cause and consequence, then assess it against the organization's matrix, or change the filters.",
|
|
28009
|
+
)}
|
|
28010
|
+
/>
|
|
27369
28011
|
);
|
|
27370
28012
|
}
|
|
27371
28013
|
```
|