@e-llm-studio/instant-learning 1.0.6 → 1.0.7

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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react/jsx-runtime"),n=require("react"),r=require("lucide-react"),s=require("./store/useLearningTemplateStore.js"),a=require("primereact/toast"),i=require("./styles/LearningTemplateManagement.module.css.js"),o=require("./LearningTemplateLayout.js"),l=require("./components/EmptyLearningState.js"),u=require("./store/useAuthStore.js"),c=require("./apis/scopeApis.js"),d=require("./hooks/useLearningTemplateQueryParams.js"),p=require("./components/ConfirmationModal.js"),f=require("./components/LearningTemplateManagementSkeleton.js"),g=require("./utils/treeUtils.js"),S=require("./store/useEnvStore.js"),m=require("./store/useConfigStore.js"),v=require("./components/ToolTip.js"),_=require("./components/CreateRuleSetLegacyModal.js"),h=require("./store/usePermissionsStore.js"),y=require("./store/useAppSecRolesStore.js"),T=require("./queries/useApprovalQueries.js"),b=require("./RuleContent/AddScopeModal.js"),C=require("react-router-dom"),L=require("./shared/SuccessToastContent.js"),j=require("./shared/ErrorToastContent.js"),E=require("./RuleContent/RenameScopeModal.js"),A=[{id:"learnings",label:"Learnings",icon:r.BookOpen,badgeKey:"learningsCount"},{id:"access",label:"Access",icon:r.Users}],R=new Set(A.map(function(e){return e.id}));exports.default=function(r){var w,O=this,I=r.userDetails,q=r.llmStudioUrl,N=r.audacyBackendUrl,P=r.ilLabels,k=r.config,x=r.rbacConfig,D=r.app_integration_id,U=r.backwardCompatibility,M=void 0!==U&&U,B=s.useLearningTemplateStore(function(e){return e.selectedRuleSetId}),G=s.useLearningTemplateStore(function(e){return e.setSelectedRuleSetId}),F=s.useLearningTemplateStore(function(e){return e.error}),Q=s.useLearningTemplateStore(function(e){return e.setError}),Y=s.useLearningTemplateStore(function(e){return e.setStations}),K=s.useLearningTemplateStore(function(e){return e.scopeTreeData}),z=s.useLearningTemplateStore(function(e){return e.setScopeTreeData}),H=n.useState({isOpen:!1,type:"GLOBAL"}),V=H[0],W=H[1],J=n.useState(!1),X=J[0],Z=J[1],$=n.useState(!1),ee=$[0],te=$[1],ne=n.useState("learnings"),re=ne[0],se=ne[1],ae=n.useState(null),ie=ae[0],oe=ae[1],le=n.useState(null),ue=le[0],ce=le[1],de=n.useRef(null),pe=n.useRef(null),fe=n.useRef(null),ge=u.default();ge.user;var Se=ge.setUser,me=m.useConfigStore(),ve=me.setConfig,_e=me.setIlLabels,he=e.__spreadArray([{type:"GLOBAL",label:"Global",addChildLabel:"Add Scope",addChildType:"SCOPE"},e.__assign({type:"SCOPE",label:"Scope"},!M&&{addChildLabel:"Add Subscope",addChildType:"SUBSCOPE"})],M?[]:[{type:"SUBSCOPE",label:"Subscope"}],!0),ye=function(){try{return C.useLocation()}catch(e){return{search:""}}}();n.useEffect(function(){var e=new URLSearchParams(window.location.search),t=e.get(d.QUERY_PARAM_KEYS.RULESET_ID),n=e.get(d.QUERY_PARAM_KEYS.SECTION),r=n&&R.has(n)?n:"learnings";(null==t?void 0:t.length)&&G&&se&&(G(t),se(r))},[null==ye?void 0:ye.search,se,G]);var Te=h.usePermissionsStore(function(e){return e.fetchPermissions}),be=h.usePermissionsStore(function(e){return e.hasPermission}),Ce=y.useAppSecRolesStore(function(e){return e.setRoles}),Le=S.default(function(e){return e.appsecRbacUrl})===x.appsecRbacUrl,je=T.useGetAppSecRolesQuery(x.applicationId,Le).data;n.useEffect(function(){je&&Ce(je.map(function(e){return{_id:e._id,name:e.name}}))},[je,Ce]),n.useEffect(function(){var e;console.log("userDetails",I),Se(I),console.log("llmStudioUrl",q),console.log("audacyBackendUrl",N),S.default.getState().setLlmStudioUrl(q),S.default.getState().setAudacyBackendUrl(N),S.default.getState().setRbacConfig(x),ve(k),_e(P),s.useLearningTemplateStore.getState().setAppIntegrationId(null!=D?D:null),s.useLearningTemplateStore.getState().setBackwardCompatibility(M),s.useLearningTemplateStore.getState().setToken(null!==(e=I.accessToken)&&void 0!==e?e:null)},[I,Se,q,N,x,k,ve,P,_e,D,M]),n.useEffect(function(){(null==I?void 0:I.accessToken)&&q&&c.fetchTiers()},[D,null==I?void 0:I.accessToken,q]);var Ee=function(t){return void 0===t&&(t=!0),e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l;return e.__generator(this,function(u){switch(u.label){case 0:t&&Z(!0),Q(null),u.label=1;case 1:return u.trys.push([1,4,5,6]),[4,Te(x.applicationId)];case 2:return u.sent(),n=function(t){if(!h.usePermissionsStore.getState().hasPermission("ilotj.scope.view",t.id))return null;var r=t.children?t.children.map(function(e){return n(e)}).filter(function(e){return null!==e}):[];return e.__assign(e.__assign({},t),{children:r})},[4,c.fetchScopes(D,I.accessToken)];case 3:return(r=u.sent())&&r.data&&r.data.data&&(a=r.data.data,Array.isArray(a)&&(a=a.length>0?a[0]:null),a?(i=n(a))?(oe(null),z({data:i}),pe.current?(G(pe.current),se("learnings"),pe.current=null):s.useLearningTemplateStore.getState().selectedRuleSetId||G(i.id)):(oe(null!==(l=a.id)&&void 0!==l?l:null),z(null)):(oe(null),z(null))),[3,6];case 4:return o=u.sent(),console.error("Failed to fetch rule sets or permissions",o),Q("Failed to load data. Please try again later."),[3,6];case 5:return Z(!1),[7];case 6:return[2]}})})};n.useEffect(function(){var e;(null===(e=null==I?void 0:I.accessToken)||void 0===e?void 0:e.length)&&Le?Ee(!0):console.warn("Error: Trying to fetch rules without access token",I)},[null==I?void 0:I.accessToken,Q,Y,x.applicationId,Le]);var Ae=function(n){return e.__awaiter(O,void 0,void 0,function(){var r,s,a,o;return e.__generator(this,function(l){switch(l.label){case 0:te(!0),l.label=1;case 1:return l.trys.push([1,4,5,6]),V.scopeId?[4,c.renameScope({scope_id:V.scopeId,scope_name:n})]:[2];case 2:return l.sent(),[4,Ee(!0)];case 3:return l.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),[3,6];case 4:throw r=l.sent(),console.error("An error occurred during scope rename.",r),null===(s=fe.current)||void 0===s||s.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:(null===(o=null===(a=null==r?void 0:r.response)||void 0===a?void 0:a.data)||void 0===o?void 0:o.message)||"There was an error renaming the scope. Please try again."})}),r;case 5:return te(!1),[7];case 6:return[2]}})})},Re=function(t,n,r){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l,u,d;return e.__generator(this,function(p){switch(p.label){case 0:te(!0),p.label=1;case 1:return p.trys.push([1,4,5,6]),[4,c.deleteRuleSet(t,I.accessToken)];case 2:return p.sent(),s.useLearningTemplateStore.getState().selectedRuleSetId===t&&(n=s.useLearningTemplateStore.getState().scopeTreeData,(r=g.findNodePathById((null==n?void 0:n.data)||null,t))&&r.length>1&&(a=r[r.length-2],G(a),se("learnings"))),[4,Ee(!0)];case 3:return p.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),null===(o=fe.current)||void 0===o||o.show({severity:"success",summary:"Deleted Successfully",detail:"The scope was permanently removed."}),[3,6];case 4:return i=p.sent(),console.error("An error occurred during scope deletion.",i),null===(l=fe.current)||void 0===l||l.show({severity:"error",summary:"Delete Failed",detail:(null===(d=null===(u=null==i?void 0:i.response)||void 0===u?void 0:u.data)||void 0===d?void 0:d.message)||"There was an error deleting the scope. Please try again."}),[3,6];case 5:return te(!1),[7];case 6:return[2]}})})},we=K,Oe=ue?{data:{id:ue.stationId,name:ue.stationName,type:"STATION",metrics:{learningsCount:ue.learningsCount,stationsCount:0},children:[]}}:we,Ie=!!(null==Oe?void 0:Oe.data);null===(w=null==Oe?void 0:Oe.data)||void 0===w||w.type;var qe=h.usePermissionsStore(function(e){return e.hasGlobalPermission})("ilotj.scope.global.create",x.applicationResourceId||""),Ne=(ue?A.filter(function(e){return"stations"!==e.id}):A).filter(function(e){return!(!M&&"access"===e.id)});return t.jsx(v.TooltipProvider,{children:t.jsxs("div",e.__assign({className:i.default.learningManagementContainer},{children:[t.jsx("div",e.__assign({className:i.default.mainWrapper},{children:X?t.jsx(f.default,{}):F?t.jsxs("div",e.__assign({className:i.default.errorContainer},{children:[t.jsx("div",e.__assign({className:i.default.errorTitle},{children:"Error Loading Data"})),t.jsx("p",e.__assign({className:i.default.errorDesc},{children:F})),t.jsx("button",e.__assign({onClick:function(){return Ee(!0)},className:i.default.tryAgainBtn},{children:"Try Again"}))]})):Ie?t.jsx(o.default,{onOpenCreateModal:function(){return W({isOpen:!0,type:"GLOBAL"})},onAddChild:function(e,t,n){return W({isOpen:!0,type:t,parentId:e,parentName:n})},onRenameChild:function(e,t){return W({isOpen:!0,type:"RENAME",scopeId:e,initialName:t})},onDeleteChild:function(t,n,r){return e.__awaiter(O,void 0,void 0,function(){var a,i,o;return e.__generator(this,function(e){switch(e.label){case 0:return a=s.useLearningTemplateStore.getState().scopeTreeData,i=g.findNodePathById((null==a?void 0:a.data)||null,t),o=!!i&&3===i.length,0!==r?[3,2]:[4,Re(t)];case 1:return e.sent(),[3,3];case 2:W({isOpen:!0,type:"DELETE",scopeId:t,initialName:n,isSubscope:o}),e.label=3;case 3:return[2]}})})},canDeleteScope:function(e){return be("ilotj.scope.delete",e)},canEditScope:function(e){return be("ilotj.scope.edit",e)},canCreateScope:function(e){return be("ilotj.scope.create",e)},onSectionSelect:function(e,t){var n;console.log("Section Selected:",{scopeId:e,sectionId:t}),d.setQueryParams(((n={})[d.QUERY_PARAM_KEYS.SECTION]="learnings"===t?null:t,n)),se(t),G(e)},activeSectionId:re,scopeTreeData:Oe,sectionsConfig:Ne,onViewStation:function(e){de.current=B,ce(e),se("learnings"),G(e.stationId)},onRefreshRuleSets:function(e,t){void 0===e&&(e=!0),t&&(pe.current=t),Ee(e)},nodeTypesConfig:he,app_integration_id:D,token:I.accessToken}):t.jsx(l.default,{onCreate:function(){return W({isOpen:!0,type:"GLOBAL"})},title:"No Global Scope has been added!",desc:"Start by creating a Global scope to define base learnings that apply across all stations.",button:"Create Global Scope",canCreateRule:qe,noAccessTitle:"Access Restricted",noAccessDesc:"You do not have access to create a Global scope for this application.",onRequestAccess:function(){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,o,l,u,d,p,f;return e.__generator(this,function(e){switch(e.label){case 0:if(!(n=(null===(o=null===(a=s.useLearningTemplateStore.getState().scopeTreeData)||void 0===a?void 0:a.data)||void 0===o?void 0:o.id)||ie))return null===(l=fe.current)||void 0===l||l.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:"Unable to identify the global scope for this access request."})}),[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,c.requestAccess(n)];case 2:return e.sent(),null===(u=fe.current)||void 0===u||u.show({severity:"success",sticky:!1,life:3e3,className:i.default.successToast,content:t.jsx(L.default,{message:"Access request submitted successfully!"})}),[3,4];case 3:return r=e.sent(),null===(d=fe.current)||void 0===d||d.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:(null===(f=null===(p=null==r?void 0:r.response)||void 0===p?void 0:p.data)||void 0===f?void 0:f.detail)||"Failed to request access. Please try again."})}),[3,4];case 4:return[2]}})})}})})),t.jsx(a.Toast,{ref:fe,pt:{root:{style:{zIndex:9999}}}}),M&&V.isOpen&&"DELETE"!==V.type&&"RENAME"!==V.type?t.jsx(_.default,{isOpen:!0,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onSubmit:function(t){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l,u,d,p,f,g,S,m,v,_,h,y,T,b,C;return e.__generator(this,function(L){switch(L.label){case 0:te(!0),n=s.useLearningTemplateStore.getState().backwardCompatibility,L.label=1;case 1:return L.trys.push([1,12,13,14]),r=void 0,n&&"object"==typeof t?r=t:(a=t,i="SCOPE"===V.type&&V.parentId,o=i?"genreRuleSet":V.type,r={topic:o,scope_reference_id:null,scopeDescription:"demo",parentScopeId:V.parentId||null,scopeName:a,scopeReferenceMetadata:{},applicationMappingId:D}),[4,c.createRuleSet(r,I.accessToken)];case 2:if(l=L.sent(),!(u=null===(v=null==l?void 0:l.data)||void 0===v?void 0:v.scopeId))return[3,10];if(pe.current=u,d=n&&(null===(_=r.topic)||void 0===_?void 0:_.toLowerCase().includes("genre")),p=!n&&"GLOBAL"!==V.type&&V.parentId,!d&&!p)return[3,10];if(!(f=n?null===(y=null===(h=s.useLearningTemplateStore.getState().scopeTreeData)||void 0===h?void 0:h.data)||void 0===y?void 0:y.id:V.parentId))return[3,10];if(!M)return[3,7];L.label=3;case 3:return L.trys.push([3,5,,6]),[4,c.inheritScopeBackwardCompatible({source_scope_id:f,target_scope_id:u})];case 4:return L.sent(),[3,6];case 5:return g=L.sent(),console.error("Failed to inherit rules for the new scope:",g),[3,6];case 6:return[3,10];case 7:return L.trys.push([7,9,,10]),[4,c.inheritScope({source_scope_id:f,target_scope_id:u,application_mapping_id:D||"",is_copy_parent_variant_id:!1})];case 8:return L.sent(),[3,10];case 9:return S=L.sent(),console.error("Failed to inherit rules for the new scope:",S),[3,10];case 10:return[4,Ee(!0)];case 11:return L.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),[3,14];case 12:throw m=L.sent(),console.error("An error occurred during scope creation.",m),null===(T=fe.current)||void 0===T||T.show({severity:"error",summary:"Creation Failed",detail:(null===(C=null===(b=null==m?void 0:m.response)||void 0===b?void 0:b.data)||void 0===C?void 0:C.message)||"There was an error creating the scope. Please try again."}),m;case 13:return te(!1),[7];case 14:return[2]}})})},hasGlobalRuleSet:Ie,canCreateGlobal:qe}):t.jsxs(t.Fragment,{children:[t.jsx(b.default,{isOpen:V.isOpen&&"DELETE"!==V.type&&"RENAME"!==V.type,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onCreate:function(e){return Ae(null!=e?e:"")},hasGlobalRuleSet:Ie}),t.jsx(E.default,{isOpen:V.isOpen&&"RENAME"===V.type,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onSave:Ae,initialName:V.initialName})]}),t.jsx(p.default,{isOpen:V.isOpen&&"DELETE"===V.type,onCancel:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onConfirm:function(){return Re(V.scopeId,V.initialName,V.isSubscope)},title:"Delete Scope",description:t.jsxs(t.Fragment,{children:["Deleting ",t.jsx("span",e.__assign({className:i.default.highlight},{children:V.initialName||"this scope"}))," will permanently remove all Learnings, Access rules, and Change History inside it. This cannot be undone."]}),confirmText:"Delete",confirmBgColor:"#EF4444",isLoading:ee})]}))})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react/jsx-runtime"),n=require("react"),r=require("lucide-react"),s=require("./store/useLearningTemplateStore.js"),a=require("primereact/toast"),i=require("./styles/LearningTemplateManagement.module.css.js"),o=require("./LearningTemplateLayout.js"),l=require("./components/EmptyLearningState.js"),u=require("./store/useAuthStore.js"),c=require("./apis/scopeApis.js"),d=require("./hooks/useLearningTemplateQueryParams.js"),p=require("./components/ConfirmationModal.js"),g=require("./components/LearningTemplateManagementSkeleton.js"),f=require("./utils/treeUtils.js"),S=require("./store/useEnvStore.js"),m=require("./store/useConfigStore.js"),v=require("./components/ToolTip.js"),h=require("./components/CreateRuleSetLegacyModal.js"),_=require("./store/usePermissionsStore.js"),y=require("./store/useAppSecRolesStore.js"),T=require("./queries/useApprovalQueries.js"),b=require("./RuleContent/AddScopeModal.js"),C=require("react-router-dom"),L=require("./shared/SuccessToastContent.js"),j=require("./shared/ErrorToastContent.js"),E=require("./RuleContent/RenameScopeModal.js"),A=[{id:"learnings",label:"Learnings",icon:r.BookOpen,badgeKey:"learningsCount"},{id:"access",label:"Access",icon:r.Users},{id:"history",label:"Change History",icon:r.History}],R=new Set(A.map(function(e){return e.id}));exports.default=function(r){var w,O=this,I=r.userDetails,q=r.llmStudioUrl,N=r.audacyBackendUrl,P=r.ilLabels,k=r.config,x=r.rbacConfig,D=r.app_integration_id,U=r.backwardCompatibility,M=void 0!==U&&U,B=s.useLearningTemplateStore(function(e){return e.selectedRuleSetId}),G=s.useLearningTemplateStore(function(e){return e.setSelectedRuleSetId}),F=s.useLearningTemplateStore(function(e){return e.error}),Q=s.useLearningTemplateStore(function(e){return e.setError}),Y=s.useLearningTemplateStore(function(e){return e.setStations}),K=s.useLearningTemplateStore(function(e){return e.scopeTreeData}),H=s.useLearningTemplateStore(function(e){return e.setScopeTreeData}),z=n.useState({isOpen:!1,type:"GLOBAL"}),V=z[0],W=z[1],J=n.useState(!1),X=J[0],Z=J[1],$=n.useState(!1),ee=$[0],te=$[1],ne=n.useState("learnings"),re=ne[0],se=ne[1],ae=n.useState(null),ie=ae[0],oe=ae[1],le=n.useState(null),ue=le[0],ce=le[1],de=n.useRef(null),pe=n.useRef(null),ge=n.useRef(null),fe=u.default();fe.user;var Se=fe.setUser,me=m.useConfigStore(),ve=me.setConfig,he=me.setIlLabels,_e=e.__spreadArray([{type:"GLOBAL",label:"Global",addChildLabel:"Add Scope",addChildType:"SCOPE"},e.__assign({type:"SCOPE",label:"Scope"},!M&&{addChildLabel:"Add Subscope",addChildType:"SUBSCOPE"})],M?[]:[{type:"SUBSCOPE",label:"Subscope"}],!0),ye=function(){try{return C.useLocation()}catch(e){return{search:""}}}();n.useEffect(function(){var e=new URLSearchParams(window.location.search),t=e.get(d.QUERY_PARAM_KEYS.RULESET_ID),n=e.get(d.QUERY_PARAM_KEYS.SECTION),r=n&&R.has(n)?n:"learnings";(null==t?void 0:t.length)&&G&&se&&(G(t),se(r))},[null==ye?void 0:ye.search,se,G]);var Te=_.usePermissionsStore(function(e){return e.fetchPermissions}),be=_.usePermissionsStore(function(e){return e.hasPermission}),Ce=y.useAppSecRolesStore(function(e){return e.setRoles}),Le=S.default(function(e){return e.appsecRbacUrl})===x.appsecRbacUrl,je=T.useGetAppSecRolesQuery(x.applicationId,Le).data;n.useEffect(function(){je&&Ce(je.map(function(e){return{_id:e._id,name:e.name}}))},[je,Ce]),n.useEffect(function(){var e;console.log("userDetails",I),Se(I),console.log("llmStudioUrl",q),console.log("audacyBackendUrl",N),S.default.getState().setLlmStudioUrl(q),S.default.getState().setAudacyBackendUrl(N),S.default.getState().setRbacConfig(x),ve(k),he(P),s.useLearningTemplateStore.getState().setAppIntegrationId(null!=D?D:null),s.useLearningTemplateStore.getState().setBackwardCompatibility(M),s.useLearningTemplateStore.getState().setToken(null!==(e=I.accessToken)&&void 0!==e?e:null)},[I,Se,q,N,x,k,ve,P,he,D,M]),n.useEffect(function(){(null==I?void 0:I.accessToken)&&q&&c.fetchTiers()},[D,null==I?void 0:I.accessToken,q]);var Ee=function(t){return void 0===t&&(t=!0),e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l;return e.__generator(this,function(u){switch(u.label){case 0:t&&Z(!0),Q(null),u.label=1;case 1:return u.trys.push([1,4,5,6]),[4,Te(x.applicationId)];case 2:return u.sent(),n=function(t){if(!_.usePermissionsStore.getState().hasPermission("ilotj.scope.view",t.id))return null;var r=t.children?t.children.map(function(e){return n(e)}).filter(function(e){return null!==e}):[];return e.__assign(e.__assign({},t),{children:r})},[4,c.fetchScopes(D,I.accessToken)];case 3:return(r=u.sent())&&r.data&&r.data.data&&(a=r.data.data,Array.isArray(a)&&(a=a.length>0?a[0]:null),a?(i=n(a))?(oe(null),H({data:i}),pe.current?(G(pe.current),se("learnings"),pe.current=null):s.useLearningTemplateStore.getState().selectedRuleSetId||G(i.id)):(oe(null!==(l=a.id)&&void 0!==l?l:null),H(null)):(oe(null),H(null))),[3,6];case 4:return o=u.sent(),console.error("Failed to fetch rule sets or permissions",o),Q("Failed to load data. Please try again later."),[3,6];case 5:return Z(!1),[7];case 6:return[2]}})})};n.useEffect(function(){var e;(null===(e=null==I?void 0:I.accessToken)||void 0===e?void 0:e.length)&&Le?Ee(!0):console.warn("Error: Trying to fetch rules without access token",I)},[null==I?void 0:I.accessToken,Q,Y,x.applicationId,Le]);var Ae=function(n){return e.__awaiter(O,void 0,void 0,function(){var r,s,a,o;return e.__generator(this,function(l){switch(l.label){case 0:te(!0),l.label=1;case 1:return l.trys.push([1,4,5,6]),V.scopeId?[4,c.renameScope({scope_id:V.scopeId,scope_name:n})]:[2];case 2:return l.sent(),[4,Ee(!0)];case 3:return l.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),[3,6];case 4:throw r=l.sent(),console.error("An error occurred during scope rename.",r),null===(s=ge.current)||void 0===s||s.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:(null===(o=null===(a=null==r?void 0:r.response)||void 0===a?void 0:a.data)||void 0===o?void 0:o.message)||"There was an error renaming the scope. Please try again."})}),r;case 5:return te(!1),[7];case 6:return[2]}})})},Re=function(t,n,r){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l,u,d;return e.__generator(this,function(p){switch(p.label){case 0:te(!0),p.label=1;case 1:return p.trys.push([1,4,5,6]),[4,c.deleteRuleSet(t,I.accessToken)];case 2:return p.sent(),s.useLearningTemplateStore.getState().selectedRuleSetId===t&&(n=s.useLearningTemplateStore.getState().scopeTreeData,(r=f.findNodePathById((null==n?void 0:n.data)||null,t))&&r.length>1&&(a=r[r.length-2],G(a),se("learnings"))),[4,Ee(!0)];case 3:return p.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),null===(o=ge.current)||void 0===o||o.show({severity:"success",summary:"Deleted Successfully",detail:"The scope was permanently removed."}),[3,6];case 4:return i=p.sent(),console.error("An error occurred during scope deletion.",i),null===(l=ge.current)||void 0===l||l.show({severity:"error",summary:"Delete Failed",detail:(null===(d=null===(u=null==i?void 0:i.response)||void 0===u?void 0:u.data)||void 0===d?void 0:d.message)||"There was an error deleting the scope. Please try again."}),[3,6];case 5:return te(!1),[7];case 6:return[2]}})})},we=K,Oe=ue?{data:{id:ue.stationId,name:ue.stationName,type:"STATION",metrics:{learningsCount:ue.learningsCount,stationsCount:0},children:[]}}:we,Ie=!!(null==Oe?void 0:Oe.data);null===(w=null==Oe?void 0:Oe.data)||void 0===w||w.type;var qe=_.usePermissionsStore(function(e){return e.hasGlobalPermission})("ilotj.scope.global.create",x.applicationResourceId||""),Ne=(ue?A.filter(function(e){return"stations"!==e.id}):A).filter(function(e){return!(!M&&"access"===e.id)});return t.jsx(v.TooltipProvider,{children:t.jsxs("div",e.__assign({className:i.default.learningManagementContainer},{children:[t.jsx("div",e.__assign({className:i.default.mainWrapper},{children:X?t.jsx(g.default,{}):F?t.jsxs("div",e.__assign({className:i.default.errorContainer},{children:[t.jsx("div",e.__assign({className:i.default.errorTitle},{children:"Error Loading Data"})),t.jsx("p",e.__assign({className:i.default.errorDesc},{children:F})),t.jsx("button",e.__assign({onClick:function(){return Ee(!0)},className:i.default.tryAgainBtn},{children:"Try Again"}))]})):Ie?t.jsx(o.default,{onOpenCreateModal:function(){return W({isOpen:!0,type:"GLOBAL"})},onAddChild:function(e,t,n){return W({isOpen:!0,type:t,parentId:e,parentName:n})},onRenameChild:function(e,t){return W({isOpen:!0,type:"RENAME",scopeId:e,initialName:t})},onDeleteChild:function(t,n,r){return e.__awaiter(O,void 0,void 0,function(){var a,i,o;return e.__generator(this,function(e){switch(e.label){case 0:return a=s.useLearningTemplateStore.getState().scopeTreeData,i=f.findNodePathById((null==a?void 0:a.data)||null,t),o=!!i&&3===i.length,0!==r?[3,2]:[4,Re(t)];case 1:return e.sent(),[3,3];case 2:W({isOpen:!0,type:"DELETE",scopeId:t,initialName:n,isSubscope:o}),e.label=3;case 3:return[2]}})})},canDeleteScope:function(e){return be("ilotj.scope.delete",e)},canEditScope:function(e){return be("ilotj.scope.edit",e)},canCreateScope:function(e){return be("ilotj.scope.create",e)},onSectionSelect:function(e,t){var n;console.log("Section Selected:",{scopeId:e,sectionId:t}),d.setQueryParams(((n={})[d.QUERY_PARAM_KEYS.SECTION]="learnings"===t?null:t,n)),se(t),G(e)},activeSectionId:re,scopeTreeData:Oe,sectionsConfig:Ne,onViewStation:function(e){de.current=B,ce(e),se("learnings"),G(e.stationId)},onRefreshRuleSets:function(e,t){void 0===e&&(e=!0),t&&(pe.current=t),Ee(e)},nodeTypesConfig:_e,app_integration_id:D,token:I.accessToken}):t.jsx(l.default,{onCreate:function(){return W({isOpen:!0,type:"GLOBAL"})},title:"No Global Scope has been added!",desc:"Start by creating a Global scope to define base learnings that apply across all stations.",button:"Create Global Scope",canCreateRule:qe,noAccessTitle:"Access Restricted",noAccessDesc:"You do not have access to create a Global scope for this application.",onRequestAccess:function(){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,o,l,u,d,p,g;return e.__generator(this,function(e){switch(e.label){case 0:if(!(n=(null===(o=null===(a=s.useLearningTemplateStore.getState().scopeTreeData)||void 0===a?void 0:a.data)||void 0===o?void 0:o.id)||ie))return null===(l=ge.current)||void 0===l||l.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:"Unable to identify the global scope for this access request."})}),[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,c.requestAccess(n)];case 2:return e.sent(),null===(u=ge.current)||void 0===u||u.show({severity:"success",sticky:!1,life:3e3,className:i.default.successToast,content:t.jsx(L.default,{message:"Access request submitted successfully!"})}),[3,4];case 3:return r=e.sent(),null===(d=ge.current)||void 0===d||d.show({severity:"error",sticky:!1,className:i.default.errorToast,content:t.jsx(j.default,{message:(null===(g=null===(p=null==r?void 0:r.response)||void 0===p?void 0:p.data)||void 0===g?void 0:g.detail)||"Failed to request access. Please try again."})}),[3,4];case 4:return[2]}})})}})})),t.jsx(a.Toast,{ref:ge,pt:{root:{style:{zIndex:9999}}}}),M&&V.isOpen&&"DELETE"!==V.type&&"RENAME"!==V.type?t.jsx(h.default,{isOpen:!0,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onSubmit:function(t){return e.__awaiter(O,void 0,void 0,function(){var n,r,a,i,o,l,u,d,p,g,f,S,m,v,h,_,y,T,b,C;return e.__generator(this,function(L){switch(L.label){case 0:te(!0),n=s.useLearningTemplateStore.getState().backwardCompatibility,L.label=1;case 1:return L.trys.push([1,12,13,14]),r=void 0,n&&"object"==typeof t?r=t:(a=t,i="SCOPE"===V.type&&V.parentId,o=i?"genreRuleSet":V.type,r={topic:o,scope_reference_id:null,scopeDescription:"demo",parentScopeId:V.parentId||null,scopeName:a,scopeReferenceMetadata:{},applicationMappingId:D}),[4,c.createRuleSet(r,I.accessToken)];case 2:if(l=L.sent(),!(u=null===(v=null==l?void 0:l.data)||void 0===v?void 0:v.scopeId))return[3,10];if(pe.current=u,d=n&&(null===(h=r.topic)||void 0===h?void 0:h.toLowerCase().includes("genre")),p=!n&&"GLOBAL"!==V.type&&V.parentId,!d&&!p)return[3,10];if(!(g=n?null===(y=null===(_=s.useLearningTemplateStore.getState().scopeTreeData)||void 0===_?void 0:_.data)||void 0===y?void 0:y.id:V.parentId))return[3,10];if(!M)return[3,7];L.label=3;case 3:return L.trys.push([3,5,,6]),[4,c.inheritScopeBackwardCompatible({source_scope_id:g,target_scope_id:u})];case 4:return L.sent(),[3,6];case 5:return f=L.sent(),console.error("Failed to inherit rules for the new scope:",f),[3,6];case 6:return[3,10];case 7:return L.trys.push([7,9,,10]),[4,c.inheritScope({source_scope_id:g,target_scope_id:u,application_mapping_id:D||"",is_copy_parent_variant_id:!1})];case 8:return L.sent(),[3,10];case 9:return S=L.sent(),console.error("Failed to inherit rules for the new scope:",S),[3,10];case 10:return[4,Ee(!0)];case 11:return L.sent(),W(function(t){return e.__assign(e.__assign({},t),{isOpen:!1})}),[3,14];case 12:throw m=L.sent(),console.error("An error occurred during scope creation.",m),null===(T=ge.current)||void 0===T||T.show({severity:"error",summary:"Creation Failed",detail:(null===(C=null===(b=null==m?void 0:m.response)||void 0===b?void 0:b.data)||void 0===C?void 0:C.message)||"There was an error creating the scope. Please try again."}),m;case 13:return te(!1),[7];case 14:return[2]}})})},hasGlobalRuleSet:Ie,canCreateGlobal:qe}):t.jsxs(t.Fragment,{children:[t.jsx(b.default,{isOpen:V.isOpen&&"DELETE"!==V.type&&"RENAME"!==V.type,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onCreate:function(e){return Ae(null!=e?e:"")},hasGlobalRuleSet:Ie}),t.jsx(E.default,{isOpen:V.isOpen&&"RENAME"===V.type,onClose:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onSave:Ae,initialName:V.initialName})]}),t.jsx(p.default,{isOpen:V.isOpen&&"DELETE"===V.type,onCancel:function(){return W(e.__assign(e.__assign({},V),{isOpen:!1}))},onConfirm:function(){return Re(V.scopeId,V.initialName,V.isSubscope)},title:"Delete Scope",description:t.jsxs(t.Fragment,{children:["Deleting ",t.jsx("span",e.__assign({className:i.default.highlight},{children:V.initialName||"this scope"}))," will permanently remove all Learnings, Access rules, and Change History inside it. This cannot be undone."]}),confirmText:"Delete",confirmBgColor:"#EF4444",isLoading:ee})]}))})};
2
2
  //# sourceMappingURL=LearningManagement.js.map
@@ -1,2 +1,2 @@
1
- import{__spreadArray as e,__assign as t,__awaiter as n,__generator as r}from"tslib";import{jsx as o,jsxs as s,Fragment as i}from"react/jsx-runtime";import{useState as a,useRef as l,useEffect as c}from"react";import{BookOpen as u,Users as d}from"lucide-react";import{useLearningTemplateStore as p}from"./store/useLearningTemplateStore.js";import{Toast as m}from"primereact/toast";import f from"./styles/LearningTemplateManagement.module.css.js";import v from"./LearningTemplateLayout.js";import h from"./components/EmptyLearningState.js";import g from"./store/useAuthStore.js";import{fetchTiers as y,fetchScopes as S,inheritScope as b,inheritScopeBackwardCompatible as C,createRuleSet as T,renameScope as E,deleteRuleSet as O,requestAccess as w}from"./apis/scopeApis.js";import{QUERY_PARAM_KEYS as A,setQueryParams as I}from"./hooks/useLearningTemplateQueryParams.js";import L from"./components/ConfirmationModal.js";import R from"./components/LearningTemplateManagementSkeleton.js";import{findNodePathById as j}from"./utils/treeUtils.js";import N from"./store/useEnvStore.js";import{useConfigStore as k}from"./store/useConfigStore.js";import{TooltipProvider as D}from"./components/ToolTip.js";import _ from"./components/CreateRuleSetLegacyModal.js";import{usePermissionsStore as P}from"./store/usePermissionsStore.js";import{useAppSecRolesStore as U}from"./store/useAppSecRolesStore.js";import{useGetAppSecRolesQuery as G}from"./queries/useApprovalQueries.js";import M from"./RuleContent/AddScopeModal.js";import{useLocation as B}from"react-router-dom";import F from"./shared/SuccessToastContent.js";import q from"./shared/ErrorToastContent.js";import x from"./RuleContent/RenameScopeModal.js";var Q=[{id:"learnings",label:"Learnings",icon:u,badgeKey:"learningsCount"},{id:"access",label:"Access",icon:d}],z=new Set(Q.map(function(e){return e.id}));function H(u){var d,H=this,K=u.userDetails,V=u.llmStudioUrl,W=u.audacyBackendUrl,Y=u.ilLabels,J=u.config,X=u.rbacConfig,Z=u.app_integration_id,$=u.backwardCompatibility,ee=void 0!==$&&$,te=p(function(e){return e.selectedRuleSetId}),ne=p(function(e){return e.setSelectedRuleSetId}),re=p(function(e){return e.error}),oe=p(function(e){return e.setError}),se=p(function(e){return e.setStations}),ie=p(function(e){return e.scopeTreeData}),ae=p(function(e){return e.setScopeTreeData}),le=a({isOpen:!1,type:"GLOBAL"}),ce=le[0],ue=le[1],de=a(!1),pe=de[0],me=de[1],fe=a(!1),ve=fe[0],he=fe[1],ge=a("learnings"),ye=ge[0],Se=ge[1],be=a(null),Ce=be[0],Te=be[1],Ee=a(null),Oe=Ee[0],we=Ee[1],Ae=l(null),Ie=l(null),Le=l(null),Re=g();Re.user;var je=Re.setUser,Ne=k(),ke=Ne.setConfig,De=Ne.setIlLabels,_e=e([{type:"GLOBAL",label:"Global",addChildLabel:"Add Scope",addChildType:"SCOPE"},t({type:"SCOPE",label:"Scope"},!ee&&{addChildLabel:"Add Subscope",addChildType:"SUBSCOPE"})],ee?[]:[{type:"SUBSCOPE",label:"Subscope"}],!0),Pe=function(){try{return B()}catch(e){return{search:""}}}();c(function(){var e=new URLSearchParams(window.location.search),t=e.get(A.RULESET_ID),n=e.get(A.SECTION),r=n&&z.has(n)?n:"learnings";(null==t?void 0:t.length)&&ne&&Se&&(ne(t),Se(r))},[null==Pe?void 0:Pe.search,Se,ne]);var Ue=P(function(e){return e.fetchPermissions}),Ge=P(function(e){return e.hasPermission}),Me=U(function(e){return e.setRoles}),Be=N(function(e){return e.appsecRbacUrl})===X.appsecRbacUrl,Fe=G(X.applicationId,Be).data;c(function(){Fe&&Me(Fe.map(function(e){return{_id:e._id,name:e.name}}))},[Fe,Me]),c(function(){var e;console.log("userDetails",K),je(K),console.log("llmStudioUrl",V),console.log("audacyBackendUrl",W),N.getState().setLlmStudioUrl(V),N.getState().setAudacyBackendUrl(W),N.getState().setRbacConfig(X),ke(J),De(Y),p.getState().setAppIntegrationId(null!=Z?Z:null),p.getState().setBackwardCompatibility(ee),p.getState().setToken(null!==(e=K.accessToken)&&void 0!==e?e:null)},[K,je,V,W,X,J,ke,Y,De,Z,ee]),c(function(){(null==K?void 0:K.accessToken)&&V&&y()},[Z,null==K?void 0:K.accessToken,V]);var qe=function(e){return void 0===e&&(e=!0),n(H,void 0,void 0,function(){var n,o,s,i,a,l;return r(this,function(r){switch(r.label){case 0:e&&me(!0),oe(null),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,Ue(X.applicationId)];case 2:return r.sent(),n=function(e){if(!P.getState().hasPermission("ilotj.scope.view",e.id))return null;var r=e.children?e.children.map(function(e){return n(e)}).filter(function(e){return null!==e}):[];return t(t({},e),{children:r})},[4,S(Z,K.accessToken)];case 3:return(o=r.sent())&&o.data&&o.data.data&&(s=o.data.data,Array.isArray(s)&&(s=s.length>0?s[0]:null),s?(i=n(s))?(Te(null),ae({data:i}),Ie.current?(ne(Ie.current),Se("learnings"),Ie.current=null):p.getState().selectedRuleSetId||ne(i.id)):(Te(null!==(l=s.id)&&void 0!==l?l:null),ae(null)):(Te(null),ae(null))),[3,6];case 4:return a=r.sent(),console.error("Failed to fetch rule sets or permissions",a),oe("Failed to load data. Please try again later."),[3,6];case 5:return me(!1),[7];case 6:return[2]}})})};c(function(){var e;(null===(e=null==K?void 0:K.accessToken)||void 0===e?void 0:e.length)&&Be?qe(!0):console.warn("Error: Trying to fetch rules without access token",K)},[null==K?void 0:K.accessToken,oe,se,X.applicationId,Be]);var xe=function(e){return n(H,void 0,void 0,function(){var n,s,i,a;return r(this,function(r){switch(r.label){case 0:he(!0),r.label=1;case 1:return r.trys.push([1,4,5,6]),ce.scopeId?[4,E({scope_id:ce.scopeId,scope_name:e})]:[2];case 2:return r.sent(),[4,qe(!0)];case 3:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),[3,6];case 4:throw n=r.sent(),console.error("An error occurred during scope rename.",n),null===(s=Le.current)||void 0===s||s.show({severity:"error",sticky:!1,className:f.errorToast,content:o(q,{message:(null===(a=null===(i=null==n?void 0:n.response)||void 0===i?void 0:i.data)||void 0===a?void 0:a.message)||"There was an error renaming the scope. Please try again."})}),n;case 5:return he(!1),[7];case 6:return[2]}})})},Qe=function(e,o,s){return n(H,void 0,void 0,function(){var n,o,s,i,a,l,c,u;return r(this,function(r){switch(r.label){case 0:he(!0),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,O(e,K.accessToken)];case 2:return r.sent(),p.getState().selectedRuleSetId===e&&(n=p.getState().scopeTreeData,(o=j((null==n?void 0:n.data)||null,e))&&o.length>1&&(s=o[o.length-2],ne(s),Se("learnings"))),[4,qe(!0)];case 3:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),null===(a=Le.current)||void 0===a||a.show({severity:"success",summary:"Deleted Successfully",detail:"The scope was permanently removed."}),[3,6];case 4:return i=r.sent(),console.error("An error occurred during scope deletion.",i),null===(l=Le.current)||void 0===l||l.show({severity:"error",summary:"Delete Failed",detail:(null===(u=null===(c=null==i?void 0:i.response)||void 0===c?void 0:c.data)||void 0===u?void 0:u.message)||"There was an error deleting the scope. Please try again."}),[3,6];case 5:return he(!1),[7];case 6:return[2]}})})},ze=ie,He=Oe?{data:{id:Oe.stationId,name:Oe.stationName,type:"STATION",metrics:{learningsCount:Oe.learningsCount,stationsCount:0},children:[]}}:ze,Ke=!!(null==He?void 0:He.data);null===(d=null==He?void 0:He.data)||void 0===d||d.type;var Ve=P(function(e){return e.hasGlobalPermission})("ilotj.scope.global.create",X.applicationResourceId||""),We=(Oe?Q.filter(function(e){return"stations"!==e.id}):Q).filter(function(e){return!(!ee&&"access"===e.id)});return o(D,{children:s("div",t({className:f.learningManagementContainer},{children:[o("div",t({className:f.mainWrapper},{children:pe?o(R,{}):re?s("div",t({className:f.errorContainer},{children:[o("div",t({className:f.errorTitle},{children:"Error Loading Data"})),o("p",t({className:f.errorDesc},{children:re})),o("button",t({onClick:function(){return qe(!0)},className:f.tryAgainBtn},{children:"Try Again"}))]})):Ke?o(v,{onOpenCreateModal:function(){return ue({isOpen:!0,type:"GLOBAL"})},onAddChild:function(e,t,n){return ue({isOpen:!0,type:t,parentId:e,parentName:n})},onRenameChild:function(e,t){return ue({isOpen:!0,type:"RENAME",scopeId:e,initialName:t})},onDeleteChild:function(e,t,o){return n(H,void 0,void 0,function(){var n,s,i;return r(this,function(r){switch(r.label){case 0:return n=p.getState().scopeTreeData,s=j((null==n?void 0:n.data)||null,e),i=!!s&&3===s.length,0!==o?[3,2]:[4,Qe(e)];case 1:return r.sent(),[3,3];case 2:ue({isOpen:!0,type:"DELETE",scopeId:e,initialName:t,isSubscope:i}),r.label=3;case 3:return[2]}})})},canDeleteScope:function(e){return Ge("ilotj.scope.delete",e)},canEditScope:function(e){return Ge("ilotj.scope.edit",e)},canCreateScope:function(e){return Ge("ilotj.scope.create",e)},onSectionSelect:function(e,t){var n;console.log("Section Selected:",{scopeId:e,sectionId:t}),I(((n={})[A.SECTION]="learnings"===t?null:t,n)),Se(t),ne(e)},activeSectionId:ye,scopeTreeData:He,sectionsConfig:We,onViewStation:function(e){Ae.current=te,we(e),Se("learnings"),ne(e.stationId)},onRefreshRuleSets:function(e,t){void 0===e&&(e=!0),t&&(Ie.current=t),qe(e)},nodeTypesConfig:_e,app_integration_id:Z,token:K.accessToken}):o(h,{onCreate:function(){return ue({isOpen:!0,type:"GLOBAL"})},title:"No Global Scope has been added!",desc:"Start by creating a Global scope to define base learnings that apply across all stations.",button:"Create Global Scope",canCreateRule:Ve,noAccessTitle:"Access Restricted",noAccessDesc:"You do not have access to create a Global scope for this application.",onRequestAccess:function(){return n(H,void 0,void 0,function(){var e,t,n,s,i,a,l,c,u;return r(this,function(r){switch(r.label){case 0:if(!(e=(null===(s=null===(n=p.getState().scopeTreeData)||void 0===n?void 0:n.data)||void 0===s?void 0:s.id)||Ce))return null===(i=Le.current)||void 0===i||i.show({severity:"error",sticky:!1,className:f.errorToast,content:o(q,{message:"Unable to identify the global scope for this access request."})}),[2];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,w(e)];case 2:return r.sent(),null===(a=Le.current)||void 0===a||a.show({severity:"success",sticky:!1,life:3e3,className:f.successToast,content:o(F,{message:"Access request submitted successfully!"})}),[3,4];case 3:return t=r.sent(),null===(l=Le.current)||void 0===l||l.show({severity:"error",sticky:!1,className:f.errorToast,content:o(q,{message:(null===(u=null===(c=null==t?void 0:t.response)||void 0===c?void 0:c.data)||void 0===u?void 0:u.detail)||"Failed to request access. Please try again."})}),[3,4];case 4:return[2]}})})}})})),o(m,{ref:Le,pt:{root:{style:{zIndex:9999}}}}),ee&&ce.isOpen&&"DELETE"!==ce.type&&"RENAME"!==ce.type?o(_,{isOpen:!0,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onSubmit:function(e){return n(H,void 0,void 0,function(){var n,o,s,i,a,l,c,u,d,m,f,v,h,g,y,S,E,O,w,A;return r(this,function(r){switch(r.label){case 0:he(!0),n=p.getState().backwardCompatibility,r.label=1;case 1:return r.trys.push([1,12,13,14]),o=void 0,n&&"object"==typeof e?o=e:(s=e,i="SCOPE"===ce.type&&ce.parentId,a=i?"genreRuleSet":ce.type,o={topic:a,scope_reference_id:null,scopeDescription:"demo",parentScopeId:ce.parentId||null,scopeName:s,scopeReferenceMetadata:{},applicationMappingId:Z}),[4,T(o,K.accessToken)];case 2:if(l=r.sent(),!(c=null===(g=null==l?void 0:l.data)||void 0===g?void 0:g.scopeId))return[3,10];if(Ie.current=c,u=n&&(null===(y=o.topic)||void 0===y?void 0:y.toLowerCase().includes("genre")),d=!n&&"GLOBAL"!==ce.type&&ce.parentId,!u&&!d)return[3,10];if(!(m=n?null===(E=null===(S=p.getState().scopeTreeData)||void 0===S?void 0:S.data)||void 0===E?void 0:E.id:ce.parentId))return[3,10];if(!ee)return[3,7];r.label=3;case 3:return r.trys.push([3,5,,6]),[4,C({source_scope_id:m,target_scope_id:c})];case 4:return r.sent(),[3,6];case 5:return f=r.sent(),console.error("Failed to inherit rules for the new scope:",f),[3,6];case 6:return[3,10];case 7:return r.trys.push([7,9,,10]),[4,b({source_scope_id:m,target_scope_id:c,application_mapping_id:Z||"",is_copy_parent_variant_id:!1})];case 8:return r.sent(),[3,10];case 9:return v=r.sent(),console.error("Failed to inherit rules for the new scope:",v),[3,10];case 10:return[4,qe(!0)];case 11:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),[3,14];case 12:throw h=r.sent(),console.error("An error occurred during scope creation.",h),null===(O=Le.current)||void 0===O||O.show({severity:"error",summary:"Creation Failed",detail:(null===(A=null===(w=null==h?void 0:h.response)||void 0===w?void 0:w.data)||void 0===A?void 0:A.message)||"There was an error creating the scope. Please try again."}),h;case 13:return he(!1),[7];case 14:return[2]}})})},hasGlobalRuleSet:Ke,canCreateGlobal:Ve}):s(i,{children:[o(M,{isOpen:ce.isOpen&&"DELETE"!==ce.type&&"RENAME"!==ce.type,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onCreate:function(e){return xe(null!=e?e:"")},hasGlobalRuleSet:Ke}),o(x,{isOpen:ce.isOpen&&"RENAME"===ce.type,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onSave:xe,initialName:ce.initialName})]}),o(L,{isOpen:ce.isOpen&&"DELETE"===ce.type,onCancel:function(){return ue(t(t({},ce),{isOpen:!1}))},onConfirm:function(){return Qe(ce.scopeId,ce.initialName,ce.isSubscope)},title:"Delete Scope",description:s(i,{children:["Deleting ",o("span",t({className:f.highlight},{children:ce.initialName||"this scope"}))," will permanently remove all Learnings, Access rules, and Change History inside it. This cannot be undone."]}),confirmText:"Delete",confirmBgColor:"#EF4444",isLoading:ve})]}))})}export{H as default};
1
+ import{__spreadArray as e,__assign as t,__awaiter as n,__generator as r}from"tslib";import{jsx as o,jsxs as s,Fragment as i}from"react/jsx-runtime";import{useState as a,useRef as l,useEffect as c}from"react";import{BookOpen as u,Users as d,History as p}from"lucide-react";import{useLearningTemplateStore as m}from"./store/useLearningTemplateStore.js";import{Toast as f}from"primereact/toast";import v from"./styles/LearningTemplateManagement.module.css.js";import h from"./LearningTemplateLayout.js";import g from"./components/EmptyLearningState.js";import y from"./store/useAuthStore.js";import{fetchTiers as S,fetchScopes as b,inheritScope as C,inheritScopeBackwardCompatible as T,createRuleSet as E,renameScope as O,deleteRuleSet as w,requestAccess as A}from"./apis/scopeApis.js";import{QUERY_PARAM_KEYS as I,setQueryParams as L}from"./hooks/useLearningTemplateQueryParams.js";import R from"./components/ConfirmationModal.js";import j from"./components/LearningTemplateManagementSkeleton.js";import{findNodePathById as N}from"./utils/treeUtils.js";import k from"./store/useEnvStore.js";import{useConfigStore as D}from"./store/useConfigStore.js";import{TooltipProvider as _}from"./components/ToolTip.js";import P from"./components/CreateRuleSetLegacyModal.js";import{usePermissionsStore as U}from"./store/usePermissionsStore.js";import{useAppSecRolesStore as G}from"./store/useAppSecRolesStore.js";import{useGetAppSecRolesQuery as M}from"./queries/useApprovalQueries.js";import B from"./RuleContent/AddScopeModal.js";import{useLocation as F}from"react-router-dom";import q from"./shared/SuccessToastContent.js";import x from"./shared/ErrorToastContent.js";import H from"./RuleContent/RenameScopeModal.js";var Q=[{id:"learnings",label:"Learnings",icon:u,badgeKey:"learningsCount"},{id:"access",label:"Access",icon:d},{id:"history",label:"Change History",icon:p}],z=new Set(Q.map(function(e){return e.id}));function K(u){var d,p=this,K=u.userDetails,V=u.llmStudioUrl,W=u.audacyBackendUrl,Y=u.ilLabels,J=u.config,X=u.rbacConfig,Z=u.app_integration_id,$=u.backwardCompatibility,ee=void 0!==$&&$,te=m(function(e){return e.selectedRuleSetId}),ne=m(function(e){return e.setSelectedRuleSetId}),re=m(function(e){return e.error}),oe=m(function(e){return e.setError}),se=m(function(e){return e.setStations}),ie=m(function(e){return e.scopeTreeData}),ae=m(function(e){return e.setScopeTreeData}),le=a({isOpen:!1,type:"GLOBAL"}),ce=le[0],ue=le[1],de=a(!1),pe=de[0],me=de[1],fe=a(!1),ve=fe[0],he=fe[1],ge=a("learnings"),ye=ge[0],Se=ge[1],be=a(null),Ce=be[0],Te=be[1],Ee=a(null),Oe=Ee[0],we=Ee[1],Ae=l(null),Ie=l(null),Le=l(null),Re=y();Re.user;var je=Re.setUser,Ne=D(),ke=Ne.setConfig,De=Ne.setIlLabels,_e=e([{type:"GLOBAL",label:"Global",addChildLabel:"Add Scope",addChildType:"SCOPE"},t({type:"SCOPE",label:"Scope"},!ee&&{addChildLabel:"Add Subscope",addChildType:"SUBSCOPE"})],ee?[]:[{type:"SUBSCOPE",label:"Subscope"}],!0),Pe=function(){try{return F()}catch(e){return{search:""}}}();c(function(){var e=new URLSearchParams(window.location.search),t=e.get(I.RULESET_ID),n=e.get(I.SECTION),r=n&&z.has(n)?n:"learnings";(null==t?void 0:t.length)&&ne&&Se&&(ne(t),Se(r))},[null==Pe?void 0:Pe.search,Se,ne]);var Ue=U(function(e){return e.fetchPermissions}),Ge=U(function(e){return e.hasPermission}),Me=G(function(e){return e.setRoles}),Be=k(function(e){return e.appsecRbacUrl})===X.appsecRbacUrl,Fe=M(X.applicationId,Be).data;c(function(){Fe&&Me(Fe.map(function(e){return{_id:e._id,name:e.name}}))},[Fe,Me]),c(function(){var e;console.log("userDetails",K),je(K),console.log("llmStudioUrl",V),console.log("audacyBackendUrl",W),k.getState().setLlmStudioUrl(V),k.getState().setAudacyBackendUrl(W),k.getState().setRbacConfig(X),ke(J),De(Y),m.getState().setAppIntegrationId(null!=Z?Z:null),m.getState().setBackwardCompatibility(ee),m.getState().setToken(null!==(e=K.accessToken)&&void 0!==e?e:null)},[K,je,V,W,X,J,ke,Y,De,Z,ee]),c(function(){(null==K?void 0:K.accessToken)&&V&&S()},[Z,null==K?void 0:K.accessToken,V]);var qe=function(e){return void 0===e&&(e=!0),n(p,void 0,void 0,function(){var n,o,s,i,a,l;return r(this,function(r){switch(r.label){case 0:e&&me(!0),oe(null),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,Ue(X.applicationId)];case 2:return r.sent(),n=function(e){if(!U.getState().hasPermission("ilotj.scope.view",e.id))return null;var r=e.children?e.children.map(function(e){return n(e)}).filter(function(e){return null!==e}):[];return t(t({},e),{children:r})},[4,b(Z,K.accessToken)];case 3:return(o=r.sent())&&o.data&&o.data.data&&(s=o.data.data,Array.isArray(s)&&(s=s.length>0?s[0]:null),s?(i=n(s))?(Te(null),ae({data:i}),Ie.current?(ne(Ie.current),Se("learnings"),Ie.current=null):m.getState().selectedRuleSetId||ne(i.id)):(Te(null!==(l=s.id)&&void 0!==l?l:null),ae(null)):(Te(null),ae(null))),[3,6];case 4:return a=r.sent(),console.error("Failed to fetch rule sets or permissions",a),oe("Failed to load data. Please try again later."),[3,6];case 5:return me(!1),[7];case 6:return[2]}})})};c(function(){var e;(null===(e=null==K?void 0:K.accessToken)||void 0===e?void 0:e.length)&&Be?qe(!0):console.warn("Error: Trying to fetch rules without access token",K)},[null==K?void 0:K.accessToken,oe,se,X.applicationId,Be]);var xe=function(e){return n(p,void 0,void 0,function(){var n,s,i,a;return r(this,function(r){switch(r.label){case 0:he(!0),r.label=1;case 1:return r.trys.push([1,4,5,6]),ce.scopeId?[4,O({scope_id:ce.scopeId,scope_name:e})]:[2];case 2:return r.sent(),[4,qe(!0)];case 3:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),[3,6];case 4:throw n=r.sent(),console.error("An error occurred during scope rename.",n),null===(s=Le.current)||void 0===s||s.show({severity:"error",sticky:!1,className:v.errorToast,content:o(x,{message:(null===(a=null===(i=null==n?void 0:n.response)||void 0===i?void 0:i.data)||void 0===a?void 0:a.message)||"There was an error renaming the scope. Please try again."})}),n;case 5:return he(!1),[7];case 6:return[2]}})})},He=function(e,o,s){return n(p,void 0,void 0,function(){var n,o,s,i,a,l,c,u;return r(this,function(r){switch(r.label){case 0:he(!0),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,w(e,K.accessToken)];case 2:return r.sent(),m.getState().selectedRuleSetId===e&&(n=m.getState().scopeTreeData,(o=N((null==n?void 0:n.data)||null,e))&&o.length>1&&(s=o[o.length-2],ne(s),Se("learnings"))),[4,qe(!0)];case 3:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),null===(a=Le.current)||void 0===a||a.show({severity:"success",summary:"Deleted Successfully",detail:"The scope was permanently removed."}),[3,6];case 4:return i=r.sent(),console.error("An error occurred during scope deletion.",i),null===(l=Le.current)||void 0===l||l.show({severity:"error",summary:"Delete Failed",detail:(null===(u=null===(c=null==i?void 0:i.response)||void 0===c?void 0:c.data)||void 0===u?void 0:u.message)||"There was an error deleting the scope. Please try again."}),[3,6];case 5:return he(!1),[7];case 6:return[2]}})})},Qe=ie,ze=Oe?{data:{id:Oe.stationId,name:Oe.stationName,type:"STATION",metrics:{learningsCount:Oe.learningsCount,stationsCount:0},children:[]}}:Qe,Ke=!!(null==ze?void 0:ze.data);null===(d=null==ze?void 0:ze.data)||void 0===d||d.type;var Ve=U(function(e){return e.hasGlobalPermission})("ilotj.scope.global.create",X.applicationResourceId||""),We=(Oe?Q.filter(function(e){return"stations"!==e.id}):Q).filter(function(e){return!(!ee&&"access"===e.id)});return o(_,{children:s("div",t({className:v.learningManagementContainer},{children:[o("div",t({className:v.mainWrapper},{children:pe?o(j,{}):re?s("div",t({className:v.errorContainer},{children:[o("div",t({className:v.errorTitle},{children:"Error Loading Data"})),o("p",t({className:v.errorDesc},{children:re})),o("button",t({onClick:function(){return qe(!0)},className:v.tryAgainBtn},{children:"Try Again"}))]})):Ke?o(h,{onOpenCreateModal:function(){return ue({isOpen:!0,type:"GLOBAL"})},onAddChild:function(e,t,n){return ue({isOpen:!0,type:t,parentId:e,parentName:n})},onRenameChild:function(e,t){return ue({isOpen:!0,type:"RENAME",scopeId:e,initialName:t})},onDeleteChild:function(e,t,o){return n(p,void 0,void 0,function(){var n,s,i;return r(this,function(r){switch(r.label){case 0:return n=m.getState().scopeTreeData,s=N((null==n?void 0:n.data)||null,e),i=!!s&&3===s.length,0!==o?[3,2]:[4,He(e)];case 1:return r.sent(),[3,3];case 2:ue({isOpen:!0,type:"DELETE",scopeId:e,initialName:t,isSubscope:i}),r.label=3;case 3:return[2]}})})},canDeleteScope:function(e){return Ge("ilotj.scope.delete",e)},canEditScope:function(e){return Ge("ilotj.scope.edit",e)},canCreateScope:function(e){return Ge("ilotj.scope.create",e)},onSectionSelect:function(e,t){var n;console.log("Section Selected:",{scopeId:e,sectionId:t}),L(((n={})[I.SECTION]="learnings"===t?null:t,n)),Se(t),ne(e)},activeSectionId:ye,scopeTreeData:ze,sectionsConfig:We,onViewStation:function(e){Ae.current=te,we(e),Se("learnings"),ne(e.stationId)},onRefreshRuleSets:function(e,t){void 0===e&&(e=!0),t&&(Ie.current=t),qe(e)},nodeTypesConfig:_e,app_integration_id:Z,token:K.accessToken}):o(g,{onCreate:function(){return ue({isOpen:!0,type:"GLOBAL"})},title:"No Global Scope has been added!",desc:"Start by creating a Global scope to define base learnings that apply across all stations.",button:"Create Global Scope",canCreateRule:Ve,noAccessTitle:"Access Restricted",noAccessDesc:"You do not have access to create a Global scope for this application.",onRequestAccess:function(){return n(p,void 0,void 0,function(){var e,t,n,s,i,a,l,c,u;return r(this,function(r){switch(r.label){case 0:if(!(e=(null===(s=null===(n=m.getState().scopeTreeData)||void 0===n?void 0:n.data)||void 0===s?void 0:s.id)||Ce))return null===(i=Le.current)||void 0===i||i.show({severity:"error",sticky:!1,className:v.errorToast,content:o(x,{message:"Unable to identify the global scope for this access request."})}),[2];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,A(e)];case 2:return r.sent(),null===(a=Le.current)||void 0===a||a.show({severity:"success",sticky:!1,life:3e3,className:v.successToast,content:o(q,{message:"Access request submitted successfully!"})}),[3,4];case 3:return t=r.sent(),null===(l=Le.current)||void 0===l||l.show({severity:"error",sticky:!1,className:v.errorToast,content:o(x,{message:(null===(u=null===(c=null==t?void 0:t.response)||void 0===c?void 0:c.data)||void 0===u?void 0:u.detail)||"Failed to request access. Please try again."})}),[3,4];case 4:return[2]}})})}})})),o(f,{ref:Le,pt:{root:{style:{zIndex:9999}}}}),ee&&ce.isOpen&&"DELETE"!==ce.type&&"RENAME"!==ce.type?o(P,{isOpen:!0,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onSubmit:function(e){return n(p,void 0,void 0,function(){var n,o,s,i,a,l,c,u,d,p,f,v,h,g,y,S,b,O,w,A;return r(this,function(r){switch(r.label){case 0:he(!0),n=m.getState().backwardCompatibility,r.label=1;case 1:return r.trys.push([1,12,13,14]),o=void 0,n&&"object"==typeof e?o=e:(s=e,i="SCOPE"===ce.type&&ce.parentId,a=i?"genreRuleSet":ce.type,o={topic:a,scope_reference_id:null,scopeDescription:"demo",parentScopeId:ce.parentId||null,scopeName:s,scopeReferenceMetadata:{},applicationMappingId:Z}),[4,E(o,K.accessToken)];case 2:if(l=r.sent(),!(c=null===(g=null==l?void 0:l.data)||void 0===g?void 0:g.scopeId))return[3,10];if(Ie.current=c,u=n&&(null===(y=o.topic)||void 0===y?void 0:y.toLowerCase().includes("genre")),d=!n&&"GLOBAL"!==ce.type&&ce.parentId,!u&&!d)return[3,10];if(!(p=n?null===(b=null===(S=m.getState().scopeTreeData)||void 0===S?void 0:S.data)||void 0===b?void 0:b.id:ce.parentId))return[3,10];if(!ee)return[3,7];r.label=3;case 3:return r.trys.push([3,5,,6]),[4,T({source_scope_id:p,target_scope_id:c})];case 4:return r.sent(),[3,6];case 5:return f=r.sent(),console.error("Failed to inherit rules for the new scope:",f),[3,6];case 6:return[3,10];case 7:return r.trys.push([7,9,,10]),[4,C({source_scope_id:p,target_scope_id:c,application_mapping_id:Z||"",is_copy_parent_variant_id:!1})];case 8:return r.sent(),[3,10];case 9:return v=r.sent(),console.error("Failed to inherit rules for the new scope:",v),[3,10];case 10:return[4,qe(!0)];case 11:return r.sent(),ue(function(e){return t(t({},e),{isOpen:!1})}),[3,14];case 12:throw h=r.sent(),console.error("An error occurred during scope creation.",h),null===(O=Le.current)||void 0===O||O.show({severity:"error",summary:"Creation Failed",detail:(null===(A=null===(w=null==h?void 0:h.response)||void 0===w?void 0:w.data)||void 0===A?void 0:A.message)||"There was an error creating the scope. Please try again."}),h;case 13:return he(!1),[7];case 14:return[2]}})})},hasGlobalRuleSet:Ke,canCreateGlobal:Ve}):s(i,{children:[o(B,{isOpen:ce.isOpen&&"DELETE"!==ce.type&&"RENAME"!==ce.type,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onCreate:function(e){return xe(null!=e?e:"")},hasGlobalRuleSet:Ke}),o(H,{isOpen:ce.isOpen&&"RENAME"===ce.type,onClose:function(){return ue(t(t({},ce),{isOpen:!1}))},onSave:xe,initialName:ce.initialName})]}),o(R,{isOpen:ce.isOpen&&"DELETE"===ce.type,onCancel:function(){return ue(t(t({},ce),{isOpen:!1}))},onConfirm:function(){return He(ce.scopeId,ce.initialName,ce.isSubscope)},title:"Delete Scope",description:s(i,{children:["Deleting ",o("span",t({className:v.highlight},{children:ce.initialName||"this scope"}))," will permanently remove all Learnings, Access rules, and Change History inside it. This cannot be undone."]}),confirmText:"Delete",confirmBgColor:"#EF4444",isLoading:ve})]}))})}export{K as default};
2
2
  //# sourceMappingURL=LearningManagement.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-llm-studio/instant-learning",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "author": "Devesh Patel",
5
5
  "description": "",
6
6
  "license": "MIT",