@nocobase/plugin-workflow-manual 0.18.0-alpha.1 → 0.18.0-alpha.9
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.
- package/dist/client/index.js +4 -4
- package/dist/externalVersion.js +7 -7
- package/dist/server/ManualInstruction.d.ts +2 -2
- package/dist/server/ManualInstruction.js +8 -8
- package/dist/server/Plugin.d.ts +0 -2
- package/dist/server/Plugin.js +7 -8
- package/dist/server/actions.js +13 -3
- package/dist/server/forms/create.js +3 -3
- package/dist/server/forms/update.js +3 -3
- package/package.json +2 -3
- package/src/client/WorkflowTodo.tsx +2 -2
- package/src/client/instruction/DetailsBlockProvider.tsx +4 -3
- package/src/client/instruction/FormBlockProvider.tsx +2 -1
- package/src/server/ManualInstruction.ts +6 -6
- package/src/server/Plugin.ts +7 -8
- package/src/server/__tests__/instruction.test.ts +0 -2
- package/src/server/actions.ts +2 -2
- package/src/server/forms/create.ts +2 -2
- package/src/server/forms/update.ts +2 -2
- /package/dist/server/{collecions → collections}/jobs.d.ts +0 -0
- /package/dist/server/{collecions → collections}/jobs.js +0 -0
- /package/dist/server/{collecions → collections}/users.d.ts +0 -0
- /package/dist/server/{collecions → collections}/users.js +0 -0
- /package/dist/server/{collecions → collections}/users_jobs.d.ts +0 -0
- /package/dist/server/{collecions → collections}/users_jobs.js +0 -0
- /package/src/server/{collecions → collections}/jobs.ts +0 -0
- /package/src/server/{collecions → collections}/users.ts +0 -0
- /package/src/server/{collecions → collections}/users_jobs.ts +0 -0
package/dist/client/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function(f,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@nocobase/plugin-workflow/client"),require("react/jsx-runtime"),require("react"),require("@formily/antd-v5"),require("@formily/core"),require("@formily/react"),require("antd"),require("react-i18next"),require("@nocobase/utils/client"),require("lodash"),require("@ant-design/icons"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/plugin-workflow/client","react/jsx-runtime","react","@formily/antd-v5","@formily/core","@formily/react","antd","react-i18next","@nocobase/utils/client","lodash","@ant-design/icons","dayjs"],e):(f=typeof globalThis!="undefined"?globalThis:f||self,e(f["@nocobase/plugin-workflow-manual"]={},f["@nocobase/client"],f["@nocobase/plugin-workflow"],f.jsxRuntime,f.react,f["@formily/antd-v5"],f["@formily/core"],f["@formily/react"],f.antd,f["react-i18next"],f["@nocobase/utils"],f.lodash,f["@ant-design/icons"],f.dayjs))})(this,function(f,e,l,s,m,q,E,b,v,j,T,_,U,se){"use strict";var We=Object.defineProperty,Re=Object.defineProperties;var eo=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var L=(f,e,l)=>e in f?We(f,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):f[e]=l,y=(f,e)=>{for(var l in e||(e={}))ne.call(e,l)&&L(f,l,e[l]);if(J)for(var l of J(e))re.call(e,l)&&L(f,l,e[l]);return f},F=(f,e)=>Re(f,eo(e));var M=(f,e)=>{var l={};for(var s in f)ne.call(f,s)&&e.indexOf(s)<0&&(l[s]=f[s]);if(f!=null&&J)for(var s of J(f))e.indexOf(s)<0&&re.call(f,s)&&(l[s]=f[s]);return l};var N=(f,e,l)=>(L(f,typeof e!="symbol"?e+"":e,l),l);var $=(f,e,l)=>new Promise((s,m)=>{var q=v=>{try{b(l.next(v))}catch(j){m(j)}},E=v=>{try{b(l.throw(v))}catch(j){m(j)}},b=v=>v.done?s(v.value):Promise.resolve(v.value).then(q,E);b((l=l.apply(f,e)).next())});const C="workflow-manual";function B(o,n={}){const{t:r}=ie(n);return r(o)}function ie(o){return j.useTranslation(C,o)}function ae(o){const{execution:n,nodes:r}=l.useFlowContext(),t=m.useMemo(()=>r.reduce((p,d)=>Object.assign(p,{[d.id]:d.key}),{}),[r]),i=m.useMemo(()=>{var p;return{$context:n==null?void 0:n.context,$jobsMapByNodeKey:((p=n==null?void 0:n.jobs)!=null?p:[]).reduce((d,c)=>Object.assign(d,{[t[c.nodeId]]:c.result}),{})}},[n==null?void 0:n.context,n==null?void 0:n.jobs,t]);return m.useMemo(()=>T.parse(o)(i),[i,o])}function Q(o){const n=b.useField(),r=m.useRef(null),{appends:t,updateAssociationValues:i}=e.useAssociationNames(),a=ae(o.dataSource),p=m.useMemo(()=>E.createForm({values:a,readPretty:!0}),[a]),d={appends:t},c={loading:!1,data:{data:a}},g=e.useAPIClient().resource(o.collection),h=m.useContext(e.BlockRequestContext);return s.jsx(e.CollectionProvider,{collection:o.collection,children:s.jsx(e.RecordProvider,{record:a,parent:!1,children:s.jsx(e.BlockRequestContext.Provider,{value:{block:"form",field:n,service:c,resource:g,__parent:h},children:s.jsx(e.FormBlockContext.Provider,{value:{params:d,form:p,field:n,service:c,updateAssociationValues:i,formBlockRef:r},children:o.children})})})})}function Y(o){var O,A,D;const n=e.useRecord(),r=b.useFieldSchema(),t=b.useField(),i=m.useRef(null),{appends:a,updateAssociationValues:p}=e.useAssociationNames(),[d]=Object.keys((O=r.toJSON().properties)!=null?O:{}),c=(A=n==null?void 0:n.result)==null?void 0:A[d],{findComponent:x}=e.useDesignable(),g=x((D=t.component)==null?void 0:D[0])||m.Fragment,h=m.useMemo(()=>E.createForm({initialValues:c}),[c]),u=m.useMemo(()=>y({appends:a},o.params),[a,o.params]),S=m.useMemo(()=>({loading:!1,data:{data:c}}),[c]),k=e.useAPIClient().resource(o.collection),I=m.useContext(e.BlockRequestContext),z=m.useMemo(()=>({params:u,form:h,field:t,service:S,updateAssociationValues:p,formBlockRef:i}),[t,h,u,S,p]);return!n.status||c?s.jsx(e.CollectionProvider,{collection:o.collection,children:s.jsx(e.RecordProvider,{record:c,parent:!1,children:s.jsx(e.FormActiveFieldsProvider,{name:"form",children:s.jsx(e.BlockRequestContext.Provider,{value:{block:"form",props:o,field:t,service:S,resource:k,__parent:I},children:s.jsx(e.FormBlockContext.Provider,{value:z,children:s.jsxs(g,F(y({},t.componentProps),{children:[s.jsx(e.FormV2.Templates,{style:{marginBottom:18},form:h}),s.jsx("div",{ref:i,children:s.jsx(b.RecursionField,{schema:r,onlyRenderProperties:!0})})]}))})})})})}):null}function ce(r){var t=r,{schema:o}=t,n=M(t,["schema"]);const{getTemplateSchemaByMode:i}=e.useSchemaTemplateManager(),{insert:a}=e.useSchemaInitializer(),p=e.useRecordCollectionDataSourceItems("FormItem");function d(x){return $(this,arguments,function*({item:c}){const g=c.template?yield i(c):null,h=e.createFormBlockSchema(F(y({actionInitializers:"AddActionButton",actions:{resolve:{type:"void",title:`{{t("Continue the process", { ns: "${C}" })}}`,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:l.JOB_STATUS.RESOLVED},"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useSubmit }}"},"x-designer":"ManualActionDesigner","x-designer-props":{}}}},o),{template:g}));delete h["x-acl-action-props"],delete h["x-acl-action"];const[u]=Object.keys(h.properties);h.properties[u].properties.actions["x-decorator"]="ActionBarProvider",h.properties[u].properties.actions["x-component-props"].style={marginTop:"1.5em",flexWrap:"wrap"},l.traverseSchema(h,S=>{S["x-uid"]&&delete S["x-uid"]}),a(h)})}return s.jsx(e.SchemaInitializerItem,F(y({},n),{onClick:d,items:p}))}function H(){var n;const o=e.useSchemaInitializerItem();return s.jsx(e.CollectionProvider,{collection:(n=o.schema)==null?void 0:n.collection,children:s.jsx(ce,y({},o))})}function P(o,n,r=!1){const t=[];return o?n(o)&&(!r||!o.properties)?(t.push(o),t):(o.properties&&Object.keys(o.properties).forEach(i=>{t.push(...P(o.properties[i],n))}),t):t}function le(){const{name:o,title:n}=e.useCollection();return s.jsxs(e.GeneralSchemaDesigner,{title:n||o,children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsLinkageRules,{collectionName:o}),s.jsx(e.SchemaSettingsDataTemplates,{collectionName:o}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const pe={title:`{{t("Create record form", { ns: "${C}" })}}`,config:{useInitializer({collections:o}){const n=m.useMemo(()=>o.map(a=>({name:_.camelCase(`createRecordForm-child-${a.name}`),type:"item",title:a.title,label:a.label,schema:{collection:a.name,title:`{{t("Create record", { ns: "${C}" })}}`,formType:"create","x-designer":"CreateFormDesigner"},Component:H})),[o]),[r,t]=m.useState(!1),i=e.useMenuSearch(n,r,!0);return{name:"createRecordForm",key:"createRecordForm",type:"subMenu",title:`{{t("Create record form", { ns: "${C}" })}}`,componentProps:{onOpenChange(a){t(a.length>0)}},children:i}},initializers:{},components:{CreateFormDesigner:le},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="FormBlockProvider"&&t["x-decorator-props"].formType==="create").forEach(t=>{var p;const[i]=Object.keys(t.properties),a=t.properties[i];n[i]={type:"create",title:((p=t["x-component-props"])==null?void 0:p.title)||i,actions:P(a.properties.actions,d=>d["x-component"]==="Action").map(d=>{var c,x;return{status:d["x-decorator-props"].value,values:(x=(c=d["x-action-settings"])==null?void 0:c.assignedValues)==null?void 0:x.values,key:d.name}}),collection:t["x-decorator-props"].collection}}),n}},block:{scope:{},components:{}}};function X(o){var x,g,h,u;const[n,r]=m.useState((g=(x=o.collection)==null?void 0:x.fields)!=null?g:[]),t=e.useRecord(),i=b.useField(),a=b.useFieldSchema(),[p]=Object.keys((h=a.toJSON().properties)!=null?h:{}),d=(u=t==null?void 0:t.result)==null?void 0:u[p],c=m.useMemo(()=>E.createForm({initialValues:d}),[d]);return!t.status||d?s.jsx(e.CollectionProvider,{collection:F(y({},o.collection),{fields:n}),children:s.jsx(e.RecordProvider,{record:d,parent:!1,children:s.jsx(e.FormBlockContext.Provider,{value:{form:c,field:i,setCollectionFields:r},children:o.children})})}):null}function de(){const{insert:o}=e.useSchemaInitializer(),n=e.useSchemaInitializerItem();return s.jsx(e.SchemaInitializerItem,F(y({},n),{onClick:()=>{o({type:"void","x-decorator":"CustomFormBlockProvider","x-decorator-props":{collection:{name:T.uid(),fields:[]}},"x-component":"CardItem","x-component-props":{title:'{{t("Form")}}'},"x-designer":"SimpleDesigner","x-designer-props":{type:"customForm"},properties:{[T.uid()]:{type:"void","x-component":"FormV2","x-component-props":{useProps:"{{ useFormBlockProps }}"},properties:{grid:{type:"void","x-component":"Grid","x-initializer":"AddCustomFormField"},actions:{type:"void","x-decorator":"ActionBarProvider","x-component":"ActionBar","x-component-props":{layout:"one-column",style:{marginTop:"1.5em",flexWrap:"wrap"}},"x-initializer":"AddActionButton",properties:{resolve:{type:"void",title:`{{t("Continue the process", { ns: "${C}" })}}`,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:l.JOB_STATUS.RESOLVED},"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useSubmit }}"},"x-designer":"ManualActionDesigner"}}}}}}})}}))}const Z={basic:'{{t("Basic")}}',choices:'{{t("Choices")}}',media:'{{t("Media")}}',datetime:'{{t("Date & Time")}}',relation:'{{t("Relation")}}',advanced:'{{t("Advanced type")}}',systemInfo:'{{t("System info")}}',others:'{{t("Others")}}'};function ue(o){const n={};return Object.keys(o).forEach(r=>{const t=o[r],{group:i="others"}=t;n[i]=n[i]||{},_.set(n,[i,r],t)}),Object.keys(Z).filter(r=>["basic","choices","datetime","media"].includes(r)).map(r=>({title:Z[r],children:Object.keys(n[r]||{}).map(t=>{const i=n[r][t];return y({value:t,title:i.title,name:t},n[r][t])}).sort((t,i)=>t.order-i.order)}))}function me(){const{interfaces:o}=e.useCollectionManager();return ue(o).map(r=>({name:r.title,type:"itemGroup",title:r.title,children:r.children.map(t=>({name:t.name,type:"item",title:t.title,Component:xe,fieldInterface:t.name}))}))}const W=m.createContext({}),fe=o=>{const[n,r]=m.useState(null),[t,i]=m.useState(),a=me(),p=m.useContext(e.CollectionContext),{setCollectionFields:d}=m.useContext(e.FormBlockContext);return s.jsxs(W.Provider,{value:{onAddField(c){const S=_.cloneDeep(c),{properties:w}=S,k=w,{unique:x,type:g}=k,h=M(k,["unique","type"]),u=M(S,["properties"]);delete h.name["x-disabled"],r(F(y({},u),{properties:h}))},setCallback:i},children:[s.jsx(e.SchemaInitializerItems,F(y({},o),{items:a})),s.jsx(e.ActionContextProvider,{value:{visible:!!n},children:n?s.jsx(e.SchemaComponent,{schema:{type:"void",name:"drawer",title:'{{t("Configure field")}}',"x-decorator":"Form","x-component":"Action.Drawer",properties:F(y({},n.properties),{footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{type:"void",title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction(){const c=b.useForm();return{run(){return $(this,null,function*(){i(null),r(null),c.reset()})}}}}},submit:{type:"void",title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction(){const{values:c,query:x}=b.useForm(),g=[B("Field name existed in form")];return{run(){return $(this,null,function*(){var I,z,O,A;const{default:u}=n,S=T.uid();if(u.name=(I=c.name)!=null?I:S,u.uiSchema.title=(O=(z=c.uiSchema)==null?void 0:z.title)!=null?O:S,u.interface=n.name,(A=p.fields)==null?void 0:A.find(D=>D.name===u.name)){x("name").take().setFeedback({type:"error",messages:g});return}const k=T.merge(u,c);d([...p.fields,k]),t({name:u.name,type:u.uiSchema.type,"x-decorator":"FormItem","x-component":"CollectionField","x-component-props":{field:k},"x-collection-field":`${p.name}.${u.name}`,"x-designer":"FormItem.Designer"}),i(null),r(null)})}}}}}}}})},components:{ArrayTable:q.ArrayTable}}):null})]})},he=new e.SchemaInitializer({name:"AddCustomFormField",wrap:e.gridRowColWrap,insertPosition:"beforeEnd",title:"{{t('Configure fields')}}",ItemsComponent:fe});function xe(){const o=e.useSchemaInitializerItem(),{insert:n,setVisible:r}=e.useSchemaInitializer(),{onAddField:t,setCallback:i}=m.useContext(W),{getInterface:a}=e.useCollectionManager(),p=a(o.fieldInterface);return s.jsx(e.SchemaInitializerItem,y({onClick:()=>{i(()=>n),t(p),r(!1)}},o),o.fieldInterface)}const R={title:`{{t("Custom form", { ns: "${C}" })}}`,config:{useInitializer(){return{name:"customForm",type:"item",title:`{{t("Custom form", { ns: "${C}" })}}`,Component:de}},initializers:{},components:{CustomFormBlockProvider:X},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="CustomFormBlockProvider").forEach(t=>{var d;const[i]=Object.keys(t.properties),a=t.properties[i],p=P(a.properties.grid,c=>c["x-component"]==="CollectionField",!0);t["x-decorator-props"].collection.fields=p.map(c=>{var x,g;return(g=(x=c["x-component-props"])==null?void 0:x.field)!=null?g:c["x-interface-options"]}),n[i]={type:"custom",title:((d=t["x-component-props"])==null?void 0:d.title)||i,actions:P(a.properties.actions,c=>c["x-component"]==="Action").map(c=>{var x,g;return{status:c["x-decorator-props"].value,values:(g=(x=c["x-action-settings"])==null?void 0:x.assignedValues)==null?void 0:g.values,key:c.name}}),collection:t["x-decorator-props"].collection}}),n}},block:{scope:{},components:{CustomFormBlockProvider:X}}};function Ce(){const{name:o,title:n}=e.useCollection(),r=b.useFieldSchema(),{t}=j.useTranslation(),{dn:i}=e.useDesignable();return s.jsxs(e.GeneralSchemaDesigner,{title:n||o,children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsActionModalItem,{title:t("Filter settings",{ns:C}),schema:{name:"filter",type:"object",title:'{{t("Filter")}}',"x-component":"Filter","x-component-props":{useProps(){var p;return{options:e.useCollectionFilterOptions((p=r==null?void 0:r["x-decorator-props"])==null?void 0:p.collection)}},dynamicComponent:"FilterDynamicComponent"}},initialValues:r==null?void 0:r["x-decorator-props"],onSubmit:({filter:a})=>{r["x-decorator-props"].filter=a,i.emit("patch",{schema:{"x-decorator-props":r["x-decorator-props"]}}),i.refresh()}}),s.jsx(e.SchemaSettingsLinkageRules,{collectionName:o}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const ge={title:`{{t("Update record form", { ns: "${C}" })}}`,config:{useInitializer({collections:o}){const n=m.useMemo(()=>o.map(a=>({name:_.camelCase(`updateRecordForm-child-${a.name}`),type:"item",title:a.title,label:a.label,schema:{collection:a.name,title:`{{t("Update record", { ns: "${C}" })}}`,formType:"update","x-designer":"UpdateFormDesigner"},Component:H})),[o]),[r,t]=m.useState(!1),i=e.useMenuSearch(n,r,!0);return{name:"updateRecordForm",key:"updateRecordForm",type:"subMenu",title:`{{t("Update record form", { ns: "${C}" })}}`,componentProps:{onOpenChange(a){t(a.length>0)}},children:i}},initializers:{},components:{FilterDynamicComponent:l.FilterDynamicComponent,UpdateFormDesigner:Ce},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="FormBlockProvider"&&t["x-decorator-props"].formType==="update").forEach(t=>{var p;const[i]=Object.keys(t.properties),a=t.properties[i];n[i]=F(y({},t["x-decorator-props"]),{type:"update",title:((p=t["x-component-props"])==null?void 0:p.title)||i,actions:P(a.properties.actions,d=>d["x-component"]==="Action").map(d=>{var c,x;return{status:d["x-decorator-props"].value,values:(x=(c=d["x-action-settings"])==null?void 0:c.assignedValues)==null?void 0:x.values,key:d.name}})})}),n}},block:{scope:{},components:{}}},V=new T.Registry;V.register("customForm",R),V.register("createForm",pe),V.register("updateForm",ge);function ye(){const{workflow:o}=l.useFlowContext(),n=l.useTrigger();return n.useInitializers?n.useInitializers(o.config):null}const be={customForm:R.title,record:`{{t("Data record", { ns: "${C}" })}}`};function Se(){var t,i;const o=b.useFieldSchema(),n=(i=be[(t=o["x-designer-props"])==null?void 0:t.type])!=null?i:'{{t("Block")}}',r=e.useCompile();return s.jsxs(e.GeneralSchemaDesigner,{title:r(n),children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const ve=new e.SchemaInitializer({name:"AddBlockButton",wrap:e.gridRowColWrap,title:'{{t("Add block")}}',items:[{type:"itemGroup",name:"dataBlocks",title:'{{t("Data blocks")}}',checkChildrenLength:!0,useChildren(){const o=e.usePlugin(l),n=l.useNodeContext(),r=l.useAvailableUpstreams(n),t=[ye()].filter(Boolean),i=r.map(p=>{var c;const d=o.instructions.get(p.type);return(c=d==null?void 0:d.useInitializers)==null?void 0:c.call(d,p)}).filter(Boolean);return[...t,...i.length?[{name:"nodes",type:"subMenu",title:`{{t("Node result", { ns: "${C}" })}}`,children:i}]:[]].filter(Boolean)}},{type:"itemGroup",name:"form",title:'{{t("Form")}}',useChildren(){const{collections:o}=e.useCollectionManager();return Array.from(V.getValues()).map(n=>{const{useInitializer:r}=n.config;return r({collections:o})})}},{type:"itemGroup",name:"otherBlocks",title:'{{t("Other blocks")}}',children:[{name:"markdown",title:'{{t("Markdown")}}',Component:"MarkdownBlockInitializer"}]}]});function Fe(){var I,z,O;const o=m.useContext(e.SchemaComponentContext),{t:n}=j.useTranslation(),r=b.useFieldSchema(),t=l.useWorkflowVariableOptions(),[i,a]=m.useState(!1),[p,d]=m.useState((O=(z=(I=r==null?void 0:r["x-action-settings"])==null?void 0:I.assignedValues)==null?void 0:z.schema)!=null?O:{type:"void","x-component":"Grid","x-initializer":"CustomFormItemInitializers",properties:{}}),[c,x]=m.useState(null),{components:g}=e.useSchemaOptionsContext();m.useEffect(()=>{x(new b.Schema({properties:{grid:p}}))},[p]);const h=m.useMemo(()=>{var D,G;const A=(G=(D=r==null?void 0:r["x-action-settings"])==null?void 0:D.assignedValues)==null?void 0:G.values;return E.createForm({initialValues:T.lodash.cloneDeep(A),values:T.lodash.cloneDeep(A)})},[r]),u=e.useFormActiveFields(),S=n("Assign field values");function w(){a(!1)}function k(){r["x-action-settings"]||(r["x-action-settings"]={}),r["x-action-settings"].assignedValues||(r["x-action-settings"].assignedValues={}),r["x-action-settings"].assignedValues.schema=p,r["x-action-settings"].assignedValues.values=h.values,a(!1),setTimeout(()=>{var A;(A=o.refresh)==null||A.call(o)},300)}return s.jsxs(s.Fragment,{children:[s.jsx(e.SchemaSettingsItem,{title:S,onClick:()=>a(!0),children:S}),s.jsx(v.Modal,{width:"50%",title:S,open:i,onCancel:w,footer:s.jsxs(v.Space,{children:[s.jsx(v.Button,{onClick:w,children:n("Cancel")}),s.jsx(v.Button,{type:"primary",onClick:k,children:n("Submit")})]}),children:s.jsx(e.DefaultValueProvider,{isAllowToSetDefaultValue:()=>!1,children:s.jsx(e.VariableScopeProvider,{scope:t,children:s.jsx(e.FormActiveFieldsProvider,{name:"form",getActiveFieldsName:u==null?void 0:u.getActiveFieldsName,children:s.jsx(b.FormProvider,{form:h,children:s.jsxs(q.FormLayout,{layout:"vertical",children:[s.jsx(v.Alert,{message:B("Values preset in this form will override user submitted ones when continue or reject.")}),s.jsx("br",{}),i&&c&&s.jsx(e.SchemaComponentContext.Provider,{value:F(y({},o),{refresh(){d(T.lodash.get(c.toJSON(),"properties.grid"))}}),children:s.jsx(e.SchemaComponent,{schema:c,components:g})})]})})})})})})]})}function ke(o){return s.jsxs(e.GeneralSchemaDesigner,F(y({},o),{disableInitializer:!0,children:[s.jsx(e.Action.Designer.ButtonEditor,{}),s.jsx(Fe,{}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"ActionBar"}})]}))}function Ie(){const a=e.useSchemaInitializerItem(),{action:n,actionProps:r}=a,t=M(a,["action","actionProps"]),{insert:i}=e.useSchemaInitializer();return s.jsx(e.SchemaInitializerItem,F(y({},t),{onClick:()=>{i({type:"void",title:t.title,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:n},"x-component":"Action","x-component-props":F(y({},r),{useAction:"{{ useSubmit }}"}),"x-designer":"ManualActionDesigner","x-action-settings":{}})}}))}function ee(){const o=e.useSchemaInitializerItem(),i=o,{action:n,actionProps:r}=i,t=M(i,["action","actionProps"]);return s.jsx(e.InitializerWithSwitch,F(y({},t),{item:o,schema:{type:"void",title:t.title,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:n},"x-component":"Action","x-component-props":F(y({},r),{useAction:"{{ useSubmit }}"}),"x-designer":"Action.Designer","x-action":`${n}`},type:"x-action"}))}const Ae=new e.SchemaInitializer({name:"AddActionButton",title:'{{t("Configure actions")}}',items:[{name:"jobStatusResolved",title:`{{t("Continue the process", { ns: "${C}" })}}`,Component:Ie,action:l.JOB_STATUS.RESOLVED,actionProps:{type:"primary"}},{name:"jobStatusRejected",title:`{{t("Terminate the process", { ns: "${C}" })}}`,Component:ee,action:l.JOB_STATUS.REJECTED,actionProps:{danger:!0}},{name:"jobStatusPending",title:`{{t("Save temporarily", { ns: "${C}" })}}`,Component:ee,action:l.JOB_STATUS.PENDING}]});function we(){return{run(){}}}function Be({value:o,onChange:n}){const r=e.usePlugin(l),t=m.useContext(e.SchemaComponentContext),i=l.useNodeContext(),a=l.useAvailableUpstreams(i),p=b.useForm(),{workflow:d}=l.useFlowContext(),c={},x={};a.forEach(u=>{const S=r.instructions.get(u.type);Object.assign(c,S.initializers),Object.assign(x,S.components)});const g=m.useMemo(()=>new b.Schema({properties:{drawer:{type:"void",title:`{{t("User interface", { ns: "${C}" })}}`,"x-decorator":"Form","x-component":"Action.Drawer","x-component-props":{className:e.css`
|
|
1
|
+
(function(h,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@nocobase/plugin-workflow/client"),require("react/jsx-runtime"),require("react"),require("@formily/antd-v5"),require("@formily/core"),require("@formily/react"),require("antd"),require("react-i18next"),require("@nocobase/utils/client"),require("lodash"),require("@ant-design/icons"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/plugin-workflow/client","react/jsx-runtime","react","@formily/antd-v5","@formily/core","@formily/react","antd","react-i18next","@nocobase/utils/client","lodash","@ant-design/icons","dayjs"],e):(h=typeof globalThis!="undefined"?globalThis:h||self,e(h["@nocobase/plugin-workflow-manual"]={},h["@nocobase/client"],h["@nocobase/plugin-workflow"],h.jsxRuntime,h.react,h["@formily/antd-v5"],h["@formily/core"],h["@formily/react"],h.antd,h["react-i18next"],h["@nocobase/utils"],h.lodash,h["@ant-design/icons"],h.dayjs))})(this,function(h,e,p,s,m,U,q,b,v,j,T,G,_,se){"use strict";var We=Object.defineProperty,Re=Object.defineProperties;var eo=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var L=(h,e,p)=>e in h?We(h,e,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[e]=p,y=(h,e)=>{for(var p in e||(e={}))ne.call(e,p)&&L(h,p,e[p]);if(J)for(var p of J(e))re.call(e,p)&&L(h,p,e[p]);return h},F=(h,e)=>Re(h,eo(e));var M=(h,e)=>{var p={};for(var s in h)ne.call(h,s)&&e.indexOf(s)<0&&(p[s]=h[s]);if(h!=null&&J)for(var s of J(h))e.indexOf(s)<0&&re.call(h,s)&&(p[s]=h[s]);return p};var $=(h,e,p)=>(L(h,typeof e!="symbol"?e+"":e,p),p);var E=(h,e,p)=>new Promise((s,m)=>{var U=v=>{try{b(p.next(v))}catch(j){m(j)}},q=v=>{try{b(p.throw(v))}catch(j){m(j)}},b=v=>v.done?s(v.value):Promise.resolve(v.value).then(U,q);b((p=p.apply(h,e)).next())});const C="workflow-manual";function B(o,n={}){const{t:r}=ie(n);return r(o)}function ie(o){return j.useTranslation(C,o)}function ae(o){const{execution:n,nodes:r}=p.useFlowContext(),t=m.useMemo(()=>r.reduce((c,d)=>Object.assign(c,{[d.id]:d.key}),{}),[r]),i=m.useMemo(()=>{var c;return{$context:n==null?void 0:n.context,$jobsMapByNodeKey:((c=n==null?void 0:n.jobs)!=null?c:[]).reduce((d,l)=>Object.assign(d,{[t[l.nodeId]]:l.result}),{})}},[n==null?void 0:n.context,n==null?void 0:n.jobs,t]);return m.useMemo(()=>T.parse(o)(i),[i,o])}function Q(o){const n=b.useField(),r=m.useRef(null),{getAssociationAppends:t}=e.useAssociationNames(),{appends:i,updateAssociationValues:a}=t(),c=ae(o.dataSource),d=m.useMemo(()=>q.createForm({values:c,readPretty:!0}),[c]),l={appends:i},f={loading:!1,data:{data:c}},x=e.useAPIClient().resource(o.collection),u=m.useContext(e.BlockRequestContext);return s.jsx(e.CollectionProvider,{collection:o.collection,children:s.jsx(e.RecordProvider,{record:c,parent:!1,children:s.jsx(e.BlockRequestContext.Provider,{value:{block:"form",field:n,service:f,resource:x,__parent:u},children:s.jsx(e.FormBlockContext.Provider,{value:{params:l,form:d,field:n,service:f,updateAssociationValues:a,formBlockRef:r},children:o.children})})})})}function Y(o){var w,D,N;const n=e.useRecord(),r=b.useFieldSchema(),t=b.useField(),i=m.useRef(null),{getAssociationAppends:a}=e.useAssociationNames(),{appends:c,updateAssociationValues:d}=a(),[l]=Object.keys((w=r.toJSON().properties)!=null?w:{}),f=(D=n==null?void 0:n.result)==null?void 0:D[l],{findComponent:g}=e.useDesignable(),x=g((N=t.component)==null?void 0:N[0])||m.Fragment,u=m.useMemo(()=>q.createForm({initialValues:f}),[f]),S=m.useMemo(()=>y({appends:c},o.params),[c,o.params]),k=m.useMemo(()=>({loading:!1,data:{data:f}}),[f]),A=e.useAPIClient().resource(o.collection),O=m.useContext(e.BlockRequestContext),z=m.useMemo(()=>({params:S,form:u,field:t,service:k,updateAssociationValues:d,formBlockRef:i}),[t,u,S,k,d]);return!n.status||f?s.jsx(e.CollectionProvider,{collection:o.collection,children:s.jsx(e.RecordProvider,{record:f,parent:!1,children:s.jsx(e.FormActiveFieldsProvider,{name:"form",children:s.jsx(e.BlockRequestContext.Provider,{value:{block:"form",props:o,field:t,service:k,resource:A,__parent:O},children:s.jsx(e.FormBlockContext.Provider,{value:z,children:s.jsxs(x,F(y({},t.componentProps),{children:[s.jsx(e.FormV2.Templates,{style:{marginBottom:18},form:u}),s.jsx("div",{ref:i,children:s.jsx(b.RecursionField,{schema:r,onlyRenderProperties:!0})})]}))})})})})}):null}function ce(r){var t=r,{schema:o}=t,n=M(t,["schema"]);const{getTemplateSchemaByMode:i}=e.useSchemaTemplateManager(),{insert:a}=e.useSchemaInitializer(),c=e.useRecordCollectionDataSourceItems("FormItem");function d(f){return E(this,arguments,function*({item:l}){const g=l.template?yield i(l):null,x=e.createFormBlockSchema(F(y({actionInitializers:"AddActionButton",actions:{resolve:{type:"void",title:`{{t("Continue the process", { ns: "${C}" })}}`,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:p.JOB_STATUS.RESOLVED},"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useSubmit }}"},"x-designer":"ManualActionDesigner","x-designer-props":{}}}},o),{template:g}));delete x["x-acl-action-props"],delete x["x-acl-action"];const[u]=Object.keys(x.properties);x.properties[u].properties.actions["x-decorator"]="ActionBarProvider",x.properties[u].properties.actions["x-component-props"].style={marginTop:"1.5em",flexWrap:"wrap"},p.traverseSchema(x,S=>{S["x-uid"]&&delete S["x-uid"]}),a(x)})}return s.jsx(e.SchemaInitializerItem,F(y({},n),{onClick:d,items:c}))}function H(){var n;const o=e.useSchemaInitializerItem();return s.jsx(e.CollectionProvider,{collection:(n=o.schema)==null?void 0:n.collection,children:s.jsx(ce,y({},o))})}function P(o,n,r=!1){const t=[];return o?n(o)&&(!r||!o.properties)?(t.push(o),t):(o.properties&&Object.keys(o.properties).forEach(i=>{t.push(...P(o.properties[i],n))}),t):t}function le(){const{name:o,title:n}=e.useCollection();return s.jsxs(e.GeneralSchemaDesigner,{title:n||o,children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsLinkageRules,{collectionName:o}),s.jsx(e.SchemaSettingsDataTemplates,{collectionName:o}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const pe={title:`{{t("Create record form", { ns: "${C}" })}}`,config:{useInitializer({collections:o}){const n=m.useMemo(()=>o.map(a=>({name:G.camelCase(`createRecordForm-child-${a.name}`),type:"item",title:a.title,label:a.label,schema:{collection:a.name,title:`{{t("Create record", { ns: "${C}" })}}`,formType:"create","x-designer":"CreateFormDesigner"},Component:H})),[o]),[r,t]=m.useState(!1),i=e.useMenuSearch(n,r,!0);return{name:"createRecordForm",key:"createRecordForm",type:"subMenu",title:`{{t("Create record form", { ns: "${C}" })}}`,componentProps:{onOpenChange(a){t(a.length>0)}},children:i}},initializers:{},components:{CreateFormDesigner:le},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="FormBlockProvider"&&t["x-decorator-props"].formType==="create").forEach(t=>{var c;const[i]=Object.keys(t.properties),a=t.properties[i];n[i]={type:"create",title:((c=t["x-component-props"])==null?void 0:c.title)||i,actions:P(a.properties.actions,d=>d["x-component"]==="Action").map(d=>{var l,f;return{status:d["x-decorator-props"].value,values:(f=(l=d["x-action-settings"])==null?void 0:l.assignedValues)==null?void 0:f.values,key:d.name}}),collection:t["x-decorator-props"].collection}}),n}},block:{scope:{},components:{}}};function X(o){var f,g,x,u;const[n,r]=m.useState((g=(f=o.collection)==null?void 0:f.fields)!=null?g:[]),t=e.useRecord(),i=b.useField(),a=b.useFieldSchema(),[c]=Object.keys((x=a.toJSON().properties)!=null?x:{}),d=(u=t==null?void 0:t.result)==null?void 0:u[c],l=m.useMemo(()=>q.createForm({initialValues:d}),[d]);return!t.status||d?s.jsx(e.CollectionProvider,{collection:F(y({},o.collection),{fields:n}),children:s.jsx(e.RecordProvider,{record:d,parent:!1,children:s.jsx(e.FormBlockContext.Provider,{value:{form:l,field:i,setCollectionFields:r},children:o.children})})}):null}function de(){const{insert:o}=e.useSchemaInitializer(),n=e.useSchemaInitializerItem();return s.jsx(e.SchemaInitializerItem,F(y({},n),{onClick:()=>{o({type:"void","x-decorator":"CustomFormBlockProvider","x-decorator-props":{collection:{name:T.uid(),fields:[]}},"x-component":"CardItem","x-component-props":{title:'{{t("Form")}}'},"x-designer":"SimpleDesigner","x-designer-props":{type:"customForm"},properties:{[T.uid()]:{type:"void","x-component":"FormV2","x-component-props":{useProps:"{{ useFormBlockProps }}"},properties:{grid:{type:"void","x-component":"Grid","x-initializer":"AddCustomFormField"},actions:{type:"void","x-decorator":"ActionBarProvider","x-component":"ActionBar","x-component-props":{layout:"one-column",style:{marginTop:"1.5em",flexWrap:"wrap"}},"x-initializer":"AddActionButton",properties:{resolve:{type:"void",title:`{{t("Continue the process", { ns: "${C}" })}}`,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:p.JOB_STATUS.RESOLVED},"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useSubmit }}"},"x-designer":"ManualActionDesigner"}}}}}}})}}))}const Z={basic:'{{t("Basic")}}',choices:'{{t("Choices")}}',media:'{{t("Media")}}',datetime:'{{t("Date & Time")}}',relation:'{{t("Relation")}}',advanced:'{{t("Advanced type")}}',systemInfo:'{{t("System info")}}',others:'{{t("Others")}}'};function ue(o){const n={};return Object.keys(o).forEach(r=>{const t=o[r],{group:i="others"}=t;n[i]=n[i]||{},G.set(n,[i,r],t)}),Object.keys(Z).filter(r=>["basic","choices","datetime","media"].includes(r)).map(r=>({title:Z[r],children:Object.keys(n[r]||{}).map(t=>{const i=n[r][t];return y({value:t,title:i.title,name:t},n[r][t])}).sort((t,i)=>t.order-i.order)}))}function me(){const{interfaces:o}=e.useCollectionManager();return ue(o).map(r=>({name:r.title,type:"itemGroup",title:r.title,children:r.children.map(t=>({name:t.name,type:"item",title:t.title,Component:xe,fieldInterface:t.name}))}))}const W=m.createContext({}),fe=o=>{const[n,r]=m.useState(null),[t,i]=m.useState(),a=me(),c=m.useContext(e.CollectionContext),{setCollectionFields:d}=m.useContext(e.FormBlockContext);return s.jsxs(W.Provider,{value:{onAddField(l){const S=G.cloneDeep(l),{properties:k}=S,I=k,{unique:f,type:g}=I,x=M(I,["unique","type"]),u=M(S,["properties"]);delete x.name["x-disabled"],r(F(y({},u),{properties:x}))},setCallback:i},children:[s.jsx(e.SchemaInitializerItems,F(y({},o),{items:a})),s.jsx(e.ActionContextProvider,{value:{visible:!!n},children:n?s.jsx(e.SchemaComponent,{schema:{type:"void",name:"drawer",title:'{{t("Configure field")}}',"x-decorator":"Form","x-component":"Action.Drawer",properties:F(y({},n.properties),{footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{type:"void",title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction(){const l=b.useForm();return{run(){return E(this,null,function*(){i(null),r(null),l.reset()})}}}}},submit:{type:"void",title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction(){const{values:l,query:f}=b.useForm(),g=[B("Field name existed in form")];return{run(){return E(this,null,function*(){var A,O,z,w;const{default:u}=n,S=T.uid();if(u.name=(A=l.name)!=null?A:S,u.uiSchema.title=(z=(O=l.uiSchema)==null?void 0:O.title)!=null?z:S,u.interface=n.name,(w=c.fields)==null?void 0:w.find(D=>D.name===u.name)){f("name").take().setFeedback({type:"error",messages:g});return}const I=T.merge(u,l);d([...c.fields,I]),t({name:u.name,type:u.uiSchema.type,"x-decorator":"FormItem","x-component":"CollectionField","x-component-props":{field:I},"x-collection-field":`${c.name}.${u.name}`,"x-designer":"FormItem.Designer"}),i(null),r(null)})}}}}}}}})},components:{ArrayTable:U.ArrayTable}}):null})]})},he=new e.SchemaInitializer({name:"AddCustomFormField",wrap:e.gridRowColWrap,insertPosition:"beforeEnd",title:"{{t('Configure fields')}}",ItemsComponent:fe});function xe(){const o=e.useSchemaInitializerItem(),{insert:n,setVisible:r}=e.useSchemaInitializer(),{onAddField:t,setCallback:i}=m.useContext(W),{getInterface:a}=e.useCollectionManager(),c=a(o.fieldInterface);return s.jsx(e.SchemaInitializerItem,y({onClick:()=>{i(()=>n),t(c),r(!1)}},o),o.fieldInterface)}const R={title:`{{t("Custom form", { ns: "${C}" })}}`,config:{useInitializer(){return{name:"customForm",type:"item",title:`{{t("Custom form", { ns: "${C}" })}}`,Component:de}},initializers:{},components:{CustomFormBlockProvider:X},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="CustomFormBlockProvider").forEach(t=>{var d;const[i]=Object.keys(t.properties),a=t.properties[i],c=P(a.properties.grid,l=>l["x-component"]==="CollectionField",!0);t["x-decorator-props"].collection.fields=c.map(l=>{var f,g;return(g=(f=l["x-component-props"])==null?void 0:f.field)!=null?g:l["x-interface-options"]}),n[i]={type:"custom",title:((d=t["x-component-props"])==null?void 0:d.title)||i,actions:P(a.properties.actions,l=>l["x-component"]==="Action").map(l=>{var f,g;return{status:l["x-decorator-props"].value,values:(g=(f=l["x-action-settings"])==null?void 0:f.assignedValues)==null?void 0:g.values,key:l.name}}),collection:t["x-decorator-props"].collection}}),n}},block:{scope:{},components:{CustomFormBlockProvider:X}}};function Ce(){const{name:o,title:n}=e.useCollection(),r=b.useFieldSchema(),{t}=j.useTranslation(),{dn:i}=e.useDesignable();return s.jsxs(e.GeneralSchemaDesigner,{title:n||o,children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsActionModalItem,{title:t("Filter settings",{ns:C}),schema:{name:"filter",type:"object",title:'{{t("Filter")}}',"x-component":"Filter","x-component-props":{useProps(){var c;return{options:e.useCollectionFilterOptions((c=r==null?void 0:r["x-decorator-props"])==null?void 0:c.collection)}},dynamicComponent:"FilterDynamicComponent"}},initialValues:r==null?void 0:r["x-decorator-props"],onSubmit:({filter:a})=>{r["x-decorator-props"].filter=a,i.emit("patch",{schema:{"x-decorator-props":r["x-decorator-props"]}}),i.refresh()}}),s.jsx(e.SchemaSettingsLinkageRules,{collectionName:o}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const ge={title:`{{t("Update record form", { ns: "${C}" })}}`,config:{useInitializer({collections:o}){const n=m.useMemo(()=>o.map(a=>({name:G.camelCase(`updateRecordForm-child-${a.name}`),type:"item",title:a.title,label:a.label,schema:{collection:a.name,title:`{{t("Update record", { ns: "${C}" })}}`,formType:"update","x-designer":"UpdateFormDesigner"},Component:H})),[o]),[r,t]=m.useState(!1),i=e.useMenuSearch(n,r,!0);return{name:"updateRecordForm",key:"updateRecordForm",type:"subMenu",title:`{{t("Update record form", { ns: "${C}" })}}`,componentProps:{onOpenChange(a){t(a.length>0)}},children:i}},initializers:{},components:{FilterDynamicComponent:p.FilterDynamicComponent,UpdateFormDesigner:Ce},parseFormOptions(o){const n={};return P(o,t=>t["x-decorator"]==="FormBlockProvider"&&t["x-decorator-props"].formType==="update").forEach(t=>{var c;const[i]=Object.keys(t.properties),a=t.properties[i];n[i]=F(y({},t["x-decorator-props"]),{type:"update",title:((c=t["x-component-props"])==null?void 0:c.title)||i,actions:P(a.properties.actions,d=>d["x-component"]==="Action").map(d=>{var l,f;return{status:d["x-decorator-props"].value,values:(f=(l=d["x-action-settings"])==null?void 0:l.assignedValues)==null?void 0:f.values,key:d.name}})})}),n}},block:{scope:{},components:{}}},V=new T.Registry;V.register("customForm",R),V.register("createForm",pe),V.register("updateForm",ge);function ye(){const{workflow:o}=p.useFlowContext(),n=p.useTrigger();return n.useInitializers?n.useInitializers(o.config):null}const be={customForm:R.title,record:`{{t("Data record", { ns: "${C}" })}}`};function Se(){var t,i;const o=b.useFieldSchema(),n=(i=be[(t=o["x-designer-props"])==null?void 0:t.type])!=null?i:'{{t("Block")}}',r=e.useCompile();return s.jsxs(e.GeneralSchemaDesigner,{title:r(n),children:[s.jsx(e.SchemaSettingsBlockTitleItem,{}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"Grid"}})]})}const ve=new e.SchemaInitializer({name:"AddBlockButton",wrap:e.gridRowColWrap,title:'{{t("Add block")}}',items:[{type:"itemGroup",name:"dataBlocks",title:'{{t("Data blocks")}}',checkChildrenLength:!0,useChildren(){const o=e.usePlugin(p),n=p.useNodeContext(),r=p.useAvailableUpstreams(n),t=[ye()].filter(Boolean),i=r.map(c=>{var l;const d=o.instructions.get(c.type);return(l=d==null?void 0:d.useInitializers)==null?void 0:l.call(d,c)}).filter(Boolean);return[...t,...i.length?[{name:"nodes",type:"subMenu",title:`{{t("Node result", { ns: "${C}" })}}`,children:i}]:[]].filter(Boolean)}},{type:"itemGroup",name:"form",title:'{{t("Form")}}',useChildren(){const{collections:o}=e.useCollectionManager();return Array.from(V.getValues()).map(n=>{const{useInitializer:r}=n.config;return r({collections:o})})}},{type:"itemGroup",name:"otherBlocks",title:'{{t("Other blocks")}}',children:[{name:"markdown",title:'{{t("Markdown")}}',Component:"MarkdownBlockInitializer"}]}]});function Fe(){var A,O,z;const o=m.useContext(e.SchemaComponentContext),{t:n}=j.useTranslation(),r=b.useFieldSchema(),t=p.useWorkflowVariableOptions(),[i,a]=m.useState(!1),[c,d]=m.useState((z=(O=(A=r==null?void 0:r["x-action-settings"])==null?void 0:A.assignedValues)==null?void 0:O.schema)!=null?z:{type:"void","x-component":"Grid","x-initializer":"CustomFormItemInitializers",properties:{}}),[l,f]=m.useState(null),{components:g}=e.useSchemaOptionsContext();m.useEffect(()=>{f(new b.Schema({properties:{grid:c}}))},[c]);const x=m.useMemo(()=>{var D,N;const w=(N=(D=r==null?void 0:r["x-action-settings"])==null?void 0:D.assignedValues)==null?void 0:N.values;return q.createForm({initialValues:T.lodash.cloneDeep(w),values:T.lodash.cloneDeep(w)})},[r]),u=e.useFormActiveFields(),S=n("Assign field values");function k(){a(!1)}function I(){r["x-action-settings"]||(r["x-action-settings"]={}),r["x-action-settings"].assignedValues||(r["x-action-settings"].assignedValues={}),r["x-action-settings"].assignedValues.schema=c,r["x-action-settings"].assignedValues.values=x.values,a(!1),setTimeout(()=>{var w;(w=o.refresh)==null||w.call(o)},300)}return s.jsxs(s.Fragment,{children:[s.jsx(e.SchemaSettingsItem,{title:S,onClick:()=>a(!0),children:S}),s.jsx(v.Modal,{width:"50%",title:S,open:i,onCancel:k,footer:s.jsxs(v.Space,{children:[s.jsx(v.Button,{onClick:k,children:n("Cancel")}),s.jsx(v.Button,{type:"primary",onClick:I,children:n("Submit")})]}),children:s.jsx(e.DefaultValueProvider,{isAllowToSetDefaultValue:()=>!1,children:s.jsx(e.VariableScopeProvider,{scope:t,children:s.jsx(e.FormActiveFieldsProvider,{name:"form",getActiveFieldsName:u==null?void 0:u.getActiveFieldsName,children:s.jsx(b.FormProvider,{form:x,children:s.jsxs(U.FormLayout,{layout:"vertical",children:[s.jsx(v.Alert,{message:B("Values preset in this form will override user submitted ones when continue or reject.")}),s.jsx("br",{}),i&&l&&s.jsx(e.SchemaComponentContext.Provider,{value:F(y({},o),{refresh(){d(T.lodash.get(l.toJSON(),"properties.grid"))}}),children:s.jsx(e.SchemaComponent,{schema:l,components:g})})]})})})})})})]})}function ke(o){return s.jsxs(e.GeneralSchemaDesigner,F(y({},o),{disableInitializer:!0,children:[s.jsx(e.Action.Designer.ButtonEditor,{}),s.jsx(Fe,{}),s.jsx(e.SchemaSettingsDivider,{}),s.jsx(e.SchemaSettingsRemove,{removeParentsIfNoChildren:!0,breakRemoveOn:{"x-component":"ActionBar"}})]}))}function Ie(){const a=e.useSchemaInitializerItem(),{action:n,actionProps:r}=a,t=M(a,["action","actionProps"]),{insert:i}=e.useSchemaInitializer();return s.jsx(e.SchemaInitializerItem,F(y({},t),{onClick:()=>{i({type:"void",title:t.title,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:n},"x-component":"Action","x-component-props":F(y({},r),{useAction:"{{ useSubmit }}"}),"x-designer":"ManualActionDesigner","x-action-settings":{}})}}))}function ee(){const o=e.useSchemaInitializerItem(),i=o,{action:n,actionProps:r}=i,t=M(i,["action","actionProps"]);return s.jsx(e.InitializerWithSwitch,F(y({},t),{item:o,schema:{type:"void",title:t.title,"x-decorator":"ManualActionStatusProvider","x-decorator-props":{value:n},"x-component":"Action","x-component-props":F(y({},r),{useAction:"{{ useSubmit }}"}),"x-designer":"Action.Designer","x-action":`${n}`},type:"x-action"}))}const Ae=new e.SchemaInitializer({name:"AddActionButton",title:'{{t("Configure actions")}}',items:[{name:"jobStatusResolved",title:`{{t("Continue the process", { ns: "${C}" })}}`,Component:Ie,action:p.JOB_STATUS.RESOLVED,actionProps:{type:"primary"}},{name:"jobStatusRejected",title:`{{t("Terminate the process", { ns: "${C}" })}}`,Component:ee,action:p.JOB_STATUS.REJECTED,actionProps:{danger:!0}},{name:"jobStatusPending",title:`{{t("Save temporarily", { ns: "${C}" })}}`,Component:ee,action:p.JOB_STATUS.PENDING}]});function we(){return{run(){}}}function Be({value:o,onChange:n}){const r=e.usePlugin(p),t=m.useContext(e.SchemaComponentContext),i=p.useNodeContext(),a=p.useAvailableUpstreams(i),c=b.useForm(),{workflow:d}=p.useFlowContext(),l={},f={};a.forEach(u=>{const S=r.instructions.get(u.type);Object.assign(l,S.initializers),Object.assign(f,S.components)});const g=m.useMemo(()=>new b.Schema({properties:{drawer:{type:"void",title:`{{t("User interface", { ns: "${C}" })}}`,"x-decorator":"Form","x-component":"Action.Drawer","x-component-props":{className:e.css`
|
|
2
2
|
.ant-drawer-body {
|
|
3
3
|
background: var(--nb-box-bg);
|
|
4
4
|
}
|
|
5
|
-
`},properties:{tabs:{type:"void","x-component":"Tabs","x-component-props":{},"x-initializer":"TabPaneInitializers","x-initializer-props":{gridInitializer:"AddBlockButton"},properties:o!=null?o:{tab1:{type:"void",title:`{{t("Manual", { ns: "${C}" })}}`,"x-component":"Tabs.TabPane","x-designer":"Tabs.Designer",properties:{grid:{type:"void","x-component":"Grid","x-initializer":"AddBlockButton",properties:{}}}}}}}}}}),[]),
|
|
5
|
+
`},properties:{tabs:{type:"void","x-component":"Tabs","x-component-props":{},"x-initializer":"TabPaneInitializers","x-initializer-props":{gridInitializer:"AddBlockButton"},properties:o!=null?o:{tab1:{type:"void",title:`{{t("Manual", { ns: "${C}" })}}`,"x-component":"Tabs.TabPane","x-designer":"Tabs.Designer",properties:{grid:{type:"void","x-component":"Grid","x-initializer":"AddBlockButton",properties:{}}}}}}}}}}),[]),x=m.useCallback(function(){const{tabs:S}=T.lodash.get(g.toJSON(),"properties.drawer.properties"),k=Array.from(V.getValues()).reduce((I,A)=>Object.assign(I,A.config.parseFormOptions(S)),{});c.setValuesIn("forms",k),n(S.properties)},[c,n,g]);return s.jsx(e.SchemaComponentContext.Provider,{value:F(y({},t),{designable:!d.executed,refresh:x}),children:s.jsx(e.SchemaComponent,{schema:g,components:F(y(y({},f),Array.from(V.getValues()).reduce((u,S)=>Object.assign(u,S.config.components),{})),{FormBlockProvider:Y,DetailsBlockProvider:Q,ManualActionStatusProvider(u){return u.children},ActionBarProvider(u){return u.children},SimpleDesigner:Se,ManualActionDesigner:ke}),scope:{useSubmit:we,useDetailsBlockProps:e.useFormBlockContext}})})}function Te(o){const{workflow:n}=p.useFlowContext(),[r,t]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(v.Button,{type:"primary",onClick:()=>t(!0),disabled:!1,children:B(n.executed?"View user interface":"Configure user interface")}),s.jsx(e.ActionContextProvider,{value:{visible:r,setVisible:t,formValueChanged:!1},children:o.children})]})}function Oe({value:o,onChange:n}){const r=s.jsx("fieldset",{children:s.jsx(U.FormLayout,{layout:"vertical",children:s.jsx(e.FormItem,{label:B("Negotiation"),children:s.jsxs(v.Radio.Group,{value:o,onChange:n,children:[s.jsx(v.Radio,{value:1,children:s.jsxs(v.Tooltip,{title:B("Everyone should pass"),placement:"bottom",children:[s.jsx("span",{children:B("All pass")}),s.jsx(_.QuestionCircleOutlined,{style:{color:"#999"}})]})}),s.jsx(v.Radio,{value:-1,children:s.jsxs(v.Tooltip,{title:B("Anyone pass"),placement:"bottom",children:[s.jsx("span",{children:B("Any pass")}),s.jsx(_.QuestionCircleOutlined,{style:{color:"#999"}})]})})]})})})});return s.jsxs("fieldset",{className:e.css`
|
|
6
6
|
.ant-radio-group {
|
|
7
7
|
.anticon {
|
|
8
8
|
margin-left: 0.5em;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
`,children:[s.jsx(v.Form.Item,{children:s.jsxs(v.Radio.Group,{value:!!o,onChange:({target:{value:t}})=>{console.log(t),n(Number(t))},children:[s.jsx(v.Radio,{value:!0,children:s.jsxs(v.Tooltip,{title:B("Each user has own task"),placement:"bottom",children:[s.jsx("span",{children:B("Separately")}),s.jsx(U.QuestionCircleOutlined,{style:{color:"#999"}})]})}),s.jsx(v.Radio,{value:!1,children:s.jsxs(v.Tooltip,{title:B("Everyone shares one task"),placement:"bottom",children:[s.jsx("span",{children:B("Collaboratively")}),s.jsx(U.QuestionCircleOutlined,{style:{color:"#999"}})]})})]})}),o?r:null]})}function ze(o){return o.isForeignKey?o.target==="users":o.collectionName==="users"&&o.name==="id"}function De({multiple:o=!1,value:n=[],onChange:r}){const t=l.useWorkflowVariableOptions({types:[ze]});return s.jsx(e.Variable.Input,{scope:t,value:n[0],onChange:i=>{r([i])},children:s.jsx(e.RemoteSelect,{fieldNames:{label:"nickname",value:"id"},service:{resource:"users"},manual:!1,value:n[0],onChange:i=>{r(i!=null?[i]:[])}})})}class Me extends l.Instruction{constructor(){super(...arguments);N(this,"title",`{{t("Manual", { ns: "${C}" })}}`);N(this,"type","manual");N(this,"group","manual");N(this,"description",`{{t("Could be used for manually submitting data, and determine whether to continue or exit. Workflow will generate a todo item for assigned user when it reaches a manual node, and continue processing after user submits the form.", { ns: "${C}" })}}`);N(this,"fieldset",{assignees:{type:"array",title:`{{t("Assignees", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"AssigneesSelect","x-component-props":{},required:!0,default:[]},mode:{type:"number",title:`{{t("Mode", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"ModeConfig",default:1,"x-reactions":{dependencies:["assignees"],fulfill:{state:{visible:"{{$deps[0].length > 1}}"}}}},schema:{type:"void",title:`{{t("User interface", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"SchemaConfigButton",properties:{schema:{type:"object","x-component":"SchemaConfig",default:null}}},forms:{type:"object",default:{}}});N(this,"components",{SchemaConfigButton:Te,SchemaConfig:Be,ModeConfig:Oe,AssigneesSelect:De})}useVariables({key:r,title:t,config:i},{types:a,fieldNames:p=l.defaultFieldNames}){var h;const d=e.useCompile(),{getCollectionFields:c}=e.useCollectionManager(),x=Object.keys((h=i.forms)!=null?h:{});if(!x.length)return null;const g=x.map(u=>{var I;const S=i.forms[u],w=l.getCollectionFieldOptions({fields:(I=S.collection)==null?void 0:I.fields,collection:S.collection,types:a,compile:d,getCollectionFields:c}),k=d(S.title)||u;return w.length?{key:u,value:u,label:k,title:k,children:w}:null}).filter(Boolean);return g.length?{[p.value]:r,[p.label]:t,[p.children]:g}:null}useInitializers(r){var p;const{getCollection:t}=e.useCollectionManager(),i=Object.keys((p=r.config.forms)!=null?p:{});if(!i.length||r.config.mode)return null;const a=i.map(d=>{var g,h;const c=r.config.forms[d],{fields:x=[]}=t(c.collection);return x.length?{name:(g=c.title)!=null?g:d,type:"item",title:(h=c.title)!=null?h:d,Component:l.CollectionBlockInitializer,collection:c.collection,dataSource:`{{$jobsMapByNodeKey.${r.key}.${d}}}`}:null}).filter(Boolean);return a.length?{name:`#${r.id}`,key:"forms",type:"subMenu",title:r.title,children:a}:null}}const Pe={title:`{{t("Task", { ns: "${C}" })}}`,name:"flow_nodes",fields:[{type:"bigInt",name:"id",interface:"m2o",uiSchema:{type:"number",title:"ID","x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"flow_nodes",params:{filter:{type:"manual"}}}}}},{type:"string",name:"title",interface:"input",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}}]},Ve={title:`{{t("Workflow", { ns: "${C}" })}}`,name:"workflows",fields:[{type:"string",name:"title",interface:"input",uiSchema:{title:'{{t("Name")}}',type:"string","x-component":"Input",required:!0}}]},je={title:`{{t("Workflow todos", { ns: "${C}" })}}`,name:"users_jobs",fields:[{type:"belongsTo",name:"user",target:"users",foreignKey:"userId",interface:"m2o",uiSchema:{type:"number",title:'{{t("User")}}',"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"nickname",value:"id"},service:{resource:"users"}}}},{type:"belongsTo",name:"node",target:"flow_nodes",foreignKey:"nodeId",interface:"m2o",isAssociation:!0,uiSchema:{type:"number",title:`{{t("Task", { ns: "${C}" })}}`,"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"flow_nodes"}}}},{type:"belongsTo",name:"workflow",target:"workflows",foreignKey:"workflowId",interface:"m2o",uiSchema:{type:"number",title:`{{t("Workflow", { ns: "${C}" })}}`,"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"workflows"}}}},{type:"integer",name:"status",interface:"select",uiSchema:{type:"number",title:`{{t("Status", { ns: "${C}" })}}`,"x-component":"Select",enum:l.JobStatusOptions}},{name:"createdAt",type:"date",interface:"createdAt",uiSchema:{type:"datetime",title:'{{t("Created at")}}',"x-component":"DatePicker","x-component-props":{showTime:!0}}}]},Ne=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.title)!=null?t:`#${(r=o.value)==null?void 0:r.id}`},{displayName:"NodeColumn"}),$e=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.title)!=null?t:`#${(r=o.value)==null?void 0:r.id}`},{displayName:"WorkflowColumn"}),Ee=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.nickname)!=null?t:(r=o.value)==null?void 0:r.id},{displayName:"UserColumn"}),K=()=>s.jsx(e.SchemaComponent,{components:{NodeColumn:Ne,WorkflowColumn:$e,UserColumn:Ee},schema:{type:"void",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-designer":"Filter.Action.Designer","x-component":"Filter.Action","x-component-props":{icon:"FilterOutlined",useProps:"{{ useFilterActionProps }}"},"x-align":"left"},refresher:{type:"void",title:'{{ t("Refresh") }}',"x-action":"refresh","x-component":"Action","x-designer":"Action.Designer","x-component-props":{icon:"ReloadOutlined",useProps:"{{ useRefreshActionProps }}"},"x-align":"right"}}},table:{type:"array","x-component":"TableV2","x-component-props":{rowKey:"id",useProps:"{{ useTableBlockProps }}"},properties:{node:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Task", { ns: "${C}" })}}`,properties:{node:{"x-component":"NodeColumn","x-read-pretty":!0}}},workflow:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Workflow", { ns: "${C}" })}}`,properties:{workflow:{"x-component":"WorkflowColumn","x-read-pretty":!0}}},createdAt:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{createdAt:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},user:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Assignee", { ns: "${C}" })}}`,properties:{user:{"x-component":"UserColumn","x-read-pretty":!0}}},status:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{status:{"x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:'{{t("Actions")}}',properties:{view:{type:"void","x-component":"Action.Link",title:'{{t("View")}}',properties:{drawer:{"x-component":"WorkflowTodo.Drawer"}}}}}}}}}});function qe(o){var x;const{data:n}=e.useCurrentUserContext(),{userJob:r}=l.useFlowContext(),{status:t,result:i,userId:a}=r,p=b.useFieldSchema(),{name:d}=p.parent.toJSON();let{children:c}=o;return t?i[d]||(c=null):((x=n==null?void 0:n.data)==null?void 0:x.id)!==a&&(c=null),c}const Ue=m.createContext(null);function _e({value:o,children:n}){const{userJob:r}=l.useFlowContext(),t=b.useField(),i=b.useFieldSchema();return m.useEffect(()=>{r.status&&(t.disabled=!0,t.visible=r.status===o&&r.result._===i.name)},[r,o,t,i.name]),s.jsx(Ue.Provider,{value:o,children:n})}function Ge(){const o=e.useAPIClient(),{setVisible:n}=e.useActionContext(),{values:r,submit:t}=b.useForm(),i=b.useFieldSchema(),{service:a}=e.useTableBlockContext(),{userJob:p}=l.useFlowContext(),{name:d}=i,{name:c}=i.parent.parent;return{run(){return $(this,null,function*(){p.status||(yield t(),yield o.resource("users_jobs").submit({filterByTk:p.id,values:{result:{[c]:r,_:d}}}),n(!1),a.refresh())})}}}function Je(o){var g;const n=e.usePlugin(l),r=e.useAPIClient(),{id:t}=e.useRecord(),[i,a]=m.useState(null),[p,d]=m.useState(null);m.useEffect(()=>{var h,u;t&&((u=(h=r.resource("users_jobs")).get)==null||u.call(h,{filterByTk:t,appends:["node","workflow","workflow.nodes","execution","execution.jobs"]}).then(({data:S})=>{var A;const D=(A=S==null?void 0:S.data)!=null?A:{},{node:w,workflow:G={}}=D,oe=G,{nodes:k=[]}=oe,I=M(oe,["nodes"]),te=D,{execution:z}=te,O=M(te,["node","workflow","execution"]);l.linkNodes(k),d(w),a({userJob:O,workflow:I,nodes:k,execution:z})}))},[r,t]);const x=l.useAvailableUpstreams(i==null?void 0:i.nodes.find(h=>h.id===p.id)).reduce((h,{type:u})=>Object.assign(h,n.instructions.get(u).components),{});return p&&i?s.jsx(l.FlowContext.Provider,{value:i,children:s.jsx(e.SchemaComponent,{components:y(y({FormBlockProvider:Y,DetailsBlockProvider:Q,ActionBarProvider:qe,ManualActionStatusProvider:_e},Array.from(V.getValues()).reduce((h,u)=>Object.assign(h,u.block.components),{})),x),scope:y({useSubmit:Ge,useFormBlockProps:Ke,useDetailsBlockProps:Le},Array.from(V.getValues()).reduce((h,u)=>Object.assign(h,u.block.scope),{})),schema:{type:"void",name:"tabs","x-component":"Tabs",properties:(g=p.config)==null?void 0:g.schema}})}):s.jsx(v.Spin,{})}function Ke(){var a;const{userJob:o}=l.useFlowContext(),n=e.useRecord(),{data:r}=e.useCurrentUserContext(),{form:t}=e.useFormBlockContext(),i=o.status?n?"readPretty":"disabled":((a=r==null?void 0:r.data)==null?void 0:a.id)!==o.userId?"disabled":"editable";return m.useEffect(()=>{t==null||t.setPattern(i)},[i,t]),{form:t}}function Le(){const{form:o}=e.useFormBlockContext();return{form:o}}function Qe(){const o=e.useCompile(),{status:n,updatedAt:r}=e.useRecord(),t=l.JobStatusOptionsMap[n];return n?s.jsxs(v.Space,{children:[s.jsx("time",{className:e.css`
|
|
11
|
+
`,children:[s.jsx(v.Form.Item,{children:s.jsxs(v.Radio.Group,{value:!!o,onChange:({target:{value:t}})=>{console.log(t),n(Number(t))},children:[s.jsx(v.Radio,{value:!0,children:s.jsxs(v.Tooltip,{title:B("Each user has own task"),placement:"bottom",children:[s.jsx("span",{children:B("Separately")}),s.jsx(_.QuestionCircleOutlined,{style:{color:"#999"}})]})}),s.jsx(v.Radio,{value:!1,children:s.jsxs(v.Tooltip,{title:B("Everyone shares one task"),placement:"bottom",children:[s.jsx("span",{children:B("Collaboratively")}),s.jsx(_.QuestionCircleOutlined,{style:{color:"#999"}})]})})]})}),o?r:null]})}function ze(o){return o.isForeignKey?o.target==="users":o.collectionName==="users"&&o.name==="id"}function De({multiple:o=!1,value:n=[],onChange:r}){const t=p.useWorkflowVariableOptions({types:[ze]});return s.jsx(e.Variable.Input,{scope:t,value:n[0],onChange:i=>{r([i])},children:s.jsx(e.RemoteSelect,{fieldNames:{label:"nickname",value:"id"},service:{resource:"users"},manual:!1,value:n[0],onChange:i=>{r(i!=null?[i]:[])}})})}class Me extends p.Instruction{constructor(){super(...arguments);$(this,"title",`{{t("Manual", { ns: "${C}" })}}`);$(this,"type","manual");$(this,"group","manual");$(this,"description",`{{t("Could be used for manually submitting data, and determine whether to continue or exit. Workflow will generate a todo item for assigned user when it reaches a manual node, and continue processing after user submits the form.", { ns: "${C}" })}}`);$(this,"fieldset",{assignees:{type:"array",title:`{{t("Assignees", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"AssigneesSelect","x-component-props":{},required:!0,default:[]},mode:{type:"number",title:`{{t("Mode", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"ModeConfig",default:1,"x-reactions":{dependencies:["assignees"],fulfill:{state:{visible:"{{$deps[0].length > 1}}"}}}},schema:{type:"void",title:`{{t("User interface", { ns: "${C}" })}}`,"x-decorator":"FormItem","x-component":"SchemaConfigButton",properties:{schema:{type:"object","x-component":"SchemaConfig",default:null}}},forms:{type:"object",default:{}}});$(this,"components",{SchemaConfigButton:Te,SchemaConfig:Be,ModeConfig:Oe,AssigneesSelect:De})}useVariables({key:r,title:t,config:i},{types:a,fieldNames:c=p.defaultFieldNames}){var x;const d=e.useCompile(),{getCollectionFields:l}=e.useCollectionManager(),f=Object.keys((x=i.forms)!=null?x:{});if(!f.length)return null;const g=f.map(u=>{var A;const S=i.forms[u],k=p.getCollectionFieldOptions({fields:(A=S.collection)==null?void 0:A.fields,collection:S.collection,types:a,compile:d,getCollectionFields:l}),I=d(S.title)||u;return k.length?{key:u,value:u,label:I,title:I,children:k}:null}).filter(Boolean);return g.length?{[c.value]:r,[c.label]:t,[c.children]:g}:null}useInitializers(r){var c;const{getCollection:t}=e.useCollectionManager(),i=Object.keys((c=r.config.forms)!=null?c:{});if(!i.length||r.config.mode)return null;const a=i.map(d=>{var g,x;const l=r.config.forms[d],{fields:f=[]}=t(l.collection);return f.length?{name:(g=l.title)!=null?g:d,type:"item",title:(x=l.title)!=null?x:d,Component:p.CollectionBlockInitializer,collection:l.collection,dataSource:`{{$jobsMapByNodeKey.${r.key}.${d}}}`}:null}).filter(Boolean);return a.length?{name:`#${r.id}`,key:"forms",type:"subMenu",title:r.title,children:a}:null}}const Pe={title:`{{t("Task", { ns: "${C}" })}}`,name:"flow_nodes",fields:[{type:"bigInt",name:"id",interface:"m2o",uiSchema:{type:"number",title:"ID","x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"flow_nodes",params:{filter:{type:"manual"}}}}}},{type:"string",name:"title",interface:"input",uiSchema:{type:"string",title:'{{t("Title")}}',"x-component":"Input"}}]},Ve={title:`{{t("Workflow", { ns: "${C}" })}}`,name:"workflows",fields:[{type:"string",name:"title",interface:"input",uiSchema:{title:'{{t("Name")}}',type:"string","x-component":"Input",required:!0}}]},je={title:`{{t("Workflow todos", { ns: "${C}" })}}`,name:"users_jobs",fields:[{type:"belongsTo",name:"user",target:"users",foreignKey:"userId",interface:"m2o",uiSchema:{type:"number",title:'{{t("User")}}',"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"nickname",value:"id"},service:{resource:"users"}}}},{type:"belongsTo",name:"node",target:"flow_nodes",foreignKey:"nodeId",interface:"m2o",isAssociation:!0,uiSchema:{type:"number",title:`{{t("Task", { ns: "${C}" })}}`,"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"flow_nodes"}}}},{type:"belongsTo",name:"workflow",target:"workflows",foreignKey:"workflowId",interface:"m2o",uiSchema:{type:"number",title:`{{t("Workflow", { ns: "${C}" })}}`,"x-component":"RemoteSelect","x-component-props":{fieldNames:{label:"title",value:"id"},service:{resource:"workflows"}}}},{type:"integer",name:"status",interface:"select",uiSchema:{type:"number",title:`{{t("Status", { ns: "${C}" })}}`,"x-component":"Select",enum:p.JobStatusOptions}},{name:"createdAt",type:"date",interface:"createdAt",uiSchema:{type:"datetime",title:'{{t("Created at")}}',"x-component":"DatePicker","x-component-props":{showTime:!0}}}]},Ne=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.title)!=null?t:`#${(r=o.value)==null?void 0:r.id}`},{displayName:"NodeColumn"}),$e=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.title)!=null?t:`#${(r=o.value)==null?void 0:r.id}`},{displayName:"WorkflowColumn"}),Ee=b.observer(()=>{var n,r,t;const o=b.useField();return(t=(n=o==null?void 0:o.value)==null?void 0:n.nickname)!=null?t:(r=o.value)==null?void 0:r.id},{displayName:"UserColumn"}),K=()=>s.jsx(e.SchemaComponent,{components:{NodeColumn:Ne,WorkflowColumn:$e,UserColumn:Ee},schema:{type:"void",properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{filter:{type:"void",title:'{{ t("Filter") }}',"x-action":"filter","x-designer":"Filter.Action.Designer","x-component":"Filter.Action","x-component-props":{icon:"FilterOutlined",useProps:"{{ useFilterActionProps }}"},"x-align":"left"},refresher:{type:"void",title:'{{ t("Refresh") }}',"x-action":"refresh","x-component":"Action","x-designer":"Action.Designer","x-component-props":{icon:"ReloadOutlined",useProps:"{{ useRefreshActionProps }}"},"x-align":"right"}}},table:{type:"array","x-component":"TableV2","x-component-props":{rowKey:"id",useProps:"{{ useTableBlockProps }}"},properties:{node:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Task", { ns: "${C}" })}}`,properties:{node:{"x-component":"NodeColumn","x-read-pretty":!0}}},workflow:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Workflow", { ns: "${C}" })}}`,properties:{workflow:{"x-component":"WorkflowColumn","x-read-pretty":!0}}},createdAt:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{createdAt:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},user:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:`{{t("Assignee", { ns: "${C}" })}}`,properties:{user:{"x-component":"UserColumn","x-read-pretty":!0}}},status:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",properties:{status:{"x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void","x-decorator":"TableV2.Column.Decorator","x-component":"TableV2.Column",title:'{{t("Actions")}}',properties:{view:{type:"void","x-component":"Action.Link",title:'{{t("View")}}',properties:{drawer:{"x-component":"WorkflowTodo.Drawer"}}}}}}}}}});function qe(o){var f;const{data:n}=e.useCurrentUserContext(),{userJob:r}=p.useFlowContext(),{status:t,result:i,userId:a}=r,c=b.useFieldSchema(),{name:d}=c.parent.toJSON();let{children:l}=o;return t?i[d]||(l=null):((f=n==null?void 0:n.data)==null?void 0:f.id)!==a&&(l=null),l}const Ue=m.createContext(null);function _e({value:o,children:n}){const{userJob:r}=p.useFlowContext(),t=b.useField(),i=b.useFieldSchema();return m.useEffect(()=>{r.status&&(t.disabled=!0,t.visible=r.status===o&&r.result._===i.name)},[r,o,t,i.name]),s.jsx(Ue.Provider,{value:o,children:n})}function Ge(){const o=e.useAPIClient(),{setVisible:n}=e.useActionContext(),{values:r,submit:t}=b.useForm(),i=b.useFieldSchema(),{service:a}=e.useTableBlockContext(),{userJob:c}=p.useFlowContext(),{name:d}=i,{name:l}=i.parent.parent;return{run(){return E(this,null,function*(){c.status||(yield t(),yield o.resource("users_jobs").submit({filterByTk:c.id,values:{result:{[l]:r,_:d}}}),n(!1),a.refresh())})}}}function Je(o){var g;const n=e.usePlugin(p),r=e.useAPIClient(),{id:t}=e.useRecord(),[i,a]=m.useState(null),[c,d]=m.useState(null);m.useEffect(()=>{var x,u;t&&((u=(x=r.resource("users_jobs")).get)==null||u.call(x,{filterByTk:t,appends:["node","workflow","workflow.nodes","execution","execution.jobs"]}).then(({data:S})=>{var w;const D=(w=S==null?void 0:S.data)!=null?w:{},{node:k,workflow:N={}}=D,oe=N,{nodes:I=[]}=oe,A=M(oe,["nodes"]),te=D,{execution:O}=te,z=M(te,["node","workflow","execution"]);p.linkNodes(I),d(k),a({userJob:z,workflow:A,nodes:I,execution:O})}))},[r,t]);const f=p.useAvailableUpstreams(i==null?void 0:i.nodes.find(x=>x.id===c.id)).reduce((x,{type:u})=>Object.assign(x,n.instructions.get(u).components),{});return c&&i?s.jsx(p.FlowContext.Provider,{value:i,children:s.jsx(e.SchemaComponent,{components:y(y({FormBlockProvider:Y,DetailsBlockProvider:Q,ActionBarProvider:qe,ManualActionStatusProvider:_e},Array.from(V.getValues()).reduce((x,u)=>Object.assign(x,u.block.components),{})),f),scope:y({useSubmit:Ge,useFormBlockProps:Ke,useDetailsBlockProps:Le},Array.from(V.getValues()).reduce((x,u)=>Object.assign(x,u.block.scope),{})),schema:{type:"void",name:"tabs","x-component":"Tabs",properties:(g=c.config)==null?void 0:g.schema}})}):s.jsx(v.Spin,{})}function Ke(){var a;const{userJob:o}=p.useFlowContext(),n=e.useRecord(),{data:r}=e.useCurrentUserContext(),{form:t}=e.useFormBlockContext(),i=o.status?n?"readPretty":"disabled":((a=r==null?void 0:r.data)==null?void 0:a.id)!==o.userId?"disabled":"editable";return m.useEffect(()=>{t==null||t.setPattern(i)},[i,t]),{form:t}}function Le(){const{form:o}=e.useFormBlockContext();return{form:o}}function Qe(){const o=e.useCompile(),{status:n,updatedAt:r}=e.useRecord(),t=p.JobStatusOptionsMap[n];return n?s.jsxs(v.Space,{children:[s.jsx("time",{className:e.css`
|
|
12
12
|
margin-right: 0.5em;
|
|
13
|
-
`,children:se(r).format("YYYY-MM-DD HH:mm:ss")}),s.jsx(v.Tag,{icon:t.icon,color:t.color,children:o(t.label)})]}):null}function Ye(){var a;const o=m.useContext(e.SchemaComponentContext),{id:n,node:r,workflow:t,status:i}=e.useRecord();return s.jsx(e.SchemaComponentContext.Provider,{value:F(y({},o),{reset(){},designable:!1}),children:s.jsx(e.SchemaComponent,{components:{FooterStatus:Qe,FlowContextProvider:Je},schema:{type:"void",name:`drawer-${n}-${i}`,"x-component":"Action.Drawer","x-component-props":{className:"nb-action-popup"},title:`${t.title} - ${(a=r.title)!=null?a:`#${r.id}`}`,properties:{tabs:{type:"void","x-component":"FlowContextProvider"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{content:{type:"void","x-component":"FooterStatus"}}}}}})})}function He({params:o={},children:n}){const a=e.useCollectionManager(),{collections:r}=a,t=M(a,["collections"]),i={collection:"users_jobs",resource:"users_jobs",action:"list",params:F(y({pageSize:20,sort:["-createdAt"]},o),{appends:["user","node","workflow"],except:["node.config","workflow.config","workflow.options"]}),rowKey:"id",showIndex:!0,dragSort:!1};return s.jsx(e.CollectionManagerProvider,F(y({},t),{collections:[...r,Pe,Ve,je],children:s.jsx(e.TableBlockProvider,F(y({name:"workflow-todo"},i),{children:n}))}))}K.Drawer=Ye,K.Decorator=He;const Xe=()=>{const o=e.useSchemaInitializerItem(),{insert:n}=e.useSchemaInitializer();return s.jsx(e.SchemaInitializerItem,F(y({icon:s.jsx(
|
|
13
|
+
`,children:se(r).format("YYYY-MM-DD HH:mm:ss")}),s.jsx(v.Tag,{icon:t.icon,color:t.color,children:o(t.label)})]}):null}function Ye(){var a;const o=m.useContext(e.SchemaComponentContext),{id:n,node:r,workflow:t,status:i}=e.useRecord();return s.jsx(e.SchemaComponentContext.Provider,{value:F(y({},o),{reset(){},designable:!1}),children:s.jsx(e.SchemaComponent,{components:{FooterStatus:Qe,FlowContextProvider:Je},schema:{type:"void",name:`drawer-${n}-${i}`,"x-component":"Action.Drawer","x-component-props":{className:"nb-action-popup"},title:`${t.title} - ${(a=r.title)!=null?a:`#${r.id}`}`,properties:{tabs:{type:"void","x-component":"FlowContextProvider"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{content:{type:"void","x-component":"FooterStatus"}}}}}})})}function He({params:o={},children:n}){const a=e.useCollectionManager(),{collections:r}=a,t=M(a,["collections"]),i={collection:"users_jobs",resource:"users_jobs",action:"list",params:F(y({pageSize:20,sort:["-createdAt"]},o),{appends:["user","node","workflow"],except:["node.config","workflow.config","workflow.options"]}),rowKey:"id",showIndex:!0,dragSort:!1};return s.jsx(e.CollectionManagerProvider,F(y({},t),{collections:[...r,Pe,Ve,je],children:s.jsx(e.TableBlockProvider,F(y({name:"workflow-todo"},i),{children:n}))}))}K.Drawer=Ye,K.Decorator=He;const Xe=()=>{const o=e.useSchemaInitializerItem(),{insert:n}=e.useSchemaInitializer();return s.jsx(e.SchemaInitializerItem,F(y({icon:s.jsx(_.TableOutlined,{})},o),{onClick:()=>{n({type:"void","x-decorator":"WorkflowTodo.Decorator","x-decorator-props":{},"x-component":"CardItem","x-designer":"TableBlockDesigner",properties:{todos:{type:"void","x-component":"WorkflowTodo"}}})}}))};class Ze extends e.Plugin{afterAdd(){return E(this,null,function*(){})}load(){return E(this,null,function*(){this.addComponents();const n=this.app.pm.get("workflow"),r=new Me;n.instructions.register(r.type,r),this.app.schemaInitializerManager.add(ve),this.app.schemaInitializerManager.add(Ae),this.app.schemaInitializerManager.add(he),this.app.schemaInitializerManager.get("BlockInitializers").add("otherBlocks.workflowTodos",{title:`{{t("Workflow todos", { ns: "${C}" })}}`,Component:"WorkflowTodoBlockInitializer",icon:"CheckSquareOutlined"})})}addComponents(){this.app.addComponents({WorkflowTodo:K,WorkflowTodoBlockInitializer:Xe})}}h.default=Ze,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -3,16 +3,16 @@ module.exports = {
|
|
|
3
3
|
"@formily/react": "2.3.0",
|
|
4
4
|
"antd": "5.12.2",
|
|
5
5
|
"dayjs": "1.11.10",
|
|
6
|
-
"@nocobase/client": "0.18.0-alpha.
|
|
7
|
-
"@nocobase/plugin-workflow": "0.18.0-alpha.
|
|
6
|
+
"@nocobase/client": "0.18.0-alpha.9",
|
|
7
|
+
"@nocobase/plugin-workflow": "0.18.0-alpha.9",
|
|
8
8
|
"@ant-design/icons": "5.2.6",
|
|
9
9
|
"react-i18next": "11.18.6",
|
|
10
|
-
"@nocobase/utils": "0.18.0-alpha.
|
|
11
|
-
"@nocobase/server": "0.18.0-alpha.
|
|
12
|
-
"@nocobase/actions": "0.18.0-alpha.
|
|
13
|
-
"@nocobase/resourcer": "0.18.0-alpha.
|
|
10
|
+
"@nocobase/utils": "0.18.0-alpha.9",
|
|
11
|
+
"@nocobase/server": "0.18.0-alpha.9",
|
|
12
|
+
"@nocobase/actions": "0.18.0-alpha.9",
|
|
13
|
+
"@nocobase/resourcer": "0.18.0-alpha.9",
|
|
14
14
|
"@formily/core": "2.3.0",
|
|
15
15
|
"@formily/antd-v5": "1.1.9",
|
|
16
|
-
"@nocobase/database": "0.18.0-alpha.
|
|
16
|
+
"@nocobase/database": "0.18.0-alpha.9",
|
|
17
17
|
"lodash": "4.17.21"
|
|
18
18
|
};
|
|
@@ -19,9 +19,9 @@ export interface ManualConfig {
|
|
|
19
19
|
mode?: number;
|
|
20
20
|
}
|
|
21
21
|
export default class extends Instruction {
|
|
22
|
-
|
|
22
|
+
workflow: WorkflowPlugin;
|
|
23
23
|
formTypes: Registry<FormHandler>;
|
|
24
|
-
constructor(
|
|
24
|
+
constructor(workflow: WorkflowPlugin);
|
|
25
25
|
run(node: any, prevJob: any, processor: Processor): Promise<any>;
|
|
26
26
|
resume(node: any, job: any, processor: Processor): Promise<any>;
|
|
27
27
|
}
|
|
@@ -92,9 +92,9 @@ function getMode(mode) {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
95
|
-
constructor(
|
|
96
|
-
super(
|
|
97
|
-
this.
|
|
95
|
+
constructor(workflow) {
|
|
96
|
+
super(workflow);
|
|
97
|
+
this.workflow = workflow;
|
|
98
98
|
(0, import_forms.default)(this);
|
|
99
99
|
}
|
|
100
100
|
formTypes = new import_utils.Registry();
|
|
@@ -107,7 +107,7 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
107
107
|
nodeId: node.id,
|
|
108
108
|
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
|
|
109
109
|
});
|
|
110
|
-
const UserJobModel =
|
|
110
|
+
const UserJobModel = this.workflow.app.db.getModel("users_jobs");
|
|
111
111
|
await UserJobModel.bulkCreate(
|
|
112
112
|
assignees.map((userId) => ({
|
|
113
113
|
userId,
|
|
@@ -118,7 +118,7 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
118
118
|
status: import_plugin_workflow.JOB_STATUS.PENDING
|
|
119
119
|
})),
|
|
120
120
|
{
|
|
121
|
-
transaction: processor.transaction
|
|
121
|
+
// transaction: processor.transaction,
|
|
122
122
|
}
|
|
123
123
|
);
|
|
124
124
|
return job;
|
|
@@ -126,13 +126,13 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
126
126
|
async resume(node, job, processor) {
|
|
127
127
|
var _a;
|
|
128
128
|
const { assignees = [], mode } = node.config;
|
|
129
|
-
const UserJobModel =
|
|
129
|
+
const UserJobModel = this.workflow.app.db.getModel("users_jobs");
|
|
130
130
|
const distribution = await UserJobModel.count({
|
|
131
131
|
where: {
|
|
132
132
|
jobId: job.id
|
|
133
133
|
},
|
|
134
|
-
group: ["status"]
|
|
135
|
-
transaction: processor.transaction
|
|
134
|
+
group: ["status"]
|
|
135
|
+
// transaction: processor.transaction,
|
|
136
136
|
});
|
|
137
137
|
const submitted = distribution.reduce(
|
|
138
138
|
(count, item) => item.status !== import_plugin_workflow.JOB_STATUS.PENDING ? count + item.count : count,
|
package/dist/server/Plugin.d.ts
CHANGED
package/dist/server/Plugin.js
CHANGED
|
@@ -32,14 +32,13 @@ __export(Plugin_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(Plugin_exports);
|
|
33
33
|
var import_server = require("@nocobase/server");
|
|
34
34
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
35
|
-
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
36
|
-
var import_jobs = __toESM(require("./
|
|
37
|
-
var import_users = __toESM(require("./
|
|
38
|
-
var import_users_jobs = __toESM(require("./
|
|
35
|
+
var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
|
|
36
|
+
var import_jobs = __toESM(require("./collections/jobs"));
|
|
37
|
+
var import_users = __toESM(require("./collections/users"));
|
|
38
|
+
var import_users_jobs = __toESM(require("./collections/users_jobs"));
|
|
39
39
|
var import_actions2 = require("./actions");
|
|
40
40
|
var import_ManualInstruction = __toESM(require("./ManualInstruction"));
|
|
41
41
|
class Plugin_default extends import_server.Plugin {
|
|
42
|
-
workflow;
|
|
43
42
|
async load() {
|
|
44
43
|
this.app.db.collection(import_users_jobs.default);
|
|
45
44
|
this.app.db.extendCollection(import_users.default);
|
|
@@ -66,8 +65,8 @@ class Plugin_default extends import_server.Plugin {
|
|
|
66
65
|
submit: import_actions2.submit
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
workflowPlugin.
|
|
68
|
+
this.app.acl.allow("users_jobs", ["list", "get", "submit"], "loggedIn");
|
|
69
|
+
const workflowPlugin = this.app.getPlugin(import_plugin_workflow.default);
|
|
70
|
+
workflowPlugin.registerInstruction("manual", import_ManualInstruction.default);
|
|
72
71
|
}
|
|
73
72
|
}
|
package/dist/server/actions.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
var actions_exports = {};
|
|
19
29
|
__export(actions_exports, {
|
|
@@ -21,7 +31,7 @@ __export(actions_exports, {
|
|
|
21
31
|
});
|
|
22
32
|
module.exports = __toCommonJS(actions_exports);
|
|
23
33
|
var import_actions = require("@nocobase/actions");
|
|
24
|
-
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
34
|
+
var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
|
|
25
35
|
async function submit(context, next) {
|
|
26
36
|
var _a, _b, _c;
|
|
27
37
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
@@ -30,7 +40,7 @@ async function submit(context, next) {
|
|
|
30
40
|
if (!currentUser) {
|
|
31
41
|
return context.throw(401);
|
|
32
42
|
}
|
|
33
|
-
const plugin = context.app.
|
|
43
|
+
const plugin = context.app.getPlugin(import_plugin_workflow.default);
|
|
34
44
|
const instruction = plugin.instructions.get("manual");
|
|
35
45
|
const userJob = await repository.findOne({
|
|
36
46
|
filterByTk,
|
|
@@ -78,7 +88,7 @@ async function submit(context, next) {
|
|
|
78
88
|
if (handler && userJob.status) {
|
|
79
89
|
await handler.call(instruction, userJob, forms[formKey], processor);
|
|
80
90
|
}
|
|
81
|
-
await userJob.save(
|
|
91
|
+
await userJob.save();
|
|
82
92
|
await processor.exit();
|
|
83
93
|
context.body = userJob;
|
|
84
94
|
context.status = 202;
|
|
@@ -21,7 +21,7 @@ __export(create_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(create_exports);
|
|
23
23
|
async function create_default(instance, { collection }, processor) {
|
|
24
|
-
const repo = this.
|
|
24
|
+
const repo = this.workflow.db.getRepository(collection);
|
|
25
25
|
if (!repo) {
|
|
26
26
|
throw new Error(`collection ${collection} for create data on manual node not found`);
|
|
27
27
|
}
|
|
@@ -35,7 +35,7 @@ async function create_default(instance, { collection }, processor) {
|
|
|
35
35
|
},
|
|
36
36
|
context: {
|
|
37
37
|
executionId: processor.execution.id
|
|
38
|
-
}
|
|
39
|
-
transaction: processor.transaction
|
|
38
|
+
}
|
|
39
|
+
// transaction: processor.transaction,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -21,7 +21,7 @@ __export(update_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(update_exports);
|
|
23
23
|
async function update_default(instance, { collection, filter = {} }, processor) {
|
|
24
|
-
const repo = this.
|
|
24
|
+
const repo = this.workflow.db.getRepository(collection);
|
|
25
25
|
if (!repo) {
|
|
26
26
|
throw new Error(`collection ${collection} for update data on manual node not found`);
|
|
27
27
|
}
|
|
@@ -35,7 +35,7 @@ async function update_default(instance, { collection, filter = {} }, processor)
|
|
|
35
35
|
},
|
|
36
36
|
context: {
|
|
37
37
|
executionId: processor.execution.id
|
|
38
|
-
}
|
|
39
|
-
transaction: processor.transaction
|
|
38
|
+
}
|
|
39
|
+
// transaction: processor.transaction,
|
|
40
40
|
});
|
|
41
41
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "工作流:人工处理节点",
|
|
5
5
|
"description": "Could be used for workflows which some of decisions are made by users.",
|
|
6
6
|
"description.zh-CN": "用于人工控制部分决策的流程。",
|
|
7
|
-
"version": "0.18.0-alpha.
|
|
7
|
+
"version": "0.18.0-alpha.9",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"devDependencies": {
|
|
@@ -24,10 +24,9 @@
|
|
|
24
24
|
"@nocobase/plugin-collection-manager": "0.x",
|
|
25
25
|
"@nocobase/plugin-users": "0.x",
|
|
26
26
|
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
27
|
-
"@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
|
|
28
27
|
"@nocobase/server": "0.x",
|
|
29
28
|
"@nocobase/test": "0.x",
|
|
30
29
|
"@nocobase/utils": "0.x"
|
|
31
30
|
},
|
|
32
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "34ca0df4eede2e83fc86297b0fe19eba970e2b1b"
|
|
33
32
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React, { useRef, useMemo, useContext } from 'react';
|
|
2
1
|
import { createForm } from '@formily/core';
|
|
3
2
|
import { useField } from '@formily/react';
|
|
4
3
|
import {
|
|
@@ -9,8 +8,9 @@ import {
|
|
|
9
8
|
useAPIClient,
|
|
10
9
|
useAssociationNames,
|
|
11
10
|
} from '@nocobase/client';
|
|
12
|
-
import { parse } from '@nocobase/utils/client';
|
|
13
11
|
import { useFlowContext } from '@nocobase/plugin-workflow/client';
|
|
12
|
+
import { parse } from '@nocobase/utils/client';
|
|
13
|
+
import React, { useContext, useMemo, useRef } from 'react';
|
|
14
14
|
|
|
15
15
|
function useFlowContextData(dataSource) {
|
|
16
16
|
const { execution, nodes } = useFlowContext();
|
|
@@ -37,7 +37,8 @@ function useFlowContextData(dataSource) {
|
|
|
37
37
|
export function DetailsBlockProvider(props) {
|
|
38
38
|
const field = useField();
|
|
39
39
|
const formBlockRef = useRef(null);
|
|
40
|
-
const {
|
|
40
|
+
const { getAssociationAppends } = useAssociationNames();
|
|
41
|
+
const { appends, updateAssociationValues } = getAssociationAppends();
|
|
41
42
|
const values = useFlowContextData(props.dataSource);
|
|
42
43
|
|
|
43
44
|
const form = useMemo(
|
|
@@ -19,7 +19,8 @@ export function FormBlockProvider(props) {
|
|
|
19
19
|
const fieldSchema = useFieldSchema();
|
|
20
20
|
const field = useField();
|
|
21
21
|
const formBlockRef = useRef(null);
|
|
22
|
-
const {
|
|
22
|
+
const { getAssociationAppends } = useAssociationNames();
|
|
23
|
+
const { appends, updateAssociationValues } = getAssociationAppends();
|
|
23
24
|
const [formKey] = Object.keys(fieldSchema.toJSON().properties ?? {});
|
|
24
25
|
const values = userJob?.result?.[formKey];
|
|
25
26
|
|
|
@@ -85,8 +85,8 @@ function getMode(mode) {
|
|
|
85
85
|
export default class extends Instruction {
|
|
86
86
|
formTypes = new Registry<FormHandler>();
|
|
87
87
|
|
|
88
|
-
constructor(public
|
|
89
|
-
super(
|
|
88
|
+
constructor(public workflow: WorkflowPlugin) {
|
|
89
|
+
super(workflow);
|
|
90
90
|
|
|
91
91
|
initFormTypes(this);
|
|
92
92
|
}
|
|
@@ -103,7 +103,7 @@ export default class extends Instruction {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
// NOTE: batch create users jobs
|
|
106
|
-
const UserJobModel =
|
|
106
|
+
const UserJobModel = this.workflow.app.db.getModel('users_jobs');
|
|
107
107
|
await UserJobModel.bulkCreate(
|
|
108
108
|
assignees.map((userId) => ({
|
|
109
109
|
userId,
|
|
@@ -114,7 +114,7 @@ export default class extends Instruction {
|
|
|
114
114
|
status: JOB_STATUS.PENDING,
|
|
115
115
|
})),
|
|
116
116
|
{
|
|
117
|
-
transaction: processor.transaction,
|
|
117
|
+
// transaction: processor.transaction,
|
|
118
118
|
},
|
|
119
119
|
);
|
|
120
120
|
|
|
@@ -125,13 +125,13 @@ export default class extends Instruction {
|
|
|
125
125
|
// NOTE: check all users jobs related if all done then continue as parallel
|
|
126
126
|
const { assignees = [], mode } = node.config as ManualConfig;
|
|
127
127
|
|
|
128
|
-
const UserJobModel =
|
|
128
|
+
const UserJobModel = this.workflow.app.db.getModel('users_jobs');
|
|
129
129
|
const distribution = await UserJobModel.count({
|
|
130
130
|
where: {
|
|
131
131
|
jobId: job.id,
|
|
132
132
|
},
|
|
133
133
|
group: ['status'],
|
|
134
|
-
transaction: processor.transaction,
|
|
134
|
+
// transaction: processor.transaction,
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const submitted = distribution.reduce(
|
package/src/server/Plugin.ts
CHANGED
|
@@ -3,16 +3,14 @@ import actions from '@nocobase/actions';
|
|
|
3
3
|
import { HandlerType } from '@nocobase/resourcer';
|
|
4
4
|
import WorkflowPlugin, { JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
5
5
|
|
|
6
|
-
import jobsCollection from './
|
|
7
|
-
import usersCollection from './
|
|
8
|
-
import usersJobsCollection from './
|
|
6
|
+
import jobsCollection from './collections/jobs';
|
|
7
|
+
import usersCollection from './collections/users';
|
|
8
|
+
import usersJobsCollection from './collections/users_jobs';
|
|
9
9
|
import { submit } from './actions';
|
|
10
10
|
|
|
11
11
|
import ManualInstruction from './ManualInstruction';
|
|
12
12
|
|
|
13
13
|
export default class extends Plugin {
|
|
14
|
-
workflow: WorkflowPlugin;
|
|
15
|
-
|
|
16
14
|
async load() {
|
|
17
15
|
this.app.db.collection(usersJobsCollection);
|
|
18
16
|
this.app.db.extendCollection(usersCollection);
|
|
@@ -41,8 +39,9 @@ export default class extends Plugin {
|
|
|
41
39
|
},
|
|
42
40
|
});
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
workflowPlugin.
|
|
42
|
+
this.app.acl.allow('users_jobs', ['list', 'get', 'submit'], 'loggedIn');
|
|
43
|
+
|
|
44
|
+
const workflowPlugin = this.app.getPlugin<WorkflowPlugin>(WorkflowPlugin);
|
|
45
|
+
workflowPlugin.registerInstruction('manual', ManualInstruction);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Database from '@nocobase/database';
|
|
2
|
-
import UserPlugin from '@nocobase/plugin-users';
|
|
3
2
|
import { MockServer } from '@nocobase/test';
|
|
4
3
|
import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
5
4
|
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
|
@@ -38,7 +37,6 @@ describe('workflow > instructions > manual', () => {
|
|
|
38
37
|
{ id: 2, nickname: 'b' },
|
|
39
38
|
]);
|
|
40
39
|
|
|
41
|
-
const userPlugin = app.getPlugin('users') as UserPlugin;
|
|
42
40
|
userAgents = users.map((user) => app.agent().login(user));
|
|
43
41
|
|
|
44
42
|
workflow = await WorkflowModel.create({
|
package/src/server/actions.ts
CHANGED
|
@@ -12,7 +12,7 @@ export async function submit(context: Context, next) {
|
|
|
12
12
|
return context.throw(401);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const plugin: WorkflowPlugin = context.app.
|
|
15
|
+
const plugin: WorkflowPlugin = context.app.getPlugin(WorkflowPlugin);
|
|
16
16
|
const instruction = plugin.instructions.get('manual') as ManualInstruction;
|
|
17
17
|
|
|
18
18
|
const userJob = await repository.findOne({
|
|
@@ -81,7 +81,7 @@ export async function submit(context: Context, next) {
|
|
|
81
81
|
await handler.call(instruction, userJob, forms[formKey], processor);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
await userJob.save(
|
|
84
|
+
await userJob.save();
|
|
85
85
|
|
|
86
86
|
await processor.exit();
|
|
87
87
|
|
|
@@ -2,7 +2,7 @@ import { Processor } from '@nocobase/plugin-workflow';
|
|
|
2
2
|
import ManualInstruction from '../ManualInstruction';
|
|
3
3
|
|
|
4
4
|
export default async function (this: ManualInstruction, instance, { collection }, processor: Processor) {
|
|
5
|
-
const repo = this.
|
|
5
|
+
const repo = this.workflow.db.getRepository(collection);
|
|
6
6
|
if (!repo) {
|
|
7
7
|
throw new Error(`collection ${collection} for create data on manual node not found`);
|
|
8
8
|
}
|
|
@@ -18,6 +18,6 @@ export default async function (this: ManualInstruction, instance, { collection }
|
|
|
18
18
|
context: {
|
|
19
19
|
executionId: processor.execution.id,
|
|
20
20
|
},
|
|
21
|
-
transaction: processor.transaction,
|
|
21
|
+
// transaction: processor.transaction,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -2,7 +2,7 @@ import { Processor } from '@nocobase/plugin-workflow';
|
|
|
2
2
|
import ManualInstruction from '../ManualInstruction';
|
|
3
3
|
|
|
4
4
|
export default async function (this: ManualInstruction, instance, { collection, filter = {} }, processor: Processor) {
|
|
5
|
-
const repo = this.
|
|
5
|
+
const repo = this.workflow.db.getRepository(collection);
|
|
6
6
|
if (!repo) {
|
|
7
7
|
throw new Error(`collection ${collection} for update data on manual node not found`);
|
|
8
8
|
}
|
|
@@ -18,6 +18,6 @@ export default async function (this: ManualInstruction, instance, { collection,
|
|
|
18
18
|
context: {
|
|
19
19
|
executionId: processor.execution.id,
|
|
20
20
|
},
|
|
21
|
-
transaction: processor.transaction,
|
|
21
|
+
// transaction: processor.transaction,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|