p3x-redis-ui-material
Version:
💿 P3X Redis UI triple frontend — Angular + React/MUI + Vue/Vuetify with 54 languages, 7 themes, Socket.IO, desktop notifications, and full feature parity
1 lines • 10.1 kB
JavaScript
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{i as t,it as n,t as r}from"./Box-CN-vzd2M.js";import{n as i,o as a}from"./i18n.store-cEFY1tQT.js";import{n as o}from"./KeyboardArrowDown-D7WhzLBq.js";import{i as ee,n as s,r as te,t as ne}from"./Delete--d__ZiCF.js";import{t as re}from"./ListItem-yYGw6TjL.js";import{i as ie,n as ae,r as oe,t as se}from"./SkipPrevious-BCX6mTI2.js";import{r as ce}from"./redis-state.store-DegzWxJZ.js";import{B as le,G as ue,J as c,R as de,U as l,V as u,X as d,_ as fe,d as f,m as pe,q as p,r as m,x as me,z as h}from"./index-B6abhTyw.js";import{t as he}from"./redis-version-D5h1AGvN.js";import{t as g}from"./P3xrAccordion-DoDeoAbj.js";var _=n(),ge=t((0,_.jsx)(`path`,{d:`M19 13H5v-2h14z`}),`Remove`),v=e(a());function y(){let e=i(e=>e.strings),t=ce(e=>e.connection),{toast:n,confirm:a,generalHandleError:y}=fe(),b=pe(),_e=de(`(min-width: 960px)`),x=t?.readonly===!0,[S,ve]=(0,v.useState)([]),[C,w]=(0,v.useState)(``),[T,ye]=(0,v.useState)(`*`),[E,D]=(0,v.useState)(0),[O,k]=(0,v.useState)(0),[A,j]=(0,v.useState)([]),[M,N]=(0,v.useState)(null),[be,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,xe]=(0,v.useState)(!1),[R,Se]=(0,v.useState)(``),[z,Ce]=(0,v.useState)(``),[B,we]=(0,v.useState)(10),[V,H]=(0,v.useState)(``),[U,Te]=(0,v.useState)(``),[W,G]=(0,v.useState)([{name:``,type:`TEXT`,sortable:!1}]),K=Math.ceil(O/20),Ee=Math.floor(E/20)+1,q=e=>Object.keys(e).filter(e=>e!==`_key`),J=(0,v.useCallback)(async()=>{try{let e=await f({action:`search/list`,payload:{}});return ve(e.data),e.data}catch{return[]}},[]),Y=(0,v.useCallback)(async e=>{let t=e||C;if(t)try{N((await f({action:`search/index-info`,payload:{index:t}})).data)}catch(e){y(e)}},[C,y]),X=(0,v.useCallback)(async e=>{if(!(!C||!T))try{let t;t=L&&R&&z?await f({action:`search/hybrid`,payload:{index:C,query:T,vectorField:R,vectorValues:z.split(`,`).map(e=>parseFloat(e.trim())).filter(e=>!isNaN(e)),count:B,offset:e??E,limit:20}}):await f({action:`search/query`,payload:{index:C,query:T,offset:e??E,limit:20}}),k(t.data.total),j(t.data.docs)}catch(e){y(e),j([]),k(0)}finally{P(!0)}},[C,T,E,y]),Z=(0,v.useCallback)(async e=>{if(e){I(!0);try{let t=await f({action:`ai/redis-query`,payload:{prompt:e,context:{indexes:S,schema:M}}});ye(t.command),t.explanation&&n(t.explanation),D(0);let r=await f({action:`search/query`,payload:{index:C,query:t.command,offset:0,limit:20}});k(r.data.total),j(r.data.docs),P(!0),await Y()}catch(e){y(e)}finally{I(!1)}}},[S,M,C,n,Y,y]),De=(0,v.useCallback)(async()=>{let e=(T||``).trim();if(/^ai:\s*/i.test(e)){await Z(e.replace(/^ai:\s*/i,``).trim());return}try{await Promise.all([X(0),Y()])}catch{if(e.length>2&&e!==`*`&&/\s/.test(e)){b.show();try{await Z(e)}finally{b.hide()}}}},[T,X,Y,Z,b]),Q=(0,v.useCallback)(e=>{let t=E;switch(e){case`first`:t=0;break;case`prev`:t=Math.max(0,E-20);break;case`next`:t=Math.min((K-1)*20,E+20);break;case`last`:t=(K-1)*20;break}D(t),X(t)},[E,K,X]),Oe=(0,v.useCallback)(async()=>{if(C)try{await a({message:e?.confirm?.dropIndex}),await f({action:`search/index-drop`,payload:{index:C}}),n(e?.status?.indexDropped),w(``),j([]),k(0),P(!1),N(null),await J()}catch(e){e!==void 0&&y(e)}},[C,e,a,n,J,y]),ke=()=>G(e=>[...e,{name:``,type:`TEXT`,sortable:!1}]),Ae=(0,v.useCallback)(async t=>{try{await a({message:e?.intention?.delete+`?`}),G(e=>e.filter((e,n)=>n!==t))}catch(e){e!==void 0&&y(e)}},[e,a,y]),je=(0,v.useCallback)(async()=>{if(!V.trim())return;let t=W.filter(e=>e.name.trim());if(t.length!==0)try{await f({action:`search/index-create`,payload:{name:V.trim(),prefix:U.trim()||void 0,schema:t}}),n(e?.status?.indexCreated),H(``),Te(``),G([{name:``,type:`TEXT`,sortable:!1}]),await J()}catch(e){y(e)}},[V,U,W,e,n,J,y]),Me=t?.id;(0,v.useEffect)(()=>{w(``),j([]),k(0),P(!1),N(null),J().then(e=>{e.length>0&&(w(e[0]),Y(e[0]))})},[Me]);let Ne=e=>{w(e),D(0),N(null),Y(e)},$=e?.page?.search||{},Pe=({icon:e,label:t,color:n=`primary`,onClick:r,disabled:i})=>_e?(0,_.jsxs)(d,{variant:`contained`,color:n,size:`small`,onClick:r,disabled:i,sx:{gap:`3px`},children:[e,(0,_.jsx)(`span`,{children:t})]}):(0,_.jsx)(o,{title:t,placement:`top`,children:(0,_.jsx)(`span`,{children:(0,_.jsx)(d,{variant:`contained`,color:n,onClick:r,disabled:i,sx:{minWidth:40,width:40,height:40,p:0,borderRadius:`4px`},children:e})})});return(0,_.jsxs)(r,{children:[(0,_.jsx)(g,{title:$.title,accordionKey:`search-query`,children:(0,_.jsxs)(r,{sx:{p:2},children:[S.length===0&&(0,_.jsx)(r,{sx:{opacity:.5},children:$.noIndex}),S.length>0&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(r,{sx:{display:`flex`,alignItems:`center`,gap:1},children:[(0,_.jsxs)(p,{fullWidth:!0,size:`small`,children:[(0,_.jsx)(ue,{children:$.index}),(0,_.jsx)(le,{value:C,label:$.index,onChange:e=>Ne(e.target.value),children:S.map(e=>(0,_.jsx)(u,{value:e,children:e},e))})]}),!x&&C&&(0,_.jsx)(o,{title:$.dropIndex,children:(0,_.jsx)(d,{variant:`contained`,color:`error`,onClick:Oe,sx:{minWidth:40,width:40,height:40,p:0,borderRadius:`4px`},children:(0,_.jsx)(ne,{fontSize:`small`})})})]}),(0,_.jsx)(h,{fullWidth:!0,size:`small`,sx:{mt:1},label:$.query,value:T,onChange:e=>ye(e.target.value),disabled:F,onKeyDown:e=>{e.key===`Enter`&&(D(0),De())}}),he(ce.getState().info?.server?.redis_version).isAtLeast(8,4)&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(ee,{sx:{mt:1},control:(0,_.jsx)(te,{checked:L,onChange:(e,t)=>xe(t),color:`primary`}),label:$.hybridMode}),L&&(0,_.jsxs)(r,{sx:{display:`flex`,gap:1,flexWrap:`wrap`,mt:1},children:[(0,_.jsx)(h,{size:`small`,sx:{flex:1,minWidth:150},label:$.vectorField,placeholder:`embedding`,value:R,onChange:e=>Se(e.target.value)}),(0,_.jsx)(h,{size:`small`,sx:{flex:2,minWidth:200},label:$.vectorValues,placeholder:`0.1, 0.2, 0.3, ...`,value:z,onChange:e=>Ce(e.target.value)}),(0,_.jsx)(h,{size:`small`,sx:{width:80},type:`number`,label:`Count`,value:B,onChange:e=>we(parseInt(e.target.value)||10)})]})]}),(0,_.jsx)(r,{sx:{mt:1,textAlign:`right`},children:(0,_.jsx)(Pe,{icon:(0,_.jsx)(me,{fontSize:`small`}),label:F?e?.label?.aiTranslating:$.title,onClick:()=>{D(0),De()},disabled:F})})]})]})}),be&&O===0&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r,{sx:{mt:1}}),(0,_.jsx)(g,{title:`${$.results} (0)`,accordionKey:`search-results`,children:(0,_.jsx)(r,{sx:{p:2,opacity:.5},children:e?.label?.noResults})})]}),(A.length>0||O>0)&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r,{sx:{mt:1}}),(0,_.jsx)(g,{title:`${$.results} (${O})`,accordionKey:`search-results`,actions:K>1?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(m,{icon:(0,_.jsx)(se,{sx:{fontSize:18}}),label:``,color:`inherit`,onClick:e=>{e.stopPropagation(),Q(`first`)}}),(0,_.jsx)(m,{icon:(0,_.jsx)(ie,{sx:{fontSize:18}}),label:``,color:`inherit`,onClick:e=>{e.stopPropagation(),Q(`prev`)}}),(0,_.jsxs)(r,{component:`span`,sx:{fontSize:12,opacity:.7},children:[Ee,` / `,K]}),(0,_.jsx)(m,{icon:(0,_.jsx)(oe,{sx:{fontSize:18}}),label:``,color:`inherit`,onClick:e=>{e.stopPropagation(),Q(`next`)}}),(0,_.jsx)(m,{icon:(0,_.jsx)(ae,{sx:{fontSize:18}}),label:``,color:`inherit`,onClick:e=>{e.stopPropagation(),Q(`last`)}})]}):void 0,children:(0,_.jsx)(l,{disablePadding:!0,children:A.map(e=>(0,_.jsxs)(r,{children:[(0,_.jsx)(re,{sx:{px:2,py:1},children:(0,_.jsxs)(r,{sx:{display:`flex`,width:`100%`,alignItems:`center`},children:[(0,_.jsx)(r,{sx:{flex:1},children:(0,_.jsx)(r,{component:`kbd`,sx:{px:`6px`,py:`2px`,borderRadius:`4px`,fontSize:11,bgcolor:`action.hover`,fontFamily:`'Roboto Mono', monospace`},children:e._key})}),(0,_.jsx)(r,{sx:{fontFamily:`'Roboto Mono', monospace`,fontSize:12},children:q(e).map((t,n)=>(0,_.jsxs)(`span`,{children:[t,`: `,e[t],n<q(e).length-1&&` · `]},t))})]})}),(0,_.jsx)(c,{})]},e._key))})})]}),C&&M&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r,{sx:{mt:1}}),(0,_.jsx)(g,{title:`${$.indexInfo}: ${C}`,accordionKey:`search-index-info`,actions:x?void 0:(0,_.jsx)(m,{icon:(0,_.jsx)(ne,{sx:{fontSize:18}}),label:$.dropIndex,color:`inherit`,onClick:e=>{e.stopPropagation(),Oe()}}),children:(0,_.jsx)(l,{disablePadding:!0,children:q(M).map(e=>(0,_.jsxs)(r,{children:[(0,_.jsx)(re,{sx:{px:2,py:1},children:(0,_.jsxs)(r,{sx:{display:`flex`,width:`100%`},children:[(0,_.jsx)(r,{sx:{flex:1},children:e}),(0,_.jsx)(r,{sx:{fontFamily:`'Roboto Mono', monospace`,fontSize:12},children:JSON.stringify(M[e])})]})}),(0,_.jsx)(c,{})]},e))})})]}),!x&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(r,{sx:{mt:1}}),(0,_.jsx)(g,{title:$.createIndex,accordionKey:`search-create-index`,children:(0,_.jsxs)(r,{sx:{p:2},children:[(0,_.jsx)(h,{fullWidth:!0,size:`small`,label:$.indexName,value:V,onChange:e=>H(e.target.value)}),(0,_.jsx)(h,{fullWidth:!0,size:`small`,sx:{mt:1},label:$.prefix,placeholder:`e.g. doc:`,value:U,onChange:e=>Te(e.target.value)}),(0,_.jsxs)(r,{sx:{display:`flex`,alignItems:`center`,gap:1,my:1},children:[(0,_.jsx)(`strong`,{children:`Schema`}),(0,_.jsx)(o,{title:`Add`,children:(0,_.jsx)(d,{variant:`contained`,color:`primary`,onClick:ke,sx:{minWidth:40,width:40,height:40,p:0,borderRadius:`4px`},children:(0,_.jsx)(s,{fontSize:`small`})})})]}),W.map((t,n)=>(0,_.jsxs)(r,{sx:{display:`flex`,alignItems:`center`,gap:1,mb:.5,flexWrap:`wrap`},children:[(0,_.jsx)(h,{size:`small`,sx:{flex:1,minWidth:120},label:$.fieldName,value:t.name,onChange:e=>{let t=[...W];t[n]={...t[n],name:e.target.value},G(t)}}),(0,_.jsxs)(r,{sx:{display:`flex`,alignItems:`center`,gap:1,flexShrink:0},children:[(0,_.jsxs)(p,{size:`small`,sx:{width:130},children:[(0,_.jsx)(ue,{children:e?.label?.type}),(0,_.jsx)(le,{value:t.type,label:e?.label?.type,onChange:e=>{let t=[...W];t[n]={...t[n],type:e.target.value},G(t)},children:[`TEXT`,`NUMERIC`,`TAG`,`GEO`,`VECTOR`].map(e=>(0,_.jsx)(u,{value:e,children:e},e))})]}),(0,_.jsx)(o,{title:e?.intention?.delete,children:(0,_.jsx)(`span`,{children:(0,_.jsx)(d,{variant:`contained`,color:`error`,onClick:()=>Ae(n),disabled:W.length<=1,sx:{minWidth:40,width:40,height:40,p:0,borderRadius:`4px`},children:(0,_.jsx)(ge,{fontSize:`small`})})})})]})]},n)),(0,_.jsx)(r,{sx:{mt:1,textAlign:`right`},children:(0,_.jsx)(Pe,{icon:(0,_.jsx)(s,{fontSize:`small`}),label:$.createIndex,color:`secondary`,onClick:je,disabled:!V.trim()})})]})})]})]})}export{y as default};