diff --git a/apps/studio/src/features/dashboard/components/ResourceTable/ResourceTable.tsx b/apps/studio/src/features/dashboard/components/ResourceTable/ResourceTable.tsx index b2f62297d7..78e7738f32 100644 --- a/apps/studio/src/features/dashboard/components/ResourceTable/ResourceTable.tsx +++ b/apps/studio/src/features/dashboard/components/ResourceTable/ResourceTable.tsx @@ -1,5 +1,5 @@ import type { PaginationState } from "@tanstack/react-table" -import { useState } from "react" +import { useMemo, useState } from "react" import { createColumnHelper, getCoreRowModel, @@ -19,12 +19,14 @@ type ResourceTableData = RouterOutput["page"]["list"][number] const columnsHelper = createColumnHelper() -const columns = [ +const getColumns = ({ siteId }: ResourceTableProps) => [ columnsHelper.accessor("title", { minSize: 300, header: () => Title, cell: ({ row }) => ( { + const columns = useMemo( + () => getColumns({ siteId, resourceId }), + [siteId, resourceId], + ) const { data: resources } = trpc.page.list.useQuery( { siteId, diff --git a/apps/studio/src/features/dashboard/components/ResourceTable/TitleCell.tsx b/apps/studio/src/features/dashboard/components/ResourceTable/TitleCell.tsx index 01380cfbcf..aa375ba413 100644 --- a/apps/studio/src/features/dashboard/components/ResourceTable/TitleCell.tsx +++ b/apps/studio/src/features/dashboard/components/ResourceTable/TitleCell.tsx @@ -1,18 +1,34 @@ +import { useMemo } from "react" +import NextLink from "next/link" import { HStack, Icon, Text, VStack } from "@chakra-ui/react" import { BiFileBlank, BiFolder } from "react-icons/bi" import type { ResourceTableData } from "./types" -export type TitleCellProps = Pick< - ResourceTableData, - "title" | "permalink" | "type" -> +export interface TitleCellProps + extends Pick { + siteId: number +} export const TitleCell = ({ title, permalink, type, + siteId, + id, }: TitleCellProps): JSX.Element => { + const linkToResource = useMemo(() => { + const resourceType = `${type.toLowerCase()}s` + return { + pathname: "/sites/[siteId]/[resourceType]/[id]", + query: { + siteId, + resourceType, + id, + }, + } + }, [id, siteId, type]) + return ( - + {title}