Skip to content

Commit

Permalink
feat(core/presentation): Add previous execution description to spel p…
Browse files Browse the repository at this point in the history
…review
  • Loading branch information
christopherthielen authored and mergify[bot] committed Nov 11, 2019
1 parent 15007ca commit 1ebd4f7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/scripts/modules/core/src/presentation/spel/SpelInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ import {

import './SpelInput.less';

export interface IStageForSpelPreview {
executionLabel: string;
executionId: string;
stageId: string;
}

interface ISpelInputProps extends ITextInputProps {
previewExecutionId: string;
previewStageId: string;
previewStage: IStageForSpelPreview;
}

/** An Input that previews Spel expressions */
export function SpelInput(props: ISpelInputProps) {
const { previewExecutionId, previewStageId, ...rest } = props;
const { previewStage, ...rest } = props;
const [expression, isDebouncing] = useDebouncedValue(props.value, 300);
const isInitialRender = !useIsMountedRef().current;
const hasNewlines = !!/\n/.exec(rest.value);
Expand All @@ -38,7 +43,12 @@ export function SpelInput(props: ISpelInputProps) {
return asyncMessage('Updating preview...');
} else if (status === 'RESOLVED') {
// Render as a code block
return messageMessage('Preview\n\n\n```\n' + JSON.stringify(result, null, 2) + '\n```');
const previewMessage =
`Preview - based on previous execution: ${previewStage.executionLabel}\n\n\n` +
'```\n' +
JSON.stringify(result, null, 2) +
'\n```';
return messageMessage(previewMessage);
} else if (status === 'REJECTED') {
return warningMessage(error);
}
Expand All @@ -48,9 +58,9 @@ export function SpelInput(props: ISpelInputProps) {
useInternalValidator(props.validation, previewExpressionValidator);

const fetchSpelPreview = useData(
() => SpelService.evaluateExpression(expression, previewExecutionId, previewStageId),
() => SpelService.evaluateExpression(expression, previewStage.executionId, previewStage.stageId),
null,
[expression, previewExecutionId, previewStageId],
[expression, previewStage.executionId, previewStage.stageId],
);

// re-validate whenever an async event occurs
Expand Down

0 comments on commit 1ebd4f7

Please sign in to comment.