CompileErrorContainer.js 1.5 KB
Newer Older
1
2
3
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
Sophie Alpert's avatar
Sophie Alpert committed
4
5
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
6
7
8
9
 */

/* @flow */
import React, { PureComponent } from 'react';
10
import ErrorOverlay from '../components/ErrorOverlay';
11
12
13
14
import Footer from '../components/Footer';
import Header from '../components/Header';
import CodeBlock from '../components/CodeBlock';
import generateAnsiHTML from '../utils/generateAnsiHTML';
15
16
17
18
19
20
import parseCompileError from '../utils/parseCompileError';
import type { ErrorLocation } from '../utils/parseCompileError';

const codeAnchorStyle = {
  cursor: 'pointer',
};
21

22
23
type Props = {|
  error: string,
24
  editorHandler: (errorLoc: ErrorLocation) => void,
25
26
27
|};

class CompileErrorContainer extends PureComponent<Props, void> {
28
  render() {
29
30
31
    const { error, editorHandler } = this.props;
    const errLoc: ?ErrorLocation = parseCompileError(error);
    const canOpenInEditor = errLoc !== null && editorHandler !== null;
32
    return (
33
      <ErrorOverlay>
34
        <Header headerText="Failed to compile" />
35
36
37
38
39
40
41
42
        <a
          onClick={
            canOpenInEditor && errLoc ? () => editorHandler(errLoc) : null
          }
          style={canOpenInEditor ? codeAnchorStyle : null}
        >
          <CodeBlock main={true} codeHTML={generateAnsiHTML(error)} />
        </a>
43
        <Footer line1="This error occurred during the build time and cannot be dismissed." />
44
      </ErrorOverlay>
45
46
47
48
49
    );
  }
}

export default CompileErrorContainer;