1var M=Object.defineProperty;var U=(e,t,o)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var C=(e,t,o)=>U(e,typeof t!="symbol"?t+"":t,o);import{r as R,j as n}from"./react-DJo-hRcj.js";import{T,B as z,a3 as w,a as $,j as V,au as O,A as E}from"./index-B5XNITP8.js";import{I as G,c8 as v,b$ as H,bq as L,bV as Q,bd as K,be as J,bc as D}from"./vendors-_9dKRPAn.js";import{H as W}from"./index-DSSmR8GK.js";import{C as Y}from"./index-BKy_m-tN.js";import{L as X}from"./Layout-hleQVaK2.js";import{aq as I,ac as F,aV as _,b7 as Z}from"./mui-core-DIGHSUz9.js";import{R as ee}from"./RoleQueryRepository-DFJU5Qdn.js";import{a as B}from"./toastifyV2-JsPZrQKQ.js";import"./lodash-D9U91hCZ.js";import"./mui-x-WaaF4sFd.js";import"./index-wDYjRIOv.js";import"./useCheckPermissionSidebar-BJ_M-sXv.js";import"./LocalStorageManager-Brbsb2wO.js";import"./index-C6hXkfvS.js";import"./useUrlParams-9vBjnh_J.js";import"./Search-BtClgkYE.js";import"./ModalV2-Bwgoj2D8.js";import"./org-switch-rules-CALv74Cz.js";import"./useOrgList-CLYvyZdj.js";import"./DashboardQueryRepository-BaKnPLob.js";import"./Search-CSvDv4Dl.js";import"./Building-_OqbRV1u.js";import"./Check-DzZWfpvT.js";import"./languageManager-_RIZidnS.js";import"./SharedComponents-CFIIYYlL.js";import"./LocalStorageManager-Cf9EMmua.js";import"./constants-BhQb0AAi.js";import"./getHttpStatusCode-D6Fy-dO9.js";import"./getTenantId-D-FzaJmc.js";function te(e){if(!e||typeof e!="string")return"";const t=e.replace(/[-_]/g," ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function ne({group:e,actions:t,checkedActions:o,onSelectAll:i,onActionChange:a}){const{t:l}=G(),m=(c,r)=>{const b=[];for(let h=0;h<c.length;h+=r)b.push(c.slice(h,h+r));return b},x=Math.ceil(t.length/3),y=R.useMemo(()=>m(t,x).map(c=>({id:c.map(r=>r.id).join("-"),actions:c})),[t,x]);return n.jsxs(I,{sx:{overflow:"visible",backgroundColor:"#FFF",padding:"16px",borderRadius:"8px",mb:2},children:[n.jsx(T,{variant:"h4SMedium",sx:{fontSize:"16px",fontWeight:500,marginBottom:"16px"},children:e}),n.jsxs(z,{sx:{width:"100%"},children:[n.jsx(F,{control:n.jsx(w,{checked:Object.values(o[e]||{}).every(Boolean),onChange:()=>i(e),sx:{padding:"4px"}}),label:l("select_all"),sx:{margin:0,mb:2,"& .MuiTypography-root":{fontSize:"14px",marginLeft:"4px",fontWeight:500}}}),n.jsx(_,{container:!0,spacing:2,children:y.map(c=>n.jsx(_,{item:!0,xs:12,md:4,children:n.jsx(Z,{children:n.jsx(I,{gap:1,direction:"column",children:c.actions.map(r=>n.jsx(F,{control:n.jsx(w,{checked:o[e]?.[r.id]||!1,onChange:()=>a(e,r.id),sx:{padding:"4px"}}),label:n.jsx(T,{variant:"bodySmRegular",children:r.displayName||te(r.name)}),sx:{margin:0,"& .MuiTypography-root":{fontSize:"14px",marginLeft:"4px"}}},`action-${r.id}`))})})},`col-${e}-${c.id}`))})]})]})}class oe{constructor({tenantId:t,projectId:o,queryClient:i}){C(this,"tenantId");C(this,"projectId");C(this,"queryClient");this.tenantId=t,this.projectId=o,this.queryClient=i}get actionKey(){return["action",this.projectId]}getActions(){return{queryKey:this.actionKey,queryFn:()=>$.get("/v2/actions")}}}const se=["specialist","manager","member","contributor","viewer","restricted","read-tenant","write-tenant","modify-tenant","invite-tenant","read-organization_unit","write-organization_unit","modify-organization_unit","invite-organization_unit","remove-organization_unit"],ae="Report Template";function re(e,t=!1){if(!e||!Array.isArray(e))return{};const i=e.filter(a=>!se.includes(a.slug)).reduce((a,l)=>{const m=l.actionType.name||"Default Group";return a[m]||(a[m]=[]),a[m].push(l),a},{});return t||delete i[ae],i}function ie(){const{roleId:e}=v(),[t,o]=R.useState({}),i=H(),{tenantId:a,id:l}=v(),{state:m}=V(),x=m?.tenants?.find(s=>Number(s.id)===Number(a)),y=new ee({tenantId:Number(a),projectId:Number(l),queryClient:i}),c=new oe({tenantId:Number(a),projectId:Number(l),queryClient:i}),{isLoading:r,data:b}=L(y.getRoleDetail({id:Number(e)})),{isLoading:h,data:f}=L(c.getActions()),{data:k}=b?.data||{},{data:P}=f?.data||{},A=re(P,x?.isTemplateFactory??!1);function N(s,d){const u={},j=new Set(d.map(p=>p.id));
1return Object.keys(s).forEach(p=>{u[p]={},s[p].forEach(g=>{u[p][g.id]=j.has(g.id)})}),u}const S=k?.actions||[];R.useEffect(()=>{o(N(A,S))},[JSON.stringify(A),JSON.stringify(S)]);const{mutate:q}=Q(y.updateRoleActions({onSuccess:()=>{B.success()},onError:s=>{B.error({title:s.response?.data?.message||s.message})}}));return{roleData:k,groupedActions:A,checkedActions:t,handleSelectAll:s=>{const d=t[s],j=!Object.values(d).every(Boolean),p=Object.fromEntries(Object.keys(d).map(g=>[Number(g),j]));o(g=>({...g,[s]:p}))},handleActionChange:(s,d)=>{o(u=>({...u,[s]:{...u[s],[d]:!u[s][d]}}))},handleReset:()=>{o(N(A,S))},handleSave:s=>{const d=[];Object.values(t).forEach(u=>{Object.entries(u).forEach(([j,p])=>{p&&d.push(Number(j))})}),q({id:Number(e),payload:{actionIds:d}},{onSuccess:()=>{s&&s()}})},isLoading:r||h}}function Ue(){const{t:e}=G(),t=K(),{tenantId:o,id:i}=v(),{roleData:a,groupedActions:l,checkedActions:m,isLoading:x,handleSelectAll:y,handleActionChange:c,handleReset:r,handleSave:b}=ie();if(x)return null;const h=()=>{t.push(D(O,{tenantId:o,id:i}))};return n.jsxs(X,{children:[n.jsxs(J,{children:[n.jsx("title",{children:`${e("role")} > ${a?.name} - FPT Data Suite`}),n.jsx("meta",{name:"keywords",content:"Data warehouse , dashboard, reports, workspace, analytics"})]}),n.jsx(W,{title:e("role"),breadcrumbs:[{id:1,label:e("role"),value:D(O,{tenantId:o,id:i})},{id:2,label:a?.name}],onClickItem:f=>{f.value&&t.push(f.value)}}),n.jsxs(Y,{sx:{overflow:"hidden"},children:[n.jsx(I,{sx:{overflow:"auto"},children:Object.keys(l).map(f=>n.jsx(ne,{group:f,actions:l[f],checkedActions:m,onSelectAll:y,onActionChange:c},f))}),n.jsxs(z,{style:{display:"flex",justifyContent:"flex-end",marginTop:20},display:"flex",justifyContent:"flex-end",mt:5,children:[n.jsx(E,{onClick:r,variant:"tertiary",sx:{mr:2},children:e("button.reset")}),n.jsx(E,{onClick:()=>b(h),children:e("button.save")})]})]})]})}export{Ue as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.