-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5643ea1
commit 58b0571
Showing
3 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { _ } from '@splunk/ui-utils/i18n'; | ||
import { getUnifiedConfigs } from '../util/util'; | ||
|
||
class CustomMenu extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
loading: true, | ||
}; | ||
this.shouldRender = true; | ||
} | ||
|
||
componentDidMount() { | ||
const globalConfig = getUnifiedConfigs(); | ||
this.setState({ loading: true }); | ||
this.loadCustomControl().then((Control) => { | ||
const customControl = new Control(globalConfig, this.el, this.setValue); | ||
customControl.render(); | ||
this.setState({ loading: false }); | ||
}); | ||
} | ||
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
if (!nextState.loading && this.shouldRender) { | ||
this.shouldRender = false; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
setValue = (newValue) => { | ||
this.props.handleChange(newValue); | ||
}; | ||
|
||
loadCustomControl = () => { | ||
const globalConfig = getUnifiedConfigs(); | ||
const appName = globalConfig.meta.name; | ||
return new Promise((resolve) => { | ||
__non_webpack_require__( | ||
[`app/${appName}/js/build/custom/${this.props.fileName}`], | ||
(Control) => resolve(Control) | ||
); | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<> | ||
{this.state.loading && _('Loading...')} | ||
{ | ||
<span | ||
ref={(el) => { | ||
this.el = el; | ||
}} | ||
style={{ visibility: this.state.loading ? 'hidden' : 'visible' }} | ||
/> | ||
} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
CustomMenu.propTypes = { | ||
fileName: PropTypes.string.isRequired, | ||
handleChange: PropTypes.func, | ||
}; | ||
|
||
export default CustomMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
body { | ||
min-width: 960px; | ||
background-color: #eee; | ||
background-color: #fff; | ||
} |