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(components): update AsyncComponent TS interface #2135

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/components/src/AsyncComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import { ChromeAPI } from '@redhat-cloud-services/types';

export type ExcludeModulesKeys = 'module' | 'scope';

export type AsyncComponentProps = {
export type AsyncComponentProps<T extends object = object> = {
/** Loaded module, it has to start with `./`. */
module: string;
/** Optional scope, if not passed appName is used. */
scope: string;
/** React Suspense fallback component. <a href="https://reactjs.org/docs/code-splitting.html#reactlazy" target="_blank">Learn more</a>. */
fallback: React.ReactElement;
fallback?: React.ReactElement;
/** Optional wrapper component */
component: keyof JSX.IntrinsicElements;
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
component?: keyof JSX.IntrinsicElements;
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> &
T;

type BaseAsyncComponentProps = AsyncComponentProps & {
innerRef: React.MutableRefObject<HTMLElement | null> | ((instance: HTMLElement | null) => void) | null;
Expand Down Expand Up @@ -56,6 +57,9 @@ const BaseAsyncComponent: React.FunctionComponent<BaseAsyncComponentProps> = ({
* This component uses fallback as ErrorComponent, if you want to show different
* component for error pass it as ErrorComponent prop.
*/
export const AsyncComponent = React.forwardRef<HTMLElement, AsyncComponentProps>((props, ref) => <BaseAsyncComponent innerRef={ref} {...props} />);
const InternalSyncComponent = React.forwardRef<HTMLElement, AsyncComponentProps>((props, ref) => <BaseAsyncComponent innerRef={ref} {...props} />);
export function AsyncComponent<T extends object = object>(props: AsyncComponentProps & T) {
return <InternalSyncComponent {...props} />;
}

export default AsyncComponent;
2 changes: 1 addition & 1 deletion packages/components/src/Inventory/TagWithDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type TagWithDialogProps = Omit<AsyncComponentProps, ExcludeModulesKeys>;
*/
const BaseTagWithDialog: React.FC<TagWithDialogProps & { innerRef?: React.Ref<HTMLElement>; history?: unknown; store?: unknown }> = (props) => {
const store = useStore();
const Cmp = props.component;
const Cmp = props.component ?? 'section';
const SCProps: ScalprumComponentProps<ChromeAPI, TagWithDialogProps> = {
history: props.history,
store,
Expand Down
Loading