diff --git a/client/packages/lowcoder/src/components/ResCreatePanel.tsx b/client/packages/lowcoder/src/components/ResCreatePanel.tsx index 1225b99c7..75ac54db4 100644 --- a/client/packages/lowcoder/src/components/ResCreatePanel.tsx +++ b/client/packages/lowcoder/src/components/ResCreatePanel.tsx @@ -25,6 +25,7 @@ import { getUser } from "../redux/selectors/usersSelectors"; import DataSourceIcon from "./DataSourceIcon"; import { genRandomKey } from "comps/utils/idGenerator"; import { isPublicApplication } from "@lowcoder-ee/redux/selectors/applicationSelector"; +import { JS_CODE_ID } from "constants/datasourceConstants"; const Wrapper = styled.div<{ $placement: PageType }>` width: 100%; @@ -145,6 +146,7 @@ const ResButton = (props: { type: BottomResTypeEnum.Query, extra: { compType: "js", + dataSourceId: JS_CODE_ID, }, }, libraryQuery: { @@ -320,6 +322,17 @@ export function ResCreatePanel(props: ResCreateModalProps) { )} + + {placement === "queryLibrary" && ( + <> +
{trans("code")}
+
+ + + +
+ + )}
{trans("query.datasource")}
diff --git a/client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx b/client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx index 7ddf4c0d6..d78f7d6ab 100644 --- a/client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx +++ b/client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx @@ -5,6 +5,7 @@ import { isCompWithPropertyView } from "comps/utils/propertyUtils"; import { QUICK_GRAPHQL_ID, QUICK_REST_API_ID, + JS_CODE_ID } from "constants/datasourceConstants"; import { PageType } from "constants/pageConstants"; import { trans } from "i18n"; @@ -795,7 +796,8 @@ function useDatasourceStatus(datasourceId: string, datasourceType: ResourceType) datasourceType === "libraryQuery" || datasourceType === "alasql" || datasourceId === QUICK_REST_API_ID || - datasourceId === QUICK_GRAPHQL_ID + datasourceId === QUICK_GRAPHQL_ID || + datasourceId === JS_CODE_ID ) { return ""; } diff --git a/client/packages/lowcoder/src/comps/queries/resourceDropdown.tsx b/client/packages/lowcoder/src/comps/queries/resourceDropdown.tsx index 3907a3d92..9446b6ccb 100644 --- a/client/packages/lowcoder/src/comps/queries/resourceDropdown.tsx +++ b/client/packages/lowcoder/src/comps/queries/resourceDropdown.tsx @@ -15,6 +15,7 @@ import { DatasourceType, ResourceType } from "@lowcoder-ee/constants/queryConsta import { QUICK_GRAPHQL_ID, QUICK_REST_API_ID, + JS_CODE_ID } from "constants/datasourceConstants"; import { apiPluginsForQueryLibrary, @@ -78,7 +79,7 @@ interface ResourceOptionValue { } const JSOptionValue: ResourceOptionValue = { - id: "", + id: JS_CODE_ID, type: "js", }; @@ -156,6 +157,7 @@ export const ResourceDropdown = (props: ResourceDropdownProps) => { const optionValue: ResourceOptionValue = JSON.parse(value); const datasourceId = optionValue.id; const datasourceType = optionValue.type; + if (!datasourceType) { messageInstance.error("datasource invalid"); return; @@ -293,19 +295,20 @@ export const ResourceDropdown = (props: ResourceDropdownProps) => { - {context?.placement !== "queryLibrary" && ( - <> - - - {getBottomResIcon("js")} - {trans("query.executeJSCode")} - - + {/* Always show JS option regardless of placement */} + + + {getBottomResIcon("js")} + {trans("query.executeJSCode")} + + + {/* Only show Library Query option when not in Query Library */} + {context?.placement !== "queryLibrary" && ( { {trans("query.importFromQueryLibrary")} - - )} + )} ); diff --git a/client/packages/lowcoder/src/constants/datasourceConstants.ts b/client/packages/lowcoder/src/constants/datasourceConstants.ts index 640fee1af..0c65449f3 100644 --- a/client/packages/lowcoder/src/constants/datasourceConstants.ts +++ b/client/packages/lowcoder/src/constants/datasourceConstants.ts @@ -43,4 +43,5 @@ export interface Datasource { export const QUICK_REST_API_ID = "#QUICK_REST_API"; export const QUICK_GRAPHQL_ID = "#QUICK_GRAPHQL"; +export const JS_CODE_ID = "#JS_CODE"; export const OLD_LOWCODER_DATASOURCE: Partial[] = [];