Skip to content

Commit

Permalink
feat: add collection and collection page to resourcetype enum (#426)
Browse files Browse the repository at this point in the history
### TL;DR

This PR introduces support for two new resource types: `Collection` and `CollectionPage`.

### What changed?

1. Added `Collection` and `CollectionPage` to the `ResourceType` enum in Prisma schema and generated files.
2. Created a new migration file to update the `ResourceType` enum in the database.
3. Updated the `TitleCell` component to display appropriate icons for the new resource types.

### How to test?

1. Run the Prisma migrations to update the database schema.
2. Verify that the new resource types can be created and managed through the UI.
3. Check that the correct icons are displayed for the new resource types in the `ResourceTable`.

### Why make this change?

To enhance the feature set by introducing new resource types that allow better organization and categorization of content.

---
  • Loading branch information
karrui authored Aug 7, 2024
1 parent 9d8aa14 commit 5bde01a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
3 changes: 3 additions & 0 deletions apps/studio/prisma/generated/generatedEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ export const ResourceState = {
} as const
export type ResourceState = (typeof ResourceState)[keyof typeof ResourceState]
export const ResourceType = {
RootPage: "RootPage",
Page: "Page",
Folder: "Folder",
Collection: "Collection",
CollectionPage: "CollectionPage",
} as const
export type ResourceType = (typeof ResourceType)[keyof typeof ResourceType]
export const RoleType = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- AlterEnum
-- This migration adds more than one value to an enum.
-- With PostgreSQL versions 11 and earlier, this is not possible
-- in a single migration. This can be worked around by creating
-- multiple migrations, each migration adding only one value to
-- the enum.


ALTER TYPE "ResourceType" ADD VALUE 'Collection';
ALTER TYPE "ResourceType" ADD VALUE 'CollectionPage';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ResourceType" ADD VALUE 'RootPage';
3 changes: 3 additions & 0 deletions apps/studio/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ enum ResourceState {
}

enum ResourceType {
RootPage
Page
Folder
Collection
CollectionPage // Can only live inside `Collection` resources
}

model User {
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async function main() {
draftBlobId: String(blobId),
permalink: "home",
siteId,
type: "Page",
type: "RootPage",
title: "Home",
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { IconType } from "react-icons"
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 { BiData, BiFile, BiFileBlank, BiFolder, BiHome } from "react-icons/bi"

import type { ResourceTableData } from "./types"

Expand All @@ -17,23 +18,39 @@ export const TitleCell = ({
siteId,
id,
}: TitleCellProps): JSX.Element => {
const linkToResource = useMemo(() => {
const resourceType = `${type.toLowerCase()}s`
return {
pathname: "/sites/[siteId]/[resourceType]/[id]",
query: {
siteId,
resourceType,
id,
},
const linkToResource: string = useMemo(() => {
switch (type) {
case "RootPage":
case "CollectionPage":
case "Page":
return `/sites/${siteId}/pages/${id}`
case "Folder":
return `/sites/${siteId}/folders/${id}`
case "Collection":
return `/sites/${siteId}/collections/${id}`
}
}, [id, siteId, type])

const ResourceTypeIcon: IconType = useMemo(() => {
switch (type) {
case "RootPage":
return BiHome
case "Page":
return BiFileBlank
case "Folder":
return BiFolder
case "Collection":
return BiData
case "CollectionPage":
return BiFile
}
}, [type])

return (
<HStack align="center" spacing="0.625rem">
<Icon
fontSize="1.25rem"
as={type === "Page" ? BiFileBlank : BiFolder}
as={ResourceTypeIcon}
color="base.content.strong"
/>
<VStack spacing="0.25rem" align="start">
Expand Down
16 changes: 16 additions & 0 deletions apps/studio/tests/msw/handlers/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ const pageListQuery = (wait?: DelayMode | number) => {
await delay(wait)
}
return [
{
id: "1",
permalink: "",
title: "Homepage",
publishedVersionId: null,
draftBlobId: null,
type: "RootPage",
},
{
id: "1",
permalink: "newsroom",
title: "Press Releases",
publishedVersionId: null,
draftBlobId: null,
type: "Collection",
},
{
id: "4",
permalink: "test-page-1",
Expand Down

0 comments on commit 5bde01a

Please sign in to comment.