Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(collection): add blog variant for collections #924

Merged
merged 25 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ae62217
chore: wip commit for grid layout on collection results
seaerchin Dec 9, 2024
28d4b98
feat: add variant property
seaerchin Dec 9, 2024
8170820
chore: add variant for blog
seaerchin Dec 10, 2024
896d972
feat: add blog card
seaerchin Dec 10, 2024
75b653c
chore: add collection stories
seaerchin Dec 10, 2024
72ca15a
chore: blogcard stories and style fixes
seaerchin Dec 10, 2024
6369aaf
fix: sm display on collection results
seaerchin Dec 10, 2024
40d0524
chore: chnage cover to contian
seaerchin Dec 11, 2024
c341682
chore: use cover for image in blogcard
seaerchin Dec 12, 2024
e3f0a31
chore: add lines in small viewport
seaerchin Dec 12, 2024
2213543
chore: update styling
seaerchin Dec 16, 2024
cd999aa
chore: add migration for collection meta
seaerchin Dec 16, 2024
2c8b89e
chore: update publishing script to get collection meta
seaerchin Dec 17, 2024
4340c09
chore: update types
seaerchin Dec 17, 2024
0825df1
chore: generated assets
seaerchin Dec 17, 2024
147a922
chore: exhaustiveness check for types
seaerchin Dec 17, 2024
fcdb62d
chore: fix migrations
seaerchin Dec 17, 2024
d0ae11a
chore: update logic for meta
seaerchin Dec 17, 2024
8205986
chore: fix lint
seaerchin Dec 17, 2024
610d511
chore: reomve extra prop
seaerchin Dec 17, 2024
16b065e
chore: tidy formatting for generated types
seaerchin Dec 17, 2024
73738eb
chore: add comment
seaerchin Dec 18, 2024
373804f
fix: prevent showing on sidebar
seaerchin Dec 18, 2024
dbdb45d
chore: swap id to use title + category
seaerchin Dec 18, 2024
b579ec4
chore: update js script for amplify
seaerchin Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/studio/prisma/generated/generatedEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ResourceType = {
Page: "Page",
Folder: "Folder",
Collection: "Collection",
CollectionMeta: "CollectionMeta",
CollectionLink: "CollectionLink",
CollectionPage: "CollectionPage",
IndexPage: "IndexPage",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ResourceType" ADD VALUE 'CollectionMeta';
7 changes: 6 additions & 1 deletion apps/studio/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ model Resource {
// This is required so prisma does not attempt to drop the custom index.
@@unique([siteId, parentId, permalink])
@@index([siteId, id, parentId]) // note: ordering is important here!
@@index([type])
@@index([type])

// NOTE: This is used to create a inverted index using text trigrams for the title
// so that we can perform searches on the title quickly
@@index([title(ops: raw("gin_trgm_ops"))], type: Gin, name: "resource_title_trgm_idx")
seaerchin marked this conversation as resolved.
Show resolved Hide resolved
}

model Blob {
Expand All @@ -103,6 +107,7 @@ enum ResourceType {
Page
Folder
Collection
CollectionMeta // Can only ever be inside collection
CollectionLink // Can only ever be inside collection
CollectionPage // Can only live inside `Collection` resources
IndexPage // This denotes the index page of a folder or a collection
Expand Down
5 changes: 5 additions & 0 deletions apps/studio/prisma/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type {
IsomerLayoutVariants as _IsomerLayoutVariants,
IsomerPageSchemaType as _IsomerPageSchemaType,
IsomerSchema as _IsomerSchema,
IsomerSiteConfigProps as _IsomerSiteConfigProps,
Expand All @@ -20,6 +21,10 @@ declare global {
// TODO: Rename all with XXXYYYJson instead of XXXJsonYYY
type SiteJsonConfig = Tagged<_IsomerSiteConfigProps, "JSONB">
type SiteThemeJson = Tagged<_IsomerSiteThemeProps, "JSONB">
type CollectionThemeJson = Tagged<
_IsomerLayoutVariants["collection"],
"JSONB"
>
type BlobJsonContent = Tagged<_IsomerSchema, "JSONB">
type NavbarJsonContent = Tagged<
_IsomerSiteWideComponentsProps["navBarItems"],
Expand Down
31 changes: 31 additions & 0 deletions apps/studio/public/assets/css/preview-tw.css
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,10 @@ video {
margin-right: -0.5rem;
}

.-mt-1 {
margin-top: -0.25rem;
}

.-mt-8 {
margin-top: -2rem;
}
Expand Down Expand Up @@ -2540,6 +2544,11 @@ video {
padding-right: 0.25rem;
}

.px-1\.5 {
padding-left: 0.375rem;
padding-right: 0.375rem;
}

.px-10 {
padding-left: 2.5rem;
padding-right: 2.5rem;
Expand Down Expand Up @@ -2590,6 +2599,16 @@ video {
padding-right: 1px;
}

.py-0 {
padding-top: 0px;
padding-bottom: 0px;
}

.py-0\.5 {
padding-top: 0.125rem;
padding-bottom: 0.125rem;
}

.py-1 {
padding-top: 0.25rem;
padding-bottom: 0.25rem;
Expand Down Expand Up @@ -4696,6 +4715,10 @@ video {
justify-content: flex-start;
}

.sm\:gap-0 {
gap: 0px;
}

.sm\:gap-3 {
gap: 0.75rem;
}
Expand Down Expand Up @@ -4891,6 +4914,10 @@ video {
gap: 1rem;
}

.md\:gap-5 {
gap: 1.25rem;
}

.md\:gap-7 {
gap: 1.75rem;
}
Expand Down Expand Up @@ -4946,6 +4973,10 @@ video {
padding-bottom: 0.75rem;
}

.md\:pt-0 {
padding-top: 0px;
}

.md\:pt-16 {
padding-top: 4rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const ERROR_COMPONENT_PROPS: Record<ResourceType, ErrorProps> = {
"To have access, ask your site admins to assign this collection to you",
buttonText: "Back to My Sites",
},
CollectionMeta: {
seaerchin marked this conversation as resolved.
Show resolved Hide resolved
title: "You don't have access to edit this collection.",
description:
"To have access, ask your site admins to assign this collection to you",
buttonText: "Back to My Sites",
},
IndexPage: {
title: "You don't have access to edit this page.",
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function ComponentSelector() {
return []
case ResourceType.Folder:
case ResourceType.FolderMeta:
case ResourceType.CollectionMeta:
throw new Error(`Unsupported resource type: ${type}`)
default:
const exhaustiveCheck: never = type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IconType } from "react-icons"
import { ResourceType } from "~prisma/generated/generatedEnums"
import {
BiCog,
BiData,
BiFile,
BiFolder,
Expand All @@ -14,6 +15,7 @@ export const ICON_MAPPINGS: Record<ResourceType, IconType> = {
[ResourceType.Folder]: BiFolder,
[ResourceType.Collection]: BiData,
[ResourceType.CollectionPage]: BiFile,
[ResourceType.CollectionMeta]: BiCog,
seaerchin marked this conversation as resolved.
Show resolved Hide resolved
[ResourceType.CollectionLink]: BiLink,
[ResourceType.RootPage]: BiHomeAlt,
[ResourceType.IndexPage]: BiFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const useIsActive = (
case ResourceType.CollectionLink:
return siteProps.linkId === currentResourceId
case ResourceType.FolderMeta:
case ResourceType.CollectionMeta:
// TODO: Not implemented yet
return false
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HStack, Icon, Text, VStack } from "@chakra-ui/react"
import { Link } from "@opengovsg/design-system-react"
import { ResourceType } from "~prisma/generated/generatedEnums"
import {
BiCog,
BiData,
BiFile,
BiFolder,
Expand Down Expand Up @@ -43,6 +44,8 @@ export const TitleCell = ({
return BiFolder
case ResourceType.Collection:
return BiData
case ResourceType.CollectionMeta:
return BiCog
case ResourceType.CollectionPage:
return BiFile
case ResourceType.CollectionLink:
Expand Down
3 changes: 2 additions & 1 deletion apps/studio/src/server/modules/page/page.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export const pageRouter = router({
type !== ResourceType.CollectionPage &&
type !== ResourceType.RootPage &&
type !== ResourceType.IndexPage &&
type !== ResourceType.FolderMeta
type !== ResourceType.FolderMeta &&
type !== ResourceType.CollectionMeta
) {
throw new TRPCError({
code: "NOT_FOUND",
Expand Down
3 changes: 3 additions & 0 deletions apps/studio/src/server/modules/resource/resource.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const resourceRouter = router({
.select(["title", "permalink", "type", "id"])
.where("Resource.type", "!=", ResourceType.RootPage)
.where("Resource.type", "!=", ResourceType.FolderMeta)
.where("Resource.type", "!=", ResourceType.CollectionMeta)
.where("Resource.siteId", "=", Number(siteId))
.$narrowType<{
type: Extract<
Expand Down Expand Up @@ -336,6 +337,7 @@ export const resourceRouter = router({
.where("Resource.siteId", "=", siteId)
.where("Resource.type", "!=", ResourceType.RootPage)
.where("Resource.type", "!=", ResourceType.FolderMeta)
.where("Resource.type", "!=", ResourceType.CollectionMeta)
.select((eb) => [eb.fn.countAll().as("totalCount")])

if (resourceId) {
Expand All @@ -356,6 +358,7 @@ export const resourceRouter = router({
.where("Resource.siteId", "=", siteId)
.where("Resource.type", "!=", ResourceType.RootPage)
.where("Resource.type", "!=", ResourceType.FolderMeta)
.where("Resource.type", "!=", ResourceType.CollectionMeta)
.orderBy("Resource.updatedAt", "desc")
.orderBy("Resource.title", "asc")
.offset(offset)
Expand Down
6 changes: 4 additions & 2 deletions apps/studio/src/server/modules/resource/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export const getFullPageById = async (
return publishedBlob
}

// There are 6 types of pages this get query supports:
// Page, CollectionPage, RootPage, IndexPage, CollectionLink, FolderMeta
// There are 7 types of pages this get query supports:
// Page, CollectionPage, RootPage, IndexPage, CollectionLink, FolderMeta, CollectionMeta
export const getPageById = (
db: SafeKysely,
args: { resourceId: number; siteId: number },
Expand All @@ -145,6 +145,7 @@ export const getPageById = (
eb("type", "=", ResourceType.IndexPage),
eb("type", "=", ResourceType.CollectionLink),
eb("type", "=", ResourceType.FolderMeta),
eb("type", "=", ResourceType.CollectionMeta),
]),
)
.select(defaultResourceSelect)
Expand Down Expand Up @@ -309,6 +310,7 @@ export const getLocalisedSitemap = async (
return fb("Resource.parentId", "=", String(resource.parentId))
})
.where("Resource.type", "!=", ResourceType.FolderMeta)
.where("Resource.type", "!=", ResourceType.CollectionMeta)
.select(defaultResourceSelect),
)
// Step 3: Combine all the resources in a single array
Expand Down
1 change: 1 addition & 0 deletions apps/studio/src/utils/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const getResourceSubpath = (resourceType: ResourceType) => {
case ResourceType.Collection:
return "collections"
case ResourceType.FolderMeta:
case ResourceType.CollectionMeta:
// TODO: Not implemented yet
return ""
default:
Expand Down
5 changes: 3 additions & 2 deletions apps/studio/src/utils/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IsomerSitemap } from "@opengovsg/isomer-components"
import type { Resource } from "@prisma/client"
import { ResourceType } from "~prisma/generated/generatedEnums"

import type { Resource } from "~prisma/generated/selectableTypes"
import { INDEX_PAGE_PERMALINK } from "~/constants/sitemap"

type ResourceDto = Omit<
Expand All @@ -27,7 +27,8 @@ const getSitemapTreeFromArray = (
return (
resource.parentId === null &&
resource.type !== ResourceType.RootPage &&
resource.type !== ResourceType.FolderMeta
resource.type !== ResourceType.FolderMeta &&
resource.type !== ResourceType.CollectionMeta
)
}
return (
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading