2 lines
5.0 KiB
JavaScript
2 lines
5.0 KiB
JavaScript
import{r as i,aF as C,O as a,av as F,aZ as f,aW as O,aN as R,bm as P,Q as L,aL as W,b5 as I}from"./antd-Fjtw10f5.js";import{u as M,e as N,h as b,al as z}from"./index-MX8oHKxT.js";import{d as l}from"./db-work-order-api-BXZp-Gs9.js";import{N as x}from"./NButton-FHjmnDp_.js";import{g as E}from"./sort-D3DOCK5z.js";import{U as Q}from"./QuerySelects-CkSmKuzv.js";import"./react-SrRW2L_K.js";import"./monaco-DodBlCgL.js";import"./charts-ZMKDUWQn.js";import"./xterm-E8RPdd7g.js";import"./user-api-Cv3IeHAl.js";import"./department-api-BCROfIRD.js";import"./asset-api-B7Ngeewi.js";import"./website-api--YEutQ2x.js";import"./database-asset-api-UTkzCR3Q.js";const{Text:k}=O,ae=()=>{const{t:e}=M(),n=i.useRef(null),{modal:v,message:d}=C.useApp(),[y,u]=i.useState(!1),[c,p]=i.useState(""),[g,m]=i.useState(void 0),j=N({queryKey:["portal-database-assets"],queryFn:()=>z.databaseAssets(),refetchOnWindowFocus:!1}),S=b({mutationFn:t=>l.approve(t),onSuccess:()=>{n.current?.reload(),d.success(e("general.success"))}}),w=b({mutationFn:t=>l.reject(t.id,t.reason),onSuccess:()=>{n.current?.reload(),u(!1),p(""),m(void 0),d.success(e("general.success"))}}),q=b({mutationFn:t=>l.deleteById(t),onSuccess:()=>{n.current?.reload(),d.success(e("general.success"))}}),T=(t,r)=>{const o={pending:{color:"processing",label:e("db.work_order.status.pending")},approved:{color:"blue",label:e("db.work_order.status.approved")},rejected:{color:"red",label:e("db.work_order.status.rejected")},executed:{color:"green",label:e("db.work_order.status.executed")},failed:{color:"red",label:e("db.work_order.status.failed")}}[t]||{color:"default",label:t};return(t==="failed"||t==="rejected")&&r?a.jsx(f,{title:r,children:a.jsx(I,{color:o.color,children:o.label})}):a.jsx(I,{color:o.color,children:o.label})},A=[{title:e("menus.resource.submenus.database_asset"),dataIndex:"assetName",formItemProps:{name:"assetId"},renderFormItem:(t,{type:r,...s})=>r==="form"?null:a.jsx(F,{allowClear:!0,showSearch:!0,placeholder:e("menus.resource.submenus.database_asset"),loading:j.isLoading,options:(j.data||[]).map(o=>({label:o.name,value:o.id})),filterOption:(o,h)=>(h?.label??"").toString().toLowerCase().includes(o.toLowerCase()),...s}),ellipsis:!0,fixed:"left"},{title:e("db.asset.database"),dataIndex:"database",hideInSearch:!0,ellipsis:!0},{title:e("db.sql_log.sql"),dataIndex:"sql",hideInSearch:!0,render:t=>t?a.jsx(f,{title:t,placement:"topLeft",children:a.jsx(k,{ellipsis:!0,style:{maxWidth:260},children:t})}):"-"},{title:e("db.work_order.reason"),dataIndex:"requestReason",hideInSearch:!0,render:t=>t?a.jsx(f,{title:t,placement:"topLeft",children:a.jsx(k,{ellipsis:!0,style:{maxWidth:220},children:t})}):"-"},{title:e("db.work_order.requester"),dataIndex:"requesterName",formItemProps:{name:"requesterId"},renderFormItem:(t,{type:r,...s})=>r==="form"?null:a.jsx(Q,{...s}),render:t=>t||"-"},{title:e("general.status"),dataIndex:"status",valueEnum:{pending:{text:e("db.work_order.status.pending")},approved:{text:e("db.work_order.status.approved")},rejected:{text:e("db.work_order.status.rejected")},executed:{text:e("db.work_order.status.executed")},failed:{text:e("db.work_order.status.failed")}},render:(t,r)=>T(r.status,r.errorMessage||r.reason),width:120},{title:e("db.sql_log.rows_affected"),dataIndex:"rowsAffected",hideInSearch:!0,width:120},{title:e("db.work_order.approver"),dataIndex:"approverName",hideInSearch:!0,width:120},{title:e("general.created_at"),dataIndex:"createdAt",valueType:"dateTime",hideInSearch:!0,sorter:!0,width:180},{title:e("sysops.logs.exec_at"),dataIndex:"executedAt",valueType:"dateTime",hideInSearch:!0,width:180},{title:e("actions.label"),valueType:"option",key:"option",width:160,fixed:"right",render:(t,r)=>{const s=[];return r.status==="pending"&&(s.push(a.jsx(x,{onClick:()=>{v.confirm({title:e("db.work_order.approve_confirm"),onOk:async()=>S.mutate(r.id)})},children:e("db.work_order.approve")},"approve")),s.push(a.jsx(x,{danger:!0,onClick:()=>{u(!0),m(r.id)},children:e("identity.policy.action.reject")},"reject"))),r.status!=="approved"&&s.push(a.jsx(R,{title:e("general.confirm_delete"),onConfirm:()=>q.mutate(r.id),children:a.jsx(x,{danger:!0,children:e("actions.delete")},"delete")},"delete-confirm")),s}}];return a.jsxs("div",{children:[a.jsx(P,{columns:A,actionRef:n,request:async(t={},r)=>{const[s,o]=E(r),h={pageIndex:t.current,pageSize:t.pageSize,sortOrder:s,sortField:o,status:t.status,assetId:t.assetId,requesterId:t.requesterId},_=await l.paging(h);return{data:_.items,success:!0,total:_.total}},rowKey:"id",search:{labelWidth:"auto"},pagination:{defaultPageSize:10,showSizeChanger:!0},scroll:{x:"max-content"},dateFormatter:"string",headerTitle:e("menus.resource.submenus.db_work_order")}),a.jsx(L,{title:e("identity.policy.action.reject"),open:y,onOk:()=>{if(g){if(!c.trim()){d.error(e("db.work_order.reject_reason"));return}w.mutate({id:g,reason:c})}},onCancel:()=>{u(!1),p(""),m(void 0)},confirmLoading:w.isPending,children:a.jsx(W.TextArea,{rows:4,value:c,onChange:t=>p(t.target.value),placeholder:e("db.work_order.reject_reason")})})]})};export{ae as default};
|