Skip to content

Commit fb3a52c

Browse files
added onQueryExecution trigger in query
1 parent e71bd32 commit fb3a52c

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { HttpQuery } from "./httpQuery/httpQuery";
7272
import { StreamQuery } from "./httpQuery/streamQuery";
7373
import { QueryConfirmationModal } from "./queryComp/queryConfirmationModal";
7474
import { QueryNotificationControl } from "./queryComp/queryNotificationControl";
75-
import { QueryPropertyView } from "./queryComp/queryPropertyView";
75+
import { findDependentQueries, QueryPropertyView } from "./queryComp/queryPropertyView";
7676
import { getTriggerType, onlyManualTrigger } from "./queryCompUtils";
7777
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
7878

@@ -100,6 +100,7 @@ interface AfterExecuteQueryAction {
100100
export const TriggerTypeOptions = [
101101
{ label: "On Page Load", value: "onPageLoad"},
102102
{ label: "On Input Change", value: "onInputChange"},
103+
{ label: "On Query Execution", value: "onQueryExecution"},
103104
{ label: trans("query.triggerTypeAuto"), value: "automatic" },
104105
{ label: trans("query.triggerTypeManual"), value: "manual" },
105106
] as const;
@@ -159,6 +160,7 @@ const childrenMap = {
159160
},
160161
}),
161162
cancelPrevious: withDefault(BoolPureControl, false),
163+
depQueryName: SimpleNameComp,
162164
};
163165

164166
let QueryCompTmp = withTypeAndChildren<typeof QueryMap, ToInstanceType<typeof childrenMap>>(
@@ -639,6 +641,29 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
639641
const QueryListTmpComp = list(QueryComp);
640642

641643
class QueryListComp extends QueryListTmpComp implements BottomResListComp {
644+
override reduce(action: CompAction): this {
645+
if (isCustomAction<AfterExecuteQueryAction>(action, "afterExecQuery")) {
646+
if (action.path?.length === 1 && !isNaN(parseInt(action.path[0]))) {
647+
const queryIdx = parseInt(action.path[0]);
648+
const queryComps = this.getView();
649+
const queryName = queryComps?.[queryIdx]?.children.name.getView();
650+
const dependentQueries = queryComps.filter((query, idx) => {
651+
if (queryIdx === idx) return false;
652+
if (
653+
getTriggerType(query) === 'onQueryExecution'
654+
&& query.children.depQueryName.getView() === queryName
655+
) {
656+
return true;
657+
}
658+
})
659+
dependentQueries?.forEach((query) => {
660+
query.dispatch(deferAction(executeQueryAction({})));
661+
})
662+
}
663+
}
664+
return super.reduce(action);
665+
}
666+
642667
nameAndExposingInfo(): NameAndExposingInfo {
643668
const result: NameAndExposingInfo = {};
644669
Object.values(this.children).forEach((comp) => {

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

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import styled from "styled-components";
3737
import { DataSourceButton } from "pages/datasource/pluginPanel";
3838
import { Tooltip, Divider } from "antd";
3939
import { uiCompRegistry } from "comps/uiCompRegistry";
40+
import { InputTypeEnum } from "@lowcoder-ee/comps/comps/moduleContainerComp/ioComp/inputListItemComp";
4041

4142
const Wrapper = styled.div`
4243
width: 100%;
@@ -233,6 +234,35 @@ export const QueryGeneralPropertyView = (props: {
233234
return TriggerTypeOptions;
234235
}, [datasourceType]);
235236

237+
const getQueryOptions = useMemo(() => {
238+
const options: { label: string; value: string }[] =
239+
editorState
240+
?.queryCompInfoList()
241+
.map((info) => ({
242+
label: info.name,
243+
value: info.name,
244+
}))
245+
.filter((option) => {
246+
// Filter out the current query under query
247+
if (editorState.selectedBottomResType === BottomResTypeEnum.Query) {
248+
return option.value !== editorState.selectedBottomResName;
249+
}
250+
return true;
251+
}) || [];
252+
253+
// input queries
254+
editorState
255+
?.getModuleLayoutComp()
256+
?.getInputs()
257+
.forEach((i) => {
258+
const { name, type } = i.getView();
259+
if (type === InputTypeEnum.Query) {
260+
options.push({ label: name, value: name });
261+
}
262+
});
263+
return options;
264+
}, [editorState]);
265+
236266
return (
237267
<QueryPropertyViewWrapper>
238268
<QuerySectionWrapper>
@@ -336,28 +366,29 @@ export const QueryGeneralPropertyView = (props: {
336366
</QueryConfigWrapper>
337367

338368
{placement === "editor" && (
339-
<TriggerTypeStyled>
340-
<Dropdown
341-
placement={"bottom"}
342-
label={trans("query.triggerType")}
343-
options={ triggerOptions
344-
// [
345-
// { label: "On Page Load", value: "onPageLoad"},
346-
// { label: "On Input Change", value: "onInputChange"},
347-
// {
348-
// label:
349-
// (children.compType.getView() === "js" || children.compType.getView() === "streamApi")
350-
// ? trans("query.triggerTypePageLoad")
351-
// : trans("query.triggerTypeAuto"),
352-
// value: "automatic",
353-
// },
354-
// { label: trans("query.triggerTypeManual"), value: "manual" },
355-
// ] as const
356-
}
357-
value={children.triggerType.getView()}
358-
onChange={(value) => children.triggerType.dispatchChangeValueAction(value as TriggerType)}
359-
/>
360-
</TriggerTypeStyled>
369+
<>
370+
<TriggerTypeStyled>
371+
<Dropdown
372+
placement={"bottom"}
373+
label={trans("query.triggerType")}
374+
options={triggerOptions}
375+
value={children.triggerType.getView()}
376+
onChange={(value) => children.triggerType.dispatchChangeValueAction(value as TriggerType)}
377+
/>
378+
</TriggerTypeStyled>
379+
{children.triggerType.getView() === 'onQueryExecution' && (
380+
<TriggerTypeStyled>
381+
<Dropdown
382+
showSearch={true}
383+
placement={"bottom"}
384+
value={children.depQueryName.getView()}
385+
options={getQueryOptions}
386+
label={trans("eventHandler.selectQuery")}
387+
onChange={(value) => children.depQueryName.dispatchChangeValueAction(value)}
388+
/>
389+
</TriggerTypeStyled>
390+
)}
391+
</>
361392
)}
362393
</QuerySectionWrapper>
363394

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy