mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
36 lines
936 B
TypeScript
36 lines
936 B
TypeScript
import {Component} from 'react';
|
|
|
|
import {SentryPropTypeValidators} from 'sentry/sentryPropTypeValidators';
|
|
import type {Project} from 'sentry/types';
|
|
import getDisplayName from 'sentry/utils/getDisplayName';
|
|
|
|
type InjectedProjectProps = {
|
|
project?: Project;
|
|
};
|
|
|
|
/**
|
|
* Currently wraps component with project from context
|
|
*/
|
|
const withProject = <P extends InjectedProjectProps>(
|
|
WrappedComponent: React.ComponentType<P>
|
|
) =>
|
|
class extends Component<
|
|
Omit<P, keyof InjectedProjectProps> & Partial<InjectedProjectProps>
|
|
> {
|
|
static displayName = `withProject(${getDisplayName(WrappedComponent)})`;
|
|
static contextTypes = {
|
|
project: SentryPropTypeValidators.isProject,
|
|
};
|
|
|
|
render() {
|
|
const {project, ...props} = this.props;
|
|
return (
|
|
<WrappedComponent
|
|
{...({project: project ?? this.context.project, ...props} as P)}
|
|
/>
|
|
);
|
|
}
|
|
};
|
|
|
|
export default withProject;
|