Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added variables to data query#1470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
FalkWolsky merged 8 commits intodevfromfeature-dataQuery
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,20 +76,25 @@ export const KeyValueList = (props: {
list:ReactNode[];
onAdd:()=>void;
onDelete:(item:ReactNode,index:number)=>void;
isStatic?:boolean;
})=>(
<>
{props.list.map((item,index)=>(
<KeyValueListItemkey={index/* FIXME: find a proper key instead of `index` */}>
{item}
<DelIcon
onClick={()=>props.list.length>1&&props.onDelete(item,index)}
$forbidden={props.list.length===1}
/>
{!props.isStatic&&
<DelIcon
onClick={()=>props.list.length>1&&props.onDelete(item,index)}
$forbidden={props.list.length===1}
/>
}
</KeyValueListItem>
))}
{!props.isStatic&&
<AddBtnonClick={props.onAdd}>
<AddIcon/>
{trans("addItem")}
</AddBtn>
}
</>
);
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,10 +7,100 @@ import { BranchDiv, Dropdown } from "lowcoder-design";
import{BottomResTypeEnum}from"types/bottomRes";
import{getPromiseAfterDispatch}from"util/promiseUtils";
import{trans}from"i18n";
import{keyValueListControl,keyValueListToSearchStr,withDefault}from"lowcoder-sdk";
import{KeyValue}from"@lowcoder-ee/types/common";
import{useCallback,useContext,useEffect,useMemo}from"react";

