Skip to content

Commit df23d09

Browse files
committed
[FEAT]: #1488 Add JS Query in Query Library
1 parent 233c56a commit df23d09

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

client/packages/lowcoder/src/components/ResCreatePanel.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { getUser } from "../redux/selectors/usersSelectors";
2525
import DataSourceIcon from "./DataSourceIcon";
2626
import { genRandomKey } from "comps/utils/idGenerator";
2727
import { isPublicApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
28+
import { JS_CODE_ID } from "constants/datasourceConstants";
2829

2930
const Wrapper = styled.div<{ $placement: PageType }>`
3031
width: 100%;
@@ -145,6 +146,7 @@ const ResButton = (props: {
145146
type: BottomResTypeEnum.Query,
146147
extra: {
147148
compType: "js",
149+
dataSourceId: JS_CODE_ID,
148150
},
149151
},
150152
libraryQuery: {
@@ -320,6 +322,17 @@ export function ResCreatePanel(props: ResCreateModalProps) {
320322
</div>
321323
</>
322324
)}
325+
326+
{placement === "queryLibrary" && (
327+
<>
328+
<div className="section-title">{trans("code")}</div>
329+
<div className="section">
330+
<DataSourceListWrapper $placement={placement}>
331+
<ResButton size={buttonSize} identifier={"js"} onSelect={onSelect} />
332+
</DataSourceListWrapper>
333+
</div>
334+
</>
335+
)}
323336

324337
<div className="section-title">{trans("query.datasource")}</div>
325338
<div className="section">

client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isCompWithPropertyView } from "comps/utils/propertyUtils";
55
import {
66
QUICK_GRAPHQL_ID,
77
QUICK_REST_API_ID,
8+
JS_CODE_ID
89
} from "constants/datasourceConstants";
910
import { PageType } from "constants/pageConstants";
1011
import { trans } from "i18n";
@@ -795,7 +796,8 @@ function useDatasourceStatus(datasourceId: string, datasourceType: ResourceType)
795796
datasourceType === "libraryQuery" ||
796797
datasourceType === "alasql" ||
797798
datasourceId === QUICK_REST_API_ID ||
798-
datasourceId === QUICK_GRAPHQL_ID
799+
datasourceId === QUICK_GRAPHQL_ID ||
800+
datasourceId === JS_CODE_ID
799801
) {
800802
return "";
801803
}

client/packages/lowcoder/src/comps/queries/resourceDropdown.tsx

+17-15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { DatasourceType, ResourceType } from "@lowcoder-ee/constants/queryConsta
1515
import {
1616
QUICK_GRAPHQL_ID,
1717
QUICK_REST_API_ID,
18+
JS_CODE_ID
1819
} from "constants/datasourceConstants";
1920
import {
2021
apiPluginsForQueryLibrary,
@@ -78,7 +79,7 @@ interface ResourceOptionValue {
7879
}
7980

8081
const JSOptionValue: ResourceOptionValue = {
81-
id: "",
82+
id: JS_CODE_ID,
8283
type: "js",
8384
};
8485

@@ -156,6 +157,7 @@ export const ResourceDropdown = (props: ResourceDropdownProps) => {
156157
const optionValue: ResourceOptionValue = JSON.parse(value);
157158
const datasourceId = optionValue.id;
158159
const datasourceType = optionValue.type;
160+
159161
if (!datasourceType) {
160162
messageInstance.error("datasource invalid");
161163
return;
@@ -293,19 +295,20 @@ export const ResourceDropdown = (props: ResourceDropdownProps) => {
293295
</SelectOptionContains>
294296
</SelectOption>
295297

296-
{context?.placement !== "queryLibrary" && (
297-
<>
298-
<SelectOption
299-
key={JSON.stringify(JSOptionValue)}
300-
label={trans("query.executeJSCode")}
301-
value={JSON.stringify(JSOptionValue)}
302-
>
303-
<SelectOptionContains>
304-
{getBottomResIcon("js")}
305-
<SelectOptionLabel>{trans("query.executeJSCode")} </SelectOptionLabel>
306-
</SelectOptionContains>
307-
</SelectOption>
298+
{/* Always show JS option regardless of placement */}
299+
<SelectOption
300+
key={JSON.stringify(JSOptionValue)}
301+
label={trans("query.executeJSCode")}
302+
value={JSON.stringify(JSOptionValue)}
303+
>
304+
<SelectOptionContains>
305+
{getBottomResIcon("js")}
306+
<SelectOptionLabel>{trans("query.executeJSCode")} </SelectOptionLabel>
307+
</SelectOptionContains>
308+
</SelectOption>
308309

310+
{/* Only show Library Query option when not in Query Library */}
311+
{context?.placement !== "queryLibrary" && (
309312
<SelectOption
310313
key={JSON.stringify(LibraryQueryOptionValue)}
311314
label={trans("query.importFromQueryLibrary")}
@@ -316,8 +319,7 @@ export const ResourceDropdown = (props: ResourceDropdownProps) => {
316319
<SelectOptionLabel>{trans("query.importFromQueryLibrary")} </SelectOptionLabel>
317320
</SelectOptionContains>
318321
</SelectOption>
319-
</>
320-
)}
322+
)}
321323
</CustomSelect>
322324
</SelectWrapper>
323325
);

client/packages/lowcoder/src/constants/datasourceConstants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ export interface Datasource {
4343

4444
export const QUICK_REST_API_ID = "#QUICK_REST_API";
4545
export const QUICK_GRAPHQL_ID = "#QUICK_GRAPHQL";
46+
export const JS_CODE_ID = "#JS_CODE";
4647
export const OLD_LOWCODER_DATASOURCE: Partial<DatasourceType>[] = [];

0 commit comments

Comments
 (0)