Skip to content

Commit

Permalink
Bugfix for Sequence Customization (#1516)
Browse files Browse the repository at this point in the history
* Replace string output for customized sequence

* Make sure output is string or undefined

* Explicitly handle object, undefined, and null cases

---------

Co-authored-by: Carter Mak <Carter.Mak@jpl.nasa.gov>
  • Loading branch information
mattdailis and cartermak authored Oct 22, 2024
1 parent 66b24bf commit 5b66921
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/components/sequencing/SequenceEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,19 @@
const sequence = viewUpdate.state.doc.toString();
disableCopyAndExport = sequence === '';
const tree = syntaxTree(viewUpdate.state);
const output = await selectedOutputFormat?.toOutputFormat?.(tree, sequence, commandDictionary, sequenceName);
let output = await selectedOutputFormat?.toOutputFormat?.(tree, sequence, commandDictionary, sequenceName);
if ($sequenceAdaptation?.modifyOutput !== undefined && output !== undefined) {
$sequenceAdaptation?.modifyOutput(output, parameterDictionaries, channelDictionary);
const modifiedOutput = $sequenceAdaptation.modifyOutput(output, parameterDictionaries, channelDictionary);
if (modifiedOutput === null) {
output = 'modifyOutput returned null. Verify your adaptation is correct';
} else if (modifiedOutput === undefined) {
output = 'modifyOutput returned undefined. Verify your adaptation is correct';
} else if (typeof modifiedOutput === 'object') {
output = JSON.stringify(modifiedOutput);
} else {
output = `${modifiedOutput}`;
}
}
editorOutputView.dispatch({ changes: { from: 0, insert: output, to: editorOutputView.state.doc.length } });
Expand Down
21 changes: 14 additions & 7 deletions src/utilities/sequence-editor/extension-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,22 @@ export async function toInputFormat(
channelDictionary: ChannelDictionary | null,
) {
const modifyOutputParse = get(sequenceAdaptation).modifyOutputParse;
let modifiedOutput = null;

if (modifyOutputParse !== undefined) {
modifiedOutput = await modifyOutputParse(output, parameterDictionaries, channelDictionary);
}

const input = await get(inputFormat)?.toInputFormat?.(modifiedOutput ?? output);
let modifiedOutput = await modifyOutputParse(output, parameterDictionaries, channelDictionary);
if (modifiedOutput === null) {
modifiedOutput = 'modifyOutputParse returned null. Verify your adaptation is correct';
} else if (modifiedOutput === undefined) {
modifiedOutput = 'modifyOutputParse returned undefined. Verify your adaptation is correct';
} else if (typeof modifiedOutput === 'object') {
modifiedOutput = JSON.stringify(modifiedOutput);
} else {
modifiedOutput = `${modifiedOutput}`;
}

return input;
return await get(inputFormat)?.toInputFormat?.(modifiedOutput);
} else {
return await get(inputFormat)?.toInputFormat?.(output);
}
}

export function inputLinter(
Expand Down

0 comments on commit 5b66921

Please sign in to comment.