-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(multi-bucket): add multi-bucket support to storage components (…
…#5562) * initial commit to add 'bucket' property to storage components * chore: use StorageBucket type in StorageImagePathProps * remove duplicate StorageBucket type declaration * chore: update aws-amplify version to include multi-bucket support * docs: include references to new 'bucket' prop and its usage * more explicitly clarifying that can be a string in docs example * chore: changing reference of storage manager to file uploader * chore: updating yarn.lock * chore: undoing unnecessary linting changes * chore: moving yarn.lock from main branch parity * chore: updating yarn.lock to main * chore: add missing references to 'bucket' * chore: adding tests and new example app * chore: add end of file line * chore: add changeset * chore: setting more obviously fake bucket name as example * chore: adding link for setting up multi-bucket configuration to docs * chore: removing unnecessary type definitions * chore: removing unnecessary type from Storage Image props * chore: adding bucket as omitted prop to gen1 props * fix(tests): updating test data to fit expected behavior * chore: adjusting prop order, import consolidation, and added description * chore: add FileUploader example app and e2e test --------- Co-authored-by: Caleb Pollman <[email protected]>
- Loading branch information
1 parent
cd508ee
commit 2e107f9
Showing
24 changed files
with
330 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/ui-react-storage': minor | ||
--- | ||
|
||
Support for multiple buckets added to storage image and file uploader |
15 changes: 15 additions & 0 deletions
15
docs/src/pages/[platform]/connected-components/storage/fileuploader/examples/BucketExact.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FileUploader } from '@aws-amplify/ui-react-storage'; | ||
|
||
export const App = () => { | ||
return ( | ||
<FileUploader | ||
acceptedFileTypes={['image/*']} | ||
bucket={{ | ||
bucketName: 'my-bucket-xxxxxxxx', | ||
region: 'us-west-2', | ||
}} | ||
path="public/" | ||
maxFileCount={1} | ||
/> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...rc/pages/[platform]/connected-components/storage/fileuploader/examples/BucketFriendly.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { FileUploader } from '@aws-amplify/ui-react-storage'; | ||
|
||
export const App = () => { | ||
return ( | ||
<FileUploader | ||
acceptedFileTypes={['image/*']} | ||
bucket="my-bucket" | ||
path="public/" | ||
maxFileCount={1} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/next/pages/ui/components/storage/file-uploader/multi-bucket/amplify_outputs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import amplifyOutputs from '@environments/storage/gen2/amplify_outputs'; | ||
export default amplifyOutputs; |
48 changes: 48 additions & 0 deletions
48
examples/next/pages/ui/components/storage/file-uploader/multi-bucket/index.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { Amplify } from 'aws-amplify'; | ||
import { FileUploader } from '@aws-amplify/ui-react-storage'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import amplifyOutputs from './amplify_outputs'; | ||
import { Radio, RadioGroupField } from '@aws-amplify/ui-react'; | ||
Amplify.configure(amplifyOutputs); | ||
|
||
export function FileUploaderExample() { | ||
const [bucket, setBucket] = React.useState('Bucket 1'); | ||
return ( | ||
<div> | ||
<RadioGroupField | ||
defaultValue="Bucket 1" | ||
legend="Bucket" | ||
name="Bucket to upload to" | ||
onChange={(e) => setBucket(e.target.value)} | ||
> | ||
<Radio value="Bucket 1">Bucket 1</Radio> | ||
<Radio value="Bucket 2">Bucket 2</Radio> | ||
</RadioGroupField> | ||
{bucket === 'Bucket 1' ? ( | ||
<div> | ||
<FileUploader | ||
acceptedFileTypes={['*']} | ||
bucket="StorageEndToEnd" | ||
displayText={{ dropFilesText: 'Drop files into Bucket 1' }} | ||
path="public/" | ||
maxFileCount={1} | ||
showThumbnails | ||
/> | ||
</div> | ||
) : ( | ||
<div> | ||
<FileUploader | ||
acceptedFileTypes={['*']} | ||
bucket="StorageEndToEndSecondary" | ||
displayText={{ dropFilesText: 'Drop files into Bucket 2' }} | ||
path="public/" | ||
maxFileCount={1} | ||
showThumbnails | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
export default FileUploaderExample; |
2 changes: 2 additions & 0 deletions
2
examples/next/pages/ui/components/storage/storage-image/multi-bucket/amplify_outputs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import amplifyOutputs from '@environments/storage/gen2/amplify_outputs'; | ||
export default amplifyOutputs; |
42 changes: 42 additions & 0 deletions
42
examples/next/pages/ui/components/storage/storage-image/multi-bucket/index.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as React from 'react'; | ||
|
||
import { Amplify } from 'aws-amplify'; | ||
import { Text, Loader } from '@aws-amplify/ui-react'; | ||
import { StorageImage } from '@aws-amplify/ui-react-storage'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import amplifyOutputs from './amplify_outputs'; | ||
|
||
Amplify.configure(amplifyOutputs); | ||
|
||
export function StorageImageExample() { | ||
const [isFirstImgLoaded, setIsFirstImgLoaded] = React.useState(false); | ||
const [isSecondImgLoaded, setIsSecondImgLoaded] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<StorageImage | ||
alt="public cat 1" | ||
bucket="StorageEndToEnd" | ||
path="public/public-e2e.jpeg" | ||
onLoad={() => setIsFirstImgLoaded(true)} | ||
/> | ||
{isFirstImgLoaded ? ( | ||
<Text>The first public image is loaded.</Text> | ||
) : ( | ||
<Loader testId="Loader1" /> | ||
)} | ||
<StorageImage | ||
alt="public cat 2" | ||
bucket="StorageEndToEndSecondary" | ||
path={() => 'public/public-e2e.jpeg'} | ||
onLoad={() => setIsSecondImgLoaded(true)} | ||
/> | ||
{isSecondImgLoaded ? ( | ||
<Text>The second public image is loaded.</Text> | ||
) : ( | ||
<Loader testId="Loader2" /> | ||
)} | ||
</> | ||
); | ||
} | ||
export default StorageImageExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...eatures/ui/components/storage/file-uploader/upload-file-to-S3-public-multi-bucket.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Feature: Upload a file to multiple S3 buckets with public access level settings | ||
|
||
Background: | ||
Given I'm running the example "ui/components/storage/file-uploader/multi-bucket" | ||
|
||
@react | ||
Scenario: I upload a file to each bucket | ||
Given I intercept requests to host including "s3" | ||
Then I see "Drop files into Bucket 1" | ||
Then I select a file with file name "test.jpg" | ||
Then I see "test.jpg" | ||
Then I see "Uploaded" | ||
Then I confirm the "s3" request was made to host containing "storageendtoendbucket" | ||
Then I see "1 file uploaded" | ||
Then I click the "Bucket 2" radio button | ||
Then I see "Drop files into Bucket 2" | ||
Then I select a file with file name "test.jpg" | ||
Then I see "test.jpg" | ||
Then I see "Uploaded" | ||
Then I confirm the "s3" request was made to host containing "storageendtoendsecondary" |
13 changes: 13 additions & 0 deletions
13
...atures/ui/components/storage/storage-image/load-public-images-from-two-s3-buckets.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: Load two images, each from a different S3 bucket with public access level settings | ||
|
||
Background: | ||
Given I'm running the example "ui/components/storage/storage-image/multi-bucket" | ||
|
||
@react | ||
Scenario: I successfully load two images from two buckets | ||
Then I see "Loader1" element | ||
Then I see "Loader2" element | ||
Then I see the "public cat 1" image | ||
Then I see the "public cat 2" image | ||
Then I see "The first public image is loaded." | ||
Then I see "The second public image is loaded." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.