@nocobase/plugin-workflow-aggregate 0.21.0-alpha.1 → 0.21.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -161,11 +161,11 @@ export default class extends Instruction {
161
161
  title: string;
162
162
  'x-decorator': string;
163
163
  'x-component': string;
164
+ 'x-use-component-props': () => {
165
+ options: any[];
166
+ className: string;
167
+ };
164
168
  'x-component-props': {
165
- useProps(): {
166
- options: any[];
167
- className: string;
168
- };
169
169
  dynamicComponent: string;
170
170
  };
171
171
  'x-reactions': {
@@ -1,4 +1,4 @@
1
- (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("antd"),require("react"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","antd","react","@nocobase/plugin-workflow/client","react-i18next"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-workflow-aggregate"]={},e["@nocobase/client"],e.jsxRuntime,e["@formily/react"],e.antd,e.react,e["@nocobase/plugin-workflow"],e["react-i18next"]))})(this,function(e,t,o,r,S,h,s,b){"use strict";var J=Object.defineProperty,W=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var j=(e,t,o)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,N=(e,t)=>{for(var o in t||(t={}))O.call(t,o)&&j(e,o,t[o]);if(I)for(var o of I(t))A.call(t,o)&&j(e,o,t[o]);return e},V=(e,t)=>W(e,Y(t));var G=(e,t)=>{var o={};for(var r in e)O.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&I)for(var r of I(e))t.indexOf(r)<0&&A.call(e,r)&&(o[r]=e[r]);return o};var g=(e,t,o)=>(j(e,typeof t!="symbol"?t+"":t,o),o);var C=(e,t,o)=>new Promise((r,S)=>{var h=i=>{try{b(o.next(i))}catch(v){S(v)}},s=i=>{try{b(o.throw(i))}catch(v){S(v)}},b=i=>i.done?r(i.value):Promise.resolve(i.value).then(h,s);b((o=o.apply(e,t)).next())});const i="workflow-aggregate";function v(l,c={}){const{t:n}=B(c);return n(l)}function B(l){return b.useTranslation(i,l)}function P(l){return["hasMany","belongsToMany"].includes(l.type)}function K(){const l=t.useCompile();return[s.nodesOptions,s.triggerOptions].map(c=>{var d;const n=(d=c.useOptions({types:[P],appends:null,depth:4}))==null?void 0:d.filter(Boolean);return{label:l(c.label),value:c.value,key:c.value,children:l(n),disabled:n&&!n.length}})}function R(d){var u=d,{value:l,onChange:c}=u,n=G(u,["value","onChange"]);const{setValuesIn:x}=r.useForm(),{getCollection:k}=t.useCollectionManager_deprecated(),M=K(),[F,q]=h.useState(M),{associatedKey:_="",name:z}=l!=null?l:{};let w=[];const D=_.match(/^{{(.*)}}$/);D&&(w=[...D[1].trim().split(".").slice(0,-1),z]);const U=m=>C(this,null,function*(){var p;const a=m[m.length-1];!((p=a.children)!=null&&p.length)&&!a.isLeaf&&a.loadChildren&&(yield a.loadChildren(a),q(f=>[...f]))});h.useEffect(()=>{C(this,null,function*(){var p;if(!w||F.length<=1)return;let a=null;for(let f=0;f<w.length;f++){const T=w[f];try{f===0?a=F.find(y=>y.value===T):(a.loadChildren&&!((p=a.children)!=null&&p.length)&&(yield a.loadChildren(a)),a=a.children.find(y=>y.value===T))}catch(y){console.error(y)}}q([...F])})},[l,F.length]);const Q=h.useCallback((m,a)=>{if(!(m!=null&&m.length)){x("collection",null),c({});return}const{field:p}=a.pop();if(!p||!["hasMany","belongsToMany"].includes(p.type))return;const{collectionName:f,target:T,name:y,dataSourceKey:$}=p,X=k(f,$).fields.find(H=>H.primaryKey);x("collection",`${$}:${T}`),c({name:y,associatedKey:`{{${m.slice(0,-1).join(".")}.${X.name}}}`,associatedCollection:t.joinCollectionName($,f)})},[c]);return o.jsx(S.Cascader,V(N({},n),{value:w,options:F,changeOnSelect:!0,onChange:Q,loadData:U}))}class E extends s.Instruction{constructor(){super(...arguments);g(this,"title",`{{t("Aggregate", { ns: "${i}" })}}`);g(this,"type","aggregate");g(this,"group","collection");g(this,"description",`{{t("Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", { ns: "${i}" })}}`);g(this,"fieldset",{aggregator:{type:"string",title:`{{t("Aggregator function", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:"COUNT",value:"count"},{label:"SUM",value:"sum"},{label:"AVG",value:"avg"},{label:"MIN",value:"min"},{label:"MAX",value:"max"}],required:!0,default:"count"},associated:{type:"boolean",title:`{{t("Target type", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:`{{t("Data of collection", { ns: "${i}" })}}`,value:!1},{label:`{{t("Data of associated collection", { ns: "${i}" })}}`,value:!0}],required:!0,default:!1,"x-reactions":[{target:"collection",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"association",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},collectionField:{type:"void","x-decorator":"SchemaComponentContext.Provider","x-decorator-props":{value:{designable:!1}},"x-component":"Grid",properties:{row:{type:"void","x-component":"Grid.Row",properties:{target:{type:"void","x-component":"Grid.Col",properties:{collection:{type:"string",required:!0,"x-decorator":"FormItem","x-component":"DataSourceCollectionCascader",title:`{{t("Data of collection", { ns: "${i}" })}}`,"x-reactions":[{dependencies:["associated"],fulfill:{state:{display:'{{$deps[0] ? "hidden" : "visible"}}'}}},{target:"params.field",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"params.filter",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},association:{type:"object",title:`{{t("Data of associated collection", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"AssociatedConfig","x-component-props":{changeOnSelect:!0},"x-reactions":[{dependencies:["associated"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}],required:!0}}},field:{type:"void","x-component":"Grid.Col",properties:{"params.field":{type:"string",title:`{{t("Field to aggregate", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"FieldsSelect","x-component-props":{filter(n){return!n.hidden&&n.interface&&!["belongsTo","hasOne","hasMany","belongsToMany"].includes(n.type)}},required:!0,"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}}}}},params:{type:"object",properties:{distinct:{type:"boolean",title:`{{t("Distinct", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":[{dependencies:["collection","aggregator"],fulfill:{state:{visible:'{{!!$deps[0] && ["count"].includes($deps[1])}}'}}}]},filter:{type:"object",title:'{{t("Filter")}}',"x-decorator":"FormItem","x-component":"Filter","x-component-props":{useProps(){const{values:n}=r.useForm(),[d,u]=t.parseCollectionName(n==null?void 0:n.collection);return{options:t.useCollectionFilterOptions(u,d),className:t.css`
2
- position: relative;
3
- width: 100%;
4
- `}},dynamicComponent:"FilterDynamicComponent"},"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}});g(this,"scope",{useCollectionDataSource:t.useCollectionDataSource});g(this,"components",{SchemaComponentContext:t.SchemaComponentContext,FilterDynamicComponent:s.FilterDynamicComponent,FieldsSelect:s.FieldsSelect,ValueBlock:s.ValueBlock,AssociatedConfig:R})}useVariables({key:n,title:d},{types:u,fieldNames:x=s.defaultFieldNames}){return u&&!u.some(k=>k in s.BaseTypeSets||Object.values(s.BaseTypeSets).some(M=>M.has(k)))?null:{[x.value]:n,[x.label]:d}}useInitializers(n){var u;const d=v("Query result");return n.config.collection?{name:`#${n.id}`,type:"item",title:(u=n.title)!=null?u:`#${n.id}`,Component:s.ValueBlock.Initializer,node:n,resultTitle:d}:null}}class L extends t.Plugin{afterAdd(){return C(this,null,function*(){})}beforeLoad(){return C(this,null,function*(){})}load(){return C(this,null,function*(){this.app.pm.get("workflow").registerInstruction("aggregate",E)})}}e.default=L,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@formily/react"),require("antd"),require("react"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@formily/react","antd","react","@nocobase/plugin-workflow/client","react-i18next"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-workflow-aggregate"]={},e["@nocobase/client"],e.jsxRuntime,e["@formily/react"],e.antd,e.react,e["@nocobase/plugin-workflow"],e["react-i18next"]))})(this,function(e,t,o,r,S,h,s,b){"use strict";var J=Object.defineProperty,W=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var j=(e,t,o)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,N=(e,t)=>{for(var o in t||(t={}))O.call(t,o)&&j(e,o,t[o]);if(I)for(var o of I(t))A.call(t,o)&&j(e,o,t[o]);return e},V=(e,t)=>W(e,Y(t));var G=(e,t)=>{var o={};for(var r in e)O.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&I)for(var r of I(e))t.indexOf(r)<0&&A.call(e,r)&&(o[r]=e[r]);return o};var g=(e,t,o)=>(j(e,typeof t!="symbol"?t+"":t,o),o);var C=(e,t,o)=>new Promise((r,S)=>{var h=i=>{try{b(o.next(i))}catch(v){S(v)}},s=i=>{try{b(o.throw(i))}catch(v){S(v)}},b=i=>i.done?r(i.value):Promise.resolve(i.value).then(h,s);b((o=o.apply(e,t)).next())});const i="workflow-aggregate";function v(l,c={}){const{t:n}=B(c);return n(l)}function B(l){return b.useTranslation(i,l)}function K(l){return["hasMany","belongsToMany"].includes(l.type)}function P(){const l=t.useCompile();return[s.nodesOptions,s.triggerOptions].map(c=>{var d;const n=(d=c.useOptions({types:[K],appends:null,depth:4}))==null?void 0:d.filter(Boolean);return{label:l(c.label),value:c.value,key:c.value,children:l(n),disabled:n&&!n.length}})}function R(d){var u=d,{value:l,onChange:c}=u,n=G(u,["value","onChange"]);const{setValuesIn:x}=r.useForm(),{getCollection:k}=t.useCollectionManager_deprecated(),M=P(),[F,q]=h.useState(M),{associatedKey:_="",name:z}=l!=null?l:{};let w=[];const D=_.match(/^{{(.*)}}$/);D&&(w=[...D[1].trim().split(".").slice(0,-1),z]);const U=m=>C(this,null,function*(){var p;const a=m[m.length-1];!((p=a.children)!=null&&p.length)&&!a.isLeaf&&a.loadChildren&&(yield a.loadChildren(a),q(f=>[...f]))});h.useEffect(()=>{C(this,null,function*(){var p;if(!w||F.length<=1)return;let a=null;for(let f=0;f<w.length;f++){const T=w[f];try{f===0?a=F.find(y=>y.value===T):(a.loadChildren&&!((p=a.children)!=null&&p.length)&&(yield a.loadChildren(a)),a=a.children.find(y=>y.value===T))}catch(y){console.error(y)}}q([...F])})},[l,F.length]);const Q=h.useCallback((m,a)=>{if(!(m!=null&&m.length)){x("collection",null),c({});return}const{field:p}=a.pop();if(!p||!["hasMany","belongsToMany"].includes(p.type))return;const{collectionName:f,target:T,name:y,dataSourceKey:$}=p,X=k(f,$).fields.find(H=>H.primaryKey);x("collection",`${$}:${T}`),c({name:y,associatedKey:`{{${m.slice(0,-1).join(".")}.${X.name}}}`,associatedCollection:t.joinCollectionName($,f)})},[c]);return o.jsx(S.Cascader,V(N({},n),{value:w,options:F,changeOnSelect:!0,onChange:Q,loadData:U}))}class E extends s.Instruction{constructor(){super(...arguments);g(this,"title",`{{t("Aggregate", { ns: "${i}" })}}`);g(this,"type","aggregate");g(this,"group","collection");g(this,"description",`{{t("Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", { ns: "${i}" })}}`);g(this,"fieldset",{aggregator:{type:"string",title:`{{t("Aggregator function", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:"COUNT",value:"count"},{label:"SUM",value:"sum"},{label:"AVG",value:"avg"},{label:"MIN",value:"min"},{label:"MAX",value:"max"}],required:!0,default:"count"},associated:{type:"boolean",title:`{{t("Target type", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:`{{t("Data of collection", { ns: "${i}" })}}`,value:!1},{label:`{{t("Data of associated collection", { ns: "${i}" })}}`,value:!0}],required:!0,default:!1,"x-reactions":[{target:"collection",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"association",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},collectionField:{type:"void","x-decorator":"SchemaComponentContext.Provider","x-decorator-props":{value:{designable:!1}},"x-component":"Grid",properties:{row:{type:"void","x-component":"Grid.Row",properties:{target:{type:"void","x-component":"Grid.Col",properties:{collection:{type:"string",required:!0,"x-decorator":"FormItem","x-component":"DataSourceCollectionCascader",title:`{{t("Data of collection", { ns: "${i}" })}}`,"x-reactions":[{dependencies:["associated"],fulfill:{state:{display:'{{$deps[0] ? "hidden" : "visible"}}'}}},{target:"params.field",effects:["onFieldValueChange"],fulfill:{state:{value:null}}},{target:"params.filter",effects:["onFieldValueChange"],fulfill:{state:{value:null}}}]},association:{type:"object",title:`{{t("Data of associated collection", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"AssociatedConfig","x-component-props":{changeOnSelect:!0},"x-reactions":[{dependencies:["associated"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}],required:!0}}},field:{type:"void","x-component":"Grid.Col",properties:{"params.field":{type:"string",title:`{{t("Field to aggregate", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"FieldsSelect","x-component-props":{filter(n){return!n.hidden&&n.interface&&!["belongsTo","hasOne","hasMany","belongsToMany"].includes(n.type)}},required:!0,"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}}}}},params:{type:"object",properties:{distinct:{type:"boolean",title:`{{t("Distinct", { ns: "${i}" })}}`,"x-decorator":"FormItem","x-component":"Checkbox","x-reactions":[{dependencies:["collection","aggregator"],fulfill:{state:{visible:'{{!!$deps[0] && ["count"].includes($deps[1])}}'}}}]},filter:{type:"object",title:'{{t("Filter")}}',"x-decorator":"FormItem","x-component":"Filter","x-use-component-props":()=>{const{values:n}=r.useForm(),[d,u]=t.parseCollectionName(n==null?void 0:n.collection);return{options:t.useCollectionFilterOptions(u,d),className:t.css`
2
+ position: relative;
3
+ width: 100%;
4
+ `}},"x-component-props":{dynamicComponent:"FilterDynamicComponent"},"x-reactions":[{dependencies:["collection"],fulfill:{state:{visible:"{{!!$deps[0]}}"}}}]}}}});g(this,"scope",{useCollectionDataSource:t.useCollectionDataSource});g(this,"components",{SchemaComponentContext:t.SchemaComponentContext,FilterDynamicComponent:s.FilterDynamicComponent,FieldsSelect:s.FieldsSelect,ValueBlock:s.ValueBlock,AssociatedConfig:R})}useVariables({key:n,title:d},{types:u,fieldNames:x=s.defaultFieldNames}){return u&&!u.some(k=>k in s.BaseTypeSets||Object.values(s.BaseTypeSets).some(M=>M.has(k)))?null:{[x.value]:n,[x.label]:d}}useInitializers(n){var u;const d=v("Query result");return n.config.collection?{name:`#${n.id}`,type:"item",title:(u=n.title)!=null?u:`#${n.id}`,Component:s.ValueBlock.Initializer,node:n,resultTitle:d}:null}}class L extends t.Plugin{afterAdd(){return C(this,null,function*(){})}beforeLoad(){return C(this,null,function*(){})}load(){return C(this,null,function*(){this.app.pm.get("workflow").registerInstruction("aggregate",E)})}}e.default=L,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -2,13 +2,13 @@ module.exports = {
2
2
  "@formily/react": "2.3.0",
3
3
  "antd": "5.12.8",
4
4
  "react": "18.2.0",
5
- "@nocobase/client": "0.21.0-alpha.1",
6
- "@nocobase/plugin-workflow": "0.21.0-alpha.1",
5
+ "@nocobase/client": "0.21.0-alpha.10",
6
+ "@nocobase/plugin-workflow": "0.21.0-alpha.10",
7
7
  "react-i18next": "11.18.6",
8
- "@nocobase/data-source-manager": "0.21.0-alpha.1",
9
- "@nocobase/database": "0.21.0-alpha.1",
10
- "@nocobase/server": "0.21.0-alpha.1",
11
- "@nocobase/plugin-workflow-test": "0.21.0-alpha.1",
12
- "@nocobase/test": "0.21.0-alpha.1",
13
- "@nocobase/utils": "0.21.0-alpha.1"
8
+ "@nocobase/data-source-manager": "0.21.0-alpha.10",
9
+ "@nocobase/database": "0.21.0-alpha.10",
10
+ "@nocobase/server": "0.21.0-alpha.10",
11
+ "@nocobase/plugin-workflow-test": "0.21.0-alpha.10",
12
+ "@nocobase/test": "0.21.0-alpha.10",
13
+ "@nocobase/utils": "0.21.0-alpha.10"
14
14
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:聚合查询节点",
5
5
  "description": "Used to aggregate data against the database in workflow, such as: statistics, sum, average, etc.",
6
6
  "description.zh-CN": "可用于在工作流中对数据库进行聚合查询,如:统计数量、求和、平均值等。",
7
- "version": "0.21.0-alpha.1",
7
+ "version": "0.21.0-alpha.10",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow-aggregate",
@@ -21,7 +21,7 @@
21
21
  "@nocobase/server": "0.x",
22
22
  "@nocobase/test": "0.x"
23
23
  },
24
- "gitHead": "afd2f3d1341b85ea9daa7b2667dd4ace1fafb7ff",
24
+ "gitHead": "98adf5ec996a4f359c6ca1c4a6ac837c43b6e268",
25
25
  "keywords": [
26
26
  "Workflow"
27
27
  ]
@@ -341,19 +341,21 @@ export default class extends Instruction {
341
341
  title: '{{t("Filter")}}',
342
342
  'x-decorator': 'FormItem',
343
343
  'x-component': 'Filter',
344
+ 'x-use-component-props': () => {
345
+ // eslint-disable-next-line react-hooks/rules-of-hooks
346
+ const { values } = useForm();
347
+ const [dataSourceName, collectionName] = parseCollectionName(values?.collection);
348
+ // eslint-disable-next-line react-hooks/rules-of-hooks
349
+ const options = useCollectionFilterOptions(collectionName, dataSourceName);
350
+ return {
351
+ options,
352
+ className: css`
353
+ position: relative;
354
+ width: 100%;
355
+ `,
356
+ };
357
+ },
344
358
  'x-component-props': {
345
- useProps() {
346
- const { values } = useForm();
347
- const [dataSourceName, collectionName] = parseCollectionName(values?.collection);
348
- const options = useCollectionFilterOptions(collectionName, dataSourceName);
349
- return {
350
- options,
351
- className: css`
352
- position: relative;
353
- width: 100%;
354
- `,
355
- };
356
- },
357
359
  dynamicComponent: 'FilterDynamicComponent',
358
360
  },
359
361
  'x-reactions': [