"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[4007],{4007:(e,t,n)=>{n.r(t),n.d(t,{Connection:()=>b});var i=n(50493),a=n(62392),o=(n(68784),n(16682)),r=n(94430),s=n(56765),c=n(27805),d=n(53421),l=n(36179),p=n(15633);let m=class extends r.oi{constructor(){super(...arguments),this.columns={list:{fields:["name","description"]},pagination:{infinite:!0},columns:[{type:"string",name:"name",header:d.z2.t("field.name"),width:150},{type:"string",name:"description",header:d.z2.t("field.description"),width:200},{type:"string",name:"type",header:d.z2.t("field.type"),width:100},{type:"string",name:"endpoint",header:d.z2.t("field.endpoint"),width:120}]}}render(){return r.dy`
      <ox-grist
        .mode=${(0,l.s2)()?"LIST":"GRID"}
        .config=${this.columns}
        .data=${{records:this.connections}}
      ></ox-grist>

      <div class="button-container">
        <mwc-button raised @click=${this.save.bind(this)}>${d.z2.t("button.save")}</mwc-button>
      </div>
    `}async save(){var e;(null===(e=(await c.Lp.mutate({mutation:o.ZP`
        mutation importConnections($connections: [ConnectionPatch!]!) {
          importConnections(connections: $connections)
        }
      `,variables:{connections:this.connections}})).errors)||void 0===e?void 0:e.length)||this.dispatchEvent(new CustomEvent("imported"))}};m.styles=[p.Pn,r.iv`
      :host {
        display: flex;
        flex-direction: column;

        background-color: #fff;
      }
      ox-grist {
        flex: 1;
      }
      .button-container {
        display: flex;
        margin-left: auto;
        padding: var(--padding-default);
      }
      mwc-button {
        margin-left: var(--margin-default);
      }
    `],(0,i.gn)([(0,s.Cb)({type:Array}),(0,i.w6)("design:type",Object)],m.prototype,"connections",void 0),(0,i.gn)([(0,s.Cb)({type:Object}),(0,i.w6)("design:type",Object)],m.prototype,"columns",void 0),m=(0,i.gn)([(0,s.Mo)("connection-importer")],m);var h=n(28120),g=n(64710),u=n(37077),f=n(77675),y=n(51266);let b=class extends((0,h.$)(f.h)((0,d.NC)(d.z2)(f.B4))){constructor(){super(...arguments),this.active=!1}get context(){var e;return{title:d.z2.t("text.connection list"),search:{handler:e=>{this.grist.searchText=e},value:(null===(e=this.grist)||void 0===e?void 0:e.searchText)||""},help:"integration/ui/connection",actions:[Object.assign({title:d.z2.t("button.save"),action:this._updateConnectionManager.bind(this)},p.jO.save),Object.assign({title:d.z2.t("button.delete"),action:this._deleteConnections.bind(this)},p.jO.delete)],exportable:{name:d.z2.t("text.connection list"),data:this.exportHandler.bind(this)},importable:{handler:this.importHandler.bind(this)}}}render(){return r.dy`
      <ox-grist
        .mode=${(0,l.s2)()?"LIST":"GRID"}
        .config=${this.gristConfig}
        .fetchHandler=${this.fetchHandler.bind(this)}
      >
      </ox-grist>
    `}async pageInitialized(){this.fetchConnectors(),this.gristConfig={list:{fields:["name","description","type","active"]},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"row-selector",multiple:!0},{type:"gutter",gutterName:"button",name:"state",icon:e=>e&&"CONNECTED"==e.state?"link_off":"link",handlers:{click:(e,t,n,i,a)=>{i&&i.name&&"+"!=i.__dirty__&&("CONNECTED"==i.state?this.disconnect(i):this.connect(i))}}},{type:"object",name:"domain",hidden:!0},{type:"string",name:"name",label:!0,header:d.z2.t("field.name"),record:{editable:!0},filter:"search",sortable:!0,width:150,validation:function(e,t,n,i){return"CONNECTED"!=n.state||((0,u.h4)({level:"warn",message:"connection name cannot be changed during connected."}),!1)}},{type:"string",name:"description",label:!0,header:d.z2.t("field.description"),record:{editable:!0},filter:"search",width:200},{type:"checkbox",name:"active",label:!0,header:d.z2.t("field.active"),record:{editable:!0},sortable:!0,width:60},{type:"connector",name:"type",label:!0,header:d.z2.t("field.type"),record:{renderer:g.p,editable:!0,help:e=>{var t,n;return null===(n=null===(t=this.connectors)||void 0===t?void 0:t[e])||void 0===n?void 0:n.help}},filter:"search",sortable:!0,width:200},{type:"string",name:"endpoint",header:d.z2.t("field.endpoint"),record:{editable:!0},filter:"search",sortable:!0,width:200},{type:"parameters",name:"params",header:d.z2.t("field.params"),record:{editable:!0,options:async(e,t,n,i,a)=>{var o;const{name:r,help:s,parameterSpec:c}=n.type?null===(o=this.connectors)||void 0===o?void 0:o[n.type]:{};return{name:r,help:s,spec:c,context:this.grist}},renderer:"json5"},width:100},{type:"object",name:"updater",header:d.z2.t("field.updater"),record:{editable:!1},sortable:!0,width:120},{type:"datetime",name:"updatedAt",header:d.z2.t("field.updated_at"),record:{editable:!1},sortable:!0,width:180}],rows:{selectable:{multiple:!0}},sorters:[{name:"name"}]}}async fetchHandler({page:e,limit:t,sortings:n=[],filters:i=[]}){const a=await c.Lp.query({query:o.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          responses: connections(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              domain {
                id
                name
                description
              }
              name
              description
              type
              endpoint
              active
              state
              params
              updater {
                id
                name
                description
              }
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:i,pagination:{page:e,limit:t},sortings:n}});return{total:a.data.responses.total||0,records:a.data.responses.items||[]}}async fetchConnectors(){const e=await c.Lp.query({query:o.ZP`
        query {
          connectors {
            items {
              name
              help
              parameterSpec {
                type
                name
                label
                placeholder
                property
              }
            }
          }
        }
      `});e.errors?y.error("fetch connectors error"):this.connectors=e.data.connectors.items.reduce(((e,t)=>(e[t.name]=t,e)),{})}async _deleteConnections(e){if(confirm(d.z2.t("text.sure_to_x",{x:d.z2.t("text.delete")}))){const e=this.grist.selected.map((e=>e.name));if(e&&e.length>0){(await c.Lp.mutate({mutation:o.ZP`
            mutation ($names: [String!]!) {
              deleteConnections(names: $names)
            }
          `,variables:{names:e}})).errors||(this.grist.fetch(),(0,u.h4)({message:d.z2.t("text.info_x_successfully",{x:d.z2.t("text.delete")})}))}}}async _updateConnectionManager(){var e=this.grist.dirtyRecords;if(e&&e.length){e=e.map((e=>{let t=e.id?{id:e.id}:{};const n=e.__dirtyfields__;for(let e in n)t[e]=n[e].after;return t.cuFlag=e.__dirty__,t}));(await c.Lp.mutate({mutation:o.ZP`
          mutation ($patches: [ConnectionPatch!]!) {
            updateMultipleConnection(patches: $patches) {
              name
            }
          }
        `,variables:{patches:e}})).errors||this.grist.fetch()}}async connect(e){var t=(await c.Lp.mutate({mutation:o.ZP`
        mutation ($name: String!) {
          connectConnection(name: $name) {
            state
          }
        }
      `,variables:{name:e.name}})).data.connectConnection.state;e.state=t,this.grist.refresh(),(0,u.h4)({level:"info",message:`${"CONNECTED"==t?"success":"fail"} to connect : ${e.name}`})}async disconnect(e){var t=(await c.Lp.mutate({mutation:o.ZP`
        mutation ($name: String!) {
          disconnectConnection(name: $name) {
            state
          }
        }
      `,variables:{name:e.name}})).data.disconnectConnection.state;e.state=t,this.grist.refresh(),(0,u.h4)({level:"info",message:`${"CONNECTED"==t?"fail":"success"} to disconnect : ${e.name}`})}async exportHandler(){const e=this.grist.selected.length?this.grist.selected:this.grist.dirtyData.records,t=new Set(["id","name","type","description","endpoint","params"]);return e.map((e=>{let n={};for(const i of t)n[i]=e[i];return n}))}async importHandler(e){(0,u.Mw)(r.dy`
        <connection-importer
          .connections=${e}
          @imported=${()=>{history.back(),this.grist.fetch()}}
        ></connection-importer>
      `,{backdrop:!0,size:"large",title:d.z2.t("title.import connection")})}};b.styles=[p.Pn,p.Ix,r.iv`
      :host {
        display: flex;
        flex-direction: column;

        overflow: hidden;
      }

      ox-grist {
        overflow-y: auto;
        flex: 1;
      }

      #filters {
        display: flex;
        flex-direction: row;
        justify-content: space-between;

        background-color: white;
      }

      #filters > * {
        padding: var(--padding-default) var(--padding-wide);
      }
    `],(0,i.gn)([(0,s.Cb)({type:Boolean}),(0,i.w6)("design:type",Boolean)],b.prototype,"active",void 0),(0,i.gn)([(0,s.Cb)({type:Object}),(0,i.w6)("design:type",Object)],b.prototype,"gristConfig",void 0),(0,i.gn)([(0,s.Cb)({type:Object}),(0,i.w6)("design:type",Object)],b.prototype,"connectors",void 0),(0,i.gn)([(0,s.IO)("ox-grist"),(0,i.w6)("design:type",a.N)],b.prototype,"grist",void 0),b=(0,i.gn)([(0,s.Mo)("connection-page")],b)}}]);