Skip to content

Commit

Permalink
runner is only available on selected plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Apr 10, 2024
1 parent a580a13 commit dfa130d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
5 changes: 5 additions & 0 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ class App extends React.Component {
}, () => {
const plugin = this.state.plugins.find(f => f.pluginId === newSelectedPlugin)

if (!plugin) {
window.location.href = '/'
return
}

if (plugin.type === "github") {
const { filename, owner, ref } = plugin;
Service.getGithubSources(filename, owner, ref, plugin.private)
Expand Down
43 changes: 14 additions & 29 deletions ui/src/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
export class Run extends React.Component {

state = {
selectedPlugin: this.props.selectedPlugin ? { value: this.props.selectedPlugin.pluginId, label: this.props.selectedPlugin.filename } : undefined,
version: undefined,
input: JSON.stringify({}, null, 4),
functionName: 'execute',
Expand Down Expand Up @@ -57,8 +56,8 @@ export class Run extends React.Component {
}

run = () => {
const { selectedPlugin, input, functionName, version } = this.state;
const plugin = this.props.plugins.find(p => p.pluginId === selectedPlugin.value);
const { input, functionName, version } = this.state;
const plugin = this.props.plugins.find(p => p.pluginId === this.props.selectedPlugin.value);

if (!version) {
toast.error("You need to build your plugin before using the runner");
Expand Down Expand Up @@ -99,11 +98,12 @@ export class Run extends React.Component {
}

fetchExports = () => {
getExports(this.state.version.value)
.then(functions => this.setState({
functions,
functionName: functions[0]
}))
if (this.state.version)
getExports(this.state.version.value)
.then(functions => this.setState({
functions,
functionName: functions[0]
}))
}

getConfigurationFile = () => {
Expand All @@ -115,33 +115,17 @@ export class Run extends React.Component {
}

render() {
const { selectedPlugin, input, functionName, output, stdout, stderr, functions, version } = this.state;
const { input, functionName, output, stdout, stderr, functions, version } = this.state;
const { plugins } = this.props;

const selectedPluginContents = this.props.plugins.find(p => p.pluginId === selectedPlugin?.value);
if (!this.props.selectedPlugin)
return null

const configurationFile = this.props.selectedPlugin?.pluginId === selectedPlugin?.value ? this.getConfigurationFile() : selectedPluginContents?.versions
const configurationFile = this.getConfigurationFile()

return (
<div style={{ flex: 1, marginTop: 75, maxWidth: 800 }} className="px-3"
onKeyDown={e => e.stopPropagation()}>
<SelectorStep
noOptionsMessageText="no plugin"
id="selectedPlugin"
title="Plugin"
value={selectedPlugin}
options={plugins
.filter(plugin => plugin.type !== 'opa')
.map(plugin => ({ value: plugin.pluginId, label: plugin.filename }))}
onChange={e => {
this.setState({
selectedPlugin: e,
version: undefined,
functionName: "",
functions: []
})
}}
/>
<SelectorStep
noOptionsMessageText="You need to build a first version of this plugin to use it"
title="Version"
Expand Down Expand Up @@ -205,7 +189,7 @@ export class Run extends React.Component {
/>
</div>
<div className='mb-3'>
<button type="button" className='btn btn-success btn-sm' onClick={this.run} disabled={!selectedPlugin}>
<button type="button" className='btn btn-success btn-sm' onClick={this.run} >
<i className='fas fa-play me-1' />
Run
</button>
Expand Down Expand Up @@ -270,6 +254,7 @@ function SelectorStep({ id, title, value, options, onChange, noOptionsMessageTex
value={value}
options={options}
onChange={onChange}
isClearable
components={{
NoOptionsMessage: () => {
return <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center ' }}>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function Tab({ content, ext, handleContent, selected, readOnly }) {

if (ext === 'js') {
const lints = linter(esLint(new eslint.Linter(), {
files: ["**/*.js"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module"
ecmaVersion: "latest"
},
rules: {
semi: ["error", "never"]
Expand Down
2 changes: 1 addition & 1 deletion ui/src/TabsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function Header({
<Build onBuild={onBuild} />
<Release onBuild={onBuild} />
<Download onDownload={onDownload} />
{runtimeState && <Play showPlaySettings={showPlaySettings} />}
</>}
{runtimeState && <Play showPlaySettings={showPlaySettings} />}
</div>
</div>
)}
Expand Down

0 comments on commit dfa130d

Please sign in to comment.