Skip to content

Instantly share code, notes, and snippets.

@guidone
Created June 6, 2020 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidone/49e2980460b657a51462ab1e8572de78 to your computer and use it in GitHub Desktop.
Save guidone/49e2980460b657a51462ab1e8572de78 to your computer and use it in GitHub Desktop.
define(["../../src/components","code-plug","graphql-tag","lodash","react","react-apollo","rsuite","use-http"],(e,n,t,o,r,a,i,l)=>(()=>{var s={631:(e,n,t)=>{"use strict";t.r(n);var o=t(297),r=t.n(o),a=t(399),i=t(186),l=t(222),s=t(74),c=t(875),u=t.n(c),p=t(939),d=t.n(p),m=t(804),g=t.n(m);function f(){}const y=function(e,n){var t,o=0,r=1,a={},i=(n=n||{}).maxAttempts||1/0;return a.open=function(){(t=new WebSocket(e,n.protocols||[])).onmessage=n.onmessage||f,t.onopen=function(e){(n.onopen||f)(e),o=0},t.onclose=function(e){1e3===e.code||1001===e.code||1005===e.code||a.reconnect(e),(n.onclose||f)(e)},t.onerror=function(e){e&&"ECONNREFUSED"===e.code?a.reconnect(e):(n.onerror||f)(e)}},a.reconnect=function(e){r&&o++<i?r=setTimeout((function(){(n.onreconnect||f)(e),a.open()}),n.timeout||1e3):(n.onmaximum||f)(e)},a.json=function(e){t.send(JSON.stringify(e))},a.send=function(e){t.send(e)},a.close=function(e,n){r=clearTimeout(r),t.close(e||1e3,n)},a.open(),a},h=new function({url:e,maxAttempts:n=10,timeout:t=5e3}){let o={};const r=(e,...n)=>{null!=o[e]&&o[e].forEach(e=>e(...n))},a=new y(e,{timeout:t,maxAttempts:n,onmessage:e=>{let n;try{n=JSON.parse(e.data)}catch(e){}r("message",n.topic,n.payload)},onreconnect:e=>r("reconnect"),onclose:e=>r("close"),onopen:e=>r("open")}),i={on:(e,n)=>(null==o[e]&&(o[e]=[]),o[e].push(n),i),off:(e,n)=>(null!=o[e]&&(o[e]=o[e].filter(e=>e!==n)),i),close:()=>(o={},a.close(),i),send:e=>(a.send(e),i)};return i}({url:"ws://localhost:"+t(719).wsPort}),b=({reducer:e=(()=>{}),initialState:n={},onMessage:t=(()=>{})}={})=>{const r=(e,n)=>{i({type:"socket.message",topic:e,payload:n}),t(e,n)};(0,o.useEffect)(()=>(h.on("message",r),()=>h.off("message",r)),[]);const[a,i]=(0,o.useReducer)(e,n);return{state:a,dispatch:i,sendMessage:(e,n)=>h.send(JSON.stringify({topic:e,payload:n}))}},k=u()`
query($namespace: String) {
configurations(namespace: $namespace) {
id
namespace
payload
}
}
`,E=u()`
mutation($configuration: NewConfiguration!) {
createConfiguration(configuration: $configuration) {
id,
namespace,
payload
}
}
`,C=({namespace:e,onCompleted:n=(()=>{}),onLoaded:t=(()=>{})})=>{const{loading:o,error:r,data:a}=(0,s.useQuery)(k,{variables:{namespace:e},onCompleted:e=>{let n;null!=e&&null!=e.configurations&&0!==e.configurations.length&&(n=JSON.parse(e.configurations[0].payload)),t(n)}}),{sendMessage:i}=b();let l;null!=a&&null!=a.configurations&&0!==a.configurations.length&&(l=JSON.parse(a.configurations[0].payload));const[c,{loading:u,error:p}]=(0,s.useMutation)(E,{onCompleted:n});return{loading:o,saving:u,error:r||p,data:l,update:n=>{c({variables:{configuration:{namespace:e,payload:JSON.stringify(n)}}}),i("mc.configuration",{namespace:e,...n})}}},v=u()`
query {
contents(namespace: "plugins") {
id,
title,
body,
fields {
name,
value
}
}
}
`,S=()=>{const e=(0,s.useApolloClient)(),{data:n}=C({namespace:"market-place"}),[t,a]=(0,o.useState)(null),{put:i}=d()("https://api.jsonbin.io",{headers:{"Content-Type":"application/json","secret-key":null!=n?n.jsonbin_key:null,versioning:"false"}}),c=null!=n&&!g().isEmpty(n.jsonbin_key);return r().createElement(l.Button,{disabled:null!=t||!c,appearance:"primary",onClick:async()=>{a("Loading...");const t=(await e.query({query:v,fetchPolicy:"network-only"})).data.contents.map(e=>{const n=e.fields.reduce((e,n)=>({...e,[n.name]:n.value}),{});return{id:n.id,name:e.title,description:e.body,url:n.url,flow:n.flow,version:n.version,github:n.github,author:{name:n.author,url:n.author_url}}});a("Publishing..."),await i("/b/"+n.jsonbin_id,t),a(null),l.Notification.success({title:"Published",description:"Plugin list published succesfully "})}},null!=t?t:"Publish plugins")};(0,a.plug)("sidebar",null,{id:"market-place",label:"Market Place",url:"/market-place",icon:"shopping-basket"}),(0,a.plug)("sidebar",null,{id:"configuration",label:"Configuration",permission:"configure",icon:"cog",options:[{id:"configuration-market-place",label:"Market Place",url:"/configuration-market-place"}]}),(0,a.plug)("pages",(0,i.withConfigurationPage)("market-place",({value:e,onSubmit:n=(()=>{}),disabled:t=!1})=>{const[a,i]=(0,o.useState)(e),[s,c]=(0,o.useState)(null),u=(0,o.useRef)(null);return r().createElement("div",null,r().createElement(l.Form,{formValue:a,formError:s,ref:u,checkTrigger:"none",layout:"vertical",fluid:!0,onChange:e=>{i(e),c(null)},onCheck:e=>{c(e)}},r().createElement(l.FormGroup,null,r().createElement(l.ControlLabel,null,"JSONbin.io id"),r().createElement(l.FormControl,{name:"jsonbin_id",accepter:l.Input,disabled:t}),r().createElement(l.HelpBlock,null,"The ",r().createElement("em",null,"id")," of the ",r().createElement("strong",null,"jsonbin.io")," snippet of the plugins meta info")),r().createElement(l.FormGroup,null,r().createElement(l.ControlLabel,null,"JSONbin.io key"),r().createElement(l.FormControl,{name:"jsonbin_key",accepter:l.Input,disabled:t}),r().createElement(l.HelpBlock,null,"The ",r().createElement("em",null,"secret key")," to write on ",r().createElement("strong",null,"jsonbin.io"))),r().createElement(l.FormGroup,{style:{marginTop:"40px"}},r().createElement(l.ButtonToolbar,null,r().createElement(l.Button,{disabled:t,appearance:"primary",onClick:()=>{u.current.check()&&n(a)}},"Save configuration"),r().createElement(l.Button,{disabled:t,appearance:"default",onClick:()=>{confirm("Reset configuration?")&&i(e)}},"Reset")))))},{Legend:()=>r().createElement("div",null,"Configure the id and the key to access ",r().createElement("strong",null,"jsonbing.io")," for the plugins met information.",r().createElement("br",null),"Docs about the API ",r().createElement("a",{href:"https://jsonbin.io/api-reference/bins/read",target:"blank"},"here"),"."),title:"Market Place"}),{permission:"configure",url:"/configuration-market-place",title:"Market Place",id:"configuration"}),(0,a.plug)("pages",i.Content.Contents,{url:"/market-place",title:"Market Place",id:"market-place",namespace:"plugins",breadcrumbs:["Market Place","Plugins"],labels:{saveContent:"Save plugin",createContent:"Create plugin",emptyContent:"No plugins"},custom:()=>r().createElement(S,null),customFieldsSchema:[{key:"url",type:"string",description:"URL of the compiled plugin",color:"cyan"},{key:"flow",type:"string",description:"URL of the Node-RED flow for this plugin",color:"cyan"},{key:"id",type:"string",description:"Unique id of the plugin",color:"red"},{key:"version",type:"string",description:"The version of the current (latest) plugin",color:"red"},{key:"github",type:"string",description:"The URL of the github page of the plugin",color:"red"},{key:"author",type:"string",description:"The username of the author of the plugin",color:"orange"},{key:"author_url",type:"string",description:"The home page of the username, if any",color:"orange"}]})},719:e=>{e.exports={wsPort:1942,notificationPort:1943}},186:n=>{"use strict";n.exports=e},399:e=>{"use strict";e.exports=n},875:e=>{"use strict";e.exports=t},804:e=>{"use strict";e.exports=o},297:e=>{"use strict";e.exports=r},74:e=>{"use strict";e.exports=a},222:e=>{"use strict";e.exports=i},939:e=>{"use strict";e.exports=l}},c={};function u(e){if(c[e])return c[e].exports;var n=c[e]={exports:{}};return s[e](n,n.exports,u),n.exports}return u.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return u.d(n,{a:n}),n},u.d=(e,n)=>{for(var t in n)u.o(n,t)&&!u.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},u.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),u.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u(631)})());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment