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

feature(multi-bucket): add multi-bucket support to storage components #5562

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

jordanvn
Copy link
Member

Description of changes

Changes:

  • Adds optional property "bucket" to <StorageImage /> and <StorageManager />.
    • This property accepts the argument of either:
      • A string of the "friendly name" of the bucket
      • A StorageBucket object containing the bucket name generated on S3 and the region it exists in
    • If omitted, these storage components will use whichever bucket the user has designated as their "default" bucket in their configuration.

Issue #, if available

N/A

Description of how you validated changes

  • Functionality of the backend support of multiple buckets was validated
  • Example apps were modified to use multi-bucket setup
  • Multi-bucket support was confirmed in example apps

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, e2e, examples, or other private packages.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

changeset-bot bot commented Aug 10, 2024

🦋 Changeset detected

Latest commit: f6645f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ui-react-storage Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jordanvn jordanvn changed the title feature(multi-bucket): initial commit to add 'bucket' property to storage components feature(multi-bucket): add 'bucket' property to storage components Aug 10, 2024
@jordanvn jordanvn changed the title feature(multi-bucket): add 'bucket' property to storage components feature(multi-bucket): add multi-bucket support to storage components Aug 10, 2024
Copy link
Contributor

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -12,6 +12,15 @@ import {
} from './ui';
import { StorageManagerDisplayText, PathCallback, UploadTask } from './utils';

interface BucketInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should we share this type between components?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense to me. It didn't seem substantial enough to create a new shared types file for storage components, so I went with the definition in the Storage Manager types. There are already exported types and interfaces in that file, and none aside from props in Storage Image types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just import and extend FileUploaderProps in the assignment of StorageManagerProps and dedupe this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting the removal of this file and providing its exports from FileUploader types? Or reducing StorageManagerProps to export interface StorageManagerProps extends FileUploaderProps {}?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this file and doing the latter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for the clarification

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated file to extend FileUploaderProps instead of duplicating type declaration

<FileUploader
acceptedFileTypes={['image/*']}
bucket={{
bucketName: 'my-bucket-96e87892835c413e9963f3004a44e1ff',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is not an actual bucket name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note so we don't wonder about that later, or make it more obvious like "my-bucket-xxxxxxx"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I like going with "my-bucket-xxxxxxxx"

@@ -170,6 +170,27 @@ describe('StorageImage', () => {
);
});

it('should pass bucket to getUrl when supplied', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we're not duplicating the testing of the functionality of the API supporting this, so this test is just confirming that the "bucket" property is successfully passed from the component to the API in the expected format.

dbanksdesign
dbanksdesign previously approved these changes Sep 30, 2024
@@ -168,6 +168,26 @@ You can limit what users upload with these 3 props:
</ExampleCode>
</Example>

## Setting a Bucket

If you have configured your Amplify project to use multiple S3 buckets, you can use the `bucket` prop to choose which of the buckets the component will use:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we link to Multibucket setup in main docs from here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Added a link

@@ -36,6 +38,7 @@ export interface StorageImageProps extends Omit<ImageProps, 'src'> {

type OmittedPropKey =
| 'accessLevel'
| 'bucket'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we omitting bucket here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, think its related to my comment above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. This was an oversight on my part

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

[accessLevel, imgKey, identityId, onError, path, validateObjectExistence]
[
accessLevel,
bucket,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bucket is a non-memoized object will it cause any side effects in useGetUrl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the object input for bucket on the Storage Image locally, and I don't see any different behavior in the network

@@ -12,6 +12,15 @@ import {
} from './ui';
import { StorageManagerDisplayText, PathCallback, UploadTask } from './utils';

interface BucketInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just import and extend FileUploaderProps in the assignment of StorageManagerProps and dedupe this file?

@@ -15,6 +16,7 @@ export interface StorageImageProps extends Omit<ImageProps, 'src'> {
* `accessLevel` will be replaced with `path` in a future major version of Amplify UI. See https://ui.docs.amplify.aws/react/connected-components/storage/storageimage#props
*/
accessLevel: StorageAccessLevel;
bucket?: StorageBucket;
Copy link
Member

@reesscot reesscot Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we bucket here if it's only supported in Gen2? (StorageImagePathProps)

Copy link
Member Author

@jordanvn jordanvn Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we shouldn't. This was a misunderstanding on my part. I've removed this

/**
* Designates the bucket to upload to, if the user has multiple buckets configured
*/
bucket?: StorageBucket;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the one on StorageManager, not sure this is needed since multi bucket support doesn't exist in Gen1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants