Skip to content

Commit

Permalink
feat(editor): support configuring param evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
sabberworm committed Oct 10, 2024
1 parent 928d196 commit fb7b8c0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/main/frontend/model/Script.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { LogLevel } from './LogLevel';
import { Hop } from './hops';

type ParameterEvaluation = 'STRING' | 'LINES' | 'TEMPLATE' | 'EXPRESSION';
export interface Parameter {
name: string;
defaultValue: string;
type: string;
evaluation: ParameterEvaluation;
}

export interface Script {
Expand Down
17 changes: 13 additions & 4 deletions src/main/frontend/sections/RunControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ const Elm = styled('form', React.forwardRef)`
grid-auto-flow: row;
.arguments {
display: grid;
grid-template-columns: 1fr 3fr;
> input {
width: auto;
gap: 6px;
grid-template-columns: 1fr 2fr;
grid-auto-flow: row;
> label {
display: contents;
> span {
align-content: center;
}
> input {
width: auto;
}
}
}
> .options {
Expand Down Expand Up @@ -41,7 +49,8 @@ export const RunControls: FC<{ runWith: (data: FormData) => Promise<void> }> = (
{script.parameters.map(({ name, type }) => (
<React.Fragment key={name}>
<label>
{name}:<input is="coral-textfield" type={type} name={name} />
<span>{name}:</span>
<input is="coral-textfield" type={type} name={name} />
</label>
</React.Fragment>
))}
Expand Down
7 changes: 7 additions & 0 deletions src/main/frontend/sections/ScriptEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ const Elm = styled('div')`
grid-auto-rows: min-content 1fr min-content;
overflow: auto;
.parameters {
display: flex;
flex-direction: column;
gap: 6px;
> .param {
display: flex;
gap: 6px;
}
> button {
align-self: end;
}
}
`;

Expand All @@ -26,6 +32,7 @@ export const ScriptEditor: FC = () => {
name: `param_${script.parameters.length + 1}`,
defaultValue: '',
type: 'text',
evaluation: 'STRING',
});
scriptContext.commit();
}
Expand Down
39 changes: 23 additions & 16 deletions src/main/frontend/sections/editor/Parameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,19 @@ export const Parameter: FC<{ param: Script['parameters'][0]; i: number }> = ({ i

return (
<Elm>
<label>
<span>Param {i + 1}: </span>
<input
is="coral-textfield"
placeholder="Name"
name="name"
value={name}
onChange={e => {
setName(e.target.value);
}}
onBlur={e => {
param.name = e.target.value;
scriptContext.commit();
}}
></input>
</label>
<input
is="coral-textfield"
placeholder="Name"
name="name"
value={name}
onChange={e => {
setName(e.target.value);
}}
onBlur={e => {
param.name = e.target.value;
scriptContext.commit();
}}
></input>
<input
is="coral-textfield"
placeholder="Default Value"
Expand All @@ -67,6 +64,16 @@ export const Parameter: FC<{ param: Script['parameters'][0]; i: number }> = ({ i
value={param.type}
onChange={val => (param.type = val)}
/>
<Select
list={[
['STRING', 'String'],
['LINES', 'Array of Lines'],
['TEMPLATE', 'JEXL String Template'],
['EXPRESSION', 'JEXL Expression'],
]}
value={param.evaluation}
onChange={val => (param.evaluation = val as typeof param.evaluation)}
/>
<button
is="coral-button"
icon="delete"
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/sections/editor/types/FallbackStep.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { FC, useContext } from 'react';

import { AnyHop, Hop } from '../../../model/hops';
import { Hop } from '../../../model/hops';
import { StepEditor } from '../../../widgets/StepEditor';
import { ScriptContext } from '../../../App';
import { CodeEditor } from '../../../widgets/CodeEditor';

export const FallbackStep: FC<{ parentHops: Hop[]; hop: AnyHop }> = ({ parentHops, hop }) => {
export const FallbackStep: FC<{ parentHops: Hop[]; hop: Hop }> = ({ parentHops, hop }) => {
const scriptContext = useContext(ScriptContext);

const { type: hopType, ...hopWithoutType } = hop;
Expand Down
10 changes: 5 additions & 5 deletions src/main/frontend/widgets/StepEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, ReactNode, useContext } from 'react';

import { AnyHop, Hop } from '../model/hops';
import { Hop } from '../model/hops';
import { styled } from 'goober';
import { ScriptContext } from '../App';

Expand Down Expand Up @@ -167,7 +167,7 @@ const Elm = styled('div')`
}
`;

export const StepEditor: FC<{ parentHops: Hop[]; hop: AnyHop; title: string; children: ReactNode; pipeline?: ReactNode }> = ({
export const StepEditor: FC<{ parentHops: Hop[]; hop: Hop; title: string; children: ReactNode; pipeline?: ReactNode }> = ({
parentHops,
hop,
title,
Expand All @@ -176,11 +176,11 @@ export const StepEditor: FC<{ parentHops: Hop[]; hop: AnyHop; title: string; chi
}) => {
const scriptContext = useContext(ScriptContext);

const hopIndex = parentHops.indexOf(hop as Hop);
const hopIndex = parentHops.indexOf(hop);

function moveHop(isUp = false) {
parentHops.splice(hopIndex, 1);
parentHops.splice(hopIndex + (isUp ? -1 : 1), 0, hop as Hop);
parentHops.splice(hopIndex + (isUp ? -1 : 1), 0, hop);
scriptContext.commit();
}

Expand All @@ -206,7 +206,7 @@ export const StepEditor: FC<{ parentHops: Hop[]; hop: AnyHop; title: string; chi
is="coral-button"
icon="duplicate"
onClick={() => {
parentHops.splice(hopIndex, 0, hop as Hop);
parentHops.splice(hopIndex, 0, hop);
scriptContext.commit();
}}
></button>
Expand Down

0 comments on commit fb7b8c0

Please sign in to comment.