errorDisplayComponent.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import * as React from "react";
  2. import { GlobalState } from '../globalState';
  3. import { Nullable } from 'babylonjs/types';
  4. require("../scss/errorDisplay.scss");
  5. interface IErrorDisplayComponentProps {
  6. globalState: GlobalState;
  7. }
  8. export class CompilationError {
  9. message: string;
  10. lineNumber?: number;
  11. columnNumber?: number;
  12. }
  13. export class ErrorDisplayComponent extends React.Component<IErrorDisplayComponentProps, {error: Nullable<CompilationError>}> {
  14. public constructor(props: IErrorDisplayComponentProps) {
  15. super(props);
  16. this.state = {error: null};
  17. this.props.globalState.onErrorObservable.add((err) => {
  18. this.setState({error: err});
  19. });
  20. }
  21. private _onClick() {
  22. if (this.state.error && this.state.error.lineNumber && this.state.error.columnNumber) {
  23. const position = {
  24. lineNumber: this.state.error.lineNumber,
  25. column: this.state.error.columnNumber
  26. };
  27. this.props.globalState.onNavigateRequiredObservable.notifyObservers(position);
  28. }
  29. this.setState({error: null});
  30. }
  31. public render() {
  32. if (!this.state.error) {
  33. return null;
  34. }
  35. return (
  36. <div className="error-display" onClick={() => this._onClick()}>
  37. {
  38. this.state.error.lineNumber && this.state.error.columnNumber &&
  39. `Error at [${this.state.error.lineNumber}, ${this.state.error.columnNumber}]: `
  40. }
  41. {this.state.error.message}
  42. </div>
  43. )
  44. }
  45. }