All files / src/pages/main-page/components projectCardData.ts

100% Statements 2/2
57.14% Branches 4/7
100% Functions 0/0
100% Lines 2/2

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                                                                  431x   431x                                            
import type { OwnerRead, ProjectRead } from "@/api/apiStore.gen";
 
export type ProjectCardData = {
  id: number;
  defaultFlowsheetId: number;
  name: string;
  owner: OwnerRead;
  type: string;
  rootGrouping?: number | null;
  description: string;
  badges?: string[];
  lastAccessed?: string;
  binnedAt?: string;
  isStarred?: boolean;
  isBinned?: boolean;
  folderId?: number | null;
  href?: string;
  onClick?: () => void;
};
 
/** Converts an API project into the presentation model shared by project galleries. */
export function buildProjectCardData(
  project: ProjectRead,
  {
    type,
    folderId = project.folder,
    onMissingFlowsheet,
  }: {
    type: string;
    folderId?: number | null;
    onMissingFlowsheet?: () => void;
  },
): ProjectCardData {
  const timestamp = new Date(project.savedDate ?? project.created_at).getTime();
 
  return {
    id: project.id,
    defaultFlowsheetId: project.active_flowsheet!,
    owner: project.owner,
    name: project.name!,
    type,
    rootGrouping: project.active_flowsheet_rootGrouping,
    description: new Date(timestamp).toLocaleDateString("en-GB", {
      year: "numeric",
      month: "short",
      day: "numeric",
    }),
    binnedAt: project.binned_at,
    isStarred: project.is_starred,
    isBinned: project.is_binned,
    folderId,
    href: project.active_flowsheet
      ? `/project/${project.active_flowsheet}/flowsheet`
      : undefined,
    onClick: project.active_flowsheet ? undefined : onMissingFlowsheet,
  };
}