diff --git a/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx b/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx index 69af8df908..705f3fa1a7 100644 --- a/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx +++ b/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx @@ -532,10 +532,12 @@ class DynamicAutocompleteInput extends Component { } }; - updatePropertyValue(value: string, cursor: number) { + updatePropertyValue(value: string, cursor?: number) { this.editor.setValue(value); this.editor.focus(); - console.log(value, cursor); + if (cursor === undefined) { + cursor = value.length - 2; + } this.editor.setCursor({ line: 0, ch: cursor, diff --git a/app/client/src/components/editorComponents/LightningMenu/index.tsx b/app/client/src/components/editorComponents/LightningMenu/index.tsx index 411491e767..7764469938 100644 --- a/app/client/src/components/editorComponents/LightningMenu/index.tsx +++ b/app/client/src/components/editorComponents/LightningMenu/index.tsx @@ -13,7 +13,7 @@ import { mergeWith } from "lodash"; const getApiOptions = ( themeType: string, apis: RestAction[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -26,6 +26,7 @@ const getApiOptions = ( icon="plus" iconAlignment="left" themeType={themeType} + type="button" /> ), }, @@ -35,8 +36,7 @@ const getApiOptions = ( options: apis.map(api => ({ content: api.name, onSelect: () => { - const value = `{{${api.name}.data}}`; - updatePropertyValue(value, value.length + 1); + updatePropertyValue(`{{${api.name}.data}}`); }, })), }, @@ -52,7 +52,7 @@ const getApiOptions = ( const getQueryOptions = ( themeType: string, queries: RestAction[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -65,6 +65,7 @@ const getQueryOptions = ( icon="plus" iconAlignment="left" themeType={themeType} + type="button" /> ), }, @@ -74,8 +75,7 @@ const getQueryOptions = ( options: queries.map(query => ({ content: query.name, onSelect: () => { - const value = `{{${query.name}.data}}`; - updatePropertyValue(value, value.length + 1); + updatePropertyValue(`{{${query.name}.data}}`); }, })), }, @@ -91,7 +91,7 @@ const getQueryOptions = ( const getWidgetOptions = ( themeType: string, widgets: WidgetProps[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -117,15 +117,14 @@ const getWidgetOptions = ( const getWidgetData = ( themeType: string, widget: WidgetProps, - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { options: Object.keys(widget).map(widgetProp => ({ content: widgetProp, onSelect: () => { - const value = `{{${widget.widgetName}.${widgetProp}}}`; - updatePropertyValue(value, value.length); + updatePropertyValue(`{{${widget.widgetName}.${widgetProp}}}`); }, })), }, @@ -143,7 +142,7 @@ const lightningMenuOptions = ( apis: RestAction[], queries: RestAction[], widgets: WidgetProps[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ): CustomizedDropdownProps => ({ sections: [ { @@ -153,7 +152,7 @@ const lightningMenuOptions = ( disabled: false, shouldCloseDropdown: true, onSelect: () => { - updatePropertyValue("", 0); + updatePropertyValue(""); }, }, { @@ -188,7 +187,7 @@ const lightningMenuOptions = ( disabled: false, shouldCloseDropdown: true, onSelect: () => { - updatePropertyValue("{{}}", 2); + updatePropertyValue("{{}}"); }, }, { @@ -212,7 +211,7 @@ const lightningMenuOptions = ( type LightningMenuProps = { onSelect?: (value: string) => void; - updatePropertyValue: (value: string, cursor: number) => void; + updatePropertyValue: (value: string, cursor?: number) => void; themeType: string; };