theme.keycloak.v2.admin.resources.assets.NewPolicyDialog-DySSrR_B.js Maven / Gradle / Ivy
import{jsxs as y,jsx as e,Fragment as A}from"react/jsx-runtime";import*as O from"react";import{useState as k,useRef as ct,useCallback as dt,useMemo as je}from"react";import{o as ze,aM as U,bT as ge,_ as pt,bU as ut,bV as mt,bW as ht,bX as ft,bY as gt,am as Ct,m as Ce,bb as yt,bc as St,bZ as Tt,b_ as vt,b$ as It,u as te,a as R,aj as j,w as ne,ac as L,ad as F,ae as w,V as bt,K as re,c0 as xt,c1 as Ot,ag as Be,ah as We,c2 as kt,i as _,c3 as Pt,W as Rt,aq as ee,U as ie,R as ce,c as Dt,d as Ye,B as se,bj as $t,b5 as Ze,b6 as Me,L as Je,b8 as Xe,bm as Mt,M as Qe,q as et,J as ye,N as Se,aN as Ae,D as xe,s as tt,x as nt,bS as ke,ap as Pe,y as de,O as At,ai as Et,ak as it,al as oe,ao as Vt,g as _t,f as wt,a3 as Nt,P as Ht,F as Lt,A as Ft,bB as Ee,k as Ve,aa as qt,Z as _e,$ as Ut}from"./main-C7ps2lmX.js";import{u as st}from"./ConfirmDialog-hx7XKLbN.js";import{F as Gt}from"./FormAccess-DyLNkc18.js";import{V as Kt}from"./ViewHeader-B7eeFzFA.js";import{u as ot}from"./useParams-B67lSY02.js";import{u as pe}from"./useToggle-K3Kx99tM.js";import{U as ue,V as me,W as Z,X as G,Y as he,Z as K}from"./Td-D2hVFK0Z.js";import{C as jt}from"./ClientSelect-B9UqjyP6.js";import{h as zt}from"./ClientScopeTypes-BnGjMgG5.js";import{L as Bt}from"./PaginatingTableToolbar-Cjsz5Jh4.js";import{K as Wt}from"./KeycloakDataTable-DbY4la1D.js";import{g as Yt}from"./utils-DeGqqWSp.js";import{F as we}from"./filter-icon-DO0QNij3.js";import{G as Zt}from"./GroupPickerDialog-C09EjRTA.js";import{C as Jt,L as Xt}from"./CodeEditor-C-nZkUJx.js";import{D as Qt}from"./SwitchControl-C_9Y74oV.js";import{A as en,S as tn}from"./AddRoleMappingModal-DW8o4W0z.js";import{d as Te,D as nn}from"./DatePicker-DTJHSI7E.js";import{F as sn,a as Ne}from"./FlexItem-BzZfUnQ1.js";import{d as on}from"./debounce-DTNSlfWG.js";const B=" AM",W=" PM",an=(t,s,a,p,d,c)=>{const l=[],u=new Date(new Date().setHours(0,0,0,0)),f=u.getDay();for(;u.getDay()===f;){let h=u.getHours(),n=B;s&&(h===0?h=12:h>=12&&(n=W),h>12&&(h%=12)),h=s?h.toString():h.toString().padStart(2,"0");const i=u.getMinutes().toString().padStart(2,"0"),r=`${h}${a}${i}${s?n:""}`;lt(p,d,r,a,c)&&l.push(r),u.setMinutes(u.getMinutes()+t)}return l},z=(t,s,a,p,d)=>{const c=new Date(t);if(!isNaN(c.getDate())&&(t instanceof Date||t.includes("T"))){const l=p?`${c.getHours()>12?c.getHours()-12:c.getHours()}`:`${c.getHours()}`.padStart(2,"0"),u=`${c.getMinutes()}`.padStart(2,"0"),f=d?`${c.getSeconds()}`.padStart(2,"0"):"",h=f?`${a}${f}`:"";let n="";return p&&c.getHours()>11?n=W:p&&(n=B),`${l}${a}${u}${h}${n}`}else if(typeof t=="string"&&(t=t.trim(),t!==""&&at(t,s,a,p))){const[,l,u,f,h=""]=s.exec(t),n=d?`${a}${f??"00"}`:"";let i="";if(p){const r=h.toUpperCase();r===B.toUpperCase().trim()?i=B:r===W.toUpperCase().trim()?i=W:i=new Date().getHours()>11?W:B}return`${l}${a}${u}${n}${i}`}return t.toString()},at=(t,s,a,p)=>{const d=new Date(t);if(!isNaN(d.getDate())&&t.includes("T"))return!0;const c=parseInt(t.split(a)[0]),l=c>=(p?1:0)&&c<=(p?12:23);return t===""||s.test(t)&&l},He=(t,s)=>{const a=t.match(s);return a&&a.length?/pm/i.test(a[4])?parseInt(a[1])===12?parseInt(a[1]):parseInt(a[1])+12:/am/i.test(a[4])&&parseInt(a[1])===12?0:parseInt(a[1]):null},Le=(t,s)=>{const a=t.match(s);return a&&a.length?parseInt(a[2]):null},Fe=(t,s)=>{var a;const p=(a=t.match(s))===null||a===void 0?void 0:a[3];return p?parseInt(p):null},lt=(t,s,a,p,d)=>{if(a.trim()==="")return!0;const c=ve(t,p,d),l=ve(a,p,d),u=ve(s,p,d);return c<=l&&l<=u},ve=(t,s,a)=>{const d=new RegExp(`^\\s*(\\d\\d?)${s}([0-5]\\d)${s}?([0-5]\\d)?\\s*([AaPp][Mm])?\\s*$`).exec(t);if(!d||!d.length)return;let c=d[1].padStart(2,"0");const l=d[2];let u=d[3]?`${s}${d[3]}`:"";!u&&a&&(u=`${s}00`);const f=d[4]||"";return f.toUpperCase()==="PM"&&c!=="12"?c=`${parseInt(c)+12}`:f.toUpperCase()==="AM"&&c==="12"&&(c="00"),`${c}${s}${l}${u}`},ln={name:"OutlinedClockIcon",height:512,width:512,svgPath:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm0 448c-110.5 0-200-89.5-200-200S145.5 56 256 56s200 89.5 200 200-89.5 200-200 200zm61.8-104.4l-84.9-61.7c-3.1-2.3-4.9-5.9-4.9-9.7V116c0-6.6 5.4-12 12-12h32c6.6 0 12 5.4 12 12v141.7l66.8 48.6c5.4 3.9 6.5 11.4 2.6 16.8L334.6 349c-3.9 5.3-11.4 6.5-16.8 2.6z",yOffset:0,xOffset:0},rn=ze(ln),cn={name:"--pf-v5-c-date-picker__input--c-form-control--Width",value:"calc(10 * 1ch + calc(2rem + 0.5rem))",var:"var(--pf-v5-c-date-picker__input--c-form-control--Width)"};class Re extends O.Component{constructor(s){super(s),this.baseComponentRef=O.createRef(),this.toggleRef=O.createRef(),this.inputRef=O.createRef(),this.menuRef=O.createRef(),this.onDocClick=n=>{var i,r,o,g;const C=(r=(i=this.toggleRef)===null||i===void 0?void 0:i.current)===null||r===void 0?void 0:r.contains(n.target),T=(g=(o=this.menuRef)===null||o===void 0?void 0:o.current)===null||g===void 0?void 0:g.contains(n.target);this.state.isTimeOptionsOpen&&!(C||T)&&this.onToggle(!1)},this.handleGlobalKeys=n=>{var i,r,o,g;const{isTimeOptionsOpen:C,focusedIndex:T,scrollIndex:D}=this.state;!((r=(i=this.inputRef)===null||i===void 0?void 0:i.current)===null||r===void 0)&&r.contains(n.target)?!C&&n.key!==U.Tab&&n.key!==U.Escape?this.onToggle(!0):C&&(n.key===U.Escape||n.key===U.Tab?this.onToggle(!1):n.key===U.Enter?T!==null?(this.focusSelection(T),n.stopPropagation()):this.onToggle(!1):(n.key===U.ArrowDown||n.key===U.ArrowUp)&&(this.focusSelection(D),this.updateFocusedIndex(0),n.preventDefault())):!((g=(o=this.menuRef)===null||o===void 0?void 0:o.current)===null||g===void 0)&&g.contains(n.target)&&(n.key===U.ArrowDown?(this.updateFocusedIndex(1),n.preventDefault()):n.key===U.ArrowUp?(this.updateFocusedIndex(-1),n.preventDefault()):(n.key===U.Escape||n.key===U.Tab)&&(this.inputRef.current.focus(),this.onToggle(!1)))},this.updateFocusedIndex=n=>{this.setState(i=>{const r=this.getOptions().length-1;let o=i.focusedIndex!==null?i.focusedIndex+n:i.scrollIndex+n;return o<0?o=r:o>r&&(o=0),this.scrollToIndex(o),{focusedIndex:o}})},this.getIndexToScroll=n=>this.props.menuAppendTo==="inline"?n>0?n-1:0:n,this.scrollToIndex=n=>{this.getOptions()[n].closest(`.${ge.menuContent}`).scrollTop=this.getOptions()[this.getIndexToScroll(n)].offsetTop},this.focusSelection=n=>{var i;const r=n!==-1?n:0;!((i=this.menuRef)===null||i===void 0)&&i.current&&this.getOptions()[r].querySelector(`.${ge.menuItem}`).focus()},this.scrollToSelection=n=>{const{delimiter:i,is24Hour:r}=this.props;let o=n.split(this.props.delimiter),g=null;if(o.length<2?(n=`${n}${i}00`,o=n.split(i)):o.length>2&&(n=z(n,this.state.timeRegex,i,!r,!1),o=n.split(i)),!r&&o.length>1&&o[1].length<2){const T=o[1].length===0?"00":o[1]+"0";n=`${o[0]}${i}${T}${new Date().getHours()>11?W:B}`}else!r&&o.length>1&&o[1].length===2&&!n.toUpperCase().includes(B.toUpperCase().trim())&&!n.toUpperCase().includes(W.toUpperCase().trim())&&(n=`${n}${new Date().getHours()>11?W:B}`);let C=this.getOptions().findIndex(T=>T.textContent===n);if(C!==-1)this.scrollToIndex(C),g=C;else if(o.length===2){let T="";r||(o[1].toUpperCase().includes("P")?T=W:o[1].toUpperCase().includes("A")&&(T=B)),n=`${o[0]}${i}00${T}`,C=this.getOptions().findIndex(D=>D.textContent===n),C!==-1&&this.scrollToIndex(C)}this.setState({focusedIndex:g,scrollIndex:C})},this.getRegExp=(n=!0)=>{const{is24Hour:i,delimiter:r}=this.props;let o=`\\s*(\\d\\d?)${r}([0-5]\\d)`;return n&&(o+=`${r}?([0-5]\\d)?`),new RegExp(`^${o}${i?"":"\\s*([AaPp][Mm])?"}\\s*$`)},this.getOptions=()=>{var n;return!((n=this.menuRef)===null||n===void 0)&&n.current?Array.from(this.menuRef.current.querySelectorAll(`.${ge.menuListItem}`)):[]},this.isValidFormat=n=>{if(this.props.validateTime)return this.props.validateTime(n);const{delimiter:i,is24Hour:r,includeSeconds:o}=this.props;return at(n,this.getRegExp(o),i,!r)},this.isValidTime=n=>{const{delimiter:i,includeSeconds:r}=this.props,{minTimeState:o,maxTimeState:g}=this.state;return lt(o,g,n,i,r)},this.isValid=n=>this.isValidFormat(n)&&this.isValidTime(n),this.onToggle=n=>{this.setState(i=>{const{timeRegex:r,isInvalid:o,timeState:g}=i,{delimiter:C,is24Hour:T,includeSeconds:D,onChange:M}=this.props,b=z(g,r,C,!T,D);return M&&!n&&b!==g&&M(null,b,He(b,r),Le(b,r),Fe(b,r),this.isValid(b)),{isTimeOptionsOpen:n,timeState:b,isInvalid:n?o:!this.isValid(b)}}),this.props.setIsOpen(n),n||this.inputRef.current.focus()},this.onSelect=n=>{const{timeRegex:i,timeState:r}=this.state,{delimiter:o,is24Hour:g,includeSeconds:C,setIsOpen:T}=this.props,D=z(n.target.textContent,i,o,!g,C);D!==r&&this.onInputChange(n,D),this.inputRef.current.focus(),this.setState({isTimeOptionsOpen:!1,isInvalid:!1}),T(!1)},this.onInputClick=n=>{this.state.isTimeOptionsOpen||this.onToggle(!0),n.stopPropagation()},this.onInputChange=(n,i)=>{const{onChange:r}=this.props,{timeRegex:o}=this.state;r&&r(n,i,He(i,o),Le(i,o),Fe(i,o),this.isValid(i)),this.scrollToSelection(i),this.setState({timeState:i})};const{is24Hour:a,delimiter:p,time:d,includeSeconds:c,isOpen:l}=this.props;let{minTime:u,maxTime:f}=this.props;if(u===""){const n=c?`${p}00`:"";u=a?`00${p}00${n}`:`12${p}00${n} AM`}if(f===""){const n=c?`${p}59`:"";f=a?`23${p}59${n}`:`11${p}59${n} PM`}const h=this.getRegExp();this.state={isInvalid:!1,isTimeOptionsOpen:l,timeState:z(d,h,p,!a,c),focusedIndex:null,scrollIndex:0,timeRegex:h,minTimeState:z(u,h,p,!a,c),maxTimeState:z(f,h,p,!a,c)}}componentDidMount(){document.addEventListener("mousedown",this.onDocClick),document.addEventListener("touchstart",this.onDocClick),document.addEventListener("keydown",this.handleGlobalKeys),this.setState({isInvalid:!this.isValid(this.state.timeState)})}componentWillUnmount(){document.removeEventListener("mousedown",this.onDocClick),document.removeEventListener("touchstart",this.onDocClick),document.removeEventListener("keydown",this.handleGlobalKeys)}componentDidUpdate(s,a){const{timeState:p,isTimeOptionsOpen:d,isInvalid:c,timeRegex:l}=this.state,{time:u,is24Hour:f,delimiter:h,includeSeconds:n,isOpen:i,minTime:r,maxTime:o}=this.props;if(s.isOpen!==i&&this.onToggle(i),d&&!a.isTimeOptionsOpen&&p&&!c&&this.scrollToSelection(p),h!==s.delimiter&&this.setState({timeRegex:this.getRegExp()}),u!==""&&u!==s.time){const g=z(u,l,h,!f,n);this.setState({timeState:g,isInvalid:!this.isValid(g)})}r!==""&&r!==s.minTime&&this.setState({minTimeState:z(r,l,h,!f,n)}),o!==""&&o!==s.maxTime&&this.setState({maxTimeState:z(o,l,h,!f,n)})}render(){const s=this.props,{"aria-label":a,isDisabled:p,className:d,placeholder:c,id:l,menuAppendTo:u,is24Hour:f,invalidFormatErrorMessage:h,invalidMinMaxErrorMessage:n,stepMinutes:i,width:r,delimiter:o,inputProps:g,onChange:C,setIsOpen:T,isOpen:D,time:M,validateTime:b,minTime:v,maxTime:I,includeSeconds:J,zIndex:X}=s,m=pt(s,["aria-label","isDisabled","className","placeholder","id","menuAppendTo","is24Hour","invalidFormatErrorMessage","invalidMinMaxErrorMessage","stepMinutes","width","delimiter","inputProps","onChange","setIsOpen","isOpen","time","validateTime","minTime","maxTime","includeSeconds","zIndex"]),{timeState:x,isTimeOptionsOpen:N,isInvalid:$,minTimeState:H,maxTimeState:q}=this.state,ae={[cn.name]:r},fe=an(i,!f,o,H,q,J),S=this.isValidFormat(x),E=l||ut("time-picker"),P=()=>this.baseComponentRef&&this.baseComponentRef.current?this.baseComponentRef.current.parentElement:null,Y=O.createElement(mt,{ref:this.menuRef,isScrollable:!0},O.createElement(ht,{maxMenuHeight:"200px"},O.createElement(ft,{"aria-label":a},fe.map(($e,rt)=>O.createElement(gt,{onClick:this.onSelect,key:$e,id:`${E}-option-${rt}`},$e))))),V=O.createElement(Ct,Object.assign({"aria-haspopup":"menu",id:`${E}-input`,"aria-label":a,validated:$?"error":"default",placeholder:c,value:x||"",type:"text",customIcon:O.createElement(rn,null),onClick:this.onInputClick,onChange:this.onInputChange,autoComplete:"off",isDisabled:p,isExpanded:N,ref:this.inputRef},g));let Q;switch(u){case"inline":Q=()=>this.toggleRef.current;break;case"parent":Q=P;break;default:Q=u}return O.createElement("div",{ref:this.baseComponentRef,className:Ce(Te.datePicker,d)},O.createElement("div",Object.assign({className:Ce(Te.datePickerInput),style:ae},m),O.createElement(yt,null,O.createElement(St,null,O.createElement("div",{id:E},O.createElement("div",{ref:this.toggleRef,style:{paddingLeft:"0"}},O.createElement(Tt,{appendTo:Q,trigger:V,triggerRef:this.toggleRef,popper:Y,popperRef:this.menuRef,isVisible:N,zIndex:X}))))),$&&O.createElement("div",{className:Ce(Te.datePickerHelperText)},O.createElement(vt,null,O.createElement(It,{variant:"error"},S?n:h)))))}}Re.displayName="TimePicker";Re.defaultProps={className:"",isDisabled:!1,time:"",is24Hour:!1,invalidFormatErrorMessage:"Invalid time format",invalidMinMaxErrorMessage:"Invalid time entered",placeholder:"hh:mm",delimiter:":","aria-label":"Time picker",width:"150px",menuAppendTo:"inline",stepMinutes:30,inputProps:{},minTime:"",maxTime:"",isOpen:!1,setIsOpen:()=>{},zIndex:9999};const dn={name:"CaretUpIcon",height:512,width:320,svgPath:"M288.662 352H31.338c-17.818 0-26.741-21.543-14.142-34.142l128.662-128.662c7.81-7.81 20.474-7.81 28.284 0l128.662 128.662c12.6 12.599 3.676 34.142-14.142 34.142z",yOffset:0,xOffset:0},pn=ze(dn),un=({name:t,label:s,helpText:a,defaultValue:p,isRequired:d,variant:c="typeaheadMulti"})=>{const{adminClient:l}=te(),{t:u}=R(),{control:f,getValues:h,formState:{errors:n}}=j(),i=h(t),[r,o,g]=pe(),[C,T]=k([]),[D,M]=k(""),[b,v]=k(""),I=ct(),J=dt(on(v,1e3),[]);ne(()=>{const m={max:20};return b&&(m.username=b),i?.length&&!b?Promise.all(i.map(x=>l.users.findOne({id:x}))):l.users.find(m)},T,[b]);const X=m=>m.filter(x=>x!==void 0).map(x=>e(ie,{value:x.id,selected:i?.includes(x.id),children:x.username},x.id));return y(L,{label:u(s),isRequired:d,labelIcon:e(F,{helpText:a,fieldLabelId:s}),fieldId:t,children:[e(w,{name:t,defaultValue:p,control:f,rules:d&&c==="typeaheadMulti"?{validate:m=>m.length>0}:{required:d},render:({field:m})=>e(bt,{id:t,onOpenChange:o,toggle:x=>e(re,{"data-testid":t,ref:x,variant:"typeahead",onClick:o,isExpanded:r,isFullWidth:!0,status:n[t]?"danger":void 0,children:y(xt,{isPlain:!0,children:[e(Ot,{value:D,onClick:o,onChange:(N,$)=>{g(!0),M($),J($)},autoComplete:"off",innerRef:I,placeholderText:u("selectAUser"),...m.value&&{"aria-activedescendant":m.value},role:"combobox",isExpanded:r,"aria-controls":"select-create-typeahead-listbox",children:c==="typeaheadMulti"&&Array.isArray(m.value)&&e(Be,{"aria-label":"Current selections",children:m.value.map((N,$)=>e(We,{onClick:H=>{H.stopPropagation(),m.onChange(m.value.filter(q=>q!==N))},children:C.find(H=>H?.id===N)?.username},$))})}),e(kt,{children:!!b&&e(_,{variant:"plain",onClick:()=>{M(""),v(""),m.onChange([]),I?.current?.focus()},"aria-label":"Clear input value",children:e(Pt,{"aria-hidden":!0})})})]})}),isOpen:r,selected:m.value,onSelect:(x,N)=>{const $=N?.toString();if(c!=="typeaheadMulti"){const H=m.value.includes($);H?m.onChange([]):m.onChange([$]),M(H?"":C.find(q=>q?.id===$)?.username||""),g(!1)}else{const H=m.value.find(q=>q===$)?m.value.filter(q=>q!==$):[...m.value,$];m.onChange(H)}},"aria-label":u(t),children:e(Rt,{children:X(C)})})}),n[t]&&e(ee,{message:u("required")})]})},Ie=["UNANIMOUS","AFFIRMATIVE","CONSENSUS"],mn=({helpLabel:t,isDisabled:s=!1,isLimited:a=!1})=>{const{t:p}=R(),{control:d}=j();return e(L,{label:p("decisionStrategy"),labelIcon:e(F,{helpText:p(t||"decisionStrategyHelp"),fieldLabelId:"decisionStrategy"}),fieldId:"decisionStrategy",hasNoPaddingTop:!0,children:e(w,{name:"decisionStrategy","data-testid":"decisionStrategy",defaultValue:Ie[0],control:d,render:({field:c})=>e(A,{children:(a?Ie.slice(0,2):Ie).map(l=>e(ce,{id:l,"data-testid":l,isChecked:c.value===l,isDisabled:s,name:"decisionStrategy",onChange:()=>c.onChange(l),label:p(`decisionStrategies.${l}`),className:"pf-v5-u-mb-md"},l))})})})},hn={resources:{searchFunction:"listResources",fetchFunction:"getAssociatedResources"},policies:{searchFunction:"listPolicies",fetchFunction:"getAssociatedPolicies"}},fn=({name:t,clientId:s,permissionId:a,variant:p=Me.typeaheadMulti,preSelected:d,isRequired:c=!1})=>{const{adminClient:l}=te(),{realm:u}=Dt(),{t:f}=R(),h=Ye(),{control:n,formState:{errors:i,isDirty:r}}=j(),[o,g]=k([]),[C,T]=k(""),[D,M]=k(!1),[b,v]=pe(),[I,J]=k(),[X,m]=k(),x=hn[t],N=S=>({id:"_id"in S?S._id:"id"in S?S.id:void 0,name:S.name,type:S.type});ne(async()=>{const S=Object.assign({id:s,first:0,max:10,permission:"false"},C===""?null:{name:C});return await Promise.all([l.clients.listPolicyProviders({id:s}),l.clients[x.searchFunction](S),a?l.clients[x.fetchFunction]({id:s,permissionId:a}):Promise.resolve([])])},([S,...E])=>{J(S.filter(P=>P.type!=="resource"&&P.type!=="scope")),g(E.flat().filter(P=>typeof P!="string").map(N).filter(({id:P},Y,V)=>Y===V.findIndex(({id:Q})=>P===Q)))},[C]);const[$,H]=st({titleKey:f("unsavedChangesTitle"),messageKey:f("unsavedChangesConfirm"),continueButtonLabel:f("continue"),continueButtonVariant:se.danger,onConfirm:()=>X?.()}),q=S=>t==="policies"?Xe({realm:u,id:s,policyId:S.id,policyType:S.type}):Mt({realm:u,id:s,resourceId:S.id}),ae=()=>o.map(S=>e(ie,{value:S.id,children:S.name},S.id)),fe=S=>e(Be,{children:S.value?.map(E=>{const P=o.find(V=>V.id===E);if(!P)return;const Y=q(P);return e(We,{onClick:()=>{S.onChange(S.value?.filter(V=>V!==P.id))},children:e(Je,{to:Y,onClick:V=>{r&&(V.preventDefault(),m(()=>()=>h(Y)),$())},children:P.name})},P.id)})});return y(A,{children:[e(H,{}),b&&e(Dn,{policyProviders:I,onSelect:S=>{h($t({id:s,realm:u,policyType:S.type}))},toggleDialog:v}),e(w,{name:t,defaultValue:d?[d]:[],control:n,rules:{validate:S=>!c||S.length>0},render:({field:S})=>e(Ze,{toggleId:t,variant:p,onToggle:E=>M(E),onFilter:E=>(T(E),ae()),onClear:()=>{S.onChange([]),T("")},selections:S.value,onSelect:E=>{const P=E.toString();if(p===Me.typeaheadMulti){const Y=S.value?.find(V=>V===P)?S.value.filter(V=>V!==P):[...S.value,P];S.onChange(Y)}else S.onChange([P]);T("")},isOpen:D,"aria-label":f(t),isDisabled:!!d,validated:i[t]?"error":"default",typeAheadAriaLabel:f(t),chipGroupComponent:fe(S),footer:t==="policies"?e(_,{variant:"link",isInline:!0,onClick:()=>{r?(M(!1),m(()=>v),$()):v()},children:f("createPolicy")}):void 0,children:ae()})})]})},gn=()=>{const{t}=R(),{id:s}=ot();return y(A,{children:[e(L,{label:t("applyPolicy"),fieldId:"policies",labelIcon:e(F,{helpText:t("applyPolicyHelp"),fieldLabelId:"policies"}),children:e(fn,{name:"policies",clientId:s})}),e(mn,{helpLabel:"policyDecisionStagey"})]})},Cn=()=>{const{t}=R();return e(jt,{name:"clients",label:t("clients"),helpText:t("policyClientHelp"),required:!0,defaultValue:[],variant:"typeaheadMulti"})},yn=({clientScopes:t,clientName:s,open:a,toggleDialog:p,onAdd:d,isClientScopesConditionType:c})=>{const{t:l}=R(),[u,f]=k(!1),[h,n]=k([]),[i,r]=k("Name"),[o,g]=k("All"),[C,T]=pe(),[D,M]=pe(!1),b=je(()=>o==="OpenID Connect"?t.filter(m=>m.protocol==="openid-connect"):o==="SAML"?t.filter(m=>m.protocol==="saml"):t,[t,i,o]),v=m=>{const x=h.map(N=>({scope:N,type:m}));d(x),f(!1),p()},I=m=>{m==="Name"?r("Protocol"):m==="Protocol"&&(r("Name"),g("All")),T()},J=m=>{m==="SAML"?g("SAML"):m==="OpenID Connect"?g("OpenID Connect"):m==="All"&&g("All"),M()},X=[e(ie,{value:"SAML",children:l("protocolTypes.saml")},1),e(ie,{value:"OpenID Connect",children:l("protocolTypes.openid-connect")},2),e(ie,{value:"All",children:l("protocolTypes.all")},3)];return e(Qe,{variant:et.medium,title:c?l("addClientScope"):l("addClientScopesTo",{clientName:s}),isOpen:a,onClose:p,actions:c?[e(_,{id:"modal-add","data-testid":"confirm",variant:se.primary,onClick:()=>{const m=h.map(x=>({scope:x}));d(m),p()},isDisabled:h.length===0,children:l("add")},"add"),e(_,{id:"modal-cancel","data-testid":"cancel",variant:se.link,onClick:()=>{n([]),p()},children:l("cancel")},"cancel")]:[e(ye,{popperProps:{direction:"up"},onOpenChange:m=>f(m),className:"keycloak__client-scopes-add__add-dropdown",isOpen:u,toggle:m=>e(re,{ref:m,isDisabled:h.length===0,onClick:()=>f(!u),variant:"primary",id:"add-dropdown",statusIcon:e(pn,{}),children:l("add")}),children:e(Se,{children:zt(l,v)})},"add-dropdown"),e(_,{id:"modal-cancel",variant:se.link,onClick:()=>{n([]),p()},children:l("cancel")},"cancel")],children:e(Wt,{loader:b,ariaLabelKey:"chooseAMapperType",searchPlaceholderKey:i==="Name"?"searchForClientScope":void 0,isSearching:i!=="Name",searchTypeComponent:e(ye,{onSelect:()=>{I(i)},onOpenChange:T,toggle:m=>e(re,{ref:m,"data-testid":"filter-type-dropdown",id:"toggle-id-9",onClick:T,icon:e(we,{}),statusIcon:e(Ae,{}),children:i}),isOpen:C,children:e(Se,{children:e(xe,{"data-testid":"filter-type-dropdown-item",children:l(i==="Name"?"protocol":"name")},"filter-type")})}),toolbarItem:i==="Protocol"&&y(A,{children:[e(ye,{onSelect:()=>{I(i)},onOpenChange:T,"data-testid":"filter-type-dropdown",toggle:m=>e(re,{ref:m,id:"toggle-id-9",onClick:T,statusIcon:e(Ae,{}),icon:e(we,{}),children:i}),isOpen:C,children:e(Se,{children:e(xe,{"data-testid":"filter-type-dropdown-item",children:l("name")},"filter-type")})}),e(Ze,{className:"kc-protocolType-select","aria-label":l("selectOne"),onToggle:M,onSelect:m=>J(m.toString()),selections:o,isOpen:D,children:X})]}),canSelectAll:!0,onSelect:m=>n(m),columns:[{name:"name"},{name:"protocol",displayKey:"protocol",cellRenderer:m=>Yt(l,m.protocol??"openid-connect")},{name:"description"}],emptyState:e(Bt,{message:l("emptyAddClientScopes"),instructions:l("emptyAddClientScopesInstructions")})})})},Sn=()=>{const{adminClient:t}=te(),{t:s}=R(),{control:a,getValues:p,setValue:d,formState:{errors:c}}=j(),[l,u]=k(!1),[f,h]=k([]),[n,i]=k([]),r=tt();return ne(()=>t.clientScopes.find(),o=>{i(p("clientScopes").map(g=>o.find(C=>C.id===g.id))),h(r(o,nt("name")))},[]),y(L,{label:s("clientScopes"),labelIcon:e(F,{helpText:s("clientsClientScopesHelp"),fieldLabelId:"clientScopes"}),fieldId:"clientScopes",isRequired:!0,children:[e(w,{name:"clientScopes",control:a,defaultValue:[],rules:{validate:o=>o.filter(g=>g.id).length>0},render:({field:o})=>y(A,{children:[l&&e(yn,{clientScopes:f.filter(g=>!o.value.map(C=>C.id).includes(g.id)),isClientScopesConditionType:!0,open:l,toggleDialog:()=>u(!l),onAdd:g=>{i([...n,...g.map(C=>C.scope)]),o.onChange([...o.value,...g.map(C=>C.scope).map(C=>({id:C.id,required:!1}))])}}),e(_,{"data-testid":"select-scope-button",variant:"secondary",onClick:()=>{u(!0)},children:s("addClientScopes")})]})}),n.length>0&&y(ue,{variant:"compact",children:[e(me,{children:y(Z,{children:[e(G,{children:s("clientScopeTitle")}),e(G,{children:s("required")}),e(G,{"aria-hidden":"true"})]})}),e(he,{children:n.map((o,g)=>y(Z,{children:[e(K,{children:o.name}),e(K,{children:e(w,{name:`clientScopes.${g}.required`,defaultValue:!1,control:a,render:({field:C})=>e(ke,{id:"required","data-testid":"standard",name:"required",isChecked:C.value,onChange:C.onChange})})}),e(K,{children:e(_,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e(Pe,{}),onClick:()=>{d("clientScopes",[...p("clientScopes").filter(C=>C.id!==o.id)]),i([...n.filter(C=>C.id!==o.id)])}})})]},o.id))})]}),c.clientScopes&&e(ee,{message:s("requiredClientScope")})]})},Tn=()=>{const{adminClient:t}=te(),{t:s}=R(),{control:a,getValues:p,setValue:d,formState:{errors:c}}=j(),l=p("groups"),[u,f]=k(!1),[h,n]=k([]);return ne(()=>l&&l.length>0?Promise.all(l.map(i=>t.groups.findOne({id:i.id}))):Promise.resolve([]),i=>{const r=i.filter(o=>o);n(r)},[]),y(A,{children:[e(de,{name:"groupsClaim",label:s("groupsClaim"),labelIcon:s("groupsClaimHelp")}),y(L,{label:s("groups"),labelIcon:e(F,{helpText:s("policyGroupsHelp"),fieldLabelId:"groups"}),fieldId:"groups",isRequired:!0,children:[e(w,{name:"groups",control:a,defaultValue:[],rules:{validate:i=>i&&i.filter(({id:r})=>r).length>0},render:({field:i})=>y(A,{children:[u&&e(Zt,{type:"selectMany",text:{title:"addGroupsToGroupPolicy",ok:"add"},onConfirm:r=>{i.onChange([...i.value||[],...(r||[]).map(({id:o})=>({id:o}))]),n([...h,...r||[]]),f(!1)},onClose:()=>{f(!1)},filterGroups:h}),e(_,{"data-testid":"select-group-button",variant:"secondary",onClick:()=>{f(!0)},children:s("addGroups")})]})}),h.length>0&&y(ue,{variant:"compact",children:[e(me,{children:y(Z,{children:[e(G,{children:s("groups")}),e(G,{children:s("extendToChildren")}),e(G,{"aria-hidden":"true"})]})}),e(he,{children:h.map((i,r)=>y(Z,{children:[e(K,{children:i.path}),e(K,{children:e(w,{name:`groups.${r}.extendChildren`,defaultValue:!1,control:a,render:({field:o})=>e(ke,{id:"extendChildren","data-testid":"standard",name:"extendChildren",isChecked:o.value,onChange:o.onChange,isDisabled:i.subGroupCount===0})})}),e(K,{children:e(_,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e(Pe,{}),onClick:()=>{d("groups",[...(l||[]).filter(({id:o})=>o!==i.id)]),n([...h.filter(({id:o})=>o!==i.id)])}})})]},i.id))})]}),c.groups&&e(ee,{message:s("requiredGroups")})]})]})},vn=()=>{const{t}=R(),{control:s}=j();return e(L,{label:t("code"),labelIcon:e(F,{helpText:t("policyCodeHelp"),fieldLabelId:"code"}),fieldId:"code",isRequired:!0,children:e(w,{name:"code",defaultValue:"",control:s,render:({field:a})=>e(Jt,{id:"code","data-testid":"code",onChange:a.onChange,code:a.value,height:"600px",language:Xt.javascript,isReadOnly:!0})})})},qe=["POSITIVE","NEGATIVE"],In=({isDisabled:t})=>{const{t:s}=R(),{control:a}=j();return e(L,{label:s("logic"),labelIcon:e(F,{helpText:s("logicHelp"),fieldLabelId:"logic"}),fieldId:"logic",hasNoPaddingTop:!0,children:e(w,{name:"logic","data-testid":"logic",defaultValue:qe[0],control:a,render:({field:p})=>e(A,{children:qe.map(d=>e(ce,{id:d,"data-testid":d,isChecked:p.value===d,name:"logic",onChange:()=>p.onChange(d),label:s(`logicType.${d.toLowerCase()}`),className:"pf-v5-u-mb-md",isDisabled:t},d))})})})},bn=({isDisabled:t})=>{const{t:s}=R();return y(A,{children:[e(de,{name:"name",label:s("name"),rules:{required:s("required")},isDisabled:t}),e(At,{name:"description",label:s("description"),rules:{maxLength:{message:s("maxLength",{length:255}),value:255}},isDisabled:t})]})},xn=()=>{const{t}=R();return y(A,{children:[e(de,{name:"targetClaim",label:t("targetClaim"),labelIcon:t("targetClaimHelp"),rules:{required:t("required")}}),e(de,{name:"pattern",label:t("regexPattern"),labelIcon:t("regexPatternHelp"),rules:{required:t("required")}}),e(Et,{name:"targetContextAttributes",label:t("targetContextAttributes"),labelIcon:t("targetContextAttributesHelp"),labelOn:t("yes"),labelOff:t("no")})]})},On=()=>{const{adminClient:t}=te(),{t:s}=R(),{control:a,getValues:p,setValue:d,formState:{errors:c}}=j(),l=p("roles"),[u,f]=k(!1),[h,n]=k([]);return ne(async()=>{if(l&&l.length>0){const i=await Promise.all(l.map(r=>t.roles.findOneById({id:r.id})));return Promise.all(i.map(async r=>({role:r,client:r.clientRole?await t.clients.findOne({id:r?.containerId}):void 0})))}return Promise.resolve([])},n,[]),y(A,{children:[y(L,{label:s("roles"),labelIcon:e(F,{helpText:s("policyRolesHelp"),fieldLabelId:"roles"}),fieldId:"roles",isRequired:!0,children:[e(w,{name:"roles",control:a,defaultValue:[],rules:{validate:i=>i&&i.filter(r=>r.id).length>0},render:({field:i})=>y(A,{children:[u&&e(en,{id:"role",type:"roles",onAssign:r=>{i.onChange([...i.value||[],...r.map(o=>({id:o.role.id}))]),n([...h,...r]),f(!1)},onClose:()=>{f(!1)},isLDAPmapper:!0}),e(_,{"data-testid":"select-role-button",variant:"secondary",onClick:()=>{f(!0)},children:s("addRoles")})]})}),h.length>0&&y(ue,{variant:"compact",children:[e(me,{children:y(Z,{children:[e(G,{children:s("roles")}),e(G,{children:s("required")}),e(G,{"aria-hidden":"true"})]})}),e(he,{children:h.map((i,r)=>y(Z,{children:[e(K,{children:e(tn,{role:i.role,client:i.client})}),e(K,{children:e(w,{name:`roles.${r}.required`,defaultValue:!1,control:a,render:({field:o})=>e(ke,{id:"required","data-testid":"standard",name:"required",isChecked:o.value,onChange:o.onChange})})}),e(K,{children:e(_,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e(Pe,{}),onClick:()=>{d("roles",[...(l||[]).filter(o=>o.id!==i.role.id)]),n([...h.filter(o=>o.role.id!==i.role.id)])}})})]},i.role.id))})]}),c.roles&&e(ee,{message:s("requiredRoles")})]}),e(Qt,{name:"fetchRoles",label:s("fetchRoles"),labelIcon:s("fetchRolesHelp")})]})},be=/(\d\d\d\d-\d\d-\d\d)? (\d\d?):(\d\d?)/,Ue=t=>t.toString().padStart(2,"0"),Ge=({name:t})=>{const{control:s}=j(),a=(d,c)=>{if(!c)return d;const l=d.match(be);return`${[c.getFullYear(),Ue(c.getMonth()+1),Ue(c.getDate())].join("-")} ${l?l[2]:"00"}:${l?l[3]:"00"}:00`},p=(d,c,l)=>{const u=d.match(be);return l!=null?`${u?u[1]:""} ${c}:${l<10?`0${l}`:l}:00`:d};return e(w,{name:t,defaultValue:"",control:s,rules:{required:!0},render:({field:d})=>{const c=d.value.match(be)||["","","0","00"];return y(it,{hasGutter:!0,id:t,children:[e(oe,{children:e(nn,{value:c[1],onChange:(l,u,f)=>{d.onChange(a(d.value,f))}})}),e(oe,{children:e(Re,{time:`${c[2]}:${c[3]}`,onChange:(l,u,f,h)=>d.onChange(p(d.value,f,h)),is24Hour:!0})})]})}})},Ke=({name:t,min:s,max:a})=>{const{control:p}=j(),d=c=>Math.min(c,a);return e(w,{name:t,defaultValue:"",control:p,render:({field:c})=>e(Vt,{id:t,value:c.value,min:s,max:a,onPlus:()=>c.onChange(Number(c.value)+1),onMinus:()=>c.onChange(Number(c.value)-1),onChange:l=>{const u=Number(l.currentTarget.value);c.onChange(d(isNaN(u)?0:u))}})})},le=({name:t,...s})=>{const{t:a}=R();return e(L,{label:a(t),fieldId:t,labelIcon:e(F,{helpText:a(`${t}Help`),fieldLabelId:t}),children:y(it,{hasGutter:!0,children:[e(oe,{children:e(Ke,{name:t,...s})}),e(oe,{children:a("to")}),e(oe,{children:e(Ke,{name:`${t}End`,...s})})]})})},kn=()=>{const{t}=R(),{getValues:s,formState:{errors:a}}=j(),[p,d]=k(s("month"));return y(A,{children:[e(L,{label:t("repeat"),fieldId:"repeat",labelIcon:e(F,{helpText:t("repeatHelp"),fieldLabelId:"repeat"}),children:y(sn,{children:[e(Ne,{children:e(ce,{id:"notRepeat","data-testid":"notRepeat",isChecked:!p,name:"repeat",onChange:()=>d(!1),label:t("notRepeat"),className:"pf-v5-u-mb-md"})}),e(Ne,{children:e(ce,{id:"repeat","data-testid":"repeat",isChecked:p,name:"repeat",onChange:()=>d(!0),label:t("repeat"),className:"pf-v5-u-mb-md"})})]})}),p&&y(A,{children:[e(le,{name:"month",min:1,max:12}),e(le,{name:"dayMonth",min:1,max:31}),e(le,{name:"hour",min:0,max:23}),e(le,{name:"minute",min:0,max:59})]}),y(L,{label:t("startTime"),fieldId:"notBefore",labelIcon:e(F,{helpText:t("startTimeHelp"),fieldLabelId:"startTime"}),isRequired:!0,children:[e(Ge,{name:"notBefore"}),a.notBefore&&e(ee,{message:t("required")})]}),y(L,{label:t("expireTime"),fieldId:"notOnOrAfter",labelIcon:e(F,{helpText:t("expireTimeHelp"),fieldLabelId:"expireTime"}),isRequired:!0,children:[e(Ge,{name:"notOnOrAfter"}),a.notOnOrAfter&&e(ee,{message:t("required")})]})]})},Pn=()=>{const{t}=R();return e(un,{name:"users",label:"users",helpText:t("policyUsers"),defaultValue:[],variant:"typeaheadMulti",isRequired:!0})},Oe={aggregate:gn,client:Cn,user:Pn,"client-scope":Sn,group:Tn,regex:xn,role:On,time:kn,js:vn},De=t=>t in Oe;function Rn(){const{adminClient:t}=te(),{t:s}=R(),{id:a,realm:p,policyId:d,policyType:c}=ot(),l=Ye(),u=_t(),{reset:f,handleSubmit:h}=u,{addAlert:n,addError:i}=wt(),[r,o]=k(),g=c==="js";ne(async()=>{if(d){const v=await Promise.all([t.clients.findOnePolicy({id:a,type:c,policyId:d}),t.clients.getAssociatedPolicies({id:a,permissionId:d})]);if(!v[0])throw new Error(s("notFound"));return{policy:v[0],policies:v[1].map(I=>I.id)}}return{}},({policy:v,policies:I})=>{f({...v,policies:I}),o(v)},[a,c,d]);const C=async v=>{v.groups=v.groups?.filter(I=>I.id),v.clientScopes=v.clientScopes?.filter(I=>I.id),v.roles=v.roles?.filter(I=>I.id).map(I=>({...I,required:I.required||!1}));try{if(d)await t.clients.updatePolicy({id:a,type:c,policyId:d},v);else{const I=await t.clients.createPolicy({id:a,type:c},v);l(Xe({realm:p,id:a,policyType:c,policyId:I.id}))}n(s((d?"update":"create")+"PolicySuccess"),Ve.success)}catch(I){i("policySaveError",I)}},[T,D]=st({titleKey:"deletePolicy",messageKey:"deletePolicyConfirm",continueButtonLabel:"confirm",onConfirm:async()=>{try{await t.clients.delPolicy({id:a,policyId:d}),n(s("policyDeletedSuccess"),Ve.success),l(Ee({realm:p,clientId:a,tab:"policies"}))}catch(v){i("policyDeletedError",v)}}});if(d&&!r)return e(Nt,{});function M(){return De(c)?Oe[c]:Oe.js}const b=M();return y(A,{children:[e(D,{}),e(Kt,{titleKey:d?r?.name:s("createPolicyOfType",{policyType:c}),dropdownItems:d?[e(xe,{"data-testid":"delete-policy",onClick:()=>T(),children:s("delete")},"delete")]:void 0}),e(Ht,{variant:"light",children:y(Gt,{isHorizontal:!0,onSubmit:h(C),role:"anyone",children:[y(Lt,{...u,children:[e(bn,{isDisabled:g}),e(b,{}),e(In,{isDisabled:g})]}),e(Ft,{children:y("div",{className:"pf-v5-u-mt-md",children:[e(_,{isDisabled:g,variant:se.primary,className:"pf-v5-u-mr-md",type:"submit","data-testid":"save",children:s("save")}),e(_,{variant:"link","data-testid":"cancel",component:v=>e(Je,{...v,to:Ee({realm:p,clientId:a,tab:"policies"})}),children:s("cancel")})]})})]})})]})}const Xn=Object.freeze(Object.defineProperty({__proto__:null,default:Rn,isValidComponentType:De},Symbol.toStringTag,{value:"Module"})),Dn=({policyProviders:t,onSelect:s,toggleDialog:a})=>{const{t:p}=R(),d=tt(),c=je(()=>t?d(t,nt("name")):[],[t]);return e(Qe,{"aria-label":p("createPolicy"),variant:et.medium,header:y(qt,{children:[e(_e,{component:Ut.h1,children:p("chooseAPolicyType")}),e(_e,{children:p("chooseAPolicyTypeInstructions")})]}),isOpen:!0,onClose:a,children:y(ue,{"aria-label":p("policies"),variant:"compact",children:[e(me,{children:y(Z,{children:[e(G,{children:p("name")}),e(G,{children:p("description")})]})}),e(he,{children:c.map(l=>y(Z,{"data-testid":l.type,onRowClick:()=>s(l),isClickable:!0,children:[e(K,{children:l.name}),e(K,{children:De(l.type)&&p(`policyProvider.${l.type}`)})]},l.type))})]})})};export{yn as A,mn as D,Dn as N,Xn as P,fn as R,un as U};
//# sourceMappingURL=NewPolicyDialog-DySSrR_B.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy