Skip to content

Commit 2d87f5c

Browse files
committed
chore: use step name in suggestions popover
1 parent b755452 commit 2d87f5c

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

packages/frontend/src/components/RichTextEditor/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ const Editor = ({
113113
autoFocus = false,
114114
}: EditorProps) => {
115115
const { priorExecutionSteps } = useContext(StepExecutionsContext)
116+
const { allApps } = useContext(EditorContext)
116117
const isMobile = useIsMobile()
117118
const isMulticol = parentType === 'multicol'
118119

119120
const [stepsWithVariables, varInfo] = useMemo(() => {
120121
const stepsWithVars = filterVariables(
121-
extractVariables(priorExecutionSteps),
122+
extractVariables(priorExecutionSteps, allApps),
122123
(variable) => {
123124
const variableType = variable.type ?? 'text'
124125
if (variableTypes) {
@@ -130,7 +131,7 @@ const Editor = ({
130131
)
131132
const info = genVariableInfoMap(stepsWithVars)
132133
return [stepsWithVars, info]
133-
}, [priorExecutionSteps, variableTypes])
134+
}, [allApps, priorExecutionSteps, variableTypes])
134135

135136
const extensions: Array<any> = [
136137
Placeholder.configure({

packages/frontend/src/helpers/variables.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import type {
2+
IAction,
3+
IApp,
24
IDataOutMetadata,
35
IDataOutMetadatum,
46
IExecutionStep,
7+
ITrigger,
58
TDataOutMetadatumType,
69
} from '@plumber/types'
710

811
import get from 'lodash.get'
912

1013
import { RawColumn, RawRow } from '@/components/VariablesList/utils'
14+
import { TOOLBOX_ACTIONS, TOOLBOX_APP_KEY } from '@/helpers/toolbox'
1115

1216
// these are the variable types to display on the frontend (make visible)
1317
export const VISIBLE_VARIABLE_TYPES: TDataOutMetadatumType[] = [
@@ -44,6 +48,40 @@ export interface Variable {
4448
isHidden?: boolean
4549
}
4650

51+
function getStepName(executionStep: IExecutionStep, allApps: IApp[]) {
52+
const { appKey, key, step } = executionStep
53+
54+
const isTrigger = ['formsg', 'webhook', 'scheduler'].includes(appKey)
55+
const isIfThen = appKey === TOOLBOX_APP_KEY && key === TOOLBOX_ACTIONS.IfThen
56+
const app = allApps?.find((a: IApp) => a.key === appKey)
57+
const actionsOrTriggers: Array<ITrigger | IAction> =
58+
(isTrigger ? app?.triggers : app?.actions) || []
59+
60+
const selectedActionOrTrigger = actionsOrTriggers.find(
61+
(actionOrTrigger: IAction | ITrigger) => actionOrTrigger.key === key,
62+
)
63+
64+
let caption = ''
65+
const defaultCaption = selectedActionOrTrigger?.name
66+
if (step?.config?.stepName) {
67+
caption = `${step.config.stepName}`
68+
} else if (defaultCaption) {
69+
caption = defaultCaption
70+
71+
if (isIfThen) {
72+
caption = 'Condition'
73+
}
74+
} else if (app?.name) {
75+
caption = app.name
76+
}
77+
78+
return (
79+
step?.config?.stepName ||
80+
caption ||
81+
(appKey || '').charAt(0)?.toUpperCase() + appKey?.slice(1)
82+
)
83+
}
84+
4785
function sortVariables(variables: Variable[]): void {
4886
variables.sort((a, b) => {
4987
// Put vars with null order last, but preserve ordering (via `sort`'s
@@ -198,6 +236,7 @@ const process = (
198236

199237
export function extractVariables(
200238
executionSteps: IExecutionStep[],
239+
allApps?: IApp[],
201240
): StepWithVariables[] {
202241
if (!executionSteps) {
203242
return []
@@ -218,15 +257,12 @@ export function extractVariables(
218257
metadata,
219258
'',
220259
)
260+
const stepName = getStepName(executionStep, allApps || [])
221261
// sort variable by order key in-place
222262
sortVariables(variables)
223263
return {
224264
id: executionStep.stepId,
225-
name: `${executionStep.step.position}. ${
226-
executionStep.step?.config?.stepName ||
227-
(executionStep.appKey || '').charAt(0)?.toUpperCase() +
228-
executionStep.appKey?.slice(1)
229-
}`,
265+
name: `${executionStep.step.position}. ${stepName}`,
230266
output: variables,
231267
}
232268
})

0 commit comments

Comments
 (0)