From bb4e6835d44d248d26ee2c48acbf7afa1bcc27cf Mon Sep 17 00:00:00 2001 From: Danny Banks Date: Sat, 4 Nov 2023 17:17:31 -0700 Subject: [PATCH 1/3] chore(docs): fix expo snack (#4630) --- docs/src/components/ExpoSnack.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/components/ExpoSnack.tsx b/docs/src/components/ExpoSnack.tsx index 64d568f6fe4..747750d309b 100644 --- a/docs/src/components/ExpoSnack.tsx +++ b/docs/src/components/ExpoSnack.tsx @@ -31,7 +31,8 @@ const defaultOptions: SnackOptions = { loading: 'lazy', sdkVersion: '45.0.0', dependencies: [ - '@aws-amplify/ui-react-native,aws-amplify', + '@aws-amplify/ui-react-native', + 'aws-amplify@5.3.11', 'react-native-safe-area-context', 'amazon-cognito-identity-js', '@react-native-community/netinfo', From 1dbe3f46c2423c407aa2e499f383745b45b2e640 Mon Sep 17 00:00:00 2001 From: Danny Banks Date: Tue, 7 Nov 2023 09:48:41 -0800 Subject: [PATCH 2/3] fix(storage): fixing drop handler for file extensions (#4649) --- .changeset/dull-cheetahs-deliver.md | 8 +++ .../accept-file-extension/aws-exports.js | 2 + .../accept-file-extension/index.page.tsx | 19 +++++++ .../__tests__/filterAllowedFiles.test.ts | 32 ++++++++++++ .../primitives/DropZone/filterAllowedFiles.ts | 50 +++++++++++++++++++ .../src/primitives/DropZone/useDropZone.ts | 44 +--------------- 6 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 .changeset/dull-cheetahs-deliver.md create mode 100644 examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/aws-exports.js create mode 100644 examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/index.page.tsx create mode 100644 packages/react/src/primitives/DropZone/__tests__/filterAllowedFiles.test.ts create mode 100644 packages/react/src/primitives/DropZone/filterAllowedFiles.ts diff --git a/.changeset/dull-cheetahs-deliver.md b/.changeset/dull-cheetahs-deliver.md new file mode 100644 index 00000000000..e173bce57e7 --- /dev/null +++ b/.changeset/dull-cheetahs-deliver.md @@ -0,0 +1,8 @@ +--- +"@aws-amplify/ui-react-storage": patch +"@aws-amplify/ui-react": patch +--- + +fix(storage): fixing drop handler for file extensions + +Previously, adding a file extension for an `acceptedFileTypes` when a customer would drop a file it would show as rejected even if it was a valid file type. This fixes that issue. diff --git a/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/aws-exports.js b/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/aws-exports.js new file mode 100644 index 00000000000..4245c81a219 --- /dev/null +++ b/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/aws-exports.js @@ -0,0 +1,2 @@ +import awsExports from '@environments/storage/file-uploader/src/aws-exports'; +export default awsExports; diff --git a/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/index.page.tsx b/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/index.page.tsx new file mode 100644 index 00000000000..ef00f4f1e16 --- /dev/null +++ b/examples/next/pages/ui/components/storage/storage-manager/accept-file-extension/index.page.tsx @@ -0,0 +1,19 @@ +import { Amplify } from 'aws-amplify'; +import { StorageManager } from '@aws-amplify/ui-react-storage'; +import '@aws-amplify/ui-react/styles.css'; +import awsExports from './aws-exports'; +Amplify.configure(awsExports); + +export function StorageManagerExample() { + return ( + <> + + + ); +} +export default StorageManagerExample; diff --git a/packages/react/src/primitives/DropZone/__tests__/filterAllowedFiles.test.ts b/packages/react/src/primitives/DropZone/__tests__/filterAllowedFiles.test.ts new file mode 100644 index 00000000000..f877c724c12 --- /dev/null +++ b/packages/react/src/primitives/DropZone/__tests__/filterAllowedFiles.test.ts @@ -0,0 +1,32 @@ +import { filterAllowedFiles } from '../filterAllowedFiles'; + +describe('filterAllowFiles', () => { + const droppedFiles = [ + new File([], 'test.jpg', { type: 'image/jpg' }), + new File([], 'test.png', { type: 'image/png' }), + ]; + + it('should work with * MIME types', () => { + const { acceptedFiles, rejectedFiles } = filterAllowedFiles(droppedFiles, [ + 'image/*', + ]); + expect(rejectedFiles).toHaveLength(0); + expect(acceptedFiles).toHaveLength(2); + }); + + it('should work with extension types', () => { + const { acceptedFiles, rejectedFiles } = filterAllowedFiles(droppedFiles, [ + '.png', + ]); + expect(rejectedFiles).toHaveLength(1); + expect(acceptedFiles).toHaveLength(1); + }); + + it('should work with *', () => { + const { acceptedFiles, rejectedFiles } = filterAllowedFiles(droppedFiles, [ + '*', + ]); + expect(rejectedFiles).toHaveLength(0); + expect(acceptedFiles).toHaveLength(2); + }); +}); diff --git a/packages/react/src/primitives/DropZone/filterAllowedFiles.ts b/packages/react/src/primitives/DropZone/filterAllowedFiles.ts new file mode 100644 index 00000000000..3b26fa3d756 --- /dev/null +++ b/packages/react/src/primitives/DropZone/filterAllowedFiles.ts @@ -0,0 +1,50 @@ +// Drag event file shape is different than the drop event fileshape +type DragFile = + | { + kind: string; + type: string; + name?: string; + } + | File; + +export function filterAllowedFiles( + files: FileType[], + acceptedFileTypes: string[] +): { acceptedFiles: FileType[]; rejectedFiles: FileType[] } { + // Allow any files if acceptedFileTypes is undefined, empty array, or contains '*' + if ( + !acceptedFileTypes || + acceptedFileTypes.length === 0 || + acceptedFileTypes.includes('*') + ) { + return { acceptedFiles: files, rejectedFiles: [] }; + } + const acceptedFiles: FileType[] = []; + const rejectedFiles: FileType[] = []; + + function filterFile(file: DragFile) { + const { type = '', name = '' } = file; + const mimeType = type.toLowerCase(); + const baseMimeType = mimeType.split('/')[0]; + + return acceptedFileTypes.some((type) => { + const validType = type.trim().toLowerCase(); + // if the accepted file type is a file extension + // it will start with '.', check against the file name + if (validType.charAt(0) === '.') { + return name.toLowerCase().endsWith(validType); + } + // This is something like a image/* mime type + if (validType.endsWith('/*')) { + return baseMimeType === validType.split('/')[0]; + } + return mimeType === validType; + }); + } + + files.forEach((file) => { + (filterFile(file) ? acceptedFiles : rejectedFiles).push(file); + }); + + return { acceptedFiles, rejectedFiles }; +} diff --git a/packages/react/src/primitives/DropZone/useDropZone.ts b/packages/react/src/primitives/DropZone/useDropZone.ts index 102a64a2281..377b67095db 100644 --- a/packages/react/src/primitives/DropZone/useDropZone.ts +++ b/packages/react/src/primitives/DropZone/useDropZone.ts @@ -1,49 +1,7 @@ import { useState } from 'react'; import { UseDropZoneProps, UseDropZoneReturn, DragState } from './types'; import { isFunction } from '@aws-amplify/ui'; - -type DragFile = - | { - kind: string; - type: string; - } - | File; - -function filterAllowedFiles( - files: FileType[], - acceptedFileTypes: string[] -): { acceptedFiles: FileType[]; rejectedFiles: FileType[] } { - // Allow any files if acceptedFileTypes is undefined, empty array, or contains '*' - if ( - !acceptedFileTypes || - acceptedFileTypes.length === 0 || - acceptedFileTypes.includes('*') - ) { - return { acceptedFiles: files, rejectedFiles: [] }; - } - const acceptedFiles: FileType[] = []; - const rejectedFiles: FileType[] = []; - - function filterFile({ type = '' }) { - const mimeType = type.toLowerCase(); - const baseMimeType = mimeType.split('/')[0]; - - return acceptedFileTypes.some((type) => { - const validType = type.trim().toLowerCase(); - if (validType.endsWith('/*')) { - // This is something like a image/* mime type - return baseMimeType === validType.split('/')[0]; - } - return mimeType === validType; - }); - } - - files.forEach((file) => { - (filterFile(file) ? acceptedFiles : rejectedFiles).push(file); - }); - - return { acceptedFiles, rejectedFiles }; -} +import { filterAllowedFiles } from './filterAllowedFiles'; export function useDropZone({ onDropComplete, From fba81209067a6089645b304768ff5483808024f2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:31:21 -0500 Subject: [PATCH 3/3] Version Packages (#4656) Co-authored-by: github-actions[bot] --- .changeset/dull-cheetahs-deliver.md | 8 -------- docs/package.json | 4 ++-- examples/next/package.json | 8 ++++---- packages/react-liveness/CHANGELOG.md | 7 +++++++ packages/react-liveness/package.json | 4 ++-- packages/react-liveness/src/version.ts | 2 +- packages/react-notifications/CHANGELOG.md | 7 +++++++ packages/react-notifications/package.json | 4 ++-- packages/react-storage/CHANGELOG.md | 11 +++++++++++ packages/react-storage/package.json | 4 ++-- packages/react/CHANGELOG.md | 8 ++++++++ packages/react/package.json | 2 +- packages/react/src/version.ts | 2 +- 13 files changed, 48 insertions(+), 23 deletions(-) delete mode 100644 .changeset/dull-cheetahs-deliver.md diff --git a/.changeset/dull-cheetahs-deliver.md b/.changeset/dull-cheetahs-deliver.md deleted file mode 100644 index e173bce57e7..00000000000 --- a/.changeset/dull-cheetahs-deliver.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"@aws-amplify/ui-react-storage": patch -"@aws-amplify/ui-react": patch ---- - -fix(storage): fixing drop handler for file extensions - -Previously, adding a file extension for an `acceptedFileTypes` when a customer would drop a file it would show as rejected even if it was a valid file type. This fixes that issue. diff --git a/docs/package.json b/docs/package.json index c36fb2d9e1b..71dd2e11149 100644 --- a/docs/package.json +++ b/docs/package.json @@ -23,8 +23,8 @@ "test:links": "node --require esbuild-register ./scripts/link-checker-puppeteer.ts" }, "dependencies": { - "@aws-amplify/ui-react": "5.3.1", - "@aws-amplify/ui-react-storage": "2.3.1", + "@aws-amplify/ui-react": "5.3.2", + "@aws-amplify/ui-react-storage": "2.3.2", "@cucumber/gherkin": "^19.0.3", "@cucumber/messages": "^16.0.1", "@docsearch/react": "3", diff --git a/examples/next/package.json b/examples/next/package.json index 146fb10cf22..0ecf8aab518 100644 --- a/examples/next/package.json +++ b/examples/next/package.json @@ -10,10 +10,10 @@ "lint": "next lint" }, "dependencies": { - "@aws-amplify/ui-react": "^5.3.1", - "@aws-amplify/ui-react-liveness": "^2.0.10", - "@aws-amplify/ui-react-storage": "^2.3.1", - "@aws-amplify/ui-react-notifications": "^1.0.13", + "@aws-amplify/ui-react": "^5.3.2", + "@aws-amplify/ui-react-liveness": "^2.0.11", + "@aws-amplify/ui-react-storage": "^2.3.2", + "@aws-amplify/ui-react-notifications": "^1.0.14", "@aws-amplify/ui-react-geo": "^1.0.2", "@aws-sdk/credential-providers": "^3.370.0", "aws-amplify": "latest", diff --git a/packages/react-liveness/CHANGELOG.md b/packages/react-liveness/CHANGELOG.md index 110ad010402..352a878b098 100644 --- a/packages/react-liveness/CHANGELOG.md +++ b/packages/react-liveness/CHANGELOG.md @@ -1,5 +1,12 @@ # @aws-amplify/ui-react-liveness +## 2.0.11 + +### Patch Changes + +- Updated dependencies [[`1dbe3f46c`](https://github.com/aws-amplify/amplify-ui/commit/1dbe3f46c2423c407aa2e499f383745b45b2e640)]: + - @aws-amplify/ui-react@5.3.2 + ## 2.0.10 ### Patch Changes diff --git a/packages/react-liveness/package.json b/packages/react-liveness/package.json index dc8d05a29dd..22517048701 100644 --- a/packages/react-liveness/package.json +++ b/packages/react-liveness/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/ui-react-liveness", - "version": "2.0.10", + "version": "2.0.11", "main": "dist/index.js", "module": "dist/esm/index.mjs", "exports": { @@ -49,7 +49,7 @@ }, "dependencies": { "@aws-amplify/ui": "5.8.1", - "@aws-amplify/ui-react": "5.3.1", + "@aws-amplify/ui-react": "5.3.2", "@aws-sdk/client-rekognitionstreaming": "3.398.0", "@aws-sdk/util-format-url": "^3.410.0", "@smithy/eventstream-serde-browser": "^2.0.4", diff --git a/packages/react-liveness/src/version.ts b/packages/react-liveness/src/version.ts index a69767cf6f7..7b3a9bd8e89 100644 --- a/packages/react-liveness/src/version.ts +++ b/packages/react-liveness/src/version.ts @@ -1 +1 @@ -export const VERSION = '2.0.10'; +export const VERSION = '2.0.11'; diff --git a/packages/react-notifications/CHANGELOG.md b/packages/react-notifications/CHANGELOG.md index b4184fbf4b9..74b8716743e 100644 --- a/packages/react-notifications/CHANGELOG.md +++ b/packages/react-notifications/CHANGELOG.md @@ -1,5 +1,12 @@ # @aws-amplify/ui-react-notifications +## 1.0.14 + +### Patch Changes + +- Updated dependencies [[`1dbe3f46c`](https://github.com/aws-amplify/amplify-ui/commit/1dbe3f46c2423c407aa2e499f383745b45b2e640)]: + - @aws-amplify/ui-react@5.3.2 + ## 1.0.13 ### Patch Changes diff --git a/packages/react-notifications/package.json b/packages/react-notifications/package.json index 5a9af0b70a1..c5e58563024 100644 --- a/packages/react-notifications/package.json +++ b/packages/react-notifications/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/ui-react-notifications", - "version": "1.0.13", + "version": "1.0.14", "main": "dist/index.js", "module": "dist/esm/index.mjs", "exports": { @@ -41,7 +41,7 @@ }, "dependencies": { "@aws-amplify/ui": "5.8.1", - "@aws-amplify/ui-react": "5.3.1", + "@aws-amplify/ui-react": "5.3.2", "@aws-amplify/ui-react-core-notifications": "1.0.10", "classnames": "2.3.1", "tinycolor2": "1.4.2" diff --git a/packages/react-storage/CHANGELOG.md b/packages/react-storage/CHANGELOG.md index 7bd740cefb4..d71e1099048 100644 --- a/packages/react-storage/CHANGELOG.md +++ b/packages/react-storage/CHANGELOG.md @@ -1,5 +1,16 @@ # @aws-amplify/ui-react-storage +## 2.3.2 + +### Patch Changes + +- [#4649](https://github.com/aws-amplify/amplify-ui/pull/4649) [`1dbe3f46c`](https://github.com/aws-amplify/amplify-ui/commit/1dbe3f46c2423c407aa2e499f383745b45b2e640) Thanks [@dbanksdesign](https://github.com/dbanksdesign)! - fix(storage): fixing drop handler for file extensions + + Previously, adding a file extension for an `acceptedFileTypes` when a customer would drop a file it would show as rejected even if it was a valid file type. This fixes that issue. + +- Updated dependencies [[`1dbe3f46c`](https://github.com/aws-amplify/amplify-ui/commit/1dbe3f46c2423c407aa2e499f383745b45b2e640)]: + - @aws-amplify/ui-react@5.3.2 + ## 2.3.1 ### Patch Changes diff --git a/packages/react-storage/package.json b/packages/react-storage/package.json index 6023fdcd4fe..8e19238e115 100644 --- a/packages/react-storage/package.json +++ b/packages/react-storage/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/ui-react-storage", - "version": "2.3.1", + "version": "2.3.2", "main": "dist/index.js", "module": "dist/esm/index.mjs", "exports": { @@ -41,7 +41,7 @@ }, "dependencies": { "@aws-amplify/ui": "5.8.1", - "@aws-amplify/ui-react": "5.3.1", + "@aws-amplify/ui-react": "5.3.2", "@aws-amplify/ui-react-core": "2.1.33", "classnames": "2.3.1", "lodash": "4.17.21", diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 64617537d69..12a8ddd2f13 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,13 @@ # @aws-amplify/ui-react +## 5.3.2 + +### Patch Changes + +- [#4649](https://github.com/aws-amplify/amplify-ui/pull/4649) [`1dbe3f46c`](https://github.com/aws-amplify/amplify-ui/commit/1dbe3f46c2423c407aa2e499f383745b45b2e640) Thanks [@dbanksdesign](https://github.com/dbanksdesign)! - fix(storage): fixing drop handler for file extensions + + Previously, adding a file extension for an `acceptedFileTypes` when a customer would drop a file it would show as rejected even if it was a valid file type. This fixes that issue. + ## 5.3.1 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 7fc416eee62..dfe458afbd9 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/ui-react", - "version": "5.3.1", + "version": "5.3.2", "main": "dist/index.js", "module": "dist/esm/index.mjs", "exports": { diff --git a/packages/react/src/version.ts b/packages/react/src/version.ts index 07fdf7bdceb..0636cde406e 100644 --- a/packages/react/src/version.ts +++ b/packages/react/src/version.ts @@ -1 +1 @@ -export const VERSION = '5.3.1'; +export const VERSION = '5.3.2';