Skip to content

Commit

Permalink
feat: new 2-step form to configure braille outputting scripts
Browse files Browse the repository at this point in the history
Merge of PR #213
  • Loading branch information
NPavie authored Apr 9, 2024
2 parents 901ad80 + 774e6fb commit 55634eb
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 184 deletions.
77 changes: 76 additions & 1 deletion src/main/data/middlewares/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
setProperties,
setTtsEngineState,
setTtsEngineFeatures,
requestStylesheetParameters,
} from 'shared/data/slices/pipeline'

import {
Expand Down Expand Up @@ -367,7 +368,7 @@ export function pipelineMiddleware({ getState, dispatch }) {
dispatch(setTtsEngineFeatures(features))
})
.catch((e) => {
error('useWebservice', e)
error('useWebservice', e, e.parsedText)
if (
selectStatus(getState()) ==
PipelineStatus.RUNNING
Expand Down Expand Up @@ -687,6 +688,80 @@ export function pipelineMiddleware({ getState, dispatch }) {
}
}, 1000)
break
case requestStylesheetParameters.type:
const job = action.payload as Job
const stylesheet = job.jobRequest.options.filter(
(option) => option.name === 'stylesheet'
)[0]
if (
!stylesheet ||
!stylesheet.value ||
stylesheet.value == ''
) {
// No parameters provided, load defaults
dispatch(
updateJob({
...job,
stylesheetParameters: [],
})
)
} else {
pipelineAPI
.fetchStylesheetParameters(job)(webservice)
.then((parameters) => {
console.log('received parameters', parameters)
// update job options with new parameters
const options = [...job.jobRequest.options]
for (let item of parameters) {
const existingOption = options.find(
(o) => o.name === item.name
)
if (existingOption !== undefined) {
existingOption.value = item.default
} else {
// For now, only consider non-uri parameters
options.push({
name: item.name,
value: item.default,
isFile: false,
})
}
}
// Also send back the parameters to the UI
// for composition of the script options
dispatch(
updateJob({
...job,
jobRequest: {
...job.jobRequest,
options: [...options],
},
stylesheetParameters: parameters,
})
)
})
.catch((e) => {
error('error fetching stylesheet parameters', e)
dispatch(
updateJob({
...job,
jobData: {
...job.jobData,
status: JobStatus.ERROR,
},
errors: [
{
error:
e instanceof ParserException
? e.parsedText
: String(e),
},
],
})
)
})
}
break
default:
if (action.type.startsWith('settings/')) {
// FIXME : check if local pipeline props have changed and
Expand Down
44 changes: 18 additions & 26 deletions src/renderer/components/Fields/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,19 @@ export function FormField({
}: {
item: ScriptItemBase
idprefix: string
onChange: (string, ScriptItemBase) => void // function to set the value in a parent-level collection.
onChange: (value: any, item: ScriptItemBase) => void // function to set the value in a parent-level collection.
initialValue: any // the initial value for the field
}) {
const [value, setValue] = useState(initialValue)
const [checked, setChecked] = useState(true)
let controlId = `${idprefix}-${item.name}`

let onChangeValue = (newValue, scriptItem) => {
setValue(newValue)
onChange(newValue, scriptItem)
}
let dialogOpts =
item.type == 'anyFileURI'
? ['openFile']
: item.type == 'anyDirURI'
? ['openDirectory']
: ['openFile', 'openDirectory']
let dialogOpts = ['anyFileURI', 'anyURI'].includes(item.type)
? ['openFile']
: item.type == 'anyDirURI'
? ['openDirectory']
: ['openFile', 'openDirectory']

const { settings } = useWindowStore()

let matchType = (item) => {
let inputType = findInputType(item.type)
if (inputType == 'file') {
Expand All @@ -54,11 +47,11 @@ export function FormField({
elemId={controlId}
mediaType={item.mediaType}
name={item.name}
onChange={(filenames) => onChangeValue(filenames, item)}
onChange={(filenames) => onChange(filenames, item)}
useSystemPath={false}
buttonLabel="Browse"
required={item.required}
initialValue={value}
initialValue={initialValue}
ordered={item.ordered}
/>
)
Expand All @@ -77,13 +70,11 @@ export function FormField({
elemId={controlId}
mediaType={item.mediaType}
name={item.name}
onChange={(filename) =>
onChangeValue(filename, item)
}
onChange={(filename) => onChange(filename, item)}
useSystemPath={false}
buttonLabel="Browse"
required={item.required}
initialValue={value}
initialValue={initialValue}
/>
)
}
Expand All @@ -94,18 +85,20 @@ export function FormField({
<input
type={inputType}
required={item.required}
onChange={(e) => onChangeValue(e.target.checked, item)}
onChange={(e) => onChange(e.target.checked, item)}
id={controlId}
checked={value === 'true' || value === true}
checked={
initialValue === 'true' || initialValue === true
}
></input>
</>
)
} else if (inputType == 'custom') {
return (
<CustomField
item={item}
onChange={(newValue) => onChangeValue(newValue, item)}
initialValue={value ?? ''}
onChange={(newValue) => onChange(newValue, item)}
initialValue={initialValue ?? ''}
controlId={controlId}
/>
)
Expand All @@ -115,10 +108,9 @@ export function FormField({
<input
type={inputType}
required={item.required}
// @ts-ignore
value={value ?? ''}
value={initialValue ?? ''}
id={controlId}
onChange={(e) => onChangeValue(e.target.value, item)}
onChange={(e) => onChange(e.target.value, item)}
></input>
</>
)
Expand Down
Loading

0 comments on commit 55634eb

Please sign in to comment.