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

feat(storage-browser): add custom actions #6210

Merged
merged 12 commits into from
Nov 27, 2024
Merged

Conversation

calebpollman
Copy link
Member

Description of changes

Add custom actions support for StorageBrowser

  • loosen handler interfaces to improve custom action ergonomics
  • add useHandler, useAction and useList hooks
  • simplify useView
  • integrate useAction and useList hooks in to StorageBrowser views
  • refactor action config types

Usage:

import { ActionHandler, ActionViewConfig, createStorageBrowser } from '@aws-amplify/ui-react-storage';

type MyAction = ActionHandler<{ myOptionalData: string }, { myOptionalOutput: string }>
const myAction: MyAction =  () => {}

const myActionViewConfig: ActionViewConfig<MyAction, 'MyActionView'> = {}

const { useAction, StorageBrowser } = createStorageBrowser({ actions: { 
  // no view slot, just handler
  myAction,
  // with view slot
  myActionViewConfig
))

const MyActionView = () => {
  const [atomicState, atomicHandler] = useAction('myAction')

  const items = []
  const [batchState, batchHandler] = useAction('myAction', { items })
 
  return ( ... )
}

<StorageBrowser views={{ MyActionView }} />

Issue #, if available

Description of how you validated changes

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 Nov 26, 2024

⚠️ No Changeset found

Latest commit: cb47f4d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@cshfang cshfang marked this pull request as ready for review November 27, 2024 00:17
@cshfang cshfang requested a review from a team as a code owner November 27, 2024 00:17
@@ -108,6 +77,5 @@ export const isDefaultActionViewType = (

export const defaultActionConfigs = {
...defaultActionViewConfigs,
listLocationItems: listLocationItemsActionConfig,
listLocations: listLocationsActionConfig,
Copy link
Member

Choose a reason for hiding this comment

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

listLocations is no longer a default action?

<dialog open={!!query.actionType}>
<dialog
open={!!query.actionType}
style={{ width: '50vw', position: 'absolute', zIndex: 1000 }}
Copy link
Member

Choose a reason for hiding this comment

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

sanity check: intended inline css?

const isListActionViewType = (value: unknown): value is ListActionType =>
Object.keys(LIST_ACTION_HOOKS).includes(value as ListActionType);

// @ts-expect-error
Copy link
Member

Choose a reason for hiding this comment

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

sanity check: intended error suppressing?

@@ -4,8 +4,6 @@ import {
createAmplifyAuthAdapter,
createStorageBrowser,
} from '@aws-amplify/ui-react-storage/browser';
import '@aws-amplify/ui-react-storage/styles.css';
Copy link
Member

Choose a reason for hiding this comment

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

Should this be kept?

@@ -1,19 +1,104 @@
import React from 'react';
import { getUrl } from '@aws-amplify/storage/internals';
Copy link
Member

Choose a reason for hiding this comment

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

Not specific to this PR but we need to make sure we don't recommend this in our public doc

Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking but I think this file is not used anywhere and can be cleared.

Copy link
Member

Choose a reason for hiding this comment

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

I think you're probably right. We can do that separately for sure

@cshfang cshfang merged commit 3e9f95d into main Nov 27, 2024
38 checks passed
@cshfang cshfang deleted the storage-browser/actions branch November 27, 2024 23:11
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.

5 participants