diff --git a/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts b/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts index fe99c8919e..b5d5be8ecc 100644 --- a/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts +++ b/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts @@ -3,6 +3,7 @@ import type { DataTree, ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator"; import type { AutocompleteDataType } from "utils/autocomplete/CodemirrorTernService"; import type { EntityNavigationData } from "selectors/navigationSelectors"; +import type { ExpectedValueExample } from "utils/validation/common"; export enum EditorModes { TEXT = "text/plain", @@ -53,6 +54,8 @@ export type FieldEntityInformation = { entityId?: string; propertyPath?: string; blockCompletions?: Array<{ parentPath: string; subPath: string }>; + example?: ExpectedValueExample; + mode?: EditorModes; }; export type HintHelper = ( diff --git a/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts b/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts index 60e5f2a91c..222461af79 100644 --- a/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts +++ b/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts @@ -1,5 +1,8 @@ import CodeMirror from "codemirror"; -import type { HintHelper } from "components/editorComponents/CodeEditor/EditorConfig"; +import type { + FieldEntityInformation, + HintHelper, +} from "components/editorComponents/CodeEditor/EditorConfig"; import type { CommandsCompletion } from "utils/autocomplete/CodemirrorTernService"; import { AutocompleteDataType } from "utils/autocomplete/CodemirrorTernService"; import { generateQuickCommands } from "./generateQuickCommands"; @@ -29,7 +32,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => { return { showHint: ( editor: CodeMirror.Editor, - { entityId, entityType, expectedType, propertyPath }, + entityInfo: FieldEntityInformation, { datasources, executeCommand, @@ -47,6 +50,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => { featureFlags: FeatureFlags; }, ): boolean => { + const { entityType } = entityInfo; const currentEntityType = entityType || ENTITY_TYPE.ACTION || ENTITY_TYPE.JSACTION; entitiesForSuggestions = entitiesForSuggestions.filter((entity: any) => { @@ -71,9 +75,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => { recentEntities, featureFlags, }, - expectedType || "string", - entityId, - propertyPath, + entityInfo, ); let currentSelection: CommandsCompletion = { origin: "", diff --git a/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx b/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx index faf055af78..e306d283ce 100644 --- a/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx +++ b/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx @@ -16,6 +16,8 @@ import { getAssetUrl } from "@appsmith/utils/airgapHelpers"; import MagicIcon from "remixicon-react/MagicLineIcon"; import { addAISlashCommand } from "@appsmith/components/editorComponents/GPT/trigger"; import type FeatureFlags from "entities/FeatureFlags"; +import type { FieldEntityInformation } from "./EditorConfig"; +import { EditorModes } from "./EditorConfig"; enum Shortcuts { PLUS = "PLUS", @@ -141,10 +143,15 @@ export const generateQuickCommands = ( recentEntities: string[]; featureFlags: FeatureFlags; }, - expectedType: string, - entityId: any, - propertyPath: any, + entityInfo: FieldEntityInformation, ) => { + const { + entityId, + example, + expectedType = "string", + mode, + propertyPath, + } = entityInfo || {}; const suggestionsHeader: CommandsCompletion = commandsHeader("Bind Data"); const createNewHeader: CommandsCompletion = commandsHeader("Create a Query"); recentEntities.reverse(); @@ -252,7 +259,9 @@ export const generateQuickCommands = ( if ( addAISlashCommand && featureFlags.ask_ai && - currentEntityType !== ENTITY_TYPE.ACTION + (currentEntityType !== ENTITY_TYPE.ACTION || + mode === EditorModes.SQL || + mode === EditorModes.SQL_WITH_BINDING) ) { const askGPT: CommandsCompletion = generateCreateNewCommand({ text: "", @@ -266,6 +275,8 @@ export const generateQuickCommands = ( expectedType: expectedType, entityId: entityId, propertyPath: propertyPath, + example, + mode, }, }), }); diff --git a/app/client/src/components/editorComponents/CodeEditor/index.tsx b/app/client/src/components/editorComponents/CodeEditor/index.tsx index cd48399c40..59e48e00f8 100644 --- a/app/client/src/components/editorComponents/CodeEditor/index.tsx +++ b/app/client/src/components/editorComponents/CodeEditor/index.tsx @@ -1049,6 +1049,8 @@ class CodeEditor extends Component { const configTree = ConfigTreeActions.getConfigTree(); const entityInformation: FieldEntityInformation = { expectedType: expected?.autocompleteDataType, + example: expected?.example, + mode: this.props.mode, }; if (dataTreePath) { diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index 0780477b96..8fece61040 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -957,9 +957,17 @@ function* executeCommandSaga(actionPayload: ReduxAction) { const API = yield take(ReduxActionTypes.CREATE_ACTION_SUCCESS); if (callback) callback(`{{${API.payload.name}.data}}`); break; - case SlashCommand.ASK_AI: - yield put({ type: ReduxActionTypes.TOGGLE_AI_WINDOW, payload: true }); + case SlashCommand.ASK_AI: { + const context = get(actionPayload, "payload.args", {}); + yield put({ + type: ReduxActionTypes.TOGGLE_AI_WINDOW, + payload: { + show: true, + context, + }, + }); break; + } } }