Dynamics - React Glue Components
Dynamics - React Glue Components
Dynamics Wrapper
// import a definition of Xrm...
export interface Notifier {
add: (p: {message:string, removeAfter:number, level: string}) => string
remove: (token: string) => void
}
export interface ErrorHandler {
// or whatever...
report: (message: string) => void
}
export interface DynamicsContext {
Xrm: Xrm | null
notifier: Notifier
errorHandler: ErrorHandler
}
export interface DynamicsProps extends Partial<DynamcisContext> {}
class Dynamics<P extends DynamicsProps=DynamicsProps,S={}> extends React.Component<Props, S> {
constructor(props,context) {
super(props, context)
}
private defaultErrorHandler: ErrorHandler = new ConsoleErrorHandler()
private defaultNotifier: Notifier = new NotificationManager(() => this.getXrm())
getChildContext(): DynamicsContext {
console.log("getChildContext")
return {
notifier: this.props.notifier ? (this.props.notifier as Notifier) : this.defaultNotifier,
Xrm: this.getXrm() || null,
errorHandler: this.props.errorHandler ? (this.props.errorHandler as ErrorHandler):
this.defaultErrorHandler
}
}
/** Get Xrm from the props or the global environment. */
protected getXrm(): Xrm | null {
if(typeof this.props.Xrm !== "undefined" && this.props.Xrm !== null)
return this.props.Xrm as Xrm
return Utils.getXrm()
}
static childContextTypes = {
notifier: PropTypes.object,
Xrm: PropTypes.object,
errorHandler: PropTypes.object
}
render() {
const { children } = this.props;
return React.Children.only(children)
}
}Passing EntityId and EntityName Component
Simple Notifier
Last updated