-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Execute script for selected rows (#2508)
- Loading branch information
1 parent
ca2138b
commit 5d9901e
Showing
3 changed files
with
152 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
src/dashboard/Data/Browser/ExecuteScriptRowsDialog.react.js
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,78 @@ | ||
import React from 'react'; | ||
import FormModal from 'components/FormModal/FormModal.react'; | ||
import Field from 'components/Field/Field.react'; | ||
import Label from 'components/Label/Label.react'; | ||
import Dropdown from 'components/Dropdown/Dropdown.react'; | ||
import Option from 'components/Dropdown/Option.react'; | ||
import { CurrentApp } from 'context/currentApp'; | ||
|
||
export default class ExecuteScriptRowsDialog extends React.Component { | ||
static contextType = CurrentApp; | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
currentScript: null, | ||
validScripts: [], | ||
}; | ||
|
||
this.handleConfirm = this.handleConfirm.bind(this); | ||
this.handleScriptChange = this.handleScriptChange.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
const { selection, currentClass } = this.props; | ||
|
||
const validScripts = (this.context.scripts || []).filter(script => | ||
script.classes?.includes(currentClass) | ||
); | ||
|
||
if (selection && validScripts.length > 0) { | ||
this.setState({ | ||
currentScript: validScripts[0], | ||
validScripts: validScripts, | ||
}); | ||
} | ||
} | ||
|
||
handleConfirm() { | ||
return this.props.onConfirm(this.state.currentScript); | ||
} | ||
|
||
handleScriptChange(scriptName) { | ||
this.setState({ | ||
currentScript: this.state.validScripts.find(script => script.title === scriptName), | ||
}); | ||
} | ||
|
||
render() { | ||
const { validScripts } = this.state; | ||
const { selection, processedScripts } = this.props; | ||
const selectionLength = Object.keys(selection).length; | ||
return ( | ||
<FormModal | ||
open | ||
icon="gears" | ||
iconSize={40} | ||
title={selectionLength > 1 ? `Run script on ${selectionLength} selected rows` : 'Run script on selected row'} | ||
submitText="Run" | ||
inProgressText={`Executed ${processedScripts} of ${selectionLength} rows`} | ||
onClose={this.props.onCancel} | ||
onSubmit={this.handleConfirm} | ||
> | ||
<Field | ||
label={<Label text="Script" />} | ||
input={ | ||
<Dropdown value={this.state.currentScript?.title} onChange={this.handleScriptChange}> | ||
{validScripts.map(script => ( | ||
<Option key={script.title} value={script.title}> | ||
{script.title} | ||
</Option> | ||
))} | ||
</Dropdown> | ||
} | ||
/> | ||
</FormModal> | ||
); | ||
} | ||
} |