Skip to content

Commit

Permalink
fix(react-storage): expose additional storage browser types (#6219)
Browse files Browse the repository at this point in the history
* Revert "fix(react-storage): fix createStorageBrowser type issue (#6217)"

This reverts commit c59b2e2.

* fix(react-storage): expose additional storage browser types

* Update packages/react-storage/src/components/StorageBrowser/actions/configs/types.ts

Co-authored-by: Caleb Pollman <[email protected]>

* Update packages/react-storage/src/components/StorageBrowser/types.ts

Co-authored-by: Caleb Pollman <[email protected]>

* Update packages/react-storage/src/components/StorageBrowser/types.ts

Co-authored-by: Caleb Pollman <[email protected]>

* Create nine-berries-smile.md

---------

Co-authored-by: Caleb Pollman <[email protected]>
  • Loading branch information
ashwinkumar6 and calebpollman authored Nov 29, 2024
1 parent efbfd14 commit 8bf3c30
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-berries-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react-storage": minor
---

fix(react-storage): expose additional storage browser types
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export type CustomActionConfigs = Record<
ActionViewConfig | ActionHandler
>;

/**
* @internal @unstable
*/
export interface ExtendedActionConfigs {
default?: ExtendedDefaultActionConfigs;
custom?: CustomActionConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
CreateStorageBrowserOutput,
StorageBrowserProviderProps,
StorageBrowserType,
DerivedActionViews,
DerivedActionViewType,
} from './types';
import {
Expand Down Expand Up @@ -124,10 +125,10 @@ export function createStorageBrowser<
);
}

const StorageBrowser: StorageBrowserType<RInput> = ({
views,
displayText,
}) => (
const StorageBrowser: StorageBrowserType<
DerivedActionViewType<RInput>,
DerivedActionViews<RInput>
> = ({ views, displayText }) => (
<ErrorBoundary>
<Provider displayText={displayText} views={views}>
<StorageBrowserDefault />
Expand Down
14 changes: 12 additions & 2 deletions packages/react-storage/src/components/StorageBrowser/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
export { componentsDefault } from './componentsDefault';
export { createStorageBrowser } from './createStorageBrowser';
export { ActionViewConfig, ActionHandler, FileDataItem } from './actions';
export {
ActionViewConfig,
ActionHandler,
FileDataItem,
ExtendedActionConfigs,
} from './actions';
export {
createAmplifyAuthAdapter,
createManagedAuthAdapter,
CreateManagedAuthAdapterInput,
StorageBrowserAuthAdapter,
} from './adapters';
export { CreateStorageBrowserInput, StorageBrowserType } from './types';
export {
CreateStorageBrowserInput,
StorageBrowserType,
DerivedActionViewType,
DerivedActionViews,
} from './types';
export { DefaultStorageBrowserDisplayText } from './displayText';
25 changes: 15 additions & 10 deletions packages/react-storage/src/components/StorageBrowser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,35 @@ export interface StorageBrowserProviderProps<V = {}>
views?: V;
}

export interface StorageBrowserType<C extends ExtendedActionConfigs> {
(
props: StorageBrowserProps<DerivedActionViewType<C>, DerivedCustomViews<C>>
): React.JSX.Element;
export interface StorageBrowserType<K = string, V = {}> {
(props: StorageBrowserProps<K, V>): React.JSX.Element;
displayName: string;
Provider: (
props: StorageBrowserProviderProps<DerivedCustomViews<C>>
) => React.JSX.Element;
Provider: (props: StorageBrowserProviderProps<V>) => React.JSX.Element;
CopyView: CopyViewType;
CreateFolderView: CreateFolderViewType;
DeleteView: DeleteViewType;
UploadView: UploadViewType;
LocationActionView: LocationActionViewType<DerivedActionViewType<C>>;
LocationActionView: LocationActionViewType<K>;
LocationDetailView: LocationDetailViewType;
LocationsView: LocationsViewType;
}

type DefaultActionType<T = string> = Exclude<T, keyof DefaultActionConfigs>;

export type DerivedCustomViews<T extends StorageBrowserActions> = {
/**
* @internal @unstable
*/
export type DerivedActionViews<T extends StorageBrowserActions> = {
[K in keyof T['custom'] as K extends DefaultActionType<K>
? T['custom'][K] extends { viewName: `${string}View` }
? T['custom'][K]['viewName']
: never
: never]?: () => React.JSX.Element | null;
};

/**
* @internal @unstable
*/
export type DerivedActionViewType<T extends StorageBrowserActions> =
| keyof {
[K in keyof T['custom'] as K extends DefaultActionType<K>
Expand All @@ -101,7 +103,10 @@ export type DerivedActionViewType<T extends StorageBrowserActions> =
export interface CreateStorageBrowserOutput<
C extends ExtendedActionConfigs = ExtendedActionConfigs,
> {
StorageBrowser: StorageBrowserType<C>;
StorageBrowser: StorageBrowserType<
DerivedActionViewType<C>,
DerivedActionViews<C>
>;
useAction: UseAction<DerivedActionHandlers<C>>;
useView: UseView;
}

0 comments on commit 8bf3c30

Please sign in to comment.