Commit c769f06
authored
PLU-337: Allow attachments in postman (#821)
## Problem
Users want to upload a fixed file when sending email via Postman.
## Solution
Allow uploads at Postman step for users to send a fixed file with every
email.
Note: attachments are available for use in all Postman steps of the same
Pipe
**Features**:
- Upload fixed file when sending email via Postman
**Improvements**:
- Improve attachment selector to be consistent with other variable
selectors
- Improve `toPrettyDateString` function to convert `iso` and `ms` inputs
to date strings
- Improve `FileUpload` component to show as an IconButton or with text
## Before & After Screenshots
**BEFORE**:
<img width="858" alt="Screenshot 2024-12-16 at 1 43 29 PM"
src="https://github.com/user-attachments/assets/292a5a27-69b2-4058-8c92-5f186f7bc5d3"
/>
**AFTER**:
<img width="862" alt="Screenshot 2025-03-11 at 10 13 49 PM"
src="https://github.com/user-attachments/assets/82fc5f68-5b9b-4ac2-aaa9-ebf777f3bc00"
/>
<img width="862" alt="Screenshot 2025-03-11 at 10 14 02 PM"
src="https://github.com/user-attachments/assets/8d5cc665-7ddb-4a0a-8e75-d29e19ff1044"
/>
<img width="959" alt="Screenshot 2025-03-11 at 10 14 29 PM"
src="https://github.com/user-attachments/assets/a8a4b1d5-4195-4e5f-9b10-c7d5dc747674"
/>
## Tests
- [x] Existing Pipes with variable attachments are populated and checked
correctly
- [x] Existing Pipes can handle uploaded attachments and send emails
correctly with existing variable attachments
- [x] New Pipes can handle both FormSG, LetterSG and uploaded
attachments
- [x] When deleting a file in a Pipe, file should be deleted from all
Steps in the Pipe (ensures that Pipe does not fail)
- [x] When deleting a Pipe, files uploaded to the Pipe should be deleted
from S3
## Deploy Notes
- Note: infra updates required to add permissions for Malware Protection
and `GetObjectTagging`
**New scripts**:
-
`packages/backend/src/graphql/__tests__/mutations/delete-from-s3.itest.ts`
: tests for functions to delete from s3
- `packages/backend/src/graphql/__tests__/mutations/flow.mock.ts` :
mocks to create mock flow and step
-
`packages/backend/src/graphql/__tests__/mutations/generate-presigned-url.itest.ts`
: tests for function to generate pre-signed URL to upload files to S3
- `packages/backend/src/graphql/mutations/delete-from-s3.ts`: function
to delete files from S3 and corresponding steps
- `packages/backend/src/graphql/mutations/generate-presigned-url.ts`:
function to generate pre-signed URL for uploading file to S3
-
`packages/frontend/src/components/AttachmentSuggestions/components/Checkbox.tsx`:
component to display attachments as checkboxes
-
`packages/frontend/src/components/AttachmentSuggestions/components/Suggestions.tsx`:
component to display attachments in same format as variables
-
`packages/frontend/src/components/AttachmentSuggestions/components/TagList.tsx`:
component to display selected files as a Tag, with close button to
remove
-
`packages/frontend/src/components/AttachmentSuggestions/hooks/useAttachmentSelection.ts`:
hook to manage attachment selection
- `packages/frontend/src/components/AttachmentSuggestions/index.tsx`:
component for suggesting attachment variables or upload fixed
attachments
- `packages/frontend/src/components/AttachmentSuggestions/style.ts`: to
manage styles for AttachmentSuggestions
-`packages/frontend/src/components/AttachmentSuggestions/utils.ts`:
helpers for attachments including file type and size validation,
formatters to file size display, reformatting files to correct format
for saving
- `packages/frontend/src/components/SuggestionsWrapper/index.tsx`:
generic wrapper for suggestions panel
- `packages/frontend/src/graphql/mutations/delete-from-s3.ts`: to invoke
DeleteFromS3
- `packages/frontend/src/graphql/mutations/generate-presigned-url.ts`:
to call
- `packages/frontend/src/hooks/useS3Operations.ts`: hook to perform
upload and delete from S3
- `packages/frontend/src/theme/components/Checkbox.ts`: set style for
Checkbox
**New dependencies**:
- `@aws-sdk/s3-request-presigner` : to generate pre-signed URL for
uploading attachments to S31 parent 5df3814 commit c769f06
File tree
40 files changed
+2292
-93
lines changed- packages
- backend
- src
- apps/postman
- actions/send-transactional-email
- common
- graphql
- __tests__/mutations
- mutations
- helpers
- __tests__
- models
- frontend/src
- components
- AttachmentSuggestions
- components
- hooks
- FileUpload
- InputCreator
- MenuAlertDialog
- NewsDrawer
- RichTextEditor
- SuggestionsWrapper
- graphql
- mutations
- queries
- helpers
- hooks
- pages/Tiles/components
- theme/components
- types
40 files changed
+2292
-93
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
Lines changed: 114 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
Lines changed: 107 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
0 commit comments