@nocobase/plugin-action-custom-request 1.0.0-alpha.9 → 1.0.1-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.
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
(function(t,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("react/jsx-runtime"),require("@nocobase/client"),require("@formily/react"),require("@nocobase/utils/client"),require("antd"),require("react-router-dom"),require("react"),require("react-i18next"),require("@formily/antd-v5"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@nocobase/client","@formily/react","@nocobase/utils/client","antd","react-router-dom","react","react-i18next","@formily/antd-v5","@formily/shared"],n):(t=typeof globalThis!="undefined"?globalThis:t||self,n(t["@nocobase/plugin-action-custom-request"]={},t.jsxRuntime,t["@nocobase/client"],t["@formily/react"],t["@nocobase/utils"],t.antd,t["react-router-dom"],t.react,t["react-i18next"],t["@formily/antd-v5"],t["@formily/shared"]))})(this,function(t,n,e,c,I,O,D,A,R,E,ee){"use strict";var de=Object.defineProperty,fe=Object.defineProperties;var ye=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var Y=(t,n,e)=>n in t?de(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,q=(t,n)=>{for(var e in n||(n={}))$.call(n,e)&&Y(t,e,n[e]);if(M)for(var e of M(n))Q.call(n,e)&&Y(t,e,n[e]);return t},F=(t,n)=>fe(t,ye(n));var Z=(t,n)=>{var e={};for(var c in t)$.call(t,c)&&n.indexOf(c)<0&&(e[c]=t[c]);if(t!=null&&M)for(var c of M(t))n.indexOf(c)<0&&Q.call(t,c)&&(e[c]=t[c]);return e};var g=(t,n,e)=>new Promise((c,I)=>{var O=R=>{try{A(e.next(R))}catch(E){I(E)}},D=R=>{try{A(e.throw(R))}catch(E){I(E)}},A=R=>R.done?c(R.value):Promise.resolve(R.value).then(O,D);A((e=e.apply(t,n)).next())});const L="customRequests:listByCurrentRole";var P=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},z={exports:{}};(function(a,m){(function(l,i){i()})(P,function(){function l(o,r){return typeof r=="undefined"?r={autoBom:!1}:typeof r!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),r={autoBom:!r}),r.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(o.type)?new Blob(["\uFEFF",o],{type:o.type}):o}function i(o,r,h){var u=new XMLHttpRequest;u.open("GET",o),u.responseType="blob",u.onload=function(){v(u.response,r,h)},u.onerror=function(){console.error("could not download file")},u.send()}function d(o){var r=new XMLHttpRequest;r.open("HEAD",o,!1);try{r.send()}catch(h){}return 200<=r.status&&299>=r.status}function y(o){try{o.dispatchEvent(new MouseEvent("click"))}catch(h){var r=document.createEvent("MouseEvents");r.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),o.dispatchEvent(r)}}var p=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof P=="object"&&P.global===P?P:void 0,x=p.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),v=p.saveAs||(typeof window!="object"||window!==p?function(){}:"download"in HTMLAnchorElement.prototype&&!x?function(o,r,h){var u=p.URL||p.webkitURL,C=document.createElement("a");r=r||o.name||"download",C.download=r,C.rel="noopener",typeof o=="string"?(C.href=o,C.origin===location.origin?y(C):d(C.href)?i(o,r,h):y(C,C.target="_blank")):(C.href=u.createObjectURL(o),setTimeout(function(){u.revokeObjectURL(C.href)},4e4),setTimeout(function(){y(C)},0))}:"msSaveOrOpenBlob"in navigator?function(o,r,h){if(r=r||o.name||"download",typeof o!="string")navigator.msSaveOrOpenBlob(l(o,h),r);else if(d(o))i(o,r,h);else{var u=document.createElement("a");u.href=o,u.target="_blank",setTimeout(function(){y(u)})}}:function(o,r,h,u){if(u=u||open("","_blank"),u&&(u.document.title=u.document.body.innerText="downloading..."),typeof o=="string")return i(o,r,h);var C=o.type==="application/octet-stream",b=/constructor/i.test(p.HTMLElement)||p.safari,k=/CriOS\/[\d]+/.test(navigator.userAgent);if((k||C&&b||x)&&typeof FileReader!="undefined"){var s=new FileReader;s.onloadend=function(){var S=s.result;S=k?S:S.replace(/^data:[^;]*;/,"data:attachment/file;"),u?u.location.href=S:location=S,u=null},s.readAsDataURL(o)}else{var T=p.URL||p.webkitURL,w=T.createObjectURL(o);u?u.location=w:location.href=w,u=null,setTimeout(function(){T.revokeObjectURL(w)},4e4)}});p.saveAs=v.saveAs=v,a.exports=v})})(z);var te=z.exports;const oe=()=>{const a=e.useAPIClient(),m=D.useNavigate(),l=c.useFieldSchema(),i=e.useCompile(),d=c.useForm(),y=e.useRecord(),p=c.useFieldSchema(),x=c.useField(),{setVisible:v}=e.useActionContext(),{modal:o,message:r}=O.App.useApp(),h=e.useDataSourceKey();return{onClick(C,b){return g(this,null,function*(){var S,W;const{skipValidator:k,onSuccess:s}=(S=l==null?void 0:l["x-action-settings"])!=null?S:{},T=l==null?void 0:l["x-action"];k!==!0&&T==="customize:form:request"&&(yield d.submit());let w=q({},y);T==="customize:form:request"&&(w=d.values),(W=x.data)!=null||(x.data={}),x.data.loading=!0;try{const _=yield a.request({url:`/customRequests:send/${p["x-uid"]}`,method:"POST",data:{currentRecord:{dataSourceKey:h,data:w}},responseType:p["x-response-type"]==="stream"?"blob":"json"});if(_.headers["content-disposition"]){const pe=/attachment;\s*filename="([^"]+)"/,X=_.headers["content-disposition"].match(pe);X[1]&&te.saveAs(_.data,X[1])}if(x.data.loading=!1,b&&(b==null||b()),T==="customize:form:request"&&(v==null||v(!1)),!(s!=null&&s.successMessage))return;s!=null&&s.manualClose?o.success({title:i(s==null?void 0:s.successMessage),onOk:()=>g(this,null,function*(){s!=null&&s.redirecting&&(s!=null&&s.redirectTo)&&(I.isURL(s.redirectTo)?window.location.href=s.redirectTo:m(s.redirectTo))})}):(r.success(i(s==null?void 0:s.successMessage)),s!=null&&s.redirecting&&(s!=null&&s.redirectTo)&&(I.isURL(s.redirectTo)?window.location.href=s.redirectTo:m(s.redirectTo)))}finally{x.data.loading=!1}})}}},V=()=>{const m=`customRequests:get/${c.useFieldSchema()["x-uid"]}`;return e.useRequest({url:m,params:{appends:["roles"]}},{manual:!0,cacheKey:m})},B="action-custom-request";function f(a){return`{{t('${a}', { ns: '${B}', nsMode: 'fallback' })}}`}function U(){return R.useTranslation(B,{nsMode:"fallback"})}const se=()=>{const a=e.useCollection_deprecated(),{t:m}=U(),l=e.useCollectionFilterOptions(a),i=e.useCollectionFilterOptions("users",e.DEFAULT_DATA_SOURCE_KEY),d=e.useCompile(),[y,p]=A.useMemo(()=>[d(l),d(i)],[l,i]);return A.useMemo(()=>[{name:"currentRecord",title:m("Current record",{ns:"client"}),children:[...y]},{name:"currentUser",title:m("Current user",{ns:"client"}),children:p},{name:"currentTime",title:m("Current time",{ns:"client"}),children:null}],[y,p])},j=()=>e.useAPIClient().resource("customRequests"),K={type:"object",properties:{method:{type:"string",required:!0,title:f("HTTP method"),"x-decorator-props":{tooltip:f("When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data")},"x-decorator":"FormItem","x-component":"Select","x-component-props":{showSearch:!1,allowClear:!1,className:"auto-width"},enum:[{label:"GET",value:"GET"},{label:"POST",value:"POST"},{label:"PUT",value:"PUT"},{label:"PATCH",value:"PATCH"},{label:"DELETE",value:"DELETE"}],default:"POST"},url:{type:"string",required:!0,title:f("URL"),"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:"https://www.nocobase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:f("Headers"),description:f('"Content-Type" only support "application/json", and no need to specify'),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:f("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:f("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:f("Parameters"),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:f("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:f("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:f("Body"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Variable.JSON","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},changeOnSelect:!0,autoSize:{minRows:10},placeholder:f("Input request data")},description:f("Only support standard JSON data")},timeout:{type:"number",title:f("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:f("ms"),min:1,step:1e3,defaultValue:5e3}},responseType:{type:"string",title:f("Response type"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Select",default:"json",enum:[{value:"json",label:"JSON"},{value:"stream",label:"Stream"}]}}},ne={type:"object",properties:{roles:{type:"array",title:f("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:f("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,dataSource:e.DEFAULT_DATA_SOURCE_KEY,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function H(){var o;const{t:a}=U(),{name:m}=e.useCollection_deprecated(),l=e.useDataSourceKey(),i=c.useFieldSchema(),d=j(),{message:y}=O.App.useApp(),{data:p,refresh:x}=V(),{dn:v}=e.useDesignable();return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:a("Request settings"),components:{ArrayItems:E.ArrayItems},beforeOpen:()=>!p&&x(),scope:{useCustomRequestVariableOptions:se},schema:K,initialValues:q({},(o=p==null?void 0:p.data)==null?void 0:o.options),onSubmit:r=>g(this,null,function*(){const h=Z(r,[]);return i["x-response-type"]=h.responseType,yield d.updateOrCreate({values:{key:i["x-uid"],options:F(q({},h),{collectionName:m,dataSourceKey:l})},filterKeys:["key"]}),v.emit("patch",{schema:{"x-response-type":h.responseType,"x-uid":i["x-uid"]}}),x(),y.success(a("Saved successfully"))})})})}function G(){var x;const{t:a}=U(),m=c.useFieldSchema(),l=j(),{message:i}=O.App.useApp(),{data:d,refresh:y}=V(),{refresh:p}=e.useRequest({url:L},{manual:!0,cacheKey:L});return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:a("Access control"),schema:ne,initialValues:{roles:(x=d==null?void 0:d.data)==null?void 0:x.roles},beforeOpen:()=>!d&&y(),onSubmit:o=>g(this,[o],function*({roles:v}){return yield l.updateOrCreate({values:{key:m["x-uid"],roles:v},filterKeys:["key"]}),y(),p(),i.success(a("Saved successfully"))})})})}const re=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[F(q({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:H},{name:"accessControl",Component:G}]})]}),ae=()=>{const a=j(),m=c.useFieldSchema();return n.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:m["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return a.destroy({filterByTk:m["x-uid"]})}}})},ie=a=>{var y;const l=e.useAPIClient().auth.role==="root",i=c.useFieldSchema(),{data:d}=e.useRequest({url:L},{manual:l,cacheKey:L});return!l&&!((y=d==null?void 0:d.data)!=null&&y.includes(i==null?void 0:i["x-uid"]))?null:a.children},ue={"customize:table:request":e.Action.Link},N=a=>{const l=c.useFieldSchema()["x-action"],i=ue[l]||e.Action;return n.jsx(i,F(q({},a),{useProps:oe}))};N.Designer=ae,N.Decorator=ie;const ce=a=>{const m=j(),l={title:'{{ t("Custom request") }}',"x-component":"CustomRequestAction","x-action":"customize:form:request","x-toolbar":"ActionSchemaToolbar","x-settings":"actionSettings:customRequest","x-decorator":"CustomRequestAction.Decorator","x-uid":ee.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{t("Request success")}}'}}},i=e.useSchemaInitializerItem();return n.jsx(e.BlockInitializer,F(q({},i),{item:i,onClick:d=>g(this,null,function*(){yield m.create({values:{key:d["x-uid"]}})}),schema:l}))},me=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){return{isLink:c.useFieldSchema()["x-action"]==="customize:table:request"}}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:a}=e.useCollection(),{linkageRulesProps:m}=e.useSchemaToolbar();return F(q({},m),{collectionName:a})}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:e.AfterSuccess},{name:"request settings",Component:H},{name:"accessControl",Component:G},{name:"refreshDataBlockRequest",Component:e.RefreshDataBlockRequest,useComponentProps(){return{isPopupAction:!1}}},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:a}=e.useSchemaToolbar();return a}}]}),le=a=>n.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:K},components:{CustomRequestAction:N,CustomRequestInitializer:ce},children:a.children});class J extends e.Plugin{load(){return g(this,null,function*(){this.app.use(le),this.app.schemaSettingsManager.add(me),this.app.schemaSettingsManager.add(re)})}}t.PluginActionCustomRequestClient=J,t.default=J,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
10
|
+
(function(t,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("react/jsx-runtime"),require("@nocobase/client"),require("@formily/react"),require("@nocobase/utils/client"),require("antd"),require("react-router-dom"),require("react"),require("react-i18next"),require("@formily/antd-v5"),require("@formily/shared")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@nocobase/client","@formily/react","@nocobase/utils/client","antd","react-router-dom","react","react-i18next","@formily/antd-v5","@formily/shared"],n):(t=typeof globalThis!="undefined"?globalThis:t||self,n(t["@nocobase/plugin-action-custom-request"]={},t.jsxRuntime,t["@nocobase/client"],t["@formily/react"],t["@nocobase/utils"],t.antd,t["react-router-dom"],t.react,t["react-i18next"],t["@formily/antd-v5"],t["@formily/shared"]))})(this,function(t,n,e,l,F,O,D,g,S,E,_){"use strict";var fe=Object.defineProperty,he=Object.defineProperties;var ye=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var $=(t,n,e)=>n in t?fe(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e,q=(t,n)=>{for(var e in n||(n={}))Q.call(n,e)&&$(t,e,n[e]);if(M)for(var e of M(n))Z.call(n,e)&&$(t,e,n[e]);return t},I=(t,n)=>he(t,ye(n));var ee=(t,n)=>{var e={};for(var l in t)Q.call(t,l)&&n.indexOf(l)<0&&(e[l]=t[l]);if(t!=null&&M)for(var l of M(t))n.indexOf(l)<0&&Z.call(t,l)&&(e[l]=t[l]);return e};var A=(t,n,e)=>new Promise((l,F)=>{var O=S=>{try{g(e.next(S))}catch(E){F(E)}},D=S=>{try{g(e.throw(S))}catch(E){F(E)}},g=S=>S.done?l(S.value):Promise.resolve(S.value).then(O,D);g((e=e.apply(t,n)).next())});const L="customRequests:listByCurrentRole";var P=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},V={exports:{}};(function(a,p){(function(i,c){c()})(P,function(){function i(o,r){return typeof r=="undefined"?r={autoBom:!1}:typeof r!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),r={autoBom:!r}),r.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(o.type)?new Blob(["\uFEFF",o],{type:o.type}):o}function c(o,r,y){var m=new XMLHttpRequest;m.open("GET",o),m.responseType="blob",m.onload=function(){v(m.response,r,y)},m.onerror=function(){console.error("could not download file")},m.send()}function d(o){var r=new XMLHttpRequest;r.open("HEAD",o,!1);try{r.send()}catch(y){}return 200<=r.status&&299>=r.status}function f(o){try{o.dispatchEvent(new MouseEvent("click"))}catch(y){var r=document.createEvent("MouseEvents");r.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),o.dispatchEvent(r)}}var u=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof P=="object"&&P.global===P?P:void 0,x=u.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),v=u.saveAs||(typeof window!="object"||window!==u?function(){}:"download"in HTMLAnchorElement.prototype&&!x?function(o,r,y){var m=u.URL||u.webkitURL,C=document.createElement("a");r=r||o.name||"download",C.download=r,C.rel="noopener",typeof o=="string"?(C.href=o,C.origin===location.origin?f(C):d(C.href)?c(o,r,y):f(C,C.target="_blank")):(C.href=m.createObjectURL(o),setTimeout(function(){m.revokeObjectURL(C.href)},4e4),setTimeout(function(){f(C)},0))}:"msSaveOrOpenBlob"in navigator?function(o,r,y){if(r=r||o.name||"download",typeof o!="string")navigator.msSaveOrOpenBlob(i(o,y),r);else if(d(o))c(o,r,y);else{var m=document.createElement("a");m.href=o,m.target="_blank",setTimeout(function(){f(m)})}}:function(o,r,y,m){if(m=m||open("","_blank"),m&&(m.document.title=m.document.body.innerText="downloading..."),typeof o=="string")return c(o,r,y);var C=o.type==="application/octet-stream",b=/constructor/i.test(u.HTMLElement)||u.safari,k=/CriOS\/[\d]+/.test(navigator.userAgent);if((k||C&&b||x)&&typeof FileReader!="undefined"){var s=new FileReader;s.onloadend=function(){var R=s.result;R=k?R:R.replace(/^data:[^;]*;/,"data:attachment/file;"),m?m.location.href=R:location=R,m=null},s.readAsDataURL(o)}else{var T=u.URL||u.webkitURL,w=T.createObjectURL(o);m?m.location=w:location.href=w,m=null,setTimeout(function(){T.revokeObjectURL(w)},4e4)}});u.saveAs=v.saveAs=v,a.exports=v})})(V);var te=V.exports;const oe=()=>{const a=e.useAPIClient(),p=D.useNavigate(),i=l.useFieldSchema(),c=e.useCompile(),d=l.useForm(),f=e.useRecord(),u=l.useFieldSchema(),x=l.useField(),{setVisible:v}=e.useActionContext(),{modal:o,message:r}=O.App.useApp(),y=e.useDataSourceKey();return{onClick(C,b){return A(this,null,function*(){var R,X;const{skipValidator:k,onSuccess:s}=(R=i==null?void 0:i["x-action-settings"])!=null?R:{},T=i==null?void 0:i["x-action"];k!==!0&&T==="customize:form:request"&&(yield d.submit());let w=q({},f);T==="customize:form:request"&&(w=d.values),(X=x.data)!=null||(x.data={}),x.data.loading=!0;try{const z=yield a.request({url:`/customRequests:send/${u["x-uid"]}`,method:"POST",data:{currentRecord:{dataSourceKey:y,data:w}},responseType:u["x-response-type"]==="stream"?"blob":"json"});if(z.headers["content-disposition"]){const de=/attachment;\s*filename="([^"]+)"/,Y=z.headers["content-disposition"].match(de);Y[1]&&te.saveAs(z.data,Y[1])}if(x.data.loading=!1,b&&(b==null||b()),T==="customize:form:request"&&(v==null||v(!1)),!(s!=null&&s.successMessage))return;s!=null&&s.manualClose?o.success({title:c(s==null?void 0:s.successMessage),onOk:()=>A(this,null,function*(){s!=null&&s.redirecting&&(s!=null&&s.redirectTo)&&(F.isURL(s.redirectTo)?window.location.href=s.redirectTo:p(s.redirectTo))})}):(r.success(c(s==null?void 0:s.successMessage)),s!=null&&s.redirecting&&(s!=null&&s.redirectTo)&&(F.isURL(s.redirectTo)?window.location.href=s.redirectTo:p(s.redirectTo)))}finally{x.data.loading=!1}})}}},K=()=>{const p=`customRequests:get/${l.useFieldSchema()["x-uid"]}`;return e.useRequest({url:p,params:{appends:["roles"]}},{manual:!0,cacheKey:p})},B="action-custom-request";function h(a){return`{{t('${a}', { ns: '${B}', nsMode: 'fallback' })}}`}function U(){return S.useTranslation(B,{nsMode:"fallback"})}const se=()=>{const a=e.useCollection_deprecated(),{t:p}=U(),i=e.useCollectionFilterOptions(a),c=e.useCollectionFilterOptions("users",e.DEFAULT_DATA_SOURCE_KEY),d=e.useCompile(),[f,u]=g.useMemo(()=>[d(i),d(c)],[i,c]);return g.useMemo(()=>[{name:"currentRecord",title:p("Current record",{ns:"client"}),children:[...f]},{name:"currentUser",title:p("Current user",{ns:"client"}),children:u},{name:"currentTime",title:p("Current time",{ns:"client"}),children:null}],[f,u])},j=()=>e.useAPIClient().resource("customRequests"),H={type:"object",properties:{method:{type:"string",required:!0,title:h("HTTP method"),"x-decorator-props":{tooltip:h("When the HTTP method is Post, Put or Patch, and this custom request inside the form, the request body will be automatically filled in with the form data")},"x-decorator":"FormItem","x-component":"Select","x-component-props":{showSearch:!1,allowClear:!1,className:"auto-width"},enum:[{label:"GET",value:"GET"},{label:"POST",value:"POST"},{label:"PUT",value:"PUT"},{label:"PATCH",value:"PATCH"},{label:"DELETE",value:"DELETE"}],default:"POST"},url:{type:"string",required:!0,title:h("URL"),"x-decorator":"FormItem","x-component":"Variable.RawTextArea","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",autoSize:!0,fieldNames:{value:"name",label:"title"},placeholder:"https://www.nocobase.com"}},headers:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:h("Headers"),description:h('"Content-Type" only support "application/json", and no need to specify'),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:h("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:h("Add request header"),"x-component":"ArrayItems.Addition"}}},params:{type:"array","x-component":"ArrayItems","x-decorator":"FormItem",title:h("Parameters"),items:{type:"object",properties:{space:{type:"void","x-component":"Space",properties:{name:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:h("Name")}},value:{type:"string","x-decorator":"FormItem","x-component":"Variable.Input","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},useTypedConstant:!0}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:h("Add parameter"),"x-component":"ArrayItems.Addition"}}},data:{type:"string",title:h("Body"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Variable.JSON","x-component-props":{scope:"{{useCustomRequestVariableOptions}}",fieldNames:{value:"name",label:"title"},changeOnSelect:!0,autoSize:{minRows:10},placeholder:h("Input request data")},description:h("Only support standard JSON data")},timeout:{type:"number",title:h("Timeout config"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"InputNumber","x-component-props":{addonAfter:h("ms"),min:1,step:1e3,defaultValue:5e3}},responseType:{type:"string",title:h("Response type"),"x-decorator":"FormItem","x-decorator-props":{},"x-component":"Select",default:"json",enum:[{value:"json",label:"JSON"},{value:"stream",label:"Stream"}]}}},ne={type:"object",properties:{roles:{type:"array",title:h("Roles"),"x-decorator":"FormItem","x-decorator-props":{tooltip:h("If not set, all roles can see this action")},"x-component":"RemoteSelect","x-component-props":{multiple:!0,objectValue:!0,dataSource:e.DEFAULT_DATA_SOURCE_KEY,service:{resource:"roles"},manual:!1,fieldNames:{label:"title",value:"name"}}}}};function G(){var o;const{t:a}=U(),{name:p}=e.useCollection_deprecated(),i=e.useDataSourceKey(),c=l.useFieldSchema(),d=j(),{message:f}=O.App.useApp(),{data:u,refresh:x}=K(),{dn:v}=e.useDesignable();return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:a("Request settings"),components:{ArrayItems:E.ArrayItems},beforeOpen:()=>!u&&x(),scope:{useCustomRequestVariableOptions:se},schema:H,initialValues:q({},(o=u==null?void 0:u.data)==null?void 0:o.options),onSubmit:r=>A(this,null,function*(){const y=ee(r,[]);return c["x-response-type"]=y.responseType,yield d.updateOrCreate({values:{key:c["x-uid"],options:I(q({},y),{collectionName:p,dataSourceKey:i})},filterKeys:["key"]}),v.emit("patch",{schema:{"x-response-type":y.responseType,"x-uid":c["x-uid"]}}),x(),f.success(a("Saved successfully"))})})})}function J(){var x;const{t:a}=U(),p=l.useFieldSchema(),i=j(),{message:c}=O.App.useApp(),{data:d,refresh:f}=K(),{refresh:u}=e.useRequest({url:L},{manual:!0,cacheKey:L});return n.jsx(n.Fragment,{children:n.jsx(e.SchemaSettingsActionModalItem,{title:a("Access control"),schema:ne,initialValues:{roles:(x=d==null?void 0:d.data)==null?void 0:x.roles},beforeOpen:()=>!d&&f(),onSubmit:o=>A(this,[o],function*({roles:v}){return yield i.updateOrCreate({values:{key:p["x-uid"],roles:v},filterKeys:["key"]}),f(),u(),c.success(a("Saved successfully"))})})})}const re=new e.SchemaSettings({name:"CustomRequestActionSettings",items:[I(q({},e.actionSettingsItems[0]),{children:[...e.actionSettingsItems[0].children,{name:"request settings",Component:G},{name:"accessControl",Component:J}]})]}),ae=()=>{const a=j(),p=l.useFieldSchema();return n.jsx(e.Action.Designer,{linkageAction:!0,schemaSettings:"CustomRequestActionSettings",buttonEditorProps:{isLink:p["x-action"]==="customize:table:request"},linkageRulesProps:{type:"button"},removeButtonProps:{onConfirmOk(){return a.destroy({filterByTk:p["x-uid"]})}}})},ie=a=>{var f;const i=e.useAPIClient().auth.role==="root",c=l.useFieldSchema(),{data:d}=e.useRequest({url:L},{manual:i,cacheKey:L});return!i&&!((f=d==null?void 0:d.data)!=null&&f.includes(c==null?void 0:c["x-uid"]))?null:a.children},ue={"customize:table:request":e.Action.Link},N=a=>{const i=l.useFieldSchema()["x-action"],c=ue[i]||e.Action;return n.jsx(c,I(q({},a),{useProps:oe}))};N.Designer=ae,N.Decorator=ie;const ce=()=>({title:'{{ t("Custom request") }}',"x-component":"CustomRequestAction","x-action":"customize:form:request","x-toolbar":"ActionSchemaToolbar","x-settings":"actionSettings:customRequest","x-decorator":"CustomRequestAction.Decorator","x-uid":_.uid(),"x-action-settings":{onSuccess:{manualClose:!1,redirecting:!1,successMessage:'{{t("Request success")}}'}}}),me=a=>{const p=j(),i=e.useSchemaInitializerItem(),{insert:c}=e.useSchemaInitializer();return n.jsx(e.SchemaInitializerItem,I(q({},i),{onClick:()=>A(this,null,function*(){var u;const d=ce(),f=_.merge(d||{},i.schema||{});(u=i==null?void 0:i.schemaInitialize)==null||u.call(i,f),c(f),yield p.create({values:{key:f["x-uid"]}})})}))},le=new e.SchemaSettings({name:"actionSettings:customRequest",items:[{name:"editButton",Component:e.ButtonEditor,useComponentProps(){return{isLink:l.useFieldSchema()["x-action"]==="customize:table:request"}}},{name:"linkageRules",Component:e.SchemaSettingsLinkageRules,useComponentProps(){const{name:a}=e.useCollection(),{linkageRulesProps:p}=e.useSchemaToolbar();return I(q({},p),{collectionName:a})}},{name:"secondConFirm",Component:e.SecondConFirm},{name:"afterSuccessfulSubmission",Component:e.AfterSuccess},{name:"request settings",Component:G},{name:"accessControl",Component:J},{name:"refreshDataBlockRequest",Component:e.RefreshDataBlockRequest,useComponentProps(){return{isPopupAction:!1}}},{name:"delete",sort:100,Component:e.RemoveButton,useComponentProps(){const{removeButtonProps:a}=e.useSchemaToolbar();return a}}]}),pe=a=>n.jsx(e.SchemaComponentOptions,{scope:{CustomRequestConfigurationFieldsSchema:H},components:{CustomRequestAction:N,CustomRequestInitializer:me},children:a.children});class W extends e.Plugin{load(){return A(this,null,function*(){this.app.use(pe),this.app.schemaSettingsManager.add(le),this.app.schemaSettingsManager.add(re)})}}t.PluginActionCustomRequestClient=W,t.default=W,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -7,4 +7,20 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import React from 'react';
|
|
10
|
+
export declare const getNewSchema: () => {
|
|
11
|
+
title: string;
|
|
12
|
+
'x-component': string;
|
|
13
|
+
'x-action': string;
|
|
14
|
+
'x-toolbar': string;
|
|
15
|
+
'x-settings': string;
|
|
16
|
+
'x-decorator': string;
|
|
17
|
+
'x-uid': string;
|
|
18
|
+
'x-action-settings': {
|
|
19
|
+
onSuccess: {
|
|
20
|
+
manualClose: boolean;
|
|
21
|
+
redirecting: boolean;
|
|
22
|
+
successMessage: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
10
26
|
export declare const CustomRequestInitializer: React.FC<any>;
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,20 +8,20 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.0.
|
|
11
|
+
"@nocobase/client": "1.0.1-alpha.2",
|
|
12
12
|
"react": "18.2.0",
|
|
13
13
|
"react-i18next": "11.18.6",
|
|
14
14
|
"@formily/react": "2.3.0",
|
|
15
|
-
"@nocobase/logger": "1.0.
|
|
16
|
-
"@nocobase/server": "1.0.
|
|
17
|
-
"@nocobase/test": "1.0.
|
|
15
|
+
"@nocobase/logger": "1.0.1-alpha.2",
|
|
16
|
+
"@nocobase/server": "1.0.1-alpha.2",
|
|
17
|
+
"@nocobase/test": "1.0.1-alpha.2",
|
|
18
18
|
"@formily/antd-v5": "1.1.9",
|
|
19
19
|
"antd": "5.12.8",
|
|
20
|
-
"@nocobase/utils": "1.0.
|
|
20
|
+
"@nocobase/utils": "1.0.1-alpha.2",
|
|
21
21
|
"react-router-dom": "6.21.0",
|
|
22
22
|
"@formily/shared": "2.3.0",
|
|
23
|
-
"@nocobase/actions": "1.0.
|
|
24
|
-
"@nocobase/evaluators": "1.0.
|
|
23
|
+
"@nocobase/actions": "1.0.1-alpha.2",
|
|
24
|
+
"@nocobase/evaluators": "1.0.1-alpha.2",
|
|
25
25
|
"axios": "0.26.1",
|
|
26
|
-
"@nocobase/database": "1.0.
|
|
26
|
+
"@nocobase/database": "1.0.1-alpha.2"
|
|
27
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-action-custom-request",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.2",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"homepage": "https://docs.nocobase.com/handbook/action-custom-request",
|
|
6
6
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/action-custom-request",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@nocobase/server": "1.x",
|
|
23
23
|
"@nocobase/test": "1.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "fc5a8e3c812516f787cb22d3d198f058f45b1963",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Actions"
|
|
28
28
|
]
|