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

fix(react-storage): expose additional storage browser types #6219

Merged
merged 7 commits into from
Nov 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export type CustomActionConfigs = Record<
ActionViewConfig | ActionHandler
>;

/**
* @internal
**/
ashwinkumar6 marked this conversation as resolved.
Show resolved Hide resolved
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
**/
ashwinkumar6 marked this conversation as resolved.
Show resolved Hide resolved
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
**/
ashwinkumar6 marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Loading