@e-llm-studio/instant-learning 1.3.0-alpha.45 → 1.3.0-alpha.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{__awaiter as e,__generator as o,__assign as n,__spreadArray as t}from"tslib";import{jsx as r,jsxs as i,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s,useEffect as c}from"react";import{useMutation as d}from"@tanstack/react-query";import{X as u,Loader2 as p}from"lucide-react";import{Toast as m}from"primereact/toast";import{v4 as f}from"uuid";import h from"../components/StationOnboarding/StationAutocomplete.js";import g from"./AddScopeApprovalSearchComponent.js";import v from"../components/ScopeSkeletonLoader.js";import{Input as b}from"@mui/material";import y from"../store/useAuthStore.js";import{useAppSecRolesStore as S}from"../store/useAppSecRolesStore.js";import C from"../store/useEnvStore.js";import{createRuleSet as x,inheritScope as _}from"../apis/scopeApis.js";import{useLearningTemplateStore as w}from"../store/useLearningTemplateStore.js";import{IL_CONFIG_CONSTANTS as k}from"../config.js";import{dt as A}from"../store/useLMSConfigStore.js";import{MIDDLE_DRAWER_ADD_SCOPE_DT_PATH as R,MIDDLE_DRAWER_APPROVAL_SETTINGS_DT_PATH as I}from"../constants.js";var D=function(D){var j=D.isOpen,q=D.onClose,F=D.onCreate,z=D.hasGlobalRuleSet,E=D.parentId,L=a(""),B=L[0],W=L[1],N=a(""),G=N[0],T=N[1],M=a({}),O=M[0],P=M[1],K=s(null),U=y().user,H=S(function(e){return e.roles}),J=C(function(e){return e.rbacConfig}),Q=a(null),V=Q[0],X=Q[1],Y=a("approval_required"),Z=Y[0],$=Y[1],ee=a([]),oe=ee[0],ne=ee[1],te=a([]),re=te[0],ie=te[1],le=d({mutationFn:function(n){return e(void 0,void 0,void 0,function(){var e;return o(this,function(o){switch(o.label){case 0:return[4,x(n,null!==(e=null==U?void 0:U.accessToken)&&void 0!==e?e:"")];case 1:return[2,o.sent()]}})})},onSuccess:function(n){return e(void 0,void 0,void 0,function(){return o(this,function(e){return console.log("Rule Set Created Successfully",n),[2]})})}});le.data;var ae=le.isPending,se=le.mutateAsync;return c(function(){j&&(W(""),T(""),P({}),X(null),$("approval_required"),ne([]),ie([]))},[j]),j?ae?r(v,{isLoading:ae}):i("div",n({style:{position:"absolute",inset:0,zIndex:50,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.3)"}},{children:[r(m,{ref:K}),i("div",n({style:{position:"relative",width:600,borderRadius:12,backgroundColor:"white",padding:24,boxShadow:"0 25px 50px -12px rgba(0,0,0,0.25)"}},{children:[i("div",n({style:{marginBottom:24,display:"flex",alignItems:"flex-start",justifyContent:"space-between"}},{children:[i("div",{children:[r("h2",n({style:{margin:0,fontSize:18,fontWeight:500,color:"#19213D"}},{children:z?A("".concat(R,".title"),"Add Scope"):A("".concat(R,".globalTitle"),"Create Global Scope")})),r("p",n({style:{margin:"4px 0 0 0",fontSize:14,fontWeight:400,color:"#666F8D"}},{children:z?A("".concat(R,".subtitle"),"This scope will be created under Global scope and will inherit its learnings by default.",{parent:"Global"}):A("".concat(R,".globalSubtitle"),"This will be your Global scope that defines the base learnings shared across all stations.")}))]}),r("button",n({onClick:q,style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"#9CA3AF"}},{children:r(u,{size:24})}))]})),i("div",n({style:{display:"flex",flexDirection:"column",gap:20}},{children:[i("div",n({style:{position:"relative",display:"flex",flexDirection:"column",gap:6}},{children:[i("label",n({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:[r("span",n({style:{marginRight:4,fontSize:16,fontWeight:600,color:"#8F2C23"}},{children:"*"})),A("".concat(R,".scopeName"),"Scope Name")]})),"Custom"===B?r(h,{value:G,onChange:function(e){if(e.length>50)return T(e.slice(0,50)),void P(function(e){return n(n({},e),{name:"Scope Name must be 50 characters or fewer"})});T(e),P(function(e){return n(n({},e),{name:void 0})})},onStationSelect:function(e){X(e)},style:{border:O.name?"1px solid #8F2C23":void 0}}):r(b,{value:G,onChange:function(e){var o=e.target.value;if(o.length>50)return T(o.slice(0,50)),void P(function(e){return n(n({},e),{name:"Scope Name must be 50 characters or fewer"})});T(o),P(function(e){return n(n({},e),{name:void 0})})},style:{border:"1px solid ".concat(O.name?"#8F2C23":"#F0F2F5")},placeholder:"e.g. Global Learnings"}),O.name&&r("p",n({style:{margin:"4px 0 0 0",fontSize:12,color:"#8F2C23"}},{children:O.name}))]})),i("div",n({style:{display:"flex",flexDirection:"column",gap:12}},{children:[i("label",n({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:[r("span",n({style:{marginRight:4,fontSize:16,fontWeight:600,color:"#8F2C23"}},{children:"*"})),A("".concat(I,".title"),"Learning Approval Settings")]})),i("div",n({role:"radio","aria-checked":"approval_required"===Z,tabIndex:0,style:{cursor:"pointer",display:"flex",flexDirection:"column",gap:4},onClick:function(){return $("approval_required")},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||$("approval_required")}},{children:[i("div",n({style:{display:"flex",alignItems:"center",gap:8}},{children:[r("div",n({style:{display:"flex",height:16,width:16,flexShrink:0,alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"2px solid ".concat("approval_required"===Z?"#2563EB":"#CBD5E1")}},{children:"approval_required"===Z&&r("div",{style:{height:8,width:8,borderRadius:"50%",backgroundColor:"#2563EB"}})})),r("span",n({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:A("".concat(I,".approvalRequired.title"),"Approval Required Before Publishing")}))]})),r("p",n({style:{margin:0,marginLeft:24,fontSize:12,color:"#666F8D"}},{children:A("".concat(I,".approvalRequired.subtitle"),"Learnings require approval before publishing.")}))]})),"approval_required"===Z&&r(g,{selectedApprovers:oe,selectedGroupOfApprovers:re,onApproversChange:ne,onGroupsChange:ie}),i("div",n({role:"radio","aria-checked":"publish_without"===Z,tabIndex:0,style:{cursor:"pointer",display:"flex",flexDirection:"column",gap:4},onClick:function(){$("publish_without")},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||$("publish_without")}},{children:[i("div",n({style:{display:"flex",alignItems:"center",gap:8}},{children:[r("div",n({style:{display:"flex",height:16,width:16,flexShrink:0,alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"2px solid ".concat("publish_without"===Z?"#2563EB":"#CBD5E1")}},{children:"publish_without"===Z&&r("div",{style:{height:8,width:8,borderRadius:"50%",backgroundColor:"#2563EB"}})})),r("span",n({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:A("".concat(I,".publishWithoutApproval.title"),"Publish Without Approval")}))]})),r("p",n({style:{margin:0,marginLeft:24,fontSize:12,color:"#666F8D"}},{children:A("".concat(I,".publishWithoutApproval.subtitle"),"Learnings can be published directly.")}))]}))]})),i("div",n({style:{marginTop:32,display:"flex",justifyContent:"flex-end",gap:12}},{children:[r("button",n({onClick:q,style:{borderRadius:6,border:"1px solid #E2E8F0",padding:"8px 16px",fontSize:14,fontWeight:500,color:"#64748B",backgroundColor:"white",cursor:"pointer",opacity:ae?.5:1},disabled:ae},{children:A("".concat(R,".cancel"),"Cancel")})),r("button",n({onClick:function(){return e(void 0,void 0,void 0,function(){var e,n,r,i,l,a,s,c,d,u,p,m,h,g,v,b,y,S,C,x,A;return o(this,function(o){switch(o.label){case 0:if(e={},G.trim()?G.length>50&&(e.name="Scope Name must be 50 characters or fewer"):e.name="Scope Name is required",e.name)return P(e),[2];o.label=1;case 1:return o.trys.push([1,7,,8]),n="approval_required"===Z,r=w.getState().backwardCompatibility,i=oe.length>0||re.length>0,l=r?{topic:z?"genreRuleSet":"globalRuleSet",customScopeGroupName:k.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:G,parentScopeId:null,customScopeName:G,customScopeId:f(),createByName:(null==U?void 0:U.firstname)||"System",createdBy:(null==U?void 0:U.email)||"system@audacy.com",approvalRequired:n,appsecData:{application:null==J?void 0:J.applicationId,module:null==J?void 0:J.moduleId,roles:t(t([],n&&i?[{users:oe.map(function(e){return e.email}),groups:re.map(function(e){return e._id}),role:null!==(p=null===(u=H.find(function(e){return"Learning Manager"===e.name}))||void 0===u?void 0:u._id)&&void 0!==p?p:""}]:[],!0),[{users:[null==U?void 0:U.email],groups:[],role:null!==(h=null===(m=H.find(function(e){return"Instant Learning Admin"===e.name}))||void 0===m?void 0:m._id)&&void 0!==h?h:""}],!1)}}:{topic:z?"genreRuleSet":"globalRuleSet",scope_reference_id:null,scopeDescription:G,parentScopeId:null!=E?E:null,scopeName:G,scopeReferenceMetadata:{},scopeType:"Custom",applicationMappingId:w.getState().app_integration_id,approvalRequired:n,appsecData:{application:null==J?void 0:J.applicationId,module:null==J?void 0:J.moduleId,roles:t(t([],n&&i?[{users:oe.map(function(e){return e.email}),groups:re.map(function(e){return e._id}),role:null!==(v=null===(g=H.find(function(e){return"Learning Manager"===e.name}))||void 0===g?void 0:g._id)&&void 0!==v?v:""}]:[],!0),[{users:[null==U?void 0:U.email],groups:[],role:null!==(y=null===(b=H.find(function(e){return"Instant Learning Admin"===e.name}))||void 0===b?void 0:b._id)&&void 0!==y?y:""}],!1)}},console.log("Add Scope payload:",l),[4,se(l)];case 2:if(a=o.sent(),s=null===(S=null==a?void 0:a.data)||void 0===S?void 0:S.scopeId,r||!s||!E)return[3,6];o.label=3;case 3:return o.trys.push([3,5,,6]),[4,_({source_scope_id:E,target_scope_id:s,application_mapping_id:w.getState().app_integration_id||"",is_copy_parent_variant_id:!1})];case 4:return o.sent(),[3,6];case 5:return c=o.sent(),console.error("Failed to inherit rules for the new scope:",c),[3,6];case 6:return F(s),q(),[3,8];case 7:return d=o.sent(),console.error("An error occurred during scope creation.",d),null===(C=K.current)||void 0===C||C.show({severity:"error",summary:"Adding Scope Failed",detail:(null===(A=null===(x=null==d?void 0:d.response)||void 0===x?void 0:x.data)||void 0===A?void 0:A.message)||"There was an error creating the scope. Please try again."}),[3,8];case 8:return[2]}})})},style:{display:"flex",alignItems:"center",borderRadius:6,backgroundColor:"#2563EB",padding:"8px 16px",fontSize:14,fontWeight:500,color:"white",border:"none",cursor:"pointer",opacity:ae||"Custom"===B&&!V?.5:1},disabled:ae||"Custom"===B&&!V},{children:ae?i(l,{children:[r(p,{className:"animate-spin",style:{marginRight:8,height:16,width:16,color:"white"}}),"Creating..."]}):A("".concat(R,".submitButton"),"Create Scope")}))]}))]}))]}))]})):null};export{D as default};
1
+ import{__awaiter as e,__generator as o,__assign as r,__spreadArray as n}from"tslib";import{jsxs as i,jsx as t,Fragment as l}from"react/jsx-runtime";import{useState as a,useRef as s,useEffect as c}from"react";import{useMutation as d}from"@tanstack/react-query";import{X as u,Loader2 as p}from"lucide-react";import{Toast as m}from"primereact/toast";import{v4 as f}from"uuid";import h from"../components/StationOnboarding/StationAutocomplete.js";import g from"./AddScopeApprovalSearchComponent.js";import v from"../components/ScopeSkeletonLoader.js";import{Input as y}from"@mui/material";import b from"../store/useAuthStore.js";import{useAppSecRolesStore as S}from"../store/useAppSecRolesStore.js";import C from"../store/useEnvStore.js";import{createRuleSet as x,inheritScope as _}from"../apis/scopeApis.js";import{useLearningTemplateStore as w}from"../store/useLearningTemplateStore.js";import{IL_CONFIG_CONSTANTS as k}from"../config.js";import{dt as A}from"../store/useLMSConfigStore.js";import{MIDDLE_DRAWER_ADD_SCOPE_DT_PATH as R,MIDDLE_DRAWER_APPROVAL_SETTINGS_DT_PATH as I}from"../constants.js";var D=function(D){var j=D.isOpen,q=D.onClose,F=D.onCreate,z=D.hasGlobalRuleSet,E=D.parentId,L=a(""),B=L[0],W=L[1],N=a(""),G=N[0],T=N[1],M=a({}),P=M[0],O=M[1],K=s(null),U=b().user,H=S(function(e){return e.roles}),J=C(function(e){return e.rbacConfig}),Q=a(!1),V=Q[0],X=Q[1],Y=a(null),Z=Y[0],$=Y[1],ee=a("approval_required"),oe=ee[0],re=ee[1],ne=a([]),ie=ne[0],te=ne[1],le=a([]),ae=le[0],se=le[1],ce=a(!1);ce[0];var de=ce[1],ue=d({mutationFn:function(r){return e(void 0,void 0,void 0,function(){var e;return o(this,function(o){switch(o.label){case 0:return[4,x(r,null!==(e=null==U?void 0:U.accessToken)&&void 0!==e?e:"")];case 1:return[2,o.sent()]}})})},onSuccess:function(r){return e(void 0,void 0,void 0,function(){var e,n;return o(this,function(o){return console.log("Rule Set Created Successfully",r),null===(e=K.current)||void 0===e||e.show({severity:"success",summary:"Scope Created",detail:(null===(n=null==r?void 0:r.data)||void 0===n?void 0:n.message)||"Scope created successfully",life:3e3}),[2]})})},onError:function(e){var o,r,n;console.error("Create scope failed",e),null===(o=K.current)||void 0===o||o.show({severity:"error",summary:"Creation Failed",detail:(null===(n=null===(r=null==e?void 0:e.response)||void 0===r?void 0:r.data)||void 0===n?void 0:n.message)||"There was an error creating the scope. Please try again."})}});ue.data;var pe=ue.isPending,me=ue.mutateAsync;return c(function(){j&&(W(""),T(""),O({}),$(null),re("approval_required"),te([]),se([]))},[j]),j?i("div",r({style:{position:"absolute",inset:0,zIndex:50,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.3)"}},{children:[t(m,{ref:K}),pe||V?t(v,{isLoading:pe||V}):i("div",r({style:{position:"relative",width:600,borderRadius:12,backgroundColor:"white",padding:24,boxShadow:"0 25px 50px -12px rgba(0,0,0,0.25)"}},{children:[i("div",r({style:{marginBottom:24,display:"flex",alignItems:"flex-start",justifyContent:"space-between"}},{children:[i("div",{children:[t("h2",r({style:{margin:0,fontSize:18,fontWeight:500,color:"#19213D"}},{children:z?A("".concat(R,".title"),"Add Scope"):A("".concat(R,".globalTitle"),"Create Global Scope")})),t("p",r({style:{margin:"4px 0 0 0",fontSize:14,fontWeight:400,color:"#666F8D"}},{children:z?A("".concat(R,".subtitle"),"This scope will be created under Global scope and will inherit its learnings by default.",{parent:"Global"}):A("".concat(R,".globalSubtitle"),"This will be your Global scope that defines the base learnings shared across all stations.")}))]}),t("button",r({onClick:q,style:{background:"none",border:"none",padding:0,cursor:"pointer",color:"#9CA3AF"}},{children:t(u,{size:24})}))]})),i("div",r({style:{display:"flex",flexDirection:"column",gap:20}},{children:[i("div",r({style:{position:"relative",display:"flex",flexDirection:"column",gap:6}},{children:[i("label",r({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:[t("span",r({style:{marginRight:4,fontSize:16,fontWeight:600,color:"#8F2C23"}},{children:"*"})),A("".concat(R,".scopeName"),"Scope Name")]})),"Custom"===B?t(h,{value:G,onChange:function(e){if(e.length>50)return T(e.slice(0,50)),void O(function(e){return r(r({},e),{name:"Scope Name must be 50 characters or fewer"})});T(e),O(function(e){return r(r({},e),{name:void 0})})},onStationSelect:function(e){$(e)},style:{border:P.name?"1px solid #8F2C23":void 0}}):t(y,{value:G,onChange:function(e){var o=e.target.value;if(o.length>50)return T(o.slice(0,50)),void O(function(e){return r(r({},e),{name:"Scope Name must be 50 characters or fewer"})});T(o),O(function(e){return r(r({},e),{name:void 0})})},style:{border:"1px solid ".concat(P.name?"#8F2C23":"#F0F2F5")},placeholder:"e.g. Global Learnings"}),P.name&&t("p",r({style:{margin:"4px 0 0 0",fontSize:12,color:"#8F2C23"}},{children:P.name}))]})),i("div",r({style:{display:"flex",flexDirection:"column",gap:12}},{children:[i("label",r({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:[t("span",r({style:{marginRight:4,fontSize:16,fontWeight:600,color:"#8F2C23"}},{children:"*"})),A("".concat(I,".title"),"Learning Approval Settings")]})),i("div",r({role:"radio","aria-checked":"approval_required"===oe,tabIndex:0,style:{cursor:"pointer",display:"flex",flexDirection:"column",gap:4},onClick:function(){return re("approval_required")},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||re("approval_required")}},{children:[i("div",r({style:{display:"flex",alignItems:"center",gap:8}},{children:[t("div",r({style:{display:"flex",height:16,width:16,flexShrink:0,alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"2px solid ".concat("approval_required"===oe?"#2563EB":"#CBD5E1")}},{children:"approval_required"===oe&&t("div",{style:{height:8,width:8,borderRadius:"50%",backgroundColor:"#2563EB"}})})),t("span",r({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:A("".concat(I,".approvalRequired.title"),"Approval Required Before Publishing")}))]})),t("p",r({style:{margin:0,marginLeft:24,fontSize:12,color:"#666F8D"}},{children:A("".concat(I,".approvalRequired.subtitle"),"Learnings require approval before publishing.")}))]})),"approval_required"===oe&&t(g,{selectedApprovers:ie,selectedGroupOfApprovers:ae,onApproversChange:te,onGroupsChange:se}),i("div",r({role:"radio","aria-checked":"publish_without"===oe,tabIndex:0,style:{cursor:"pointer",display:"flex",flexDirection:"column",gap:4},onClick:function(){re("publish_without")},onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||re("publish_without")}},{children:[i("div",r({style:{display:"flex",alignItems:"center",gap:8}},{children:[t("div",r({style:{display:"flex",height:16,width:16,flexShrink:0,alignItems:"center",justifyContent:"center",borderRadius:"50%",border:"2px solid ".concat("publish_without"===oe?"#2563EB":"#CBD5E1")}},{children:"publish_without"===oe&&t("div",{style:{height:8,width:8,borderRadius:"50%",backgroundColor:"#2563EB"}})})),t("span",r({style:{fontSize:14,fontWeight:500,color:"#19213D"}},{children:A("".concat(I,".publishWithoutApproval.title"),"Publish Without Approval")}))]})),t("p",r({style:{margin:0,marginLeft:24,fontSize:12,color:"#666F8D"}},{children:A("".concat(I,".publishWithoutApproval.subtitle"),"Learnings can be published directly.")}))]}))]})),i("div",r({style:{marginTop:32,display:"flex",justifyContent:"flex-end",gap:12}},{children:[t("button",r({onClick:q,style:{borderRadius:6,border:"1px solid #E2E8F0",padding:"8px 16px",fontSize:14,fontWeight:500,color:"#64748B",backgroundColor:"white",cursor:"pointer",opacity:pe?.5:1},disabled:pe},{children:A("".concat(R,".cancel"),"Cancel")})),t("button",r({onClick:function(){return e(void 0,void 0,void 0,function(){var e,r,i,t,l,a,s,c,d,u,p,m,h,g,v,y,b,S,C,x,A;return o(this,function(o){switch(o.label){case 0:if(e={},G.trim()?G.length>50&&(e.name="Scope Name must be 50 characters or fewer"):e.name="Scope Name is required",e.name)return O(e),[2];o.label=1;case 1:return o.trys.push([1,8,9,10]),X(!0),r="approval_required"===oe,i=w.getState().backwardCompatibility,t=ie.length>0||ae.length>0,l=i?{topic:z?"genreRuleSet":"globalRuleSet",customScopeGroupName:k.CUSTOM_SCOPE_GROUP_NAME,scopeDescription:G,parentScopeId:null,customScopeName:G,customScopeId:f(),createByName:(null==U?void 0:U.firstname)||"System",createdBy:(null==U?void 0:U.email)||"system@audacy.com",approvalRequired:r,appsecData:{application:null==J?void 0:J.applicationId,module:null==J?void 0:J.moduleId,roles:n(n([],r&&t?[{users:ie.map(function(e){return e.email}),groups:ae.map(function(e){return e._id}),role:null!==(p=null===(u=H.find(function(e){return"Learning Manager"===e.name}))||void 0===u?void 0:u._id)&&void 0!==p?p:""}]:[],!0),[{users:[null==U?void 0:U.email],groups:[],role:null!==(h=null===(m=H.find(function(e){return"Instant Learning Admin"===e.name}))||void 0===m?void 0:m._id)&&void 0!==h?h:""}],!1)}}:{topic:z?"genreRuleSet":"globalRuleSet",scope_reference_id:null,scopeDescription:G,parentScopeId:null!=E?E:null,scopeName:G,scopeReferenceMetadata:{},scopeType:"Custom",applicationMappingId:w.getState().app_integration_id,approvalRequired:r,appsecData:{application:null==J?void 0:J.applicationId,module:null==J?void 0:J.moduleId,roles:n(n([],r&&t?[{users:ie.map(function(e){return e.email}),groups:ae.map(function(e){return e._id}),role:null!==(v=null===(g=H.find(function(e){return"Learning Manager"===e.name}))||void 0===g?void 0:g._id)&&void 0!==v?v:""}]:[],!0),[{users:[null==U?void 0:U.email],groups:[],role:null!==(b=null===(y=H.find(function(e){return"Instant Learning Admin"===e.name}))||void 0===y?void 0:y._id)&&void 0!==b?b:""}],!1)}},console.log("Add Scope payload:",l),[4,me(l)];case 2:if(a=o.sent(),s=null===(S=null==a?void 0:a.data)||void 0===S?void 0:S.scopeId,i||!s||!E)return[3,7];de(!0),o.label=3;case 3:return o.trys.push([3,5,6,7]),[4,_({source_scope_id:E,target_scope_id:s,application_mapping_id:w.getState().app_integration_id||"",is_copy_parent_variant_id:!1})];case 4:return o.sent(),[3,7];case 5:return c=o.sent(),console.error("Failed to inherit rules for the new scope:",c),[3,7];case 6:return de(!1),[7];case 7:return F(s),q(),[3,10];case 8:return d=o.sent(),console.error("An error occurred during scope creation.",d),null===(C=K.current)||void 0===C||C.show({severity:"error",summary:"Adding Scope Failed",detail:(null===(A=null===(x=null==d?void 0:d.response)||void 0===x?void 0:x.data)||void 0===A?void 0:A.message)||"There was an error creating the scope. Please try again."}),[3,10];case 9:return X(!1),[7];case 10:return[2]}})})},style:{display:"flex",alignItems:"center",borderRadius:6,backgroundColor:"#2563EB",padding:"8px 16px",fontSize:14,fontWeight:500,color:"white",border:"none",cursor:"pointer",opacity:pe||"Custom"===B&&!Z?.5:1},disabled:pe||"Custom"===B&&!Z},{children:pe?i(l,{children:[t(p,{className:"animate-spin",style:{marginRight:8,height:16,width:16,color:"white"}}),"Creating..."]}):A("".concat(R,".submitButton"),"Create Scope")}))]}))]}))]}))]})):null};export{D as default};
2
2
  //# sourceMappingURL=AddScopeModal.js.map
@@ -1,2 +1,2 @@
1
- import{__assign as e,__awaiter as n,__generator as t}from"tslib";import{jsxs as i,jsx as o,Fragment as r}from"react/jsx-runtime";import{useState as a,useRef as l,useEffect as s}from"react";import{parseISO as c,isValid as d,format as u}from"date-fns";import{MoreVertical as p,Pause as v,Play as m,Copy as h,Eye as f,Info as g,TriangleAlert as y}from"lucide-react";import{toggleVariant as b}from"../apis/scopeApis.js";import{HistorySkeleton as T}from"./HistorySkeleton.js";import A from"./InheritanceBreadcrumb.js";import N from"./RuleConditionBlock.js";import C from"../styles/VariantCard.module.css.js";import j from"../styles/CustomTooltip.module.css.js";import w from"../components/CustomTooltip.js";import I from"../components/ConfirmationModal.js";import x from"./OverrideTimeline.js";import D from"../store/useAuthStore.js";import{usePermissionsStore as L}from"../store/usePermissionsStore.js";import B from"./PendingApprovalChip.js";import S from"./ApprovalActionButton.js";import O from"./ApprovalLearningDialog.js";import{useApproveOrRejectVariantsMutation as k}from"../queries/useApprovalQueries.js";import F from"../store/useEnvStore.js";import{dt as E}from"../store/useLMSConfigStore.js";import{VARIANT_DT_PATH as H}from"../constants.js";import{useLearningTemplateStore as _}from"../store/useLearningTemplateStore.js";var M=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.filter(Boolean).join(" ")},P=function(P){var R,V,W,z,U,G,q,Z,K,Q=P.ruleTitle,Y=P.variant,$=P.variantIndex,J=P.totalVariants,X=P.ruleId;P.pendingApprovalCount;var ee=P.ruleSetId,ne=P.tierName,te=P.displayLabel,ie=P.onEdit,oe=P.onDelete,re=P.onFetchOverrideHistory,ae=P.editButtonLabel,le=void 0===ae?E("".concat(H,".actions.edit"),"Edit"):ae,se=P.deleteButtonLabel,ce=void 0===se?E("".concat(H,".actions.delete"),"Delete"):se,de=P.whenToApplyLabel,ue=void 0===de?E("".concat(H,".whenToApply"),"When to Apply"):de,pe=P.whenNotToApplyLabel,ve=void 0===pe?E("".concat(H,".whenNotToApply"),"When Not to Apply"):pe,me=P.noConditionsText,he=void 0===me?"No conditions":me,fe=P.viewOverrideLabel,ge=void 0===fe?"View Override History":fe,ye=P.hideOverrideLabel,be=void 0===ye?"Hide Override History":ye,Te=P.enableLearningVariantLabel,Ae=void 0===Te?E("".concat(H,".actions.enable"),"Enable"):Te,Ne=P.disableLearningVariantLabel,Ce=void 0===Ne?E("".concat(H,".actions.disable"),"Disable"):Ne,je=P.historyErrorMessage,we=void 0===je?"Failed to load override history.":je,Ie=P.resolveGapsLabel,xe=void 0===Ie?"This learning has some gaps":Ie,De=P.showActionsBar,Le=void 0===De||De,Be=P.showDescriptionBox,Se=void 0===Be||Be,Oe=P.showConditions,ke=void 0===Oe||Oe,Fe=P.showInheritance,Ee=void 0===Fe||Fe,He=P.defaultApplyOpen,_e=void 0===He||He,Me=P.defaultNotApplyOpen,Pe=void 0===Me||Me,Re=P.className,Ve=P.isHighlighted,We=void 0!==Ve&&Ve,ze=P.highlightAction,Ue=P.highlightedTierNames,Ge=P.highlightedVariantIds,qe=P.headerContent,Ze=P.footerContent,Ke=P.onToggleSuccess,Qe=P.setDeleteConfirmationUsedFor,Ye=P.onCopyToTier,$e=P.onSetInitialDraftMessage,Je=D.getState().user,Xe=_.getState().tiers,en=a(_e),nn=en[0],tn=en[1],on=a(Pe),rn=on[0],an=on[1],ln=a(!1),sn=ln[0],cn=ln[1],dn=a(!1),un=dn[0],pn=dn[1],vn=a(null),mn=vn[0],hn=vn[1],fn=a(null),gn=fn[0],yn=fn[1],bn=a(!1),Tn=bn[0],An=bn[1],Nn=a(!1),Cn=Nn[0],jn=Nn[1],wn=l(null),In=!1!==Y.is_enabled,xn=a(!1),Dn=xn[0],Ln=xn[1],Bn=l(null),Sn=a({isOpen:!1,mode:"approve"}),On=Sn[0],kn=Sn[1],Fn=k(),En=F(function(e){return e.rbacConfig}),Hn=En?{application:En.applicationId,scopeLevelModuleId:null!==(R=null==En?void 0:En.moduleId)&&void 0!==R?R:"",applicationLevelModuleId:null!==(V=null==En?void 0:En.applicationModuleId)&&void 0!==V?V:"",applicationLevelResourceId:null!==(W=null==En?void 0:En.applicationResourceId)&&void 0!==W?W:""}:void 0,_n=L(function(e){return e.hasPermission}),Mn=ee,Pn=Y.inheritance&&Y.inheritance.length>1,Rn=_n("ilotj.rule.variant.edit",Mn)||_n(Pn?"ilotj.rule.variant.inherited.edit":"ilotj.rule.variant.nonInherited.edit",Mn),Vn=_n("ilotj.rule.variant.enable",Mn)||_n(Pn?"ilotj.rule.variant.inherited.enable":"ilotj.rule.variant.nonInherited.enable",Mn),Wn=_n("ilotj.rule.variant.disable",Mn)||_n(Pn?"ilotj.rule.variant.inherited.disable":"ilotj.rule.variant.nonInherited.disable",Mn),zn=_n("ilotj.rule.variant.delete",Mn),Un=_n("ilotj.rule.selfApprove",Mn),Gn=_n("ilotj.rule.approve",Mn),qn=_n("ilotj.scope.approve",Mn),Zn=_n("ilotj.rule.pendingApproval.view",Mn),Kn=_n("ilotj.rule.variant.pendingApproval.edit",Mn),Qn=Un||Gn||qn||Kn,Yn=Zn||Qn,$n="pending_approval"===(null==Y?void 0:Y.approvalStatus),Jn="rejected"===(null==Y?void 0:Y.approvalStatus),Xn=Qn&&$n;s(function(){var e=function(e){wn.current&&!wn.current.contains(e.target)&&An(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}},[]);var et=(null===(z=null==mn?void 0:mn.wta)||void 0===z?void 0:z.changeLog)||[],nt=(null===(U=null==mn?void 0:mn.wnta)||void 0===U?void 0:U.changeLog)||[],tt=We&&Ue&&ne?Ue.filter(function(e){return e!==ne}):[],it=tt.length>0&&ne?tt.every(function(e){return e>ne})?"↓":"↑":"↓",ot=function(){if(Ge)for(var e=Array.from(Ge),n=0;n<e.length;n++)if(e[n]!==Y.variantId){var t=document.querySelector('[data-variant-id="'.concat(e[n],'"]'));if(t){t.scrollIntoView({behavior:"smooth",block:"center"});break}}},rt=function(e,n){e.stopPropagation(),kn({isOpen:!0,mode:n})},at=function(e){if(!e)return"";try{var n=e.endsWith("Z")||/[+-]\d{2}:\d{2}$/.test(e)?e:"".concat(e,"Z"),t=c(n);return d(t)?u(t,"MMM d, yyyy 'at' h:mm a"):e}catch(n){return e}},lt=function(e){return e?e.includes("@")?e.split("@")[0].split(".").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" "):e:""};return i("div",e({className:M(C.variantCard,We&&C.variantHighlight,Re),"data-variant-id":Y.variantId},{children:[i("div",e({className:C.variantHeader,style:{alignItems:"flex-start",gap:"0.75rem"}},{children:[i("div",e({className:C.variantLabelSection,style:{display:"flex",flexWrap:"wrap"}},{children:[o("span",e({className:C.variantLabel},{children:"Default"===Y.variantType&&"Default"!==te?"Default | ".concat(te):te})),We&&ze&&o("span",e({className:M(C.actionChip,"new"===ze?C.actionChipNew:C.actionChipUpdated)},{children:"new"===ze?"Created":"Updated"})),(null==Y?void 0:Y.isOverridden)&&o(w,e({content:"Inherited from the ".concat((null===(G=Y.inheritance)||void 0===G?void 0:G[(null===(q=Y.inheritance)||void 0===q?void 0:q.length)-2])||"parent"," scope and overridden in this scope."),placement:"top",withArrow:!0,contentClassName:j.customTooltip,sideOffset:5},{children:o("span",e({className:C.overriddenTag},{children:"Overridden"}))})),Yn&&$n&&o(B,{}),Jn&&o("span",e({style:{backgroundColor:"#FEF2F2",color:"#EF4444",border:"1px solid #FECACA",padding:"2px 8px",borderRadius:"9999px",fontSize:"0.75rem",fontWeight:500,display:"inline-flex",alignItems:"center"}},{children:"Rejected"})),!In&&o("span",e({className:C.learningDisabledPill},{children:"Disabled"})),Ee&&1!==J&&0!==$&&o("div",e({className:C.inheritanceSection},{children:o(A,{inheritance:Y.inheritance||[]})}))]})),Le&&i("div",e({className:C.variantActions},{children:[Xn&&i(r,{children:[o(S,{variant:"approve",text:"Approve",onClick:function(e){return rt(e,"approve")}}),o(S,{variant:"reject",text:"Reject",onClick:function(e){return rt(e,"reject")}})]}),ie&&Rn&&o("button",e({className:C.editButton,onClick:function(){null==ie||ie(Y,X,ne,"edit")}},{children:le})),oe&&zn&&"Default"!==Y.variantType&&o("button",e({className:C.deleteButton,onClick:function(){null==Qe||Qe("variantDeletion"),null==oe||oe(Y.variantId,X)}},{children:ce})),i("div",e({className:C.menuWrapper,ref:wn},{children:[o("button",e({onClick:function(){return An(!Tn)},className:"".concat(C.menuTrigger," ").concat(Tn?C.menuTriggerActive:"")},{children:o(p,{size:16})})),Tn&&i("div",e({className:C.menuDropdown},{children:[(In&&Wn||!In&&Vn)&&i("button",e({onClick:function(){return n(void 0,void 0,void 0,function(){return t(this,function(e){return An(!1),Ln(!0),[2]})})},disabled:Cn,className:"".concat(C.menuItem," ").concat(Cn?C.menuItemDisabled:"")},{children:[o(In?v:m,{size:14}),In?Ce:Ae]})),ne&&1==Xe.length&&i("button",e({onClick:function(){var e="Tier 1"===ne?"Tier 2":"Tier 1",n="Add a new learning in ".concat(e," with the following details:\nLearning Title: ").concat(Q,"\nLearning Description: ").concat(Y.description,"\nWhen to apply: ").concat(Y.whenToApply,"\nWhen not to apply: ").concat(Y.whenNotToApply);null==$e||$e(n),An(!1),null==Ye||Ye(Y,X,Q||"",ne,e)},className:C.menuItem},{children:[o(h,{size:14}),"Copy to ","Tier 1"===ne?"Tier 2":"Tier 1"]})),re&&(null!==(K=null===(Z=Y.inheritance)||void 0===Z?void 0:Z.length)&&void 0!==K?K:0)>1&&i("button",e({onClick:function(){An(!1),n(void 0,void 0,void 0,function(){var e;return t(this,function(n){switch(n.label){case 0:if(sn)return cn(!1),[2];if(cn(!0),!re)return[2];pn(!0),yn(null),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,re(X,Y.variantId)];case 2:return e=n.sent(),hn(e),[3,5];case 3:return n.sent(),yn(we),[3,5];case 4:return pn(!1),[7];case 5:return[2]}})})},className:C.menuItem},{children:[o(f,{size:14}),sn?be:ge]}))]}))]}))]}))]})),qe,Se&&Y.description&&i("div",e({className:C.descriptionBox},{children:[o("p",e({className:C.descriptionText},{children:Y.description})),sn&&(un?o(T,{}):gn?o("p",e({className:C.errorText},{children:gn})):(null==mn?void 0:mn.ruleDescription)?o(x,{changeLog:mn.ruleDescription.changeLog}):o("p",e({className:C.noHistoryText},{children:"No override history found"})))]})),ke&&i("div",e({className:C.conditionsContainer},{children:[o(N,{type:"apply",conditions:Y.whenToApply||"",isOpen:nn,onToggle:function(){return tn(!nn)},labelText:ue,noConditionsText:he,showOverrideHistory:sn,isLoadingHistory:un,historyError:gn,overrideHistoryData:et}),o(N,{type:"notApply",conditions:Y.whenNotToApply||"",isOpen:rn,onToggle:function(){return an(!rn)},labelText:ve,noConditionsText:he,showOverrideHistory:sn,isLoadingHistory:un,historyError:gn,overrideHistoryData:nt})]})),We&&tt.length>0&&i("div",e({className:C.crossTierBanner},{children:[o(g,{className:C.crossTierBannerIcon}),i("span",e({className:C.crossTierBannerText},{children:["Also created in ",tt.join(", "),"."]})),i("span",e({className:C.crossTierBannerLink,onClick:ot,role:"button",tabIndex:0,onKeyDown:function(e){return"Enter"===e.key&&ot()}},{children:["Scroll to view ",it]}))]})),Ze,(Y.createdBy||Y.createdAt)&&i("div",e({className:C.variantFooter},{children:[!0===Y.is_user_accepted_risk&&i("div",e({className:C.resolveGaps},{children:[o(y,{size:14,color:"#EF4444"}),o("span",e({className:C.resolveGapsText},{children:xe})),Rn&&o("button",e({onClick:function(){null==ie||ie(Y,X,ne,"resolve_gaps")},className:C.resolveButton},{children:"Resolve"}))]})),o("div",e({className:C.variantFooterContent},{children:Y.updatedBy||Y.updatedAt?i(r,{children:[Y.updatedBy&&o(w,e({content:Y.createdBy?"Created by ".concat(lt(Y.createdBy)):"",contentClassName:j.customTooltip,sideOffset:5,placement:"top"},{children:i("span",e({className:C.variantFooterItem},{children:["Updated by ",lt(Y.updatedBy)]}))})),Y.updatedBy&&Y.updatedAt&&o("span",e({className:C.variantFooterSeparator},{children:"•"})),Y.updatedAt&&o(w,e({content:Y.createdAt?"Created at ".concat(at(Y.createdAt)):"",contentClassName:j.customTooltip,sideOffset:5,placement:"top"},{children:o("span",e({className:C.variantFooterItem},{children:at(Y.updatedAt)}))}))]}):i(r,{children:[Y.createdBy&&i("span",e({className:C.variantFooterItem},{children:["Created by ",lt(Y.createdBy)]})),Y.createdBy&&Y.createdAt&&o("span",e({className:C.variantFooterSeparator},{children:"•"})),Y.createdAt&&o("span",e({className:C.variantFooterItem},{children:at(Y.createdAt)}))]})}))]})),o(I,{isOpen:Dn,title:In?E("".concat(H,".disableDialog.title"),"Disable Learning?"):E("".concat(H,".enableDialog.title"),"Enable Learning?"),description:In?E("".concat(H,".disableDialog.desc"),"Are you sure you want to disable learning for this variant in {rule_title}?",{rule_title:null!=Q?Q:""}):E("".concat(H,".enableDialog.desc"),"Are you sure you want to enable learning for this variant in {rule_title}?",{rule_title:null!=Q?Q:""}),warning:In?E("".concat(H,".disableDialog.warningText"),"This learning will no longer influence upcoming schedules. You can enable it again anytime."):E("".concat(H,".enableDialog.warningText"),"This learning will start influencing upcoming schedules again."),confirmText:In?E("".concat(H,".disableDialog.deleteText"),"Disable"):E("".concat(H,".enableDialog.deleteText"),"Enable"),cancelText:E("".concat(H,In?".disableDialog.cancelText":".enableDialog.cancelText"),"Cancel"),loadingText:E("".concat(H,In?".disableDialog.loadingText":".enableDialog.loadingText"),"Processing..."),confirmBgColor:In?"#DC2626":"#16A34A",onConfirm:function(){return n(void 0,void 0,void 0,function(){var e;return t(this,function(n){switch(n.label){case 0:jn(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),null==Je?void 0:Je.email,[4,b([Y.variantId],!In)];case 2:return n.sent(),null==Ke||Ke(),[3,5];case 3:return e=n.sent(),console.error("Failed to toggle variant",e),[3,5];case 4:return jn(!1),An(!1),Ln(!1),[7];case 5:return[2]}})})},onCancel:function(){return Ln(!1)},isLoading:Cn,position:"fixed"}),o(O,{open:On.isOpen,mode:On.mode,onClose:function(){return kn(function(n){return e(e({},n),{isOpen:!1})})},onSubmit:function(n){ee&&Fn.mutate({variantIds:[Y.variantId],status:"approve"===On.mode?"approved":"rejected",feedback:n.feedback,is_deleted:n.deleteLearning,scopeId:ee,appsecData:Hn},{onSuccess:function(){var n;kn(function(n){return e(e({},n),{isOpen:!1})}),null==Ke||Ke(),null===(n=Bn.current)||void 0===n||n.show({severity:"success",summary:"".concat("approve"===On.mode?"Approved":"Rejected"," Successfully"),detail:"Learning ".concat("approve"===On.mode?"approved":"rejected"," successfully.")})},onError:function(e){var n;console.error("An error occurred.",e),null===(n=Bn.current)||void 0===n||n.show({severity:"error",summary:"Action Failed",detail:"There was an error processing the learning. Please try again."})}})},variantInformation:"".concat(Q," — ").concat(te),ruleTitle:Q,pendingVariants:[Y],isPending:Fn.isPending})]}))};export{P as default};
1
+ import{__assign as e,__awaiter as n,__generator as t}from"tslib";import{jsxs as i,jsx as o,Fragment as r}from"react/jsx-runtime";import{useState as a,useRef as l,useEffect as s}from"react";import{parseISO as c,isValid as d,format as u}from"date-fns";import{MoreVertical as p,Pause as v,Play as m,Copy as h,Eye as f,Info as g,TriangleAlert as y}from"lucide-react";import{toggleVariant as b}from"../apis/scopeApis.js";import{HistorySkeleton as T}from"./HistorySkeleton.js";import A from"./InheritanceBreadcrumb.js";import N from"./RuleConditionBlock.js";import C from"../styles/VariantCard.module.css.js";import j from"../styles/CustomTooltip.module.css.js";import w from"../components/CustomTooltip.js";import I from"../components/ConfirmationModal.js";import x from"./OverrideTimeline.js";import D from"../store/useAuthStore.js";import{usePermissionsStore as L}from"../store/usePermissionsStore.js";import B from"./PendingApprovalChip.js";import S from"./ApprovalActionButton.js";import O from"./ApprovalLearningDialog.js";import{useApproveOrRejectVariantsMutation as k}from"../queries/useApprovalQueries.js";import F from"../store/useEnvStore.js";import{dt as E}from"../store/useLMSConfigStore.js";import{VARIANT_DT_PATH as H}from"../constants.js";import{useLearningTemplateStore as _}from"../store/useLearningTemplateStore.js";var M=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.filter(Boolean).join(" ")},P=function(P){var R,V,W,z,U,G,q,Z,K,Q=P.ruleTitle,Y=P.variant,$=P.variantIndex,J=P.totalVariants,X=P.ruleId;P.pendingApprovalCount;var ee=P.ruleSetId,ne=P.tierName,te=P.displayLabel,ie=P.onEdit,oe=P.onDelete,re=P.onFetchOverrideHistory,ae=P.editButtonLabel,le=void 0===ae?E("".concat(H,".actions.edit"),"Edit"):ae,se=P.deleteButtonLabel,ce=void 0===se?E("".concat(H,".actions.delete"),"Delete"):se,de=P.whenToApplyLabel,ue=void 0===de?E("".concat(H,".whenToApply"),"When to Apply"):de,pe=P.whenNotToApplyLabel,ve=void 0===pe?E("".concat(H,".whenNotToApply"),"When Not to Apply"):pe,me=P.noConditionsText,he=void 0===me?"No conditions":me,fe=P.viewOverrideLabel,ge=void 0===fe?"View Override History":fe,ye=P.hideOverrideLabel,be=void 0===ye?"Hide Override History":ye,Te=P.enableLearningVariantLabel,Ae=void 0===Te?E("".concat(H,".actions.enable"),"Enable"):Te,Ne=P.disableLearningVariantLabel,Ce=void 0===Ne?E("".concat(H,".actions.disable"),"Disable"):Ne,je=P.historyErrorMessage,we=void 0===je?"Failed to load override history.":je,Ie=P.resolveGapsLabel,xe=void 0===Ie?"This learning has some gaps":Ie,De=P.showActionsBar,Le=void 0===De||De,Be=P.showDescriptionBox,Se=void 0===Be||Be,Oe=P.showConditions,ke=void 0===Oe||Oe,Fe=P.showInheritance,Ee=void 0===Fe||Fe,He=P.defaultApplyOpen,_e=void 0===He||He,Me=P.defaultNotApplyOpen,Pe=void 0===Me||Me,Re=P.className,Ve=P.isHighlighted,We=void 0!==Ve&&Ve,ze=P.highlightAction,Ue=P.highlightedTierNames,Ge=P.highlightedVariantIds,qe=P.headerContent,Ze=P.footerContent,Ke=P.onToggleSuccess,Qe=P.setDeleteConfirmationUsedFor,Ye=P.onCopyToTier,$e=P.onSetInitialDraftMessage,Je=D.getState().user,Xe=_.getState().tiers,en=a(_e),nn=en[0],tn=en[1],on=a(Pe),rn=on[0],an=on[1],ln=a(!1),sn=ln[0],cn=ln[1],dn=a(!1),un=dn[0],pn=dn[1],vn=a(null),mn=vn[0],hn=vn[1],fn=a(null),gn=fn[0],yn=fn[1],bn=a(!1),Tn=bn[0],An=bn[1],Nn=a(!1),Cn=Nn[0],jn=Nn[1],wn=l(null),In=!1!==Y.is_enabled,xn=a(!1),Dn=xn[0],Ln=xn[1],Bn=l(null),Sn=a({isOpen:!1,mode:"approve"}),On=Sn[0],kn=Sn[1],Fn=k(),En=F(function(e){return e.rbacConfig}),Hn=En?{application:En.applicationId,scopeLevelModuleId:null!==(R=null==En?void 0:En.moduleId)&&void 0!==R?R:"",applicationLevelModuleId:null!==(V=null==En?void 0:En.applicationModuleId)&&void 0!==V?V:"",applicationLevelResourceId:null!==(W=null==En?void 0:En.applicationResourceId)&&void 0!==W?W:""}:void 0,_n=L(function(e){return e.hasPermission}),Mn=ee,Pn=Y.inheritance&&Y.inheritance.length>1,Rn=_n("ilotj.rule.variant.edit",Mn)||_n(Pn?"ilotj.rule.variant.inherited.edit":"ilotj.rule.variant.nonInherited.edit",Mn),Vn=_n("ilotj.rule.variant.enable",Mn)||_n(Pn?"ilotj.rule.variant.inherited.enable":"ilotj.rule.variant.nonInherited.enable",Mn),Wn=_n("ilotj.rule.variant.disable",Mn)||_n(Pn?"ilotj.rule.variant.inherited.disable":"ilotj.rule.variant.nonInherited.disable",Mn),zn=_n("ilotj.rule.variant.delete",Mn),Un=_n("ilotj.rule.selfApprove",Mn),Gn=_n("ilotj.rule.approve",Mn),qn=_n("ilotj.scope.approve",Mn),Zn=_n("ilotj.rule.pendingApproval.view",Mn),Kn=_n("ilotj.rule.variant.pendingApproval.edit",Mn),Qn=Un||Gn||qn||Kn,Yn=Zn||Qn,$n="pending_approval"===(null==Y?void 0:Y.approvalStatus),Jn="rejected"===(null==Y?void 0:Y.approvalStatus),Xn=Qn&&$n;s(function(){var e=function(e){wn.current&&!wn.current.contains(e.target)&&An(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}},[]);var et=(null===(z=null==mn?void 0:mn.wta)||void 0===z?void 0:z.changeLog)||[],nt=(null===(U=null==mn?void 0:mn.wnta)||void 0===U?void 0:U.changeLog)||[],tt=We&&Ue&&ne?Ue.filter(function(e){return e!==ne}):[],it=tt.length>0&&ne?tt.every(function(e){return e>ne})?"↓":"↑":"↓",ot=function(){if(Ge)for(var e=Array.from(Ge),n=0;n<e.length;n++)if(e[n]!==Y.variantId){var t=document.querySelector('[data-variant-id="'.concat(e[n],'"]'));if(t){t.scrollIntoView({behavior:"smooth",block:"center"});break}}},rt=function(e,n){e.stopPropagation(),kn({isOpen:!0,mode:n})},at=function(e){if(!e)return"";try{var n=e.endsWith("Z")||/[+-]\d{2}:\d{2}$/.test(e)?e:"".concat(e,"Z"),t=c(n);return d(t)?u(t,"MMM d, yyyy 'at' h:mm a"):e}catch(n){return e}},lt=function(e){return e?e.includes("@")?e.split("@")[0].split(".").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join(" "):e:""};return i("div",e({className:M(C.variantCard,We&&C.variantHighlight,Re),"data-variant-id":Y.variantId},{children:[i("div",e({className:C.variantHeader,style:{alignItems:"flex-start",gap:"0.75rem"}},{children:[i("div",e({className:C.variantLabelSection,style:{display:"flex",flexWrap:"wrap"}},{children:[o("span",e({className:C.variantLabel},{children:"Default"===Y.variantType&&"Default"!==te?"Default | ".concat(te):te})),We&&ze&&o("span",e({className:M(C.actionChip,"new"===ze?C.actionChipNew:C.actionChipUpdated)},{children:"new"===ze?"Created":"Updated"})),(null==Y?void 0:Y.isOverridden)&&o(w,e({content:"Inherited from the ".concat((null===(G=Y.inheritance)||void 0===G?void 0:G[(null===(q=Y.inheritance)||void 0===q?void 0:q.length)-2])||"parent"," scope and overridden in this scope."),placement:"top",withArrow:!0,contentClassName:j.customTooltip,sideOffset:5},{children:o("span",e({className:C.overriddenTag},{children:"Overridden"}))})),Yn&&$n&&o(B,{}),Jn&&o("span",e({style:{backgroundColor:"#FEF2F2",color:"#EF4444",border:"1px solid #FECACA",padding:"2px 8px",borderRadius:"9999px",fontSize:"0.75rem",fontWeight:500,display:"inline-flex",alignItems:"center"}},{children:"Rejected"})),!In&&o("span",e({className:C.learningDisabledPill},{children:"Disabled"})),Ee&&1!==J&&0!==$&&o("div",e({className:C.inheritanceSection},{children:o(A,{inheritance:Y.inheritance||[]})}))]})),Le&&i("div",e({className:C.variantActions},{children:[Xn&&i(r,{children:[o(S,{variant:"approve",text:"Approve",onClick:function(e){return rt(e,"approve")}}),o(S,{variant:"reject",text:"Reject",onClick:function(e){return rt(e,"reject")}})]}),ie&&Rn&&o("button",e({className:C.editButton,onClick:function(){null==ie||ie(Y,X,ne,"edit")}},{children:le})),oe&&zn&&"Default"!==Y.variantType&&o("button",e({className:C.deleteButton,onClick:function(){null==Qe||Qe("variantDeletion"),null==oe||oe(Y.variantId,X)}},{children:ce})),i("div",e({className:C.menuWrapper,ref:wn},{children:[o("button",e({onClick:function(){return An(!Tn)},className:"".concat(C.menuTrigger," ").concat(Tn?C.menuTriggerActive:"")},{children:o(p,{size:16})})),Tn&&i("div",e({className:C.menuDropdown},{children:[(In&&Wn||!In&&Vn)&&i("button",e({onClick:function(){return n(void 0,void 0,void 0,function(){return t(this,function(e){return An(!1),Ln(!0),[2]})})},disabled:Cn,className:"".concat(C.menuItem," ").concat(Cn?C.menuItemDisabled:"")},{children:[o(In?v:m,{size:14}),In?Ce:Ae]})),ne&&Xe.length>1&&i("button",e({onClick:function(){var e="Tier 1"===ne?"Tier 2":"Tier 1",n="Add a new learning in ".concat(e," with the following details:\nLearning Title: ").concat(Q,"\nLearning Description: ").concat(Y.description,"\nWhen to apply: ").concat(Y.whenToApply,"\nWhen not to apply: ").concat(Y.whenNotToApply);null==$e||$e(n),An(!1),null==Ye||Ye(Y,X,Q||"",ne,e)},className:C.menuItem},{children:[o(h,{size:14}),"Copy to ","Tier 1"===ne?"Tier 2":"Tier 1"]})),re&&(null!==(K=null===(Z=Y.inheritance)||void 0===Z?void 0:Z.length)&&void 0!==K?K:0)>1&&i("button",e({onClick:function(){An(!1),n(void 0,void 0,void 0,function(){var e;return t(this,function(n){switch(n.label){case 0:if(sn)return cn(!1),[2];if(cn(!0),!re)return[2];pn(!0),yn(null),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,re(X,Y.variantId)];case 2:return e=n.sent(),hn(e),[3,5];case 3:return n.sent(),yn(we),[3,5];case 4:return pn(!1),[7];case 5:return[2]}})})},className:C.menuItem},{children:[o(f,{size:14}),sn?be:ge]}))]}))]}))]}))]})),qe,Se&&Y.description&&i("div",e({className:C.descriptionBox},{children:[o("p",e({className:C.descriptionText},{children:Y.description})),sn&&(un?o(T,{}):gn?o("p",e({className:C.errorText},{children:gn})):(null==mn?void 0:mn.ruleDescription)?o(x,{changeLog:mn.ruleDescription.changeLog}):o("p",e({className:C.noHistoryText},{children:"No override history found"})))]})),ke&&i("div",e({className:C.conditionsContainer},{children:[o(N,{type:"apply",conditions:Y.whenToApply||"",isOpen:nn,onToggle:function(){return tn(!nn)},labelText:ue,noConditionsText:he,showOverrideHistory:sn,isLoadingHistory:un,historyError:gn,overrideHistoryData:et}),o(N,{type:"notApply",conditions:Y.whenNotToApply||"",isOpen:rn,onToggle:function(){return an(!rn)},labelText:ve,noConditionsText:he,showOverrideHistory:sn,isLoadingHistory:un,historyError:gn,overrideHistoryData:nt})]})),We&&tt.length>0&&i("div",e({className:C.crossTierBanner},{children:[o(g,{className:C.crossTierBannerIcon}),i("span",e({className:C.crossTierBannerText},{children:["Also created in ",tt.join(", "),"."]})),i("span",e({className:C.crossTierBannerLink,onClick:ot,role:"button",tabIndex:0,onKeyDown:function(e){return"Enter"===e.key&&ot()}},{children:["Scroll to view ",it]}))]})),Ze,(Y.createdBy||Y.createdAt)&&i("div",e({className:C.variantFooter},{children:[!0===Y.is_user_accepted_risk&&i("div",e({className:C.resolveGaps},{children:[o(y,{size:14,color:"#EF4444"}),o("span",e({className:C.resolveGapsText},{children:xe})),Rn&&o("button",e({onClick:function(){null==ie||ie(Y,X,ne,"resolve_gaps")},className:C.resolveButton},{children:"Resolve"}))]})),o("div",e({className:C.variantFooterContent},{children:Y.updatedBy||Y.updatedAt?i(r,{children:[Y.updatedBy&&o(w,e({content:Y.createdBy?"Created by ".concat(lt(Y.createdBy)):"",contentClassName:j.customTooltip,sideOffset:5,placement:"top"},{children:i("span",e({className:C.variantFooterItem},{children:["Updated by ",lt(Y.updatedBy)]}))})),Y.updatedBy&&Y.updatedAt&&o("span",e({className:C.variantFooterSeparator},{children:"•"})),Y.updatedAt&&o(w,e({content:Y.createdAt?"Created at ".concat(at(Y.createdAt)):"",contentClassName:j.customTooltip,sideOffset:5,placement:"top"},{children:o("span",e({className:C.variantFooterItem},{children:at(Y.updatedAt)}))}))]}):i(r,{children:[Y.createdBy&&i("span",e({className:C.variantFooterItem},{children:["Created by ",lt(Y.createdBy)]})),Y.createdBy&&Y.createdAt&&o("span",e({className:C.variantFooterSeparator},{children:"•"})),Y.createdAt&&o("span",e({className:C.variantFooterItem},{children:at(Y.createdAt)}))]})}))]})),o(I,{isOpen:Dn,title:In?E("".concat(H,".disableDialog.title"),"Disable Learning?"):E("".concat(H,".enableDialog.title"),"Enable Learning?"),description:In?E("".concat(H,".disableDialog.desc"),"Are you sure you want to disable learning for this variant in {rule_title}?",{rule_title:null!=Q?Q:""}):E("".concat(H,".enableDialog.desc"),"Are you sure you want to enable learning for this variant in {rule_title}?",{rule_title:null!=Q?Q:""}),warning:In?E("".concat(H,".disableDialog.warningText"),"This learning will no longer influence upcoming schedules. You can enable it again anytime."):E("".concat(H,".enableDialog.warningText"),"This learning will start influencing upcoming schedules again."),confirmText:In?E("".concat(H,".disableDialog.deleteText"),"Disable"):E("".concat(H,".enableDialog.deleteText"),"Enable"),cancelText:E("".concat(H,In?".disableDialog.cancelText":".enableDialog.cancelText"),"Cancel"),loadingText:E("".concat(H,In?".disableDialog.loadingText":".enableDialog.loadingText"),"Processing..."),confirmBgColor:In?"#DC2626":"#16A34A",onConfirm:function(){return n(void 0,void 0,void 0,function(){var e;return t(this,function(n){switch(n.label){case 0:jn(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),null==Je?void 0:Je.email,[4,b([Y.variantId],!In)];case 2:return n.sent(),null==Ke||Ke(),[3,5];case 3:return e=n.sent(),console.error("Failed to toggle variant",e),[3,5];case 4:return jn(!1),An(!1),Ln(!1),[7];case 5:return[2]}})})},onCancel:function(){return Ln(!1)},isLoading:Cn,position:"fixed"}),o(O,{open:On.isOpen,mode:On.mode,onClose:function(){return kn(function(n){return e(e({},n),{isOpen:!1})})},onSubmit:function(n){ee&&Fn.mutate({variantIds:[Y.variantId],status:"approve"===On.mode?"approved":"rejected",feedback:n.feedback,is_deleted:n.deleteLearning,scopeId:ee,appsecData:Hn},{onSuccess:function(){var n;kn(function(n){return e(e({},n),{isOpen:!1})}),null==Ke||Ke(),null===(n=Bn.current)||void 0===n||n.show({severity:"success",summary:"".concat("approve"===On.mode?"Approved":"Rejected"," Successfully"),detail:"Learning ".concat("approve"===On.mode?"approved":"rejected"," successfully.")})},onError:function(e){var n;console.error("An error occurred.",e),null===(n=Bn.current)||void 0===n||n.show({severity:"error",summary:"Action Failed",detail:"There was an error processing the learning. Please try again."})}})},variantInformation:"".concat(Q," — ").concat(te),ruleTitle:Q,pendingVariants:[Y],isPending:Fn.isPending})]}))};export{P as default};
2
2
  //# sourceMappingURL=VariantCard.js.map