@nocobase/plugin-workflow-aggregate 0.19.0-alpha.9 → 0.20.0-alpha.2

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.
@@ -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,s,S,h,r,C){"use strict";var H=Object.defineProperty,J=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var $=(e,t,o)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))A.call(t,o)&&$(e,o,t[o]);if(I)for(var o of I(t))D.call(t,o)&&$(e,o,t[o]);return e},V=(e,t)=>J(e,W(t));var G=(e,t)=>{var o={};for(var s in e)A.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&I)for(var s of I(e))t.indexOf(s)<0&&D.call(e,s)&&(o[s]=e[s]);return o};var g=(e,t,o)=>($(e,typeof t!="symbol"?t+"":t,o),o);var x=(e,t,o)=>new Promise((s,S)=>{var h=i=>{try{C(o.next(i))}catch(b){S(b)}},r=i=>{try{C(o.throw(i))}catch(b){S(b)}},C=i=>i.done?s(i.value):Promise.resolve(i.value).then(h,r);C((o=o.apply(e,t)).next())});const i="workflow-aggregate";function b(l,c={}){const{t:n}=B(c);return n(l)}function B(l){return C.useTranslation(i,l)}function N(l){return["hasMany","belongsToMany"].includes(l.type)}function P(){const l=t.useCompile();return[r.nodesOptions,r.triggerOptions].map(c=>{var p;const n=(p=c.useOptions({types:[N],appends:null,depth:4}))==null?void 0:p.filter(Boolean);return{label:l(c.label),value:c.value,key:c.value,children:l(n),disabled:n&&!n.length}})}function K(p){var f=p,{value:l,onChange:c}=f,n=G(f,["value","onChange"]);const{setValuesIn:v}=s.useForm(),{getCollection:k}=t.useCollectionManager(),M=P(),[F,q]=h.useState(M),{associatedKey:L="",name:z}=l!=null?l:{};let w=[];const j=L.match(/^{{(.*)}}$/);j&&(w=[...j[1].trim().split(".").slice(0,-1),z]);const U=m=>x(this,null,function*(){var u;const a=m[m.length-1];!((u=a.children)!=null&&u.length)&&!a.isLeaf&&a.loadChildren&&(yield a.loadChildren(a),q(d=>[...d]))});h.useEffect(()=>{x(this,null,function*(){var u;if(!w||F.length<=1)return;let a=null;for(let d=0;d<w.length;d++){const T=w[d];try{d===0?a=F.find(y=>y.value===T):(a.loadChildren&&!((u=a.children)!=null&&u.length)&&(yield a.loadChildren(a)),a=a.children.find(y=>y.value===T))}catch(y){console.error(y)}}q([...F])})},[l,F.length]);const _=h.useCallback((m,a)=>{if(!(m!=null&&m.length)){v("collection",null),c({});return}const{field:u}=a.pop();if(!u||!["hasMany","belongsToMany"].includes(u.type))return;const{collectionName:d,target:T,name:y}=u,Q=k(d).fields.find(X=>X.primaryKey);v("collection",T),c({name:y,associatedKey:`{{${m.slice(0,-1).join(".")}.${Q.name}}}`,associatedCollection:d})},[c]);return o.jsx(S.Cascader,V(O({},n),{value:w,options:F,onChange:_,loadData:U}))}class R extends r.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":"CollectionSelect",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}=s.useForm();return{options:t.useCollectionFilterOptions(n==null?void 0:n.collection),className:t.css`
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,s,S,h,r,C){"use strict";var H=Object.defineProperty,J=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var $=(e,t,o)=>t in e?H(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))A.call(t,o)&&$(e,o,t[o]);if(I)for(var o of I(t))D.call(t,o)&&$(e,o,t[o]);return e},V=(e,t)=>J(e,W(t));var G=(e,t)=>{var o={};for(var s in e)A.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(e!=null&&I)for(var s of I(e))t.indexOf(s)<0&&D.call(e,s)&&(o[s]=e[s]);return o};var g=(e,t,o)=>($(e,typeof t!="symbol"?t+"":t,o),o);var x=(e,t,o)=>new Promise((s,S)=>{var h=i=>{try{C(o.next(i))}catch(b){S(b)}},r=i=>{try{C(o.throw(i))}catch(b){S(b)}},C=i=>i.done?s(i.value):Promise.resolve(i.value).then(h,r);C((o=o.apply(e,t)).next())});const i="workflow-aggregate";function b(l,c={}){const{t:n}=B(c);return n(l)}function B(l){return C.useTranslation(i,l)}function N(l){return["hasMany","belongsToMany"].includes(l.type)}function P(){const l=t.useCompile();return[r.nodesOptions,r.triggerOptions].map(c=>{var p;const n=(p=c.useOptions({types:[N],appends:null,depth:4}))==null?void 0:p.filter(Boolean);return{label:l(c.label),value:c.value,key:c.value,children:l(n),disabled:n&&!n.length}})}function K(p){var f=p,{value:l,onChange:c}=f,n=G(f,["value","onChange"]);const{setValuesIn:v}=s.useForm(),{getCollection:k}=t.useCollectionManager_deprecated(),M=P(),[F,q]=h.useState(M),{associatedKey:L="",name:_}=l!=null?l:{};let w=[];const j=L.match(/^{{(.*)}}$/);j&&(w=[...j[1].trim().split(".").slice(0,-1),_]);const z=m=>x(this,null,function*(){var u;const a=m[m.length-1];!((u=a.children)!=null&&u.length)&&!a.isLeaf&&a.loadChildren&&(yield a.loadChildren(a),q(d=>[...d]))});h.useEffect(()=>{x(this,null,function*(){var u;if(!w||F.length<=1)return;let a=null;for(let d=0;d<w.length;d++){const T=w[d];try{d===0?a=F.find(y=>y.value===T):(a.loadChildren&&!((u=a.children)!=null&&u.length)&&(yield a.loadChildren(a)),a=a.children.find(y=>y.value===T))}catch(y){console.error(y)}}q([...F])})},[l,F.length]);const U=h.useCallback((m,a)=>{if(!(m!=null&&m.length)){v("collection",null),c({});return}const{field:u}=a.pop();if(!u||!["hasMany","belongsToMany"].includes(u.type))return;const{collectionName:d,target:T,name:y}=u,Q=k(d).fields.find(X=>X.primaryKey);v("collection",T),c({name:y,associatedKey:`{{${m.slice(0,-1).join(".")}.${Q.name}}}`,associatedCollection:d})},[c]);return o.jsx(S.Cascader,V(O({},n),{value:w,options:F,onChange:U,loadData:z}))}class R extends r.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":"CollectionSelect",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}=s.useForm();return{options:t.useCollectionFilterOptions(n==null?void 0:n.collection),className:t.css`
2
2
  position: relative;