constExecuteQueryPropertyView=({
comp,
placement,
}:{
comp:any,
placement?:"query"|"table"
})=>{
constgetQueryOptions=useCallback((editorState?:EditorState)=>{
constoptions:{label:string;value:string;variable?:Record<string,string>}[]=
editorState
?.queryCompInfoList()
.map((info)=>{
return{
label:info.name,
value:info.name,
variable:info.data.variable,
}
})
.filter(
// Filter out the current query under query
(option)=>{
if(
placement==="query"&&
editorState.selectedBottomResType===BottomResTypeEnum.Query
){
returnoption.value!==editorState.selectedBottomResName;
}
returntrue;
}
)||[];

// input queries
editorState
?.getModuleLayoutComp()
?.getInputs()
.forEach((i)=>{
const{ name, type}=i.getView();
if(type===InputTypeEnum.Query){
options.push({label:name,value:name});
}
});
returnoptions;
},[placement]);

constgetVariableOptions=useCallback((editorState?:EditorState)=>{
returncomp.children.queryVariables.propertyView({
label:trans("eventHandler.queryVariables"),
layout:"vertical",
isStatic:true,
keyFixed:true,
});
},[comp.children.queryVariables.getView()])

return(
<>
<BranchDiv$type={"inline"}>
<EditorContext.Consumer>
{(editorState)=>(
<>
<Dropdown
showSearch={true}
value={comp.children.queryName.getView()}
options={getQueryOptions(editorState)}
label={trans("eventHandler.selectQuery")}
onChange={(value)=>{
constoptions=getQueryOptions(editorState);
constselectedQuery=options.find(option=>option.value===value);
constvariables=selectedQuery ?Object.keys(selectedQuery.variable||{}) :[];
comp.dispatchChangeValueAction({
queryName:value,
queryVariables:variables.map((variable)=>({key:variable,value:''})),
});
}}
/>
</>
)}
</EditorContext.Consumer>
</BranchDiv>
<BranchDiv>
<EditorContext.Consumer>
{(editorState)=>getVariableOptions(editorState)}
</EditorContext.Consumer>
</BranchDiv>
</>
);
}
constExecuteQueryTmpAction=(function(){
constchildrenMap={
queryName:SimpleNameComp,
queryVariables:withDefault(keyValueListControl(false,[],"string"),[])
};
returnnewMultiCompBuilder(childrenMap,()=>{
return()=>Promise.resolve(undefinedasunknown);
Expand All@@ -22,6 +112,15 @@ const ExecuteQueryTmpAction = (function () {
exportclassExecuteQueryActionextendsExecuteQueryTmpAction{
overridegetView(){
constqueryName=this.children.queryName.getView();
// const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
constresult=Object.values(this.children.queryVariables.childrenasRecord<string,{
children:{
key:{unevaledValue:string},
value:{unevaledValue:string}
}}>)
.filter(item=>item.children.key.unevaledValue!==""&&item.children.value.unevaledValue!=="")
.map(item=>({[item.children.key.unevaledValue]:item.children.value.unevaledValue}))
.reduce((acc,curr)=>Object.assign(acc,curr),{});
if(!queryName){
return()=>Promise.resolve();
}
Expand All@@ -30,9 +129,7 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
this.dispatch,
routeByNameAction(
queryName,
executeQueryAction({
// can add context in the future
})
executeQueryAction({args:result})
),
{notHandledError:trans("eventHandler.notHandledError")}
);
Expand All@@ -46,55 +143,11 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
}

propertyView({ placement}:{placement?:"query"|"table"}){
constgetQueryOptions=(editorState?:EditorState)=>{
constoptions:{label:string;value:string}[]=
editorState
?.queryCompInfoList()
.map((info)=>({
label:info.name,
value:info.name,
}))
.filter(
// Filter out the current query under query
(option)=>{
if(
placement==="query"&&
editorState.selectedBottomResType===BottomResTypeEnum.Query
){
returnoption.value!==editorState.selectedBottomResName;
}
returntrue;
}
)||[];

// input queries
editorState
?.getModuleLayoutComp()
?.getInputs()
.forEach((i)=>{
const{ name, type}=i.getView();
if(type===InputTypeEnum.Query){
options.push({label:name,value:name});
}
});
returnoptions;
};
return(
<BranchDiv$type={"inline"}>
<EditorContext.Consumer>
{(editorState)=>(
<>
<Dropdown
showSearch={true}
value={this.children.queryName.getView()}
options={getQueryOptions(editorState)}
label={trans("eventHandler.selectQuery")}
onChange={(value)=>this.dispatchChangeValueAction({queryName:value})}
/>
</>
)}
</EditorContext.Consumer>
</BranchDiv>
);
<ExecuteQueryPropertyView
comp={this}
placement={placement}
/>
)
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ const childrenMap = {
};

exportconstGoToURLAction=newMultiCompBuilder(childrenMap,(props)=>{
return()=>{
return()=>{
constqueryParams=keyValueListToSearchStr(
props.query.map((i)=>i.getView()asKeyValue)
);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -167,12 +167,18 @@ const EventHandlerControlPropertyView = (props: {
if(eventConfigs.length===0){
return;
}

constqueryVariables=editorState
?.selectedOrFirstQueryComp()
?.children.variables.children.variables.toJsonValue();

constqueryExecHandler={
compType:"executeQuery",
comp:{
queryName:editorState
?.selectedOrFirstQueryComp()
?.children.name.getView(),
queryVariables:queryVariables?.map((variable)=>({...variable,value:''})),
},
};
constmessageHandler={
Expand Down
27 changes: 17 additions & 10 deletionsclient/packages/lowcoder/src/comps/controls/keyValueControl.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,8 @@ export type KeyValueControlParams = ControlParams & {
typeTooltip?:ReactNode;
keyFlexBasics?:number;
valueFlexBasics?:number;
isStatic?:boolean;
keyFixed?:boolean;
};

/**
Expand DownExpand Up@@ -82,16 +84,20 @@ function keyValueControl<T extends OptionsType>(
return(
<KeyValueWrapper>
<KeyWrapper$flexBasics={params.keyFlexBasics}>
{this.children.key.propertyView({placeholder:"key",indentWithTab:false})}
{hasType&&params.showType&&(
<TypeWrapper>
{this.children.type.propertyView({
placeholder:"key",
indentWithTab:false,
tooltip:params.typeTooltip,
})}
</TypeWrapper>
)}
{params.keyFixed?
<>{this.children.key.getView()}</>
:<>
{this.children.key.propertyView({placeholder:"key",indentWithTab:false})}
{hasType&&params.showType&&(
<TypeWrapper>
{this.children.type.propertyView({
placeholder:"key",
indentWithTab:false,
tooltip:params.typeTooltip,
})}
</TypeWrapper>
)}
</>}
</KeyWrapper>
<ValueWrapper$flexBasics={params.valueFlexBasics}>
{this.children.value.propertyView({
Expand DownExpand Up@@ -136,6 +142,7 @@ export function keyValueListControl<T extends OptionsType>(
list={this.getView().map((child)=>child.propertyView(params))}
onAdd={()=>this.dispatch(this.pushAction({}))}
onDelete={(item,index)=>this.dispatch(this.deleteAction(index))}
isStatic={params.isStatic}
/>
</ControlPropertyViewWrapper>
);
Expand Down
29 changes: 28 additions & 1 deletionclient/packages/lowcoder/src/comps/queries/queryComp.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,14 +67,15 @@ import { JSONObject, JSONValue } from "../../util/jsonTypes";
import{BoolPureControl}from"../controls/boolControl";
import{millisecondsControl}from"../controls/millisecondControl";
import{paramsMillisecondsControl}from"../controls/paramsControl";
import{NameConfig,withExposingConfigs}from"../generators/withExposing";
import{DepsConfig,NameConfig,withExposingConfigs}from"../generators/withExposing";
import{HttpQuery}from"./httpQuery/httpQuery";
import{StreamQuery}from"./httpQuery/streamQuery";
import{QueryConfirmationModal}from"./queryComp/queryConfirmationModal";
import{QueryNotificationControl}from"./queryComp/queryNotificationControl";
import{QueryPropertyView}from"./queryComp/queryPropertyView";
import{getTriggerType,onlyManualTrigger}from"./queryCompUtils";
import{messageInstance}from"lowcoder-design/src/components/GlobalInstances";
import{VariablesComp}from"@lowcoder-ee/comps/queries/queryComp/variablesComp";

constlatestExecution:Record<string,string>={};

Expand DownExpand Up@@ -153,6 +154,7 @@ const childrenMap = {
defaultValue:10*1000,
}),
confirmationModal:QueryConfirmationModal,
variables:VariablesComp,
periodic:BoolPureControl,
periodicTime:millisecondsControl({
defaultValue:Number.NaN,
Expand DownExpand Up@@ -361,6 +363,8 @@ QueryCompTmp = class extends QueryCompTmp {
}
if(action.type===CompActionTypes.EXECUTE_QUERY){
if(getReduceContext().disableUpdateState)returnthis;
if(!action.args)action.args=this.children.variables.children.variables.toJsonValue().reduce((acc,curr)=>Object.assign(acc,{[curr.keyasstring]:curr.value}),{});

returnthis.executeQuery(action);
}
if(action.type===CompActionTypes.CHANGE_VALUE){
Expand DownExpand Up@@ -404,16 +408,21 @@ QueryCompTmp = class extends QueryCompTmp {
returnthis;
}




/**
* Process the execution result
*/
privateprocessResult(result:QueryResult,action:ExecuteQueryAction,startTime:number){
constlastQueryStartTime=this.children.lastQueryStartTime.getView();

if(lastQueryStartTime>startTime){
// There are more new requests, ignore this result
// FIXME: cancel this request in advance in the future
return;
}

constchangeAction=multiChangeAction({
code:this.children.code.changeValueAction(result.code??QUERY_EXECUTION_OK),
success:this.children.success.changeValueAction(result.success??true),
Expand DownExpand Up@@ -470,6 +479,7 @@ QueryCompTmp = class extends QueryCompTmp {
applicationId:applicationId,
applicationPath:parentApplicationPath,
args:action.args,
variables:action.args,
timeout:this.children.timeout,
callback:(result)=>this.processResult(result,action,startTime)
});
Expand DownExpand Up@@ -653,6 +663,23 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
newNameConfig("isFetching",trans("query.isFetchingExportDesc")),
newNameConfig("runTime",trans("query.runTimeExportDesc")),
newNameConfig("latestEndTime",trans("query.latestEndTimeExportDesc")),
newDepsConfig(
"variable",
(children:any)=>{
return{data:children.variables.children.variables.node()};
},
(input)=>{
if(!input.data){
returnundefined;
}
constnewNode=Object.values(input.data)
.filter((kvNode:any)=>kvNode.key.text.value)
.map((kvNode:any)=>({[kvNode.key.text.value]:kvNode.value.text.value}))
.reduce((prev,obj)=>({...prev, ...obj}),{});
returnnewNode;
},
trans("query.variables")
),
newNameConfig("triggerType",trans("query.triggerTypeExportDesc")),
]);

Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp