Merge pull request #789 from automatisch/issue-760
feat: show "instant" chip for webhook triggers
This commit is contained in:
@@ -381,6 +381,7 @@ type Trigger {
|
|||||||
key: String
|
key: String
|
||||||
description: String
|
description: String
|
||||||
pollInterval: Int
|
pollInterval: Int
|
||||||
|
type: String
|
||||||
substeps: [TriggerSubstep]
|
substeps: [TriggerSubstep]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ import Collapse from '@mui/material/Collapse';
|
|||||||
import ListItem from '@mui/material/ListItem';
|
import ListItem from '@mui/material/ListItem';
|
||||||
import TextField from '@mui/material/TextField';
|
import TextField from '@mui/material/TextField';
|
||||||
import Autocomplete from '@mui/material/Autocomplete';
|
import Autocomplete from '@mui/material/Autocomplete';
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import { EditorContext } from 'contexts/Editor';
|
import { EditorContext } from 'contexts/Editor';
|
||||||
@@ -38,8 +39,20 @@ const optionGenerator = (app: {
|
|||||||
value: app.key as string,
|
value: app.key as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
const getOption = (options: Record<string, unknown>[], appKey?: IApp['key']) =>
|
const eventOptionGenerator = (app: {
|
||||||
options.find((option) => option.value === (appKey as string)) || null;
|
name: string;
|
||||||
|
key: string;
|
||||||
|
type?: string;
|
||||||
|
}): { label: string; value: string; type: string } => ({
|
||||||
|
label: app.name as string,
|
||||||
|
value: app.key as string,
|
||||||
|
type: app?.type as string,
|
||||||
|
});
|
||||||
|
|
||||||
|
const getOption = <T extends { value: string }>(
|
||||||
|
options: T[],
|
||||||
|
selectedOptionValue?: string
|
||||||
|
) => options.find((option) => option.value === selectedOptionValue);
|
||||||
|
|
||||||
function ChooseAppAndEventSubstep(
|
function ChooseAppAndEventSubstep(
|
||||||
props: ChooseAppAndEventSubstepProps
|
props: ChooseAppAndEventSubstepProps
|
||||||
@@ -72,14 +85,17 @@ function ChooseAppAndEventSubstep(
|
|||||||
);
|
);
|
||||||
const actionsOrTriggers: Array<ITrigger | IAction> =
|
const actionsOrTriggers: Array<ITrigger | IAction> =
|
||||||
(isTrigger ? app?.triggers : app?.actions) || [];
|
(isTrigger ? app?.triggers : app?.actions) || [];
|
||||||
const actionOptions = React.useMemo(
|
const actionOrTriggerOptions = React.useMemo(
|
||||||
() => actionsOrTriggers.map((trigger) => optionGenerator(trigger)),
|
() => actionsOrTriggers.map((trigger) => eventOptionGenerator(trigger)),
|
||||||
[app?.key]
|
[app?.key]
|
||||||
);
|
);
|
||||||
const selectedActionOrTrigger = actionsOrTriggers.find(
|
const selectedActionOrTrigger = actionsOrTriggers.find(
|
||||||
(actionOrTrigger: IAction | ITrigger) => actionOrTrigger.key === step?.key
|
(actionOrTrigger: IAction | ITrigger) => actionOrTrigger.key === step?.key
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isWebhook =
|
||||||
|
isTrigger && (selectedActionOrTrigger as ITrigger).type === 'webhook';
|
||||||
|
|
||||||
const { name } = substep;
|
const { name } = substep;
|
||||||
|
|
||||||
const valid: boolean = !!step.key && !!step.appKey;
|
const valid: boolean = !!step.key && !!step.appKey;
|
||||||
@@ -177,14 +193,49 @@ function ChooseAppAndEventSubstep(
|
|||||||
disablePortal
|
disablePortal
|
||||||
disableClearable
|
disableClearable
|
||||||
disabled={editorContext.readOnly}
|
disabled={editorContext.readOnly}
|
||||||
options={actionOptions}
|
options={actionOrTriggerOptions}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
label={formatMessage('flowEditor.chooseEvent')}
|
label={formatMessage('flowEditor.chooseEvent')}
|
||||||
|
InputProps={{
|
||||||
|
...params.InputProps,
|
||||||
|
endAdornment: (
|
||||||
|
<React.Fragment>
|
||||||
|
{isWebhook && (
|
||||||
|
<Chip
|
||||||
|
label={formatMessage(
|
||||||
|
'flowEditor.instantTriggerType'
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{params.InputProps.endAdornment}
|
||||||
|
</React.Fragment>
|
||||||
|
),
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
value={getOption(actionOptions, step.key)}
|
renderOption={(optionProps, option) => (
|
||||||
|
<li
|
||||||
|
{...optionProps}
|
||||||
|
key={option.value.toString()}
|
||||||
|
style={{
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography>{option.label}</Typography>
|
||||||
|
|
||||||
|
{option.type === 'webhook' && (
|
||||||
|
<Chip
|
||||||
|
label={formatMessage('flowEditor.instantTriggerType')}
|
||||||
|
sx={{ mr: 3 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
value={getOption(actionOrTriggerOptions, step.key)}
|
||||||
onChange={onEventChange}
|
onChange={onEventChange}
|
||||||
data-test="choose-event-autocomplete"
|
data-test="choose-event-autocomplete"
|
||||||
/>
|
/>
|
||||||
|
@@ -59,6 +59,7 @@ export const GET_APP = gql`
|
|||||||
triggers {
|
triggers {
|
||||||
name
|
name
|
||||||
key
|
key
|
||||||
|
type
|
||||||
pollInterval
|
pollInterval
|
||||||
description
|
description
|
||||||
substeps {
|
substeps {
|
||||||
|
@@ -66,6 +66,7 @@ export const GET_APPS = gql`
|
|||||||
triggers {
|
triggers {
|
||||||
name
|
name
|
||||||
key
|
key
|
||||||
|
type
|
||||||
pollInterval
|
pollInterval
|
||||||
description
|
description
|
||||||
substeps {
|
substeps {
|
||||||
|
@@ -57,6 +57,7 @@
|
|||||||
"flowEditor.pollIntervalValue": "Every {minutes} minutes",
|
"flowEditor.pollIntervalValue": "Every {minutes} minutes",
|
||||||
"flowEditor.triggerEvent": "Trigger event",
|
"flowEditor.triggerEvent": "Trigger event",
|
||||||
"flowEditor.actionEvent": "Action event",
|
"flowEditor.actionEvent": "Action event",
|
||||||
|
"flowEditor.instantTriggerType": "Instant",
|
||||||
"chooseConnectionSubstep.continue": "Continue",
|
"chooseConnectionSubstep.continue": "Continue",
|
||||||
"chooseConnectionSubstep.addNewConnection": "Add new connection",
|
"chooseConnectionSubstep.addNewConnection": "Add new connection",
|
||||||
"chooseConnectionSubstep.chooseConnection": "Choose connection",
|
"chooseConnectionSubstep.chooseConnection": "Choose connection",
|
||||||
|
Reference in New Issue
Block a user