All files / src/apps/workspace/pages Home.tsx

100% Statements 10/10
67.85% Branches 19/28
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159                                                    1x 14x                                             1x 2x 2x 2x 2x   2x                                                                                                                         2x                                                               14x                  
import React from "react";
import { Link } from "react-router-dom";
import {
  ArrowDownToLine,
  BookOpen,
  Bot,
  FolderKanban,
  GitBranch,
  LayoutDashboard,
  Settings,
  ShieldCheck,
  Users,
} from "lucide-react";
import MainPage from "@/components/page/MainPage/MainPage";
import { MetaGrid, MetaItem, SectionCard } from "@/components/detail";
import { useWorkspace } from "@/context/WorkspaceContext";
import { ROLE_LABELS } from "@/objects/Organisation";
import { APP_ROUTES } from "@/routes/const";
 
interface Destination {
  icon: React.ElementType;
  label: string;
  description: string;
  to: string;
}
 
const Card: React.FC<Destination> = ({ icon: Icon, label, description, to }) => (
  <Link
    to={to}
    className="flex items-start gap-3 p-4 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-600 hover:shadow-sm transition-all"
  >
    <div className="p-2 rounded-lg bg-gray-100 dark:bg-gray-700 shrink-0">
      <Icon className="size-4 text-gray-600 dark:text-gray-300" />
    </div>
    <div className="min-w-0">
      <div className="text-sm font-semibold text-gray-800 dark:text-gray-200">
        {label}
      </div>
      <div className="text-xs text-gray-400 dark:text-gray-500 mt-0.5 leading-relaxed">
        {description}
      </div>
    </div>
  </Link>
);
 
/**
 * An organisation's or a project's home: what it is, the caller's place in
 * it, and its areas. Every link is written against `APP_ROUTES.USER` and
 * stays inside the workspace (`routes/router.tsx`).
 */
const WorkspaceHome: React.FC = () => {
  const ws = useWorkspace();
  const info = ws.info;
  const isProject = ws.kind === "project";
  const name = info?.name ?? (isProject ? "Project" : "Organisation");
 
  const destinations: Destination[] = [
    {
      icon: Bot,
      label: "Inference",
      description: "Agents, skills and skillsets this workspace runs.",
      to: APP_ROUTES.USER.inference,
    },
    {
      icon: BookOpen,
      label: "Knowledge",
      description: "Repositories and sources its agents ground their answers in.",
      to: APP_ROUTES.USER.knowledge,
    },
    {
      icon: ShieldCheck,
      label: "Governance",
      description: isProject
        ? "Its rules, the ones it inherits, evaluation and reviews."
        : "Rules for everything here and in its projects, evaluation and reviews.",
      to: APP_ROUTES.USER.governance,
    },
    {
      icon: LayoutDashboard,
      label: "Dashboards",
      description: "Boards over this workspace's activity and spend.",
      to: APP_ROUTES.USER.dashboards,
    },
    ...(isProject
      ? []
      : [
          {
            icon: FolderKanban,
            label: "Projects",
            description: "Workspaces for one initiative, inside this organisation.",
            to: APP_ROUTES.USER.projects,
          },
        ]),
    ...(isProject
      ? [
          {
            icon: ArrowDownToLine,
            label: "Inheritance",
            description: "What this project uses of its parent's work, and the rules it must follow.",
            to: APP_ROUTES.USER.WORKSPACE_SETTINGS.inheritance,
          },
        ]
      : []),
    {
      icon: Users,
      label: "Members",
      description: "Who belongs, their access per area, and invite links.",
      to: APP_ROUTES.USER.WORKSPACE_SETTINGS.members,
    },
    {
      icon: Settings,
      label: "Settings",
      description: `This ${isProject ? "project" : "organisation"}'s name and details.`,
      to: APP_ROUTES.USER.WORKSPACE_SETTINGS.general,
    },
  ];
 
  return (
    <MainPage
      title={name}
      description={
        isProject
          ? `A project${info?.parent?.name ? ` of ${info.parent.kind === "personal" ? "your personal workspace" : info.parent.name}` : ""}.`
          : "An organisation's shared workspace."
      }
      links={[]}
    >
      <div className="space-y-6">
        <SectionCard variant="panel" icon={GitBranch} title="This workspace">
          <MetaGrid>
            <MetaItem label="Type" value={isProject ? "Project" : "Organisation"} />
            {info?.parent && (
              <MetaItem
                label="Inside"
                value={info.parent.kind === "personal" ? "Personal" : info.parent.name}
              />
            )}
            <MetaItem
              label="Your role"
              value={
                info?.role
                  ? `${ROLE_LABELS[info.role]}${info.implicit ? " (by position)" : ""}`
                  : "—"
              }
            />
          </MetaGrid>
        </SectionCard>
        <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
          {destinations.map((d) => (
            <Card key={d.label} {...d} />
          ))}
        </div>
      </div>
    </MainPage>
  );
};
 
export default WorkspaceHome;