Skip to content

Commit 2cda6bb

Browse files
feat(collections): add pdf collection item (#782)
* chore: add new migration * refactor: add new tyupes * refactor: make resource id required * chore: update collection pdf json update to the correct layout and permalink so we can show the correct view * refactor: shift preview into 2 components 1 handle sitemap, 1 accepts sitemap as is * fix: update wizard remove merging of title for collection * refactor: use new preview for creation modals * refactor: backend to allow for collection files * fix: remove url from schema for links * chore: update dates * feat: add new icon * refactor: update to `/links` * chore: add new migration * chore: update references to be link * chore: update icons * fix: add collection to resource * chore: add new migration * chore: utils update sitemap to have homepage layout * feat: add new layout for link * fix: filter for collection link we need to return collection link because it's a valid child * feat: add new getSiblingsOf method * feat: add new page for link editing * chore: update thedetails for colletion sitemap 1. no more file layout 2. removed file details due to 1. * refactor: add previews 1. add new preview for links 2. shifts shared code for viewport out into new file * refactor: preview layout for collections 1. swap `file` -> `link` * fix: invalid date feor previvew pass date properly to the preview * chore: rename site edit navbar to page * feat: add new link edit navbar * feat: util method for generating preview sitemap shift method into new util file * chore: components export layout maps * fix: fix type errors * chore: generate types * chore: update ref for links * feat: json forms link control add file attachment in * refactor: link attachment layout * chore: styilng * refactor: use `ref` format for link page * fix: update select for getchildrenof * refactor: introduce 1 more layer of indirection to link modal 1. previously, it was taking editor directly which made it harder to reuse 2. now, we want to show the modal also on json forms so we need to abstract the `editor` prop * fix: linkeditormodal remove extra deps which we implictly have due to using the zod schema * refactor: link modal now accepts a link types to decide what to render * fix: update typing + export new type * chore: tidy up types * feat: add new form control * chore: componnet changes * chore: aded new link type * feat: edit link page * fix: edit link preview use the correct title to render * chore: remove console logs * chore: refactor link editor drawer shift error provider out so we can call it inside the component * chore: squash components for edit link * feat: add backend capabilities * feat: update atom typing * chore: format * feat: seed with backend ata * chore: relocate collection schemas to proper folder * chore: update typings * fix: use correct prop 1. use `description` rather than `summary` 2. update various wordings * refactor: full width button at bottom * fix: use correct schema * fix: update only the draftblob * fix(links): add validation to components that are links or refs (#789) * feat: add https on frontend * fix: add validation for all our links * chore: add correct states to each component * chore: fix bugs with link editor * add comment --------- Co-authored-by: adriangohjw <[email protected]> * fix: remove showing children * fix: remove form error message the attachment lib already exports their own so we are good iwth the error messages * fix: add defaults * fix: use resourcetype * fix: validation * chore: change copy and icon * chore: update ui * chore: shift shared wording out * chore: add validation * chore: remove unused * fix: add extra property for perms boundary * fix: width for error page * chore: add stories * chore: add stories * fix: remove extra story * chore: add default title and styling * fix: design review * fix: remove non-working stories * fix: styling for text * fix: remove link editing tab * fix: add category * chore: update for perms * fix: links add in draft retrieval for blobs * chore: remove unused --------- Co-authored-by: adriangohjw <[email protected]>
1 parent 72dadba commit 2cda6bb

File tree

79 files changed

+1588
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1588
-412
lines changed

apps/studio/prisma/generated/generatedEnums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const ResourceType = {
88
Page: "Page",
99
Folder: "Folder",
1010
Collection: "Collection",
11+
CollectionLink: "CollectionLink",
1112
CollectionPage: "CollectionPage",
1213
IndexPage: "IndexPage",
1314
} as const

apps/studio/prisma/generated/selectableTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type * as T from "./generatedTypes"
66
export type Blob = Selectable<T.Blob>
77
export type Footer = Selectable<T.Footer>
88
export type Navbar = Selectable<T.Navbar>
9-
export type Permission = Selectable<T.Permission>
109
export type RateLimiterFlexible = Selectable<T.RateLimiterFlexible>
1110
export type Resource = Selectable<T.Resource>
1211
export type ResourcePermission = Selectable<T.ResourcePermission>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "ResourceType" ADD VALUE 'CollectionFile';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Warnings:
3+
4+
- The values [CollectionFile] on the enum `ResourceType` will be removed. If these variants are still used in the database, this will fail.
5+
6+
*/
7+
-- AlterEnum
8+
BEGIN;
9+
CREATE TYPE "ResourceType_new" AS ENUM ('RootPage', 'Page', 'Folder', 'Collection', 'CollectionLink', 'CollectionPage');
10+
ALTER TABLE "Resource" ALTER COLUMN "type" TYPE "ResourceType_new" USING ("type"::text::"ResourceType_new");
11+
ALTER TYPE "ResourceType" RENAME TO "ResourceType_old";
12+
ALTER TYPE "ResourceType_new" RENAME TO "ResourceType";
13+
DROP TYPE "ResourceType_old";
14+
COMMIT;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "ResourceType" ADD VALUE 'IndexPage';

apps/studio/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ enum ResourceType {
103103
Page
104104
Folder
105105
Collection
106+
CollectionLink // Can only ever be inside collection
106107
CollectionPage // Can only live inside `Collection` resources
107108
IndexPage // This denotes the index page of a folder or a collection
108109
}

apps/studio/public/assets/css/preview-tw.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,11 @@ video {
23762376
background-color: transparent;
23772377
}
23782378

2379+
.bg-utility-feedback-info-faint {
2380+
--tw-bg-opacity: 1;
2381+
background-color: rgb(234 242 255 / var(--tw-bg-opacity));
2382+
}
2383+
23792384
.bg-utility-feedback-info-subtle {
23802385
--tw-bg-opacity: 1;
23812386
background-color: rgb(219 234 254 / var(--tw-bg-opacity));
@@ -3585,6 +3590,10 @@ video {
35853590
grid-template-rows: auto 1fr;
35863591
}
35873592

3593+
.\[resource\:some-resource\] {
3594+
resource: some-resource;
3595+
}
3596+
35883597
.current\:prose-label-md-medium[data-current] {
35893598
font-weight: 500;
35903599
letter-spacing: 0;
@@ -4652,6 +4661,10 @@ video {
46524661
height: 13rem;
46534662
}
46544663

4664+
.md\:h-60 {
4665+
height: 15rem;
4666+
}
4667+
46554668
.md\:h-\[240px\] {
46564669
height: 240px;
46574670
}

apps/studio/src/components/AuthWrappers/PermissionsBoundary.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const ERROR_COMPONENT_PROPS: Record<ResourceType, ErrorProps> = {
3232
"To have access, ask your site admins to assign this page to you",
3333
buttonText: "Back to Site Content",
3434
},
35+
CollectionLink: {
36+
title: "You don't have access to edit this item.",
37+
description:
38+
"To have access, ask your site admins to assign this item to you",
39+
buttonText: "Back to Site Content",
40+
},
3541
CollectionPage: {
3642
title: "You don't have access to edit this page.",
3743
description:

apps/studio/src/components/PageEditor/ComponentSelector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function ComponentSelector() {
176176
case "CollectionPage":
177177
return ARTICLE_ALLOWED_BLOCKS
178178
case "Collection":
179+
case "CollectionLink":
179180
case "IndexPage":
180181
return []
181182
case "Folder":

apps/studio/src/components/PageEditor/FileAttachment.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1+
import type { AttachmentProps } from "@opengovsg/design-system-react"
12
import { useEffect, useState } from "react"
23
import { FormControl, Skeleton, Text } from "@chakra-ui/react"
3-
import { Attachment, FormErrorMessage } from "@opengovsg/design-system-react"
4+
import { Attachment } from "@opengovsg/design-system-react"
45

56
import { MAX_PDF_FILE_SIZE_BYTES } from "~/features/editing-experience/components/form-builder/renderers/controls/constants"
67
import { useUploadAssetMutation } from "~/hooks/useUploadAssetMutation"
78
import { getPresignedPutUrlSchema } from "~/schemas/asset"
89

910
interface FileAttachmentProps {
10-
setHref: (href: string) => void
11+
setHref: (href?: string) => void
1112
siteId: number
12-
error?: string
13-
setError: (error: string) => void
14-
clearError: () => void
13+
value?: File
1514
}
1615

16+
type FileRejections = AttachmentProps<false>["rejections"]
17+
1718
export const FileAttachment = ({
1819
setHref,
1920
siteId,
20-
error,
21-
setError,
22-
clearError,
21+
value,
2322
}: FileAttachmentProps) => {
24-
const [file, setFile] = useState<File | undefined>(undefined)
23+
const [file, setFile] = useState<File | undefined>(value)
24+
const [rejections, setRejections] = useState<FileRejections>([])
2525
// TODO: Add a mutation for deletion next time of s3 resources
2626
const { mutate: uploadFile, isLoading } = useUploadAssetMutation({
2727
siteId,
@@ -40,11 +40,12 @@ export const FileAttachment = ({
4040
name="file-upload"
4141
multiple={false}
4242
value={file}
43+
rejections={rejections}
44+
onRejection={setRejections}
4345
onChange={(file) => {
4446
setFile(file)
4547
if (!file) {
46-
setHref("")
47-
setError("Please make sure you upload a file!")
48+
setHref()
4849
return
4950
}
5051

@@ -53,12 +54,10 @@ export const FileAttachment = ({
5354
{
5455
onSuccess: ({ path }) => {
5556
setHref(path)
56-
clearError()
5757
},
5858
},
5959
)
6060
}}
61-
onError={setError}
6261
maxSize={MAX_PDF_FILE_SIZE_BYTES}
6362
accept={["application/pdf"]}
6463
onFileValidation={(file) => {
@@ -78,7 +77,6 @@ export const FileAttachment = ({
7877
<Text textStyle="body-2" textColor="base.content.medium" pt="0.5rem">
7978
{`Maximum file size: ${MAX_PDF_FILE_SIZE_BYTES / 1000000} MB`}
8079
</Text>
81-
{error && <FormErrorMessage>{error}</FormErrorMessage>}
8280
</FormControl>
8381
)
8482
}

0 commit comments

Comments
 (0)