Skip to content

Commit

Permalink
Merge pull request #36 from glific/feature/function-webhook
Browse files Browse the repository at this point in the history
Added function in webhook node
  • Loading branch information
pankaj-ag authored Jun 24, 2021
2 parents 3b7ca53 + c4946f9 commit 2b2b462
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "@glific/flow-editor",
"license": "AGPL-3.0",
"repository": "git://github.com/glific/floweditor.git",
"version": "1.13.9-2",
"description": "'Standalone flow editing tool designed for use within the RapidPro suite of messaging tools but can be adopted for use outside of that ecosystem.'",
"version": "1.13.9-3",
"description": "'Standalone flow editing tool designed for use within the Glific suite of messaging tools'",
"browser": "umd/flow-editor.min.js",
"unpkg": "umd/flow-editor.min.js",
"homepage": "https://glific.org",
Expand Down
25 changes: 19 additions & 6 deletions src/components/flow/routers/webhook/WebhookRouterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,15 @@ export default class WebhookRouterForm extends React.Component<

private handleSave(): void {
// validate our url in case they haven't interacted
const valid = this.handleUpdate(
{ url: this.state.url.value, resultName: this.state.resultName.value },
true
);
let valid = false;
if (this.state.method.value.name === 'FUNCTION') {
valid = this.handleUpdate({ resultName: this.state.resultName.value }, true);
} else {
valid = this.handleUpdate(
{ url: this.state.url.value, resultName: this.state.resultName.value },
true
);
}

if (valid) {
this.props.updateRouter(stateToNode(this.props.nodeSettings, this.state));
Expand Down Expand Up @@ -325,9 +330,17 @@ export default class WebhookRouterForm extends React.Component<
<div className={styles.url}>
<TextInputElement
name={i18n.t('forms.url', 'URL')}
placeholder={i18n.t('forms.enter_a_url', 'Enter a URL')}
placeholder={
method === 'FUNCTION'
? 'Enter function'
: i18n.t('forms.enter_a_url', 'Enter a URL')
}
entry={this.state.url}
onChange={this.handleUrlUpdate}
onChange={(url, name) => {
method === 'FUNCTION'
? this.setState({ url: { value: url } })
: this.handleUrlUpdate(url, name);
}}
autocomplete={true}
/>
</div>
Expand Down
12 changes: 7 additions & 5 deletions src/components/flow/routers/webhook/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export enum Methods {
PUT = 'PUT',
DELETE = 'DELETE',
HEAD = 'HEAD',
PATCH = 'PATCH'
PATCH = 'PATCH',
FUNCTION = 'FUNCTION'
}

export interface MethodOption {
Expand All @@ -35,10 +36,11 @@ export const GET_METHOD: MethodOption = {
export const METHOD_OPTIONS: MethodOption[] = [
GET_METHOD,
{ value: Methods.POST, name: Methods.POST },
{ value: Methods.PUT, name: Methods.PUT },
{ value: Methods.DELETE, name: Methods.DELETE },
{ value: Methods.HEAD, name: Methods.HEAD },
{ value: Methods.PATCH, name: Methods.PATCH }
// { value: Methods.PUT, name: Methods.PUT },
// { value: Methods.DELETE, name: Methods.DELETE }, // These methods are not needed currently
// { value: Methods.HEAD, name: Methods.HEAD },
{ value: Methods.PATCH, name: Methods.PATCH },
{ value: Methods.FUNCTION, name: Methods.FUNCTION }
];

export const getOriginalAction = (settings: NodeEditorSettings): CallWebhook => {
Expand Down

0 comments on commit 2b2b462

Please sign in to comment.