-
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.
Merge pull request #137 from splunk/feature/ADDON-34742-custom-cell
feat(ADDON-34742): Added custom cell feature in the table and fixed sorting issue
- Loading branch information
Showing
7 changed files
with
158 additions
and
46 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
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
75 changes: 75 additions & 0 deletions
75
splunk_add_on_ucc_framework/ucc_ui_lib/src/main/webapp/components/CustomCell.jsx
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,75 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { _ } from '@splunk/ui-utils/i18n'; | ||
|
||
import { getUnifiedConfigs } from '../util/util'; | ||
|
||
class CustomCell 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.props.serviceName, | ||
this.el, | ||
this.props.field, | ||
this.props.row | ||
); | ||
customControl.render(); | ||
this.setState({ loading: false }); | ||
}); | ||
} | ||
|
||
shouldComponentUpdate(nextProps, nextState) { | ||
if (!nextState.loading && this.shouldRender) { | ||
this.shouldRender = false; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
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' }} | ||
/> | ||
} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
CustomCell.propTypes = { | ||
serviceName: PropTypes.string.isRequired, | ||
row: PropTypes.object.isRequired, | ||
field: PropTypes.string.isRequired, | ||
fileName: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default CustomCell; |
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
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