-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-browser): add custom actions (#6210)
* feat(storage-browser): add custom actions * Fix circular dependency * Remove unused variables from example apps * Update unit tests * Update unit tests. Fix types * Bump coverage down * Remove 'as const' from permissions in example * Address feedback * Fix copy regression * Fix issue with custom action view filtering * fix: task data are not being refreshed when it's updated --------- Co-authored-by: Chris Fang <[email protected]> Co-authored-by: Hui Zhao <[email protected]>
- Loading branch information
1 parent
e9b219f
commit 3e9f95d
Showing
114 changed files
with
2,265 additions
and
2,484 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
129 changes: 129 additions & 0 deletions
129
examples/next/pages/ui/components/storage/storage-browser/custom-actions/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,129 @@ | ||
import React from 'react'; | ||
|
||
import { createStorageBrowser } from '@aws-amplify/ui-react-storage/browser'; | ||
|
||
import { Flex } from '@aws-amplify/ui-react'; | ||
|
||
import '@aws-amplify/ui-react-storage/styles.css'; | ||
|
||
const { StorageBrowser } = createStorageBrowser({ | ||
actions: { | ||
default: { | ||
copy: { | ||
actionListItem: { | ||
icon: 'copy-file', | ||
label: 'Override Copy', | ||
}, | ||
handler: ({ data }) => { | ||
const { key } = data; | ||
return { | ||
result: Promise.resolve({ status: 'COMPLETE', value: { key } }), | ||
}; | ||
}, | ||
viewName: 'CopyView', | ||
}, | ||
createFolder: { | ||
actionListItem: { | ||
icon: 'create-folder', | ||
label: 'Override Create Folder', | ||
}, | ||
handler: ({ data }) => { | ||
const { key } = data; | ||
return { | ||
result: Promise.resolve({ status: 'COMPLETE', value: { key } }), | ||
}; | ||
}, | ||
viewName: 'CreateFolderView', | ||
}, | ||
delete: { | ||
actionListItem: { | ||
icon: 'delete-file', | ||
label: 'Override Delete', | ||
}, | ||
handler: ({ data }) => { | ||
const { key } = data; | ||
return { | ||
result: Promise.resolve({ status: 'COMPLETE', value: { key } }), | ||
}; | ||
}, | ||
viewName: 'DeleteView', | ||
}, | ||
download: () => { | ||
return { | ||
result: Promise.resolve({ | ||
status: 'COMPLETE', | ||
value: { url: new URL('') }, | ||
}), | ||
}; | ||
}, | ||
upload: { | ||
actionListItem: { | ||
icon: 'upload-file', | ||
label: 'Override Upload', | ||
}, | ||
handler: ({ data }) => { | ||
const { key } = data; | ||
return { | ||
result: Promise.resolve({ status: 'COMPLETE', value: { key } }), | ||
}; | ||
}, | ||
viewName: 'UploadView', | ||
}, | ||
listLocationItems: () => | ||
Promise.resolve({ | ||
items: [ | ||
{ | ||
id: 'jaskjkaska', | ||
key: 'item-key', | ||
lastModified: new Date(), | ||
size: 1008, | ||
type: 'FILE' as const, | ||
}, | ||
], | ||
nextToken: undefined, | ||
}), | ||
}, | ||
}, | ||
config: { | ||
getLocationCredentials: () => | ||
Promise.resolve({ | ||
credentials: { | ||
accessKeyId: '', | ||
expiration: new Date(), | ||
secretAccessKey: '', | ||
sessionToken: '', | ||
}, | ||
}), | ||
region: '', | ||
registerAuthListener: () => null, | ||
listLocations: () => | ||
Promise.resolve({ | ||
items: [ | ||
{ | ||
bucket: 'my-bucket', | ||
id: crypto.randomUUID(), | ||
permissions: ['delete', 'get', 'list', 'write'], | ||
prefix: 'my-prefix', | ||
type: 'PREFIX', | ||
}, | ||
], | ||
nextToken: undefined, | ||
}), | ||
}, | ||
}); | ||
|
||
function Example() { | ||
return ( | ||
<Flex | ||
direction="column" | ||
width="100vw" | ||
height="100vh" | ||
overflow="hidden" | ||
padding="xl" | ||
> | ||
<StorageBrowser /> | ||
</Flex> | ||
); | ||
} | ||
|
||
export default Example; |
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
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
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.