datajunction-ui
Version:
DataJunction UI
5 lines (3 loc) • 10.6 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("react"),f=require("./index-h1A5IisM.cjs");;/* empty css */function D({user:s}){const p=()=>{var u;return s!=null&&s.name?s.name.split(" ").map(l=>l[0]).join("").toUpperCase().slice(0,2):((u=s==null?void 0:s.username)==null?void 0:u.slice(0,2).toUpperCase())||"?"};return e.jsxs("section",{className:"settings-section",children:[e.jsx("h2",{className:"settings-section-title",children:"Profile"}),e.jsx("div",{className:"settings-card",children:e.jsxs("div",{className:"profile-info",children:[e.jsx("div",{className:"profile-avatar",children:p()}),e.jsxs("div",{className:"profile-details",children:[e.jsxs("div",{className:"profile-field",children:[e.jsx("label",{children:"Username"}),e.jsx("span",{children:(s==null?void 0:s.username)||"-"})]}),e.jsxs("div",{className:"profile-field",children:[e.jsx("label",{children:"Email"}),e.jsx("span",{children:(s==null?void 0:s.email)||"-"})]})]})]})})]})}const E=[{value:"create",label:"Create"},{value:"update",label:"Update"},{value:"delete",label:"Delete"},{value:"status_change",label:"Status Change"},{value:"refresh",label:"Refresh"},{value:"tag",label:"Tag"}];function I({subscriptions:s,onUpdate:p,onUnsubscribe:u}){const[l,r]=h.useState(null),[a,o]=h.useState([]),[i,j]=h.useState(!1),y=t=>{r(t),o([...s[t].activity_types])},v=()=>{r(null),o([])},b=t=>{a.includes(t)?o(a.filter(c=>c!==t)):o([...a,t])},x=async t=>{if(a.length===0){alert("Please select at least one activity type");return}j(!0);try{await p(t,a),r(null),o([])}catch(c){console.error("Error updating subscription:",c),alert("Failed to update subscription")}finally{j(!1)}},n=async(t,c)=>{if(window.confirm(`Unsubscribe from notifications for "${t.entity_name}"?`))try{await u(t)}catch(d){console.error("Error unsubscribing:",d)}};return e.jsxs("section",{className:"settings-section",id:"notifications",children:[e.jsx("h2",{className:"settings-section-title",children:"Notification Subscriptions"}),e.jsx("div",{className:"settings-card",children:s.length===0?e.jsx("p",{className:"empty-state",children:`You're not watching any nodes yet. Visit a node page and click "Watch" to subscribe to updates.`}):e.jsx("div",{className:"subscriptions-list",children:s.map((t,c)=>{var N;return e.jsxs("div",{className:"subscription-item",children:[e.jsxs("div",{className:"subscription-header",children:[e.jsxs("div",{className:"subscription-entity",children:[e.jsx("a",{href:`/nodes/${t.entity_name}`,children:t.entity_name}),t.node_type?e.jsx("span",{className:`node_type__${t.node_type} badge node_type`,children:t.node_type.toUpperCase()}):e.jsx("span",{className:"entity-type-badge",children:t.entity_type}),t.status==="invalid"&&e.jsx("span",{className:"status-badge status-invalid",children:"INVALID"})]}),e.jsx("div",{className:"subscription-actions",children:l===c?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn-save",onClick:()=>x(t),disabled:i,children:i?"Saving...":"Save"}),e.jsx("button",{className:"btn-cancel",onClick:v,disabled:i,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn-icon btn-edit",onClick:()=>y(c),title:"Edit subscription",children:e.jsx(f.EditIcon,{})}),e.jsx("button",{className:"btn-icon btn-unsubscribe",onClick:()=>n(t),title:"Unsubscribe",children:"×"})]})})]}),e.jsxs("div",{className:"subscription-activity-types",children:[e.jsx("label",{className:"activity-types-label",children:"Activity types:"}),l===c?e.jsx("div",{className:"activity-types-checkboxes",children:E.map(d=>e.jsxs("label",{className:"checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:a.includes(d.value),onChange:()=>b(d.value)}),d.label]},d.value))}):e.jsx("div",{className:"activity-types-badges",children:((N=t.activity_types)==null?void 0:N.map(d=>e.jsx("span",{className:`activity-badge activity-badge-${d}`,children:d},d)))||e.jsx("span",{className:"text-muted",children:"All"})})]})]},c)})})})]})}function U({isOpen:s,onClose:p,onCreate:u}){const[l,r]=h.useState(""),[a,o]=h.useState(!1),[i,j]=h.useState(null),y=async x=>{if(x.preventDefault(),!!l.trim()){o(!0);try{const n=await u(l.trim());n.client_id?(j(n),r("")):n.message&&alert(n.message)}catch(n){console.error("Error creating service account:",n),alert("Failed to create service account")}finally{o(!1)}}},v=()=>{r(""),j(null),p()},b=x=>{navigator.clipboard.writeText(x)};return s?e.jsx("div",{className:"modal-overlay",onClick:v,children:e.jsxs("div",{className:"modal-content",onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Create Service Account"}),e.jsx("button",{className:"btn-close-modal",onClick:v,title:"Close",children:"×"})]}),i?e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"credentials-success",children:[e.jsx("span",{className:"success-icon",children:"✓"}),e.jsx("h4",{children:"Service Account Created!"})]}),e.jsx("p",{className:"credentials-warning",children:"Save these credentials now. The client secret will not be shown again."}),e.jsxs("div",{className:"credentials-grid",children:[e.jsxs("div",{className:"credential-item",children:[e.jsx("label",{children:"Name"}),e.jsx("code",{children:i.name})]}),e.jsxs("div",{className:"credential-item",children:[e.jsx("label",{children:"Client ID"}),e.jsxs("div",{className:"credential-value",children:[e.jsx("code",{children:i.client_id}),e.jsx("button",{className:"btn-copy",onClick:()=>b(i.client_id),title:"Copy",children:"📋"})]})]}),e.jsxs("div",{className:"credential-item",children:[e.jsx("label",{children:"Client Secret"}),e.jsxs("div",{className:"credential-value",children:[e.jsx("code",{children:i.client_secret}),e.jsx("button",{className:"btn-copy",onClick:()=>b(i.client_secret),title:"Copy",children:"📋"})]})]})]}),e.jsx("div",{className:"modal-actions",children:e.jsx("button",{className:"btn-primary",onClick:v,children:"Done"})})]}):e.jsxs("form",{onSubmit:y,children:[e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"service-account-name",children:"Name"}),e.jsx("input",{id:"service-account-name",type:"text",placeholder:"e.g., my-pipeline, etl-job, ci-cd",value:l,onChange:x=>r(x.target.value),disabled:a,autoFocus:!0}),e.jsx("span",{className:"form-hint",children:"A descriptive name to identify this service account"})]})}),e.jsxs("div",{className:"modal-actions",children:[e.jsx("button",{type:"button",className:"btn-secondary",onClick:v,disabled:a,children:"Cancel"}),e.jsx("button",{type:"submit",className:"btn-primary",disabled:a||!l.trim(),children:a?"Creating...":"Create"})]})]})]})}):null}function P({accounts:s,onCreate:p,onDelete:u}){const[l,r]=h.useState(!1),a=async i=>{if(window.confirm(`Delete service account "${i.name}"?
This will revoke all access for this account and cannot be undone.`))try{await u(i.client_id)}catch(y){console.error("Error deleting service account:",y),alert("Failed to delete service account")}},o=async i=>await p(i);return e.jsxs("section",{className:"settings-section",id:"service-accounts",children:[e.jsxs("div",{className:"section-title-row",children:[e.jsx("h2",{className:"settings-section-title",children:"Service Accounts"}),e.jsx("button",{className:"btn-create",onClick:()=>r(!0),children:"+ Create"})]}),e.jsxs("div",{className:"settings-card",children:[e.jsx("p",{className:"section-description",children:"Service accounts allow programmatic access to the DJ API. Create accounts for your applications, scripts, or CI/CD pipelines."}),s.length>0?e.jsx("div",{className:"service-accounts-list",children:e.jsxs("table",{className:"service-accounts-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Client ID"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:s.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:i.name}),e.jsx("td",{children:e.jsx("code",{className:"client-id",children:i.client_id})}),e.jsx("td",{className:"created-date",children:new Date(i.created_at).toLocaleDateString()}),e.jsx("td",{className:"actions-cell",children:e.jsx("button",{className:"btn-icon btn-delete-account",onClick:()=>a(i),title:"Delete service account",children:"×"})})]},i.id))})]})}):e.jsx("p",{className:"empty-state",children:"No service accounts yet. Create one to enable programmatic API access."})]}),e.jsx(U,{isOpen:l,onClose:()=>r(!1),onCreate:o})]})}function T(){const s=h.useContext(f.DJClientContext).DataJunctionAPI,{currentUser:p,loading:u}=f.useCurrentUser(),[l,r]=h.useState([]),[a,o]=h.useState([]),[i,j]=h.useState(!0);h.useEffect(()=>{if(u)return;async function n(){try{const t=await s.getNotificationPreferences(),c=(t||[]).filter(m=>m.entity_type==="node").map(m=>m.entity_name);let N={};if(c.length>0){const m=await s.getNodesByNames(c);N=Object.fromEntries(m.map(g=>{var C,S,_,w,A,k;return[g.name,{node_type:(C=g.type)==null?void 0:C.toLowerCase(),display_name:(S=g.current)==null?void 0:S.displayName,status:(w=(_=g.current)==null?void 0:_.status)==null?void 0:w.toLowerCase(),mode:(k=(A=g.current)==null?void 0:A.mode)==null?void 0:k.toLowerCase()}]}))}const d=(t||[]).map(m=>({...m,...N[m.entity_name]||{}}));r(d);try{const m=await s.listServiceAccounts();o(m||[])}catch(m){console.log("Service accounts not available:",m)}}catch(t){console.error("Error fetching settings data:",t)}finally{j(!1)}}n()},[s,u]);const y=async(n,t)=>{await s.subscribeToNotifications({entity_type:n.entity_type,entity_name:n.entity_name,activity_types:t,alert_types:n.alert_types||["web"]}),r(l.map(c=>c.entity_name===n.entity_name?{...c,activity_types:t}:c))},v=async n=>{await s.unsubscribeFromNotifications({entity_type:n.entity_type,entity_name:n.entity_name}),r(l.filter(t=>t.entity_name!==n.entity_name))},b=async n=>{const t=await s.createServiceAccount(n);return t.client_id&&o([...a,t]),t},x=async n=>{await s.deleteServiceAccount(n),o(a.filter(t=>t.client_id!==n))};return i?e.jsx("div",{className:"settings-page",children:e.jsx("div",{className:"settings-container",children:e.jsx(f.LoadingIcon,{})})}):e.jsx("div",{className:"settings-page",children:e.jsxs("div",{className:"settings-container",children:[e.jsx("h1",{className:"settings-title",children:"Settings"}),e.jsx(D,{user:p}),e.jsx(I,{subscriptions:l,onUpdate:y,onUnsubscribe:v}),e.jsx(P,{accounts:a,onCreate:b,onDelete:x})]})})}exports.SettingsPage=T;
//# sourceMappingURL=index-DS3PuwCb.cjs.map