3
3
  width: 100%;
4
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:r.FilterDynamicComponent,FieldsSelect:r.FieldsSelect,ValueBlock:r.ValueBlock,AssociatedConfig:K})}useVariables({key:n,title:p},{types:f,fieldNames:v=r.defaultFieldNames}){return f&&!f.some(k=>k in r.BaseTypeSets||Object.values(r.BaseTypeSets).some(M=>M.has(k)))?null:{[v.value]:n,[v.label]:p}}useInitializers(n){var f;const p=b("Query result");return n.config.collection?{name:`#${n.id}`,type:"item",title:(f=n.title)!=null?f:`#${n.id}`,Component:r.ValueBlock.Initializer,node:n,resultTitle:p}:null}}class E extends t.Plugin{afterAdd(){return x(this,null,function*(){})}beforeLoad(){return x(this,null,function*(){})}load(){return x(this,null,function*(){this.app.pm.get("workflow").registerInstruction("aggregate",R)})}}e.default=E,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -2,12 +2,12 @@ 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.19.0-alpha.9",
6
- "@nocobase/plugin-workflow": "0.19.0-alpha.9",
5
+ "@nocobase/client": "0.20.0-alpha.2",
6
+ "@nocobase/plugin-workflow": "0.20.0-alpha.2",
7
7
  "react-i18next": "11.18.6",
8
- "@nocobase/database": "0.19.0-alpha.9",
9
- "@nocobase/server": "0.19.0-alpha.9",
10
- "@nocobase/plugin-workflow-test": "0.19.0-alpha.9",
11
- "@nocobase/test": "0.19.0-alpha.9",
12
- "@nocobase/utils": "0.19.0-alpha.9"
8
+ "@nocobase/database": "0.20.0-alpha.2",
9
+ "@nocobase/server": "0.20.0-alpha.2",
10
+ "@nocobase/plugin-workflow-test": "0.20.0-alpha.2",
11
+ "@nocobase/test": "0.20.0-alpha.2",
12
+ "@nocobase/utils": "0.20.0-alpha.2"
13
13
  };
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.19.0-alpha.9",
7
+ "version": "0.20.0-alpha.2",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/plugins/workflow-aggregate",
@@ -21,7 +21,7 @@
21
21
  "@nocobase/server": "0.x",
22
22
  "@nocobase/test": "0.x"
23
23
  },
24
- "gitHead": "975f9c58a1995df6a8d7a4d191a0dc4a9769ebc5",
24
+ "gitHead": "6fb885dfc3554e4b0f29e9a7a1eecbbe85d0eebb",
25
25
  "keywords": [
26
26
  "Workflow"
27
27
  ]
@@ -8,7 +8,7 @@ import {
8
8
  css,
9
9
  useCollectionDataSource,
10
10
  useCollectionFilterOptions,
11
- useCollectionManager,
11
+ useCollectionManager_deprecated,
12
12
  useCompile,
13
13
  } from '@nocobase/client';
14
14
 
@@ -52,7 +52,7 @@ function useAssociatedFields() {
52
52
 
53
53
  function AssociatedConfig({ value, onChange, ...props }): JSX.Element {
54
54
  const { setValuesIn } = useForm();
55
- const { getCollection } = useCollectionManager();
55
+ const { getCollection } = useCollectionManager_deprecated();
56
56
  const baseOptions = useAssociatedFields();
57
57
  const [options, setOptions] = useState(baseOptions);
58
58