Update DashboardPage to use arrow function properties

pull/1887/head
Andrew Watkins 2017-08-16 12:35:54 -07:00
parent 380d266e7e
commit cad47a9ecd
1 changed files with 52 additions and 91 deletions

View File

@ -27,31 +27,11 @@ class DashboardPage extends Component {
super(props) super(props)
this.state = { this.state = {
selectedCell: null,
isEditMode: false,
isTemplating: false,
dygraphs: [], dygraphs: [],
isEditMode: false,
selectedCell: null,
isTemplating: false,
} }
this.handleAddCell = ::this.handleAddCell
this.handleEditDashboard = ::this.handleEditDashboard
this.handleSaveEditedCell = ::this.handleSaveEditedCell
this.handleDismissOverlay = ::this.handleDismissOverlay
this.handleUpdatePosition = ::this.handleUpdatePosition
this.handleChooseTimeRange = ::this.handleChooseTimeRange
this.handleRenameDashboard = ::this.handleRenameDashboard
this.handleEditDashboardCell = ::this.handleEditDashboardCell
this.handleCancelEditDashboard = ::this.handleCancelEditDashboard
this.handleDeleteDashboardCell = ::this.handleDeleteDashboardCell
this.handleOpenTemplateManager = ::this.handleOpenTemplateManager
this.handleUpdateDashboardCell = ::this.handleUpdateDashboardCell
this.handleSummonOverlayTechnologies = ::this
.handleSummonOverlayTechnologies
this.handleRunTemplateVariableQuery = ::this.handleRunTemplateVariableQuery
this.handleEditTemplateVariables = ::this.handleEditTemplateVariables
this.handleRunQueryFailure = ::this.handleRunQueryFailure
this.handleToggleTempVarControls = ::this.handleToggleTempVarControls
this.synchronizer = ::this.synchronizer
} }
async componentDidMount() { async componentDidMount() {
@ -73,7 +53,7 @@ class DashboardPage extends Component {
await putDashboardByID(dashboardID) await putDashboardByID(dashboardID)
} }
handleOpenTemplateManager() { handleOpenTemplateManager = () => {
this.setState({isTemplating: true}) this.setState({isTemplating: true})
} }
@ -86,43 +66,43 @@ class DashboardPage extends Component {
} }
} }
handleDismissOverlay() { handleDismissOverlay = () => {
this.setState({selectedCell: null}) this.setState({selectedCell: null})
} }
handleSaveEditedCell(newCell) { handleSaveEditedCell = newCell => {
this.props.dashboardActions this.props.dashboardActions
.updateDashboardCell(this.getActiveDashboard(), newCell) .updateDashboardCell(this.getActiveDashboard(), newCell)
.then(this.handleDismissOverlay) .then(this.handleDismissOverlay)
} }
handleSummonOverlayTechnologies(cell) { handleSummonOverlayTechnologies = cell => {
this.setState({selectedCell: cell}) this.setState({selectedCell: cell})
} }
handleChooseTimeRange(timeRange) { handleChooseTimeRange = timeRange => {
this.props.dashboardActions.setTimeRange(timeRange) this.props.dashboardActions.setTimeRange(timeRange)
} }
handleUpdatePosition(cells) { handleUpdatePosition = cells => {
const newDashboard = {...this.getActiveDashboard(), cells} const newDashboard = {...this.getActiveDashboard(), cells}
this.props.dashboardActions.updateDashboard(newDashboard) this.props.dashboardActions.updateDashboard(newDashboard)
this.props.dashboardActions.putDashboard(newDashboard) this.props.dashboardActions.putDashboard(newDashboard)
} }
handleAddCell() { handleAddCell = () => {
this.props.dashboardActions.addDashboardCellAsync(this.getActiveDashboard()) this.props.dashboardActions.addDashboardCellAsync(this.getActiveDashboard())
} }
handleEditDashboard() { handleEditDashboard = () => {
this.setState({isEditMode: true}) this.setState({isEditMode: true})
} }
handleCancelEditDashboard() { handleCancelEditDashboard = () => {
this.setState({isEditMode: false}) this.setState({isEditMode: false})
} }
handleRenameDashboard(name) { handleRenameDashboard = name => {
this.setState({isEditMode: false}) this.setState({isEditMode: false})
const newDashboard = {...this.getActiveDashboard(), name} const newDashboard = {...this.getActiveDashboard(), name}
this.props.dashboardActions.updateDashboard(newDashboard) this.props.dashboardActions.updateDashboard(newDashboard)
@ -130,7 +110,7 @@ class DashboardPage extends Component {
} }
// Places cell into editing mode. // Places cell into editing mode.
handleEditDashboardCell(x, y, isEditing) { handleEditDashboardCell = (x, y, isEditing) => {
return () => { return () => {
this.props.dashboardActions.editDashboardCell( this.props.dashboardActions.editDashboardCell(
this.getActiveDashboard(), this.getActiveDashboard(),
@ -141,7 +121,7 @@ class DashboardPage extends Component {
} }
} }
handleUpdateDashboardCell(newCell) { handleUpdateDashboardCell = newCell => {
return () => { return () => {
this.props.dashboardActions.updateDashboardCell( this.props.dashboardActions.updateDashboardCell(
this.getActiveDashboard(), this.getActiveDashboard(),
@ -150,7 +130,7 @@ class DashboardPage extends Component {
} }
} }
handleDeleteDashboardCell(cell) { handleDeleteDashboardCell = cell => {
const dashboard = this.getActiveDashboard() const dashboard = this.getActiveDashboard()
this.props.dashboardActions.deleteDashboardCellAsync(dashboard, cell) this.props.dashboardActions.deleteDashboardCellAsync(dashboard, cell)
} }
@ -164,46 +144,27 @@ class DashboardPage extends Component {
) )
} }
handleRunTemplateVariableQuery( handleEditTemplateVariables = (
templateVariable, templates,
{query, db, tempVars, type, tagKey, measurement} onSaveTemplatesSuccess
) { ) => async () => {
const {source} = this.props try {
this.props.dashboardActions.runTemplateVariableQueryAsync( await this.props.dashboardActions.putDashboard({
templateVariable, ...this.getActiveDashboard(),
{ templates,
source, })
query, onSaveTemplatesSuccess()
db, } catch (error) {
// rp, TODO console.error(error)
tempVars,
type,
tagKey,
measurement,
}
)
}
handleEditTemplateVariables(templates, onSaveTemplatesSuccess) {
return async () => {
try {
await this.props.dashboardActions.putDashboard({
...this.getActiveDashboard(),
templates,
})
onSaveTemplatesSuccess()
} catch (error) {
console.error(error)
}
} }
} }
handleRunQueryFailure(error) { handleRunQueryFailure = error => {
console.error(error) console.error(error)
this.props.errorThrown(error) this.props.errorThrown(error)
} }
synchronizer(dygraph) { synchronizer = dygraph => {
const dygraphs = [...this.state.dygraphs, dygraph] const dygraphs = [...this.state.dygraphs, dygraph]
const {dashboards, params} = this.props const {dashboards, params} = this.props
const dashboard = dashboards.find(d => d.id === +params.dashboardID) const dashboard = dashboards.find(d => d.id === +params.dashboardID)
@ -221,11 +182,11 @@ class DashboardPage extends Component {
this.setState({dygraphs}) this.setState({dygraphs})
} }
handleToggleTempVarControls() { handleToggleTempVarControls = () => {
this.props.templateControlBarVisibilityToggled() this.props.templateControlBarVisibilityToggled()
} }
handleCancelEditCell(cellID) { handleCancelEditCell = cellID => {
this.props.dashboardActions.cancelEditCell( this.props.dashboardActions.cancelEditCell(
this.getActiveDashboard().id, this.getActiveDashboard().id,
cellID cellID
@ -313,49 +274,49 @@ class DashboardPage extends Component {
{isTemplating {isTemplating
? <OverlayTechnologies> ? <OverlayTechnologies>
<TemplateVariableManager <TemplateVariableManager
onClose={this.handleCloseTemplateManager}
onEditTemplateVariables={this.handleEditTemplateVariables}
source={source} source={source}
templates={dashboard.templates} templates={dashboard.templates}
onClose={this.handleCloseTemplateManager}
onRunQueryFailure={this.handleRunQueryFailure} onRunQueryFailure={this.handleRunQueryFailure}
onEditTemplateVariables={this.handleEditTemplateVariables}
/> />
</OverlayTechnologies> </OverlayTechnologies>
: null} : null}
{selectedCell {selectedCell
? <CellEditorOverlay ? <CellEditorOverlay
source={source} source={source}
dashboardID={dashboardID}
templates={templatesIncludingDashTime}
cell={selectedCell} cell={selectedCell}
timeRange={timeRange} timeRange={timeRange}
autoRefresh={autoRefresh} autoRefresh={autoRefresh}
dashboardID={dashboardID}
queryStatus={cellQueryStatus} queryStatus={cellQueryStatus}
onSave={this.handleSaveEditedCell} onSave={this.handleSaveEditedCell}
onCancel={this.handleDismissOverlay} onCancel={this.handleDismissOverlay}
templates={templatesIncludingDashTime}
editQueryStatus={dashboardActions.editCellQueryStatus} editQueryStatus={dashboardActions.editCellQueryStatus}
/> />
: null} : null}
{isEditMode {isEditMode
? <DashboardHeaderEdit ? <DashboardHeaderEdit
dashboard={dashboard} dashboard={dashboard}
onCancel={this.handleCancelEditDashboard}
onSave={this.handleRenameDashboard} onSave={this.handleRenameDashboard}
onCancel={this.handleCancelEditDashboard}
/> />
: <DashboardHeader : <DashboardHeader
buttonText={dashboard ? dashboard.name : ''}
handleChooseAutoRefresh={handleChooseAutoRefresh}
autoRefresh={autoRefresh}
timeRange={timeRange}
handleChooseTimeRange={this.handleChooseTimeRange}
isHidden={inPresentationMode}
handleClickPresentationButton={handleClickPresentationButton}
dashboard={dashboard}
sourceID={sourceID}
source={source} source={source}
sourceID={sourceID}
dashboard={dashboard}
timeRange={timeRange}
autoRefresh={autoRefresh}
isHidden={inPresentationMode}
onAddCell={this.handleAddCell} onAddCell={this.handleAddCell}
onEditDashboard={this.handleEditDashboard} onEditDashboard={this.handleEditDashboard}
onToggleTempVarControls={this.handleToggleTempVarControls} buttonText={dashboard ? dashboard.name : ''}
showTemplateControlBar={showTemplateControlBar} showTemplateControlBar={showTemplateControlBar}
handleChooseAutoRefresh={handleChooseAutoRefresh}
handleChooseTimeRange={this.handleChooseTimeRange}
onToggleTempVarControls={this.handleToggleTempVarControls}
handleClickPresentationButton={handleClickPresentationButton}
> >
{dashboards {dashboards
? dashboards.map((d, i) => ? dashboards.map((d, i) =>
@ -373,19 +334,19 @@ class DashboardPage extends Component {
dashboard={dashboard} dashboard={dashboard}
timeRange={timeRange} timeRange={timeRange}
autoRefresh={autoRefresh} autoRefresh={autoRefresh}
synchronizer={this.synchronizer}
onAddCell={this.handleAddCell} onAddCell={this.handleAddCell}
onEditCell={this.handleEditDashboardCell} synchronizer={this.synchronizer}
inPresentationMode={inPresentationMode} inPresentationMode={inPresentationMode}
onEditCell={this.handleEditDashboardCell}
onPositionChange={this.handleUpdatePosition} onPositionChange={this.handleUpdatePosition}
onSelectTemplate={this.handleSelectTemplate}
onCancelEditCell={this.handleCancelEditCell}
onDeleteCell={this.handleDeleteDashboardCell} onDeleteCell={this.handleDeleteDashboardCell}
onUpdateCell={this.handleUpdateDashboardCell} onUpdateCell={this.handleUpdateDashboardCell}
showTemplateControlBar={showTemplateControlBar}
onOpenTemplateManager={this.handleOpenTemplateManager} onOpenTemplateManager={this.handleOpenTemplateManager}
templatesIncludingDashTime={templatesIncludingDashTime} templatesIncludingDashTime={templatesIncludingDashTime}
onSummonOverlayTechnologies={this.handleSummonOverlayTechnologies} onSummonOverlayTechnologies={this.handleSummonOverlayTechnologies}
onSelectTemplate={this.handleSelectTemplate}
showTemplateControlBar={showTemplateControlBar}
onCancelEditCell={::this.handleCancelEditCell}
/> />
: null} : null}
</div> </div>