@camstack/addon-admin-ui 1.2.421 → 1.2.422
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/assets/{AddonAssetIcon-BcUAeUFA.js → AddonAssetIcon-CsoRkxbe.js} +1 -1
- package/dist/assets/{Addons-CMFKnFy_.js → Addons-D6p7m_1Q.js} +1 -1
- package/dist/assets/{AdminPage-Pnx0mTsE.js → AdminPage-BXCcRjRj.js} +1 -1
- package/dist/assets/{AdminSectionedPage-Cwqk3VSC.js → AdminSectionedPage-Dn3pfXpN.js} +1 -1
- package/dist/assets/{AiProfiles-Cm-uW0cp.js → AiProfiles-A_EtYWgt.js} +1 -1
- package/dist/assets/{BrokerForm-C29qpKHz.js → BrokerForm-B50lYczl.js} +1 -1
- package/dist/assets/{Build-jtQNSTVm.js → Build-CYzfQeUi.js} +1 -1
- package/dist/assets/{Calendars-DXVrSwsu.js → Calendars-DxzSNlaT.js} +1 -1
- package/dist/assets/{Cluster-Dt4QC5gH.js → Cluster-CdpU74GH.js} +1 -1
- package/dist/assets/{ClusterStepModel-nVqIETDq.js → ClusterStepModel-CL6OTKoe.js} +1 -1
- package/dist/assets/{CompositionEditor-CWfZxpvY.js → CompositionEditor-BpioOiB6.js} +1 -1
- package/dist/assets/{CompositionEditorPage-D2_5GID5.js → CompositionEditorPage-BtUyHyvc.js} +1 -1
- package/dist/assets/{Data-PX9MYiMq.js → Data-DjwFU5Th.js} +1 -1
- package/dist/assets/{DeviceDetail-CvBViCpU.js → DeviceDetail-_84gb-7d.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-Vpw3Hlks.js → DeviceDoActionFields-CaAhrBBq.js} +1 -1
- package/dist/assets/{Devices-NE3Jk6_G.js → Devices-Bn806mzY.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-o6tk8CLI.js → EmbedPlayerPage-BKa9M_Zh.js} +1 -1
- package/dist/assets/{Identity-DvZevqOL.js → Identity-aeXxefik.js} +1 -1
- package/dist/assets/{IntegrationDetail-pyZVXw9L.js → IntegrationDetail-NFPFWNqY.js} +1 -1
- package/dist/assets/{IntegrationHub-C--iFSMN.js → IntegrationHub-nkG_70wF.js} +1 -1
- package/dist/assets/{Integrations-Cadxh0XR.js → Integrations-BnJ0plVy.js} +1 -1
- package/dist/assets/{Integrations-B8URUnQX.js → Integrations-DwbH7OPk.js} +1 -1
- package/dist/assets/{Library-DHn4yJN3.js → Library-BeKXIn8H.js} +1 -1
- package/dist/assets/{Locations-CMXm68gm.js → Locations-LFHKGJj6.js} +1 -1
- package/dist/assets/{Logs-Bg5PD7yc.js → Logs-Bv7UFKGr.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BAPe5lDr.js → MotionZonesSettings-D_qLVNYH.js} +1 -1
- package/dist/assets/{MyAccess-BvJqlxVR.js → MyAccess-BrfWHy-Y.js} +1 -1
- package/dist/assets/{Network-Cq6PVeH5.js → Network-Dm89K78z.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BK1RxciP.js → NodeAddonsSettingsPanel-DW1CFRqr.js} +1 -1
- package/dist/assets/{Notifications-Cwp9_it6.js → Notifications--YlWuq7D.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-3MxMW9V1.js → PrivacyMaskSettings-C_nHi8iw.js} +1 -1
- package/dist/assets/{Recordings-ZhXXvJqY.js → Recordings-B3tdsucL.js} +1 -1
- package/dist/assets/{ScanNetworkModal-_RdncTUH.js → ScanNetworkModal-DVDP8rFS.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BTWYSCY4.js → SceneMonitorEditor-BzVlh6Gr.js} +1 -1
- package/dist/assets/{SessionsList-Dm6Me6Pk.js → SessionsList-BFeOCT72.js} +1 -1
- package/dist/assets/{Showroom-B6NjRCzE.js → Showroom-DBz_kmHd.js} +1 -1
- package/dist/assets/{System-Q5wNMpYV.js → System-CbZHPKfq.js} +1 -1
- package/dist/assets/{Terminal-Bq2YkQer.js → Terminal-CECng0sk.js} +1 -1
- package/dist/assets/{Viewer-CA-_IKP2.js → Viewer-Dqzwha2F.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DxkHv0jA.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-KEhfqRL3.js} +1 -1
- package/dist/assets/{addon-icons-context-BcFthDce.js → addon-icons-context-ESxHkko-.js} +1 -1
- package/dist/assets/{archive-4K83r_1n.js → archive-EESnpwDQ.js} +1 -1
- package/dist/assets/{authed-media-B1N-Y_02.js → authed-media-DbWnolm6.js} +1 -1
- package/dist/assets/{bell-off-BHt33UBf.js → bell-off-CSUO3NcL.js} +1 -1
- package/dist/assets/{boxes-BZgI7Qpt.js → boxes-F2kcHJh3.js} +1 -1
- package/dist/assets/circle-slash-C8fnQfsA.js +1 -0
- package/dist/assets/client-CLcJeoH9.js +358 -0
- package/dist/assets/{cloud-upload-5ZRXO4G8.js → cloud-upload-DaYCZ49o.js} +1 -1
- package/dist/assets/crop-CA89ugtQ.js +1 -0
- package/dist/assets/{device-integration-icon-CgVkQy_G.js → device-integration-icon-DC6GK3pO.js} +1 -1
- package/dist/assets/device-picker-model-BmKHpH-F.js +1 -0
- package/dist/assets/dist-8eKR6eC_.js +358 -0
- package/dist/assets/{dist-DtKcnSMJ.js → dist-CD_P-W4K.js} +1 -1
- package/dist/assets/{eraser-Bgk8Dzm-.js → eraser-Lfy_pBOl.js} +1 -1
- package/dist/assets/{file-up-BDHV-8n7.js → file-up-D4zDJB-k.js} +1 -1
- package/dist/assets/{hard-drive-download-Cf7DR1zn.js → hard-drive-download-W35XVpPS.js} +1 -1
- package/dist/assets/{history-BThcfo0X.js → history-DQ9vKorT.js} +1 -1
- package/dist/assets/{hostInit-CU4FJ_9p.js → hostInit-CQubQ_OP.js} +1 -1
- package/dist/assets/{icons-hV-aAVBh.js → icons-dYEMPXRw.js} +1 -1
- package/dist/assets/{index-AsTGrKva.js → index-Dbcd0nug.js} +3 -3
- package/dist/assets/{key-DKkIyX9P.js → key-BL3RAip-.js} +1 -1
- package/dist/assets/{key-round-Dzvj04Ko.js → key-round-WrVw9weZ.js} +1 -1
- package/dist/assets/{layers-D6sO1vTO.js → layers-BagSqCNw.js} +1 -1
- package/dist/assets/{list-ordered-B8fDKjS-.js → list-ordered-DZPbjPqk.js} +1 -1
- package/dist/assets/{location-owned-usage-C7aYDcAR.js → location-owned-usage-D9_fG4z9.js} +1 -1
- package/dist/assets/{log-in-lHSUE2pa.js → log-in-CPy0U03d.js} +1 -1
- package/dist/assets/{memory-stick-CttSJTx_.js → memory-stick-DyJ5Tk7i.js} +1 -1
- package/dist/assets/{message-square-plus-CwcMKafs.js → message-square-plus-brBt7pwi.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-c3f6e5ea.js → mf-entry-bootstrap-0-dcb80f94.js} +2 -2
- package/dist/assets/{mic-off-Ip3w_Vtm.js → mic-off-DjwMxkEf.js} +1 -1
- package/dist/assets/{monitor-off-BZ83JVg4.js → monitor-off-B51Pk6ca.js} +1 -1
- package/dist/assets/{monitor-smartphone-yIys4K1P.js → monitor-smartphone-BL4hI9CF.js} +1 -1
- package/dist/assets/mount-BmKHpH-F.js +1 -0
- package/dist/assets/{notification-schedule-field-Dy4ByDYy.js → notification-schedule-field-C4N-WcPT.js} +1 -1
- package/dist/assets/{octagon-alert-B71ohghx.js → octagon-alert-jd1vv87l.js} +1 -1
- package/dist/assets/{player-overlays-C20AJTgs.js → player-overlays-BOsDheHc.js} +1 -1
- package/dist/assets/{recycle-DhAxCder.js → recycle-CBztR-tu.js} +1 -1
- package/dist/assets/remoteEntry-DLWJ6wcK.js +1 -0
- package/dist/assets/{scan-eye-BbXV25vz.js → scan-eye-DbKZpfih.js} +1 -1
- package/dist/assets/{scissors-WSGBgAVG.js → scissors-DCPxjz4N.js} +1 -1
- package/dist/assets/{search-x-CaqrjMNZ.js → search-x-DUTyCa9Y.js} +1 -1
- package/dist/assets/{send-B-4ijiWE.js → send-Boyf3SIM.js} +1 -1
- package/dist/assets/{settings-2-BjwKRpE2.js → settings-2-BkCzMVmr.js} +1 -1
- package/dist/assets/{speaker-__2EFvIp.js → speaker-nmF_x7US.js} +1 -1
- package/dist/assets/{src-CIIJy_o8.js → src-CCd-7AXY.js} +17 -17
- package/dist/assets/{timer-reset-CkaW1pT6.js → timer-reset-CkFpFTeE.js} +1 -1
- package/dist/assets/{ungroup-CqbpWLek.js → ungroup-BdveVhZq.js} +1 -1
- package/dist/assets/{unlink-2_Gor_ZF.js → unlink-Biu31rTD.js} +1 -1
- package/dist/assets/{usb-Dbv88fxf.js → usb-B3PCv4C7.js} +1 -1
- package/dist/assets/{use-scenes-feed-DxSvhMQ5.js → use-scenes-feed-CVqgJ1dp.js} +1 -1
- package/dist/assets/{use-stationary-objects-BllXyUsy.js → use-stationary-objects-DBx5Fmhe.js} +1 -1
- package/dist/assets/useEventInvalidation-BmKHpH-F.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DNAtiVHu.js → useNodeUrlSelection-DD1VIgYL.js} +1 -1
- package/dist/assets/user-round-C2xetSEU.js +1 -0
- package/dist/assets/{user-x-D3HnF7fF.js → user-x-C34u0XHr.js} +1 -1
- package/dist/assets/{video-Bkjg9omB.js → video-c8H5Zs-y.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-LWvJP_B9.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-U-kBwSSC.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +284 -2
- package/package.json +1 -1
- package/dist/assets/circle-slash-Blsoe4DV.js +0 -1
- package/dist/assets/client-CKGZv6zJ.js +0 -358
- package/dist/assets/crop-gRMkMnnt.js +0 -1
- package/dist/assets/device-picker-model-C-bu65w9.js +0 -1
- package/dist/assets/dist-B51fr1vo.js +0 -358
- package/dist/assets/mount-C-bu65w9.js +0 -1
- package/dist/assets/remoteEntry-9Elsv3BT.js +0 -1
- package/dist/assets/useEventInvalidation-C-bu65w9.js +0 -1
- package/dist/assets/user-round-tDoKxf4s.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as f,It as p,On as m,Pn as h,Q as g,ar as _,bn as v,cn as y,ht as b,ot as ee,tr as te}from"./player-overlays-C20AJTgs.js";import{m as x,o as S}from"./video-Bkjg9omB.js";import{t as C}from"./log-in-lHSUE2pa.js";import{t as w}from"./monitor-smartphone-yIys4K1P.js";import{t as ne}from"./recycle-DhAxCder.js";import{Dr as T,Nt as E,ar as D}from"./client-CKGZv6zJ.js";import{$ as O,An as k,Bn as A,Dn as j,En as re,Er as ie,Ht as ae,L as oe,Ln as M,On as N,Q as P,Tn as F,Vi as I,Zn as se,_i as ce,ar as L,bn as le,di as R,fi as z,gi as ue,hi as B,jn as V,mi as H,vi as de,yi as fe,z as pe,zn as me}from"./src-CIIJy_o8.js";import{t as U}from"./useTranslation-Bc5yH9V9.js";import"./mount-C-bu65w9.js";import{C as W,I as he,Q as ge,X as _e,r as ve,s as ye,t as be}from"./index-AsTGrKva.js";import{t as xe}from"./AdminSectionedPage-Cwqk3VSC.js";import{t as Se}from"./NodeAddonsSettingsPanel-BK1RxciP.js";import{t as Ce}from"./BrokerForm-C29qpKHz.js";import{n as we,r as G,t as Te}from"./IntegrationHub-C--iFSMN.js";n();var K=`kind`,q=`name`,J=`restore`,Y=`restoreId`;function Ee(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:K,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:q,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:J,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:Y,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:J,equals:!0}}]}]}}function De(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(K);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(q);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Y);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}function Oe(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`camstack:broker-oauth`&&typeof t.ok==`boolean`}function ke(e,t){return e.split(`{{brokerId}}`).join(encodeURIComponent(t))}function Ae(e,t,n=window){let r=n.location.origin,i=!1,a=e=>{i||(i=!0,n.removeEventListener(`message`,o),window.clearInterval(s),t(e))},o=t=>{t.origin!==r||t.source!==e||Oe(t.data)&&a({ok:t.data.ok,...t.data.brokerId===void 0?{}:{brokerId:t.data.brokerId},...t.data.error===void 0?{}:{error:t.data.error}})};n.addEventListener(`message`,o);let s=window.setInterval(()=>{e.closed&&a({ok:!0})},500);return()=>{i=!0,n.removeEventListener(`message`,o),window.clearInterval(s)}}function X(e,t,n){let r=g(ve(ke(e,t))),i=be(r);if(i===null){window.location.assign(r);return}Ae(i,e=>{n?.(e)})}var je={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function Z(e){return je[e]??e}function Me(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var Ne={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Pe({status:e}){return u(L,{variant:Ne[e],className:`text-[10px]`,children:e})}function Fe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Ie({title:e,subtitle:t,onClose:n,children:i}){return u(F,{open:!0,onOpenChange:e=>!e&&n(),children:r(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(k,{children:[u(V,{children:e}),t&&u(N,{children:t})]}),u(re,{className:`space-y-3 pr-1`,children:i})]})})}function Le({kinds:e,onClose:t,onDone:n}){let a=s(),o=i(()=>Ee(e.map(e=>({key:Q(e),label:e.label}))),[e]),[l,d]=c(()=>({[K]:Q(e[0]),[q]:``,[J]:!1,[Y]:``})),[f,p]=c(null),m=e.find(e=>Q(e)===l.kind)??e[0],h=m?.kind??``,g=m?.addonId,_=m?.interactiveConnectPath,v=R({onSuccess:e=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&_!==void 0&&_.length>0&&X(_,t,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}),n()}}),y=e=>{let t=De(l);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},...g===void 0?{}:{addonId:g}})};return r(Ie,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:t,children:[u(he,{schema:o,values:l,onChange:d}),f!==null&&u(M,{message:f}),v.isError&&u(M,{message:v.error instanceof Error?v.error.message:String(v.error)}),h&&u(Ce,{kind:h,...g===void 0?{}:{addonId:g},onSubmit:y,onCancel:t,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},Q(m))]})}function Q(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Re({broker:e,onClose:t,onDone:n}){let a=s(),o=z({id:e.id,addonId:e.addonId}),c=de({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]}),a.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),l=i(()=>{let e=o.data;return e&&typeof e==`object`?{...e}:{}},[o.data]);return u(Ie,{title:`Edit ${e.name}`,subtitle:`${Z(e.kind)} · ${e.id}`,onClose:c.isPending?()=>{}:t,children:o.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(_,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):o.isError?r(`div`,{className:`space-y-3`,children:[u(M,{message:`Failed to load settings: ${o.error instanceof Error?o.error.message:`Unknown error`}`}),u(`div`,{className:`flex justify-end`,children:u(A,{variant:`outline`,size:`sm`,onClick:t,children:`Close`})})]}):r(`div`,{className:`space-y-3`,children:[c.isError&&u(M,{message:c.error instanceof Error?c.error.message:String(c.error)}),u(Ce,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:l,onSubmit:t=>{c.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:c.isPending?`Saving…`:`Save`,disabled:c.isPending})]})})}function ze({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let a=s(),o=se(),[l,d]=c(null),f=fe({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=ce({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),g=async()=>{await o({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})},v=t!==void 0&&t.length>0&&e.status!==`connected`,y=n!==void 0&&n.length>0&&e.status===`connected`;return r(`tr`,{className:`border-b border-border last:border-0`,children:[u(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),u(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:Z(e.kind)}),r(`td`,{className:`px-3 py-2`,children:[u(Pe,{status:e.status}),l&&u(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),u(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex items-center justify-end gap-1.5`,children:[v&&r(A,{variant:`primary`,size:`sm`,onClick:()=>{X(t,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign in — opens a popup that closes when done`,children:[u(C,{className:`h-3 w-3`}),` Sign in`]}),y&&r(A,{variant:`outline`,size:`sm`,onClick:()=>{X(n,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign out — clears the linked Google account on this broker`,children:[u(S,{className:`h-3 w-3`}),` Sign out`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(b,{className:`h-3 w-3`}),`Test`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:`Edit`,children:[u(h,{className:`h-3 w-3`}),` Edit`]}),r(A,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{g()},disabled:m.isPending,title:`Delete`,children:[m.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(p,{className:`h-3 w-3`}),`Delete`]})]})})]})}function Be({addonId:e}={}){let t=B({}),n=ue(),a=i(()=>Fe(t.data).filter(t=>e===void 0||t.addonId===e),[t.data,e]),[o,s]=c(!1),[l,d]=c(null),f=i(()=>{let t=new Map;for(let r of Me(n.data))if(!(e!==void 0&&r.addonId!==e))for(let e of r.kinds){let n=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${r.addonId}::${e.kind}`,{addonId:r.addonId,kind:e.kind,label:e.label,...n===void 0?{}:{interactiveConnectPath:n},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of a)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:Z(e.kind)});return[...t.values()]},[a,n.data,e]),p=i(()=>{let e=new Map;for(let t of f)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[f]);return r(`div`,{className:`space-y-3`,children:[u(`div`,{className:`flex items-center justify-end`,children:r(A,{variant:`primary`,size:`sm`,onClick:()=>s(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[u(m,{className:`h-3.5 w-3.5`}),` Add broker`]})}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:r(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[u(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background/50`,children:[u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),u(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),r(`tbody`,{children:[t.isLoading&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[u(_,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),t.isError&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,t.error instanceof Error?t.error.message:`Unknown error`]})}),!t.isLoading&&!t.isError&&a.length===0&&u(`tr`,{children:u(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),a.map(e=>{let t=p.get(e.kind);return u(ze,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:d},e.id)})]})]})}),o&&u(Le,{kinds:f,onClose:()=>s(!1),onDone:()=>s(!1)}),l&&u(Re,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}function Ve(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function He(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(Ve).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ue(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function We(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ge(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}n();var Ke=[`wasteCollections`,`listSources`],qe=[`wasteCollections`,`listCountries`];function Je(e){return e instanceof Error?e.message:String(e)}function Ye(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Xe(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`argsJson`),o=Reflect.get(n,`enabled`),s=Reflect.get(n,`formValues`),c=Reflect.get(n,`serviceId`),l=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,argsJson:typeof a==`string`?a:`{}`,enabled:typeof o==`boolean`?o:!0,formValues:typeof s==`object`&&s&&!Array.isArray(s)?s:void 0,serviceId:typeof c==`string`?c:void 0,countryId:typeof l==`string`?l:void 0})}return t}function Ze(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Qe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function $e(e,t,n){return{sections:[{id:`picker`,title:`Country & service`,columns:2,fields:[{type:`select`,key:`countryId`,label:`Country`,options:[{value:``,label:`Select country…`},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:`Service`,options:[{value:``,label:n===``?`Pick a country first`:`Select service…`},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function et({addonId:n,capName:f}){let h=ee(),g=s(),_=se(),v=oe({editKey:`wasteEdit`,newKey:`wasteNew`}),[y,b]=c(!1),[te,x]=c(null),[S,C]=c({countryId:``,serviceId:``}),[w,T]=c({label:`New source`,enabled:!0}),E=t(null),D=typeof S.countryId==`string`?S.countryId:``,O=typeof S.serviceId==`string`?S.serviceId:``,k=e((e,t)=>h.trpcClient.addons.custom.mutate({addonId:n,action:e,input:t}),[n,h]),j=a({queryKey:[...Ke,n],queryFn:async()=>Xe(await k(`listSources`,{}))}),re=a({queryKey:[...qe,n],queryFn:async()=>Ze(await k(`listCountries`,{}))}),ie=a({queryKey:[`wasteCollections`,`listServices`,n,D],enabled:D!==``,queryFn:async()=>Qe(await k(`listServices`,{countryId:D}))}),M=a({queryKey:[`wasteCollections`,`serviceFormSchema`,n,O],enabled:O!==``,queryFn:async()=>k(`serviceFormSchema`,{serviceId:O})}),N=j.data??[],P=re.data??[],F=ie.data??[],I=Ye(M.data)?M.data:void 0,ce=i(()=>$e(P,D===``?[]:F,D),[P,F,D]),R=v.state,z=R.mode===`edit`?N.find(e=>e.id===R.id)??null:null;d(()=>{if(v.state.mode===`edit`&&z!==null){let e=`edit:${z.id}`;if(E.current===e)return;E.current=e,x(null),C({countryId:z.countryId??``,serviceId:z.serviceId??``}),T(z.formValues===void 0?{label:z.label,enabled:z.enabled}:{...z.formValues});return}if(v.state.mode===`new`){if(E.current===`new`)return;E.current=`new`,x(null),C({countryId:``,serviceId:``}),T({label:`New source`,enabled:!0})}},[z,v.state]),d(()=>{if(v.state.mode!==`new`||O===``)return;let e=F.find(e=>e.id===O);e&&T(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[v.state.mode,O,F]);let ue=e(e=>{C(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),B=e(async()=>{await g.invalidateQueries({queryKey:Ke})},[g]),V=l({mutationFn:async e=>k(`deleteSource`,{id:e}),onSuccess:async()=>B()}),H=e(async e=>{await _({title:`Delete waste source?`,message:`Remove “${e.label}” (${e.id}). Its calendar under System → Calendars is dropped.`,confirmLabel:`Delete`,cancelLabel:`Cancel`,variant:`danger`})&&(await V.mutateAsync(e.id),v.state.mode===`edit`&&v.state.id===e.id&&(v.close(),E.current=null))},[_,V,v]),de=e(async()=>{let e=w.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Label is required.`);return}if(O===``){x(`Pick a country and a service.`);return}let n=v.state.mode===`new`,r=z?.id;if(!n&&(r===void 0||r===``)){x(`That source is no longer available.`);return}let i=w.enabled,a={...w};delete a.label,delete a.enabled,b(!0),x(null);try{n?await k(`createSource`,{label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await k(`updateSource`,{id:r,label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}),await B(),v.close(),E.current=null}catch(e){x(Je(e))}finally{b(!1)}},[k,z,v,w,B,O]),fe=i(()=>[{key:`label`,header:`Label`,sortValue:e=>e.label,render:e=>u(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:`Module`,sortValue:e=>e.module,render:e=>u(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:`Enabled`,sortValue:e=>+!!e.enabled,render:e=>u(L,{variant:e.enabled?`success`:`default`,children:e.enabled?`On`:`Off`})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>u(A,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`Delete ${e.label}`,"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),H(e)},children:u(p,{className:`h-3.5 w-3.5 text-danger`})})}],[H]),U=v.state.mode===`new`,W=U||z!==null,he=`${O}:${U?`new`:z?.id??`closed`}`;return r(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u(`p`,{className:`text-sm text-foreground-muted`,children:`Pick a country and a service — configuration fields come from that HACS source.`}),r(A,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>v.openNew(),children:[u(m,{className:`h-3.5 w-3.5`}),`Add source`]})]}),j.isError?u(`p`,{className:`text-sm text-danger`,children:`Could not load sources.`}):null,j.isPending?u(me,{className:`h-32 w-full`}):u(ae,{columns:fe,rows:N,rowKey:e=>e.id,pageSize:25,mobileMode:`scroll`,emptyMessage:`No waste sources yet. Add one to register a municipal service.`,onRowClick:e=>v.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),u(pe,{open:W,onClose:()=>{v.close(),x(null),E.current=null},title:U?`Add waste source`:`Edit ${z?.label??`source`}`,icon:ne,width:`xl`,testId:`waste-source-editor`,error:te,footer:u(A,{type:`button`,size:`sm`,disabled:y||O===``,onClick:()=>void de(),children:y?`Saving…`:`Save`}),children:W?r(o,{children:[u(`div`,{"data-testid":`waste-country-service`,children:u(le,{schema:ce,values:S,onChange:ue},`picker:${D}:${F.length}`)}),O!==``&&I!==void 0?u(le,{schema:I,values:w,onChange:T,bare:!0},he):O!==``&&M.isPending?u(`p`,{className:`text-sm text-foreground-muted`,children:`Loading fields…`}):u(`p`,{className:`text-sm text-foreground-muted`,children:`Choose a country and service to see the required fields.`})]}):null}),u(Se,{nodeId:`hub`,addonIds:[n],level:`global`,capability:f,hideSectionChrome:!0})]})}n();var $=1e4,tt={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},nt=[{sectionId:`exporters`,kind:`device-export`,label:`Exporters`,icon:y,installLabel:`Add export`,emptyTitle:`No device exporters installed`,emptyDescription:`Install an export addon to publish devices to Alexa, HomeKit, Google Home or Home Assistant.`},{sectionId:`email`,kind:`email`,label:`Email`,icon:te,installLabel:`Add email provider`,emptyTitle:`No email providers installed`,emptyDescription:`Install an SMTP or Gmail addon to send notification email from this hub.`},{sectionId:`brokers`,kind:`broker`,label:`Brokers`,icon:v,installLabel:`Add broker addon`,emptyTitle:`No message brokers installed`,emptyDescription:`Install a broker addon to connect Home Assistant, Homematic, MQTT, Matter and similar systems.`},{sectionId:`calendars`,kind:`calendar`,label:`Calendars`,icon:x,installLabel:`Add calendar source`,emptyTitle:`No calendar sources installed`,emptyDescription:`Install a calendar-source addon (Google Calendar, waste collections, …) to feed System → Calendars.`}];function rt(e,t,n){let i=Ue(E,e.kind),a=t.flatMap(t=>{let a=We(t,i);if(a===null)return[];let s=Ge(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:s.state,stateLabel:s.label,render:()=>u(we,{addonId:t.addonId,displayName:t.displayName,capName:a,isActive:t.processState===`running`,badges:r(o,{children:[u(st,{processState:t.processState}),u(ct,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?u(O,{addonId:t.addonId}):void 0,panels:ot(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?u(et,{addonId:t.addonId,capName:a}):void 0})}]});return{id:e.sectionId,label:e.label,entries:a,install:{capability:i[0]??e.kind,label:e.installLabel}}}function it({descriptor:e,rows:t,isLoading:n}){let r=_e(),a=i(()=>rt(e,t,r),[e,t,r]);return u(Te,{embedded:!0,icon:e.icon,title:e.label,subtitle:null,groups:[a],isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription})}function at(){let{t:e}=U(),t=ie(void 0,{refetchInterval:$}),[n,r]=ge(),a=W(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:`Connectivity`};d(()=>{let e=n.get(`tab`);if(e===null)return;let t=tt[e];t===void 0||t===e||r(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[n,r]);let o=i(()=>(t.data??[]).map(He).filter(e=>e!==null),[t.data]),s=i(()=>nt.map(e=>({id:e.sectionId,label:e.label,ownedParams:ye,content:u(it,{descriptor:e,rows:o,isLoading:t.isLoading})})),[t.isLoading,o]);return u(xe,{icon:a.icon,title:a.title,subtitle:`External systems this hub talks to — exporters, email, brokers and calendar sources.`,defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:s})}function ot(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:w,placement:`end`,content:u(P,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:v,content:u(Be,{addonId:t})}]:[]}function st({processState:e}){let{state:t,label:n}=Ge(e);return u(L,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${G} capitalize`,children:n})}function ct({kind:e,addonId:t}){return e===`broker`?u(lt,{addonId:t}):e===`device-export`?u(ut,{addonId:t}):null}function lt({addonId:e}){let{data:t}=H({addonId:e},{refetchInterval:$,retry:!1}),n=T.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return u(L,{variant:`info`,className:G,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function ut({addonId:e}){let{data:t}=I({addonId:e},{refetchInterval:$,retry:!1}),n=D.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return u(L,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:G,children:`${r} · ${i} exposed`})}export{at as IntegrationsPage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as f,It as p,On as m,Pn as h,Q as g,ar as _,bn as v,cn as y,ht as b,ot as ee,tr as te}from"./player-overlays-BOsDheHc.js";import{m as x,o as S}from"./video-c8H5Zs-y.js";import{t as C}from"./log-in-CPy0U03d.js";import{t as w}from"./monitor-smartphone-BL4hI9CF.js";import{t as ne}from"./recycle-CBztR-tu.js";import{Dr as T,Nt as E,ar as D}from"./client-CLcJeoH9.js";import{$ as O,An as k,Bn as A,Dn as j,En as re,Er as ie,Ht as ae,L as oe,Ln as M,On as N,Q as P,Tn as F,Vi as I,Zn as se,_i as ce,ar as L,bn as le,di as R,fi as z,gi as ue,hi as B,jn as V,mi as H,vi as de,yi as fe,z as pe,zn as me}from"./src-CCd-7AXY.js";import{t as U}from"./useTranslation-Bc5yH9V9.js";import"./mount-BmKHpH-F.js";import{C as W,I as he,Q as ge,X as _e,r as ve,s as ye,t as be}from"./index-Dbcd0nug.js";import{t as xe}from"./AdminSectionedPage-Dn3pfXpN.js";import{t as Se}from"./NodeAddonsSettingsPanel-DW1CFRqr.js";import{t as Ce}from"./BrokerForm-B50lYczl.js";import{n as we,r as G,t as Te}from"./IntegrationHub-nkG_70wF.js";n();var K=`kind`,q=`name`,J=`restore`,Y=`restoreId`;function Ee(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:K,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:q,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:J,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:Y,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:J,equals:!0}}]}]}}function De(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(K);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(q);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Y);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}function Oe(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`camstack:broker-oauth`&&typeof t.ok==`boolean`}function ke(e,t){return e.split(`{{brokerId}}`).join(encodeURIComponent(t))}function Ae(e,t,n=window){let r=n.location.origin,i=!1,a=e=>{i||(i=!0,n.removeEventListener(`message`,o),window.clearInterval(s),t(e))},o=t=>{t.origin!==r||t.source!==e||Oe(t.data)&&a({ok:t.data.ok,...t.data.brokerId===void 0?{}:{brokerId:t.data.brokerId},...t.data.error===void 0?{}:{error:t.data.error}})};n.addEventListener(`message`,o);let s=window.setInterval(()=>{e.closed&&a({ok:!0})},500);return()=>{i=!0,n.removeEventListener(`message`,o),window.clearInterval(s)}}function X(e,t,n){let r=g(ve(ke(e,t))),i=be(r);if(i===null){window.location.assign(r);return}Ae(i,e=>{n?.(e)})}var je={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function Z(e){return je[e]??e}function Me(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var Ne={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Pe({status:e}){return u(L,{variant:Ne[e],className:`text-[10px]`,children:e})}function Fe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Ie({title:e,subtitle:t,onClose:n,children:i}){return u(F,{open:!0,onOpenChange:e=>!e&&n(),children:r(j,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(k,{children:[u(V,{children:e}),t&&u(N,{children:t})]}),u(re,{className:`space-y-3 pr-1`,children:i})]})})}function Le({kinds:e,onClose:t,onDone:n}){let a=s(),o=i(()=>Ee(e.map(e=>({key:Q(e),label:e.label}))),[e]),[l,d]=c(()=>({[K]:Q(e[0]),[q]:``,[J]:!1,[Y]:``})),[f,p]=c(null),m=e.find(e=>Q(e)===l.kind)??e[0],h=m?.kind??``,g=m?.addonId,_=m?.interactiveConnectPath,v=R({onSuccess:e=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&_!==void 0&&_.length>0&&X(_,t,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}),n()}}),y=e=>{let t=De(l);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:h,name:n,settings:e,...r===null?{}:{id:r},...g===void 0?{}:{addonId:g}})};return r(Ie,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:t,children:[u(he,{schema:o,values:l,onChange:d}),f!==null&&u(M,{message:f}),v.isError&&u(M,{message:v.error instanceof Error?v.error.message:String(v.error)}),h&&u(Ce,{kind:h,...g===void 0?{}:{addonId:g},onSubmit:y,onCancel:t,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},Q(m))]})}function Q(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Re({broker:e,onClose:t,onDone:n}){let a=s(),o=z({id:e.id,addonId:e.addonId}),c=de({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]}),a.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),n()}}),l=i(()=>{let e=o.data;return e&&typeof e==`object`?{...e}:{}},[o.data]);return u(Ie,{title:`Edit ${e.name}`,subtitle:`${Z(e.kind)} · ${e.id}`,onClose:c.isPending?()=>{}:t,children:o.isLoading?r(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[u(_,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):o.isError?r(`div`,{className:`space-y-3`,children:[u(M,{message:`Failed to load settings: ${o.error instanceof Error?o.error.message:`Unknown error`}`}),u(`div`,{className:`flex justify-end`,children:u(A,{variant:`outline`,size:`sm`,onClick:t,children:`Close`})})]}):r(`div`,{className:`space-y-3`,children:[c.isError&&u(M,{message:c.error instanceof Error?c.error.message:String(c.error)}),u(Ce,{kind:e.kind,addonId:e.addonId,brokerId:e.id,initialValues:l,onSubmit:t=>{c.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:t,submitLabel:c.isPending?`Saving…`:`Save`,disabled:c.isPending})]})})}function ze({broker:e,interactiveConnectPath:t,interactiveDisconnectPath:n,onEdit:i}){let a=s(),o=se(),[l,d]=c(null),f=fe({onSuccess:e=>d(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>d({ok:!1,error:e instanceof Error?e.message:String(e)})}),m=ce({onSuccess:()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),g=async()=>{await o({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&m.mutate({id:e.id,addonId:e.addonId})},v=t!==void 0&&t.length>0&&e.status!==`connected`,y=n!==void 0&&n.length>0&&e.status===`connected`;return r(`tr`,{className:`border-b border-border last:border-0`,children:[u(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),u(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:Z(e.kind)}),r(`td`,{className:`px-3 py-2`,children:[u(Pe,{status:e.status}),l&&u(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),u(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex items-center justify-end gap-1.5`,children:[v&&r(A,{variant:`primary`,size:`sm`,onClick:()=>{X(t,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign in — opens a popup that closes when done`,children:[u(C,{className:`h-3 w-3`}),` Sign in`]}),y&&r(A,{variant:`outline`,size:`sm`,onClick:()=>{X(n,e.id,()=>{a.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:`Sign out — clears the linked Google account on this broker`,children:[u(S,{className:`h-3 w-3`}),` Sign out`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>f.mutate({id:e.id,addonId:e.addonId}),disabled:f.isPending,title:`Test connection`,children:[f.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(b,{className:`h-3 w-3`}),`Test`]}),r(A,{variant:`outline`,size:`sm`,onClick:()=>i(e),title:`Edit`,children:[u(h,{className:`h-3 w-3`}),` Edit`]}),r(A,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{g()},disabled:m.isPending,title:`Delete`,children:[m.isPending?u(_,{className:`h-3 w-3 animate-spin`}):u(p,{className:`h-3 w-3`}),`Delete`]})]})})]})}function Be({addonId:e}={}){let t=B({}),n=ue(),a=i(()=>Fe(t.data).filter(t=>e===void 0||t.addonId===e),[t.data,e]),[o,s]=c(!1),[l,d]=c(null),f=i(()=>{let t=new Map;for(let r of Me(n.data))if(!(e!==void 0&&r.addonId!==e))for(let e of r.kinds){let n=typeof e.interactiveConnectPath==`string`&&e.interactiveConnectPath.length>0?e.interactiveConnectPath:void 0,i=typeof e.interactiveDisconnectPath==`string`&&e.interactiveDisconnectPath.length>0?e.interactiveDisconnectPath:void 0;t.set(`${r.addonId}::${e.kind}`,{addonId:r.addonId,kind:e.kind,label:e.label,...n===void 0?{}:{interactiveConnectPath:n},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let e of a)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:Z(e.kind)});return[...t.values()]},[a,n.data,e]),p=i(()=>{let e=new Map;for(let t of f)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[f]);return r(`div`,{className:`space-y-3`,children:[u(`div`,{className:`flex items-center justify-end`,children:r(A,{variant:`primary`,size:`sm`,onClick:()=>s(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[u(m,{className:`h-3.5 w-3.5`}),` Add broker`]})}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:r(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[u(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background/50`,children:[u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),u(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),u(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),r(`tbody`,{children:[t.isLoading&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[u(_,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),t.isError&&u(`tr`,{children:r(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,t.error instanceof Error?t.error.message:`Unknown error`]})}),!t.isLoading&&!t.isError&&a.length===0&&u(`tr`,{children:u(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),a.map(e=>{let t=p.get(e.kind);return u(ze,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:d},e.id)})]})]})}),o&&u(Le,{kinds:f,onClose:()=>s(!1),onDone:()=>s(!1)}),l&&u(Re,{broker:l,onClose:()=>d(null),onDone:()=>d(null)})]})}function Ve(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function He(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(Ve).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ue(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function We(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ge(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}n();var Ke=[`wasteCollections`,`listSources`],qe=[`wasteCollections`,`listCountries`];function Je(e){return e instanceof Error?e.message:String(e)}function Ye(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Xe(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`argsJson`),o=Reflect.get(n,`enabled`),s=Reflect.get(n,`formValues`),c=Reflect.get(n,`serviceId`),l=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,argsJson:typeof a==`string`?a:`{}`,enabled:typeof o==`boolean`?o:!0,formValues:typeof s==`object`&&s&&!Array.isArray(s)?s:void 0,serviceId:typeof c==`string`?c:void 0,countryId:typeof l==`string`?l:void 0})}return t}function Ze(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Qe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function $e(e,t,n){return{sections:[{id:`picker`,title:`Country & service`,columns:2,fields:[{type:`select`,key:`countryId`,label:`Country`,options:[{value:``,label:`Select country…`},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:`Service`,options:[{value:``,label:n===``?`Pick a country first`:`Select service…`},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function et({addonId:n,capName:f}){let h=ee(),g=s(),_=se(),v=oe({editKey:`wasteEdit`,newKey:`wasteNew`}),[y,b]=c(!1),[te,x]=c(null),[S,C]=c({countryId:``,serviceId:``}),[w,T]=c({label:`New source`,enabled:!0}),E=t(null),D=typeof S.countryId==`string`?S.countryId:``,O=typeof S.serviceId==`string`?S.serviceId:``,k=e((e,t)=>h.trpcClient.addons.custom.mutate({addonId:n,action:e,input:t}),[n,h]),j=a({queryKey:[...Ke,n],queryFn:async()=>Xe(await k(`listSources`,{}))}),re=a({queryKey:[...qe,n],queryFn:async()=>Ze(await k(`listCountries`,{}))}),ie=a({queryKey:[`wasteCollections`,`listServices`,n,D],enabled:D!==``,queryFn:async()=>Qe(await k(`listServices`,{countryId:D}))}),M=a({queryKey:[`wasteCollections`,`serviceFormSchema`,n,O],enabled:O!==``,queryFn:async()=>k(`serviceFormSchema`,{serviceId:O})}),N=j.data??[],P=re.data??[],F=ie.data??[],I=Ye(M.data)?M.data:void 0,ce=i(()=>$e(P,D===``?[]:F,D),[P,F,D]),R=v.state,z=R.mode===`edit`?N.find(e=>e.id===R.id)??null:null;d(()=>{if(v.state.mode===`edit`&&z!==null){let e=`edit:${z.id}`;if(E.current===e)return;E.current=e,x(null),C({countryId:z.countryId??``,serviceId:z.serviceId??``}),T(z.formValues===void 0?{label:z.label,enabled:z.enabled}:{...z.formValues});return}if(v.state.mode===`new`){if(E.current===`new`)return;E.current=`new`,x(null),C({countryId:``,serviceId:``}),T({label:`New source`,enabled:!0})}},[z,v.state]),d(()=>{if(v.state.mode!==`new`||O===``)return;let e=F.find(e=>e.id===O);e&&T(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[v.state.mode,O,F]);let ue=e(e=>{C(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),B=e(async()=>{await g.invalidateQueries({queryKey:Ke})},[g]),V=l({mutationFn:async e=>k(`deleteSource`,{id:e}),onSuccess:async()=>B()}),H=e(async e=>{await _({title:`Delete waste source?`,message:`Remove “${e.label}” (${e.id}). Its calendar under System → Calendars is dropped.`,confirmLabel:`Delete`,cancelLabel:`Cancel`,variant:`danger`})&&(await V.mutateAsync(e.id),v.state.mode===`edit`&&v.state.id===e.id&&(v.close(),E.current=null))},[_,V,v]),de=e(async()=>{let e=w.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Label is required.`);return}if(O===``){x(`Pick a country and a service.`);return}let n=v.state.mode===`new`,r=z?.id;if(!n&&(r===void 0||r===``)){x(`That source is no longer available.`);return}let i=w.enabled,a={...w};delete a.label,delete a.enabled,b(!0),x(null);try{n?await k(`createSource`,{label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await k(`updateSource`,{id:r,label:t,serviceId:O,args:a,enabled:typeof i==`boolean`?i:!0}),await B(),v.close(),E.current=null}catch(e){x(Je(e))}finally{b(!1)}},[k,z,v,w,B,O]),fe=i(()=>[{key:`label`,header:`Label`,sortValue:e=>e.label,render:e=>u(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:`Module`,sortValue:e=>e.module,render:e=>u(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:`Enabled`,sortValue:e=>+!!e.enabled,render:e=>u(L,{variant:e.enabled?`success`:`default`,children:e.enabled?`On`:`Off`})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>u(A,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`Delete ${e.label}`,"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),H(e)},children:u(p,{className:`h-3.5 w-3.5 text-danger`})})}],[H]),U=v.state.mode===`new`,W=U||z!==null,he=`${O}:${U?`new`:z?.id??`closed`}`;return r(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u(`p`,{className:`text-sm text-foreground-muted`,children:`Pick a country and a service — configuration fields come from that HACS source.`}),r(A,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>v.openNew(),children:[u(m,{className:`h-3.5 w-3.5`}),`Add source`]})]}),j.isError?u(`p`,{className:`text-sm text-danger`,children:`Could not load sources.`}):null,j.isPending?u(me,{className:`h-32 w-full`}):u(ae,{columns:fe,rows:N,rowKey:e=>e.id,pageSize:25,mobileMode:`scroll`,emptyMessage:`No waste sources yet. Add one to register a municipal service.`,onRowClick:e=>v.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),u(pe,{open:W,onClose:()=>{v.close(),x(null),E.current=null},title:U?`Add waste source`:`Edit ${z?.label??`source`}`,icon:ne,width:`xl`,testId:`waste-source-editor`,error:te,footer:u(A,{type:`button`,size:`sm`,disabled:y||O===``,onClick:()=>void de(),children:y?`Saving…`:`Save`}),children:W?r(o,{children:[u(`div`,{"data-testid":`waste-country-service`,children:u(le,{schema:ce,values:S,onChange:ue},`picker:${D}:${F.length}`)}),O!==``&&I!==void 0?u(le,{schema:I,values:w,onChange:T,bare:!0},he):O!==``&&M.isPending?u(`p`,{className:`text-sm text-foreground-muted`,children:`Loading fields…`}):u(`p`,{className:`text-sm text-foreground-muted`,children:`Choose a country and service to see the required fields.`})]}):null}),u(Se,{nodeId:`hub`,addonIds:[n],level:`global`,capability:f,hideSectionChrome:!0})]})}n();var $=1e4,tt={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},nt=[{sectionId:`exporters`,kind:`device-export`,label:`Exporters`,icon:y,installLabel:`Add export`,emptyTitle:`No device exporters installed`,emptyDescription:`Install an export addon to publish devices to Alexa, HomeKit, Google Home or Home Assistant.`},{sectionId:`email`,kind:`email`,label:`Email`,icon:te,installLabel:`Add email provider`,emptyTitle:`No email providers installed`,emptyDescription:`Install an SMTP or Gmail addon to send notification email from this hub.`},{sectionId:`brokers`,kind:`broker`,label:`Brokers`,icon:v,installLabel:`Add broker addon`,emptyTitle:`No message brokers installed`,emptyDescription:`Install a broker addon to connect Home Assistant, Homematic, MQTT, Matter and similar systems.`},{sectionId:`calendars`,kind:`calendar`,label:`Calendars`,icon:x,installLabel:`Add calendar source`,emptyTitle:`No calendar sources installed`,emptyDescription:`Install a calendar-source addon (Google Calendar, waste collections, …) to feed System → Calendars.`}];function rt(e,t,n){let i=Ue(E,e.kind),a=t.flatMap(t=>{let a=We(t,i);if(a===null)return[];let s=Ge(t.processState);return[{id:t.addonId,name:t.displayName,fallbackIcon:e.icon,state:s.state,stateLabel:s.label,render:()=>u(we,{addonId:t.addonId,displayName:t.displayName,capName:a,isActive:t.processState===`running`,badges:r(o,{children:[u(st,{processState:t.processState}),u(ct,{kind:e.kind,addonId:t.addonId})]}),lead:e.kind===`device-export`?u(O,{addonId:t.addonId}):void 0,panels:ot(e.kind,t.addonId,e=>n(`/devices/${e}`)),settingsContent:t.addonId===`waste-collections`?u(et,{addonId:t.addonId,capName:a}):void 0})}]});return{id:e.sectionId,label:e.label,entries:a,install:{capability:i[0]??e.kind,label:e.installLabel}}}function it({descriptor:e,rows:t,isLoading:n}){let r=_e(),a=i(()=>rt(e,t,r),[e,t,r]);return u(Te,{embedded:!0,icon:e.icon,title:e.label,subtitle:null,groups:[a],isLoading:n,emptyTitle:e.emptyTitle,emptyDescription:e.emptyDescription})}function at(){let{t:e}=U(),t=ie(void 0,{refetchInterval:$}),[n,r]=ge(),a=W(`/system/integrations`,{t:e,isAdmin:!0})??{icon:f,title:`Connectivity`};d(()=>{let e=n.get(`tab`);if(e===null)return;let t=tt[e];t===void 0||t===e||r(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[n,r]);let o=i(()=>(t.data??[]).map(He).filter(e=>e!==null),[t.data]),s=i(()=>nt.map(e=>({id:e.sectionId,label:e.label,ownedParams:ye,content:u(it,{descriptor:e,rows:o,isLoading:t.isLoading})})),[t.isLoading,o]);return u(xe,{icon:a.icon,title:a.title,subtitle:`External systems this hub talks to — exporters, email, brokers and calendar sources.`,defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:s})}function ot(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:w,placement:`end`,content:u(P,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:v,content:u(Be,{addonId:t})}]:[]}function st({processState:e}){let{state:t,label:n}=Ge(e);return u(L,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${G} capitalize`,children:n})}function ct({kind:e,addonId:t}){return e===`broker`?u(lt,{addonId:t}):e===`device-export`?u(ut,{addonId:t}):null}function lt({addonId:e}){let{data:t}=H({addonId:e},{refetchInterval:$,retry:!1}),n=T.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return u(L,{variant:`info`,className:G,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function ut({addonId:e}){let{data:t}=I({addonId:e},{refetchInterval:$,retry:!1}),n=D.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return u(L,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:G,children:`${r} · ${i} exposed`})}export{at as IntegrationsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as l,On as u,Sn as d,_i as f,ar as p,bi as m,dn as h,dt as g,ln as _,ot as v,wi as y,yi as b,yn as x}from"./player-overlays-C20AJTgs.js";import{Ki as ee,M as S,Xl as C,co as te,et as w,iu as T,ma as E,mr as D,oo as O,r as k,ra as A,ro as j,rt as ne,tt as M}from"./src-CIIJy_o8.js";import{t as N}from"./useTranslation-Bc5yH9V9.js";import{K as P,Q as re,X as F}from"./index-AsTGrKva.js";import{t as I}from"./AdminPage-Pnx0mTsE.js";import"./useEventInvalidation-C-bu65w9.js";import{t as L}from"./device-integration-icon-CgVkQy_G.js";import{n as R,r as z,t as ie}from"./ScanNetworkModal-_RdncTUH.js";t();function B(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function V(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function ae({providerId:e,onImport:t,onSkip:r}){let{t:i}=N(),[a,l]=o(new Set),u=A(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||p(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(m,{className:`h-3 w-3 text-primary-foreground`})}),s(y,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}t();function H({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:a}=N(),c=F(),[l,u]=o(``),{data:d,isLoading:m}=O(),g=r(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(m)return s(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>s(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=i!==null;return n(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[n(`div`,{className:`relative`,children:[s(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),s(C,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:a(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":a(`integrations.searchProviders`,`Search integrations…`)})]}),s(`div`,{className:`grid grid-cols-2 gap-2`,children:g.map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,l=i===r.addonId,u=v;return n(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${r.addonId}`,onClick:()=>{if(!u)if(o){let e=r.existingInstances[0].id;t(),c(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind,r.mode,r.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),s(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:r.name}),r.description?s(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:r.description}):null,l?s(p,{className:`h-4 w-4 animate-spin text-primary`}):o?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(_,{className:`h-3 w-3`}),a(`integrations.manage`)]}):s(f,{className:`h-3.5 w-3.5 text-foreground-subtle`,"aria-hidden":!0})]},r.addonId)})}),g.length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?a(`integrations.noProviders`):a(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}t();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var oe=2e4;function se({open:e,onClose:t}){let{t:l}=N(),u=F(),d=a(),[f,m]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[te,w]=o(``),[T,E]=o(null),[O,k]=o(null),[ne,M]=o(!1),{data:P}=D({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),re=r(()=>P?U(P):null,[P]),I=j({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),L=A(),ie=L.data;c(()=>{f!==`discovery`||!v||!h||L.isPending||L.data||L.mutate({addonId:h})},[f,v,h,L]);let se=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o,s){if(!I.isPending){if(_(e),M(s),x(n),w(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}ce(e,r)}}async function ce(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:te,settings:{brokerId:e}});E(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=ie?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),_(null),y(null),x(`manual`),C(null),w(``),E(null),k(null),M(!1)}function Y(){t(),J()}B(e);let X=I.isPending,Z=V(X,oe);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(g,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[O&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),s(H,{onSelect:W,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(R,{addonId:h,configSchema:re??null,canTest:ne,onSave:le,onBack:()=>m(`picker`)}),f===`broker`&&S&&s(z,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&v&&s(ae,{providerId:v,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(p,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?b:f,{className:`h-3.5 w-3.5`})}),s(P,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(S,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t}=N(),a=F(),c=v(),[f]=re(),[p,m]=o(!1),h=e(()=>m(!0),[]),g=e(()=>m(!1),[]),[_,y]=o(!1),b=e(()=>y(!0),[]),ee=e(()=>y(!1),[]);k([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),k([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:D}=te(void 0),{data:O,isLoading:A,refetch:j}=E({projection:`slim`}),P=r(()=>O??[],[O]),R=r(()=>S??[],[S]),z=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=r(()=>M(S),[S]),V=r(()=>{let e=new Map;for(let t of ne(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=r(()=>R.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[R,V]),H=f.get(G),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>z.get(e)??null,[z]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:L,resolveParent:W,onNavigate:K}),[P,c.trpcClient,B,W,K]),J=e(e=>H===e.addonId,[H]),Y=r(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),j()},[D,j]),Q=C||A,$=R.length>0;return n(I,{icon:l,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(x,{className:T(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(d,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(u,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:g}),s(ie,{open:_,onClose:ee})]})}export{K as IntegrationsPage};
|
|
1
|
+
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Dn as l,On as u,Sn as d,_i as f,ar as p,bi as m,dn as h,dt as g,ln as _,ot as v,wi as y,yi as b,yn as x}from"./player-overlays-BOsDheHc.js";import{Ki as ee,M as S,Xl as C,co as te,et as w,iu as T,ma as E,mr as D,oo as O,r as k,ra as A,ro as j,rt as ne,tt as M}from"./src-CCd-7AXY.js";import{t as N}from"./useTranslation-Bc5yH9V9.js";import{K as P,Q as re,X as F}from"./index-Dbcd0nug.js";import{t as I}from"./AdminPage-BXCcRjRj.js";import"./useEventInvalidation-BmKHpH-F.js";import{t as L}from"./device-integration-icon-DC6GK3pO.js";import{n as R,r as z,t as ie}from"./ScanNetworkModal-DVDP8rFS.js";t();function B(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function V(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function ae({providerId:e,onImport:t,onSkip:r}){let{t:i}=N(),[a,l]=o(new Set),u=A(),d=u.data,f=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function p(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(f)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||p(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(m,{className:`h-3 w-3 text-primary-foreground`})}),s(y,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}t();function H({onSelect:e,onClose:t,pendingAddonId:i=null}){let{t:a}=N(),c=F(),[l,u]=o(``),{data:d,isLoading:m}=O(),g=r(()=>{let e=d??[],t=l.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[d,l]);if(m)return s(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>s(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=i!==null;return n(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[n(`div`,{className:`relative`,children:[s(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),s(C,{type:`search`,value:l,onChange:e=>u(e.target.value),placeholder:a(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":a(`integrations.searchProviders`,`Search integrations…`)})]}),s(`div`,{className:`grid grid-cols-2 gap-2`,children:g.map(r=>{let o=r.instanceMode===`unique`&&r.existingInstances.length>0,l=i===r.addonId,u=v;return n(`button`,{type:`button`,disabled:u,"data-testid":`provider-pick-${r.addonId}`,onClick:()=>{if(!u)if(o){let e=r.existingInstances[0].id;t(),c(`/integrations/${e}`)}else e(r.addonId,r.instanceMode,r.discoveryMode,r.name,r.kind,r.brokerKind,r.mode,r.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[r.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`img`,{src:r.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${r.color}15`},children:s(`span`,{className:`text-sm`,style:{color:r.color},children:`◉`})}),s(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:r.name}),r.description?s(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:r.description}):null,l?s(p,{className:`h-4 w-4 animate-spin text-primary`}):o?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(_,{className:`h-3 w-3`}),a(`integrations.manage`)]}):s(f,{className:`h-3.5 w-3.5 text-foreground-subtle`,"aria-hidden":!0})]},r.addonId)})}),g.length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(d??[]).length===0?a(`integrations.noProviders`):a(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}t();function U(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var oe=2e4;function se({open:e,onClose:t}){let{t:l}=N(),u=F(),d=a(),[f,m]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[te,w]=o(``),[T,E]=o(null),[O,k]=o(null),[ne,M]=o(!1),{data:P}=D({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),re=r(()=>P?U(P):null,[P]),I=j({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),L=A(),ie=L.data;c(()=>{f!==`discovery`||!v||!h||L.isPending||L.data||L.mutate({addonId:h})},[f,v,h,L]);let se=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function W(e,t,n,r,i,a,o,s){if(!I.isPending){if(_(e),M(s),x(n),w(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(a),m(`broker`);return}if(o===`account`){m(`config`);return}ce(e,r)}}async function ce(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function le(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?m(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await I.mutateAsync({addonId:h,name:te,settings:{brokerId:e}});E(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=ie?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:h,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){m(`picker`),_(null),y(null),x(`manual`),C(null),w(``),E(null),k(null),M(!1)}function Y(){t(),J()}B(e);let X=I.isPending,Z=V(X,oe);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?h:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(g,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[O&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:O}),s(H,{onSelect:W,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(R,{addonId:h,configSchema:re??null,canTest:ne,onSave:le,onBack:()=>m(`picker`)}),f===`broker`&&S&&s(z,{kind:S,onResolved:e=>{G(e)},onBack:()=>m(`picker`)}),f===`discovery`&&v&&s(ae,{providerId:v,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(p,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function W({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?b:f,{className:`h-3.5 w-3.5`})}),s(P,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(W,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(S,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var G=`expand`;function K(){let{t}=N(),a=F(),c=v(),[f]=re(),[p,m]=o(!1),h=e(()=>m(!0),[]),g=e(()=>m(!1),[]),[_,y]=o(!1),b=e(()=>y(!0),[]),ee=e(()=>y(!1),[]);k([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),k([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:D}=te(void 0),{data:O,isLoading:A,refetch:j}=E({projection:`slim`}),P=r(()=>O??[],[O]),R=r(()=>S??[],[S]),z=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),B=r(()=>M(S),[S]),V=r(()=>{let e=new Map;for(let t of ne(P)){let n=B(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,B]),ae=r(()=>R.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:V.get(e.id)??0})),[R,V]),H=f.get(G),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(G)===e?t.delete(G):t.set(G,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),oe=e(e=>a(`/integrations/${e.id}`),[a]),W=e(e=>z.get(e)??null,[z]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:B,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:L,resolveParent:W,onNavigate:K}),[P,c.trpcClient,B,W,K]),J=e(e=>H===e.addonId,[H]),Y=r(()=>ce({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),j()},[D,j]),Q=C||A,$=R.length>0;return n(I,{icon:l,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(x,{className:T(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:b,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(d,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:h,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(u,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:ae,getKey:Z,getSearchText:X,columns:Y,onRowClick:oe,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(se,{open:p,onClose:g}),s(ie,{open:_,onClose:ee})]})}export{K as IntegrationsPage};
|