-
Notifications
You must be signed in to change notification settings - Fork 473
/
EditorTab.js
76 lines (57 loc) · 1.52 KB
/
EditorTab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/
import React, { PureComponent } from 'react';
import ErrorTab from './ErrorTab';
import MultiSheetTab from './MultiSheetTab';
export function createTab(tabName, providers) {
class EditorTab extends PureComponent {
static getDerivedStateFromError(error) {
return {
hasError: true
};
}
constructor(props) {
super(props);
this.state = {};
this.tabRef = React.createRef();
}
triggerAction(action, options) {
return this.tabRef.current.triggerAction(action, options);
}
componentDidCatch(error, info) {
this.props.onError(error, info);
}
componentDidMount() {
this.props.onShown();
}
render() {
const {
tab,
...otherProps
} = this.props;
const {
hasError
} = this.state;
const Tab = hasError ? ErrorTab : MultiSheetTab;
return (
<Tab
id={ tab.id }
tab={ tab }
{ ...otherProps }
xml={ tab.file.contents }
ref={ this.tabRef }
providers={ providers }
/>
);
}
}
EditorTab.displayName = tabName;
return EditorTab;
}