"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8932],{"./public/app/features/folders/components/NewDashboardsFolder.tsx":(e,s,r)=>{r.r(s),r.d(s,{NewDashboardsFolder:()=>v,default:()=>g});var a,t,i=r("./node_modules/react/index.js"),n=r("./node_modules/react-redux/es/index.js"),o=r("./packages/grafana-ui/src/index.ts"),d=r("./public/app/core/components/Page/Page.tsx"),l=r("./public/app/features/folders/state/actions.ts"),c=r("./public/app/core/selectors/navModel.ts"),u=r("./public/app/features/manage-dashboards/services/ValidationSrv.ts"),p=r("./node_modules/react/jsx-runtime.js");function f(e,s,r){return s in e?Object.defineProperty(e,s,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[s]=r,e}const m={createNewFolder:l.W7},h=(0,n.connect)((e=>({navModel:(0,c.h)(e.navIndex,"manage-dashboards")})),m),b={folderName:""};class v extends i.PureComponent{constructor(...e){super(...e),f(this,"onSubmit",(e=>{this.props.createNewFolder(e.folderName)})),f(this,"validateFolderName",(e=>u.Z.validateNewFolderName(e).then((()=>!0)).catch((e=>e.message))))}render(){return(0,p.jsx)(d.Z,{navModel:this.props.navModel,children:(0,p.jsxs)(d.Z.Contents,{children:[a||(a=(0,p.jsx)("h3",{children:"New dashboard folder"})),(0,p.jsx)(o.Form,{defaultValues:b,onSubmit:this.onSubmit,children:({register:e,errors:s})=>(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(o.Field,{label:"Folder name",invalid:!!s.folderName,error:s.folderName&&s.folderName.message,children:(0,p.jsx)(o.Input,Object.assign({id:"folder-name-input"},e("folderName",{required:"Folder name is required.",validate:async e=>await this.validateFolderName(e)})))}),t||(t=(0,p.jsx)(o.Button,{type:"submit",children:"Create"}))]})})]})})}}const g=h(v)},"./public/app/features/folders/state/actions.ts":(e,s,r)=>{r.d(s,{Pb:()=>c,OD:()=>u,Go:()=>p,a:()=>f,v7:()=>h,Uk:()=>b,pz:()=>v,W7:()=>g});var a=r("./packages/grafana-data/src/index.ts"),t=r("./packages/grafana-runtime/src/index.ts"),i=r("./public/app/core/services/backend_srv.ts"),n=r("./public/app/core/actions/index.ts"),o=r("./public/app/features/folders/state/navModel.ts"),d=r("./public/app/core/app_events.ts"),l=r("./public/app/features/folders/state/reducers.ts");function c(e){return async s=>{const r=await i.ae.getFolderByUid(e);s((0,l.G3)(r)),s((0,n.RL)((0,o.B)(r)))}}function u(e){return async s=>{const r=await i.ae.put(`/api/folders/${e.uid}`,{title:e.title,version:e.version});d.Z.emit(a.AppEvents.alertSuccess,["Folder saved"]),t.locationService.push(`${r.url}/settings`)}}function p(e){return async s=>{await i.ae.delete(`/api/folders/${e}?forceDeleteRules=true`),t.locationService.push("/dashboards")}}function f(e){return async s=>{const r=await i.ae.get(`/api/folders/${e}/permissions`);s((0,l.R7)(r))}}function m(e){return{userId:e.userId,teamId:e.teamId,role:e.role,permission:e.permission}}function h(e,s){return async(r,a)=>{const t=a().folder,n=[];for(const r of t.permissions){if(r.inherited)continue;const a=m(r);e===r&&(a.permission=s),n.push(a)}await i.ae.post(`/api/folders/${t.uid}/permissions`,{items:n}),await r(f(t.uid))}}function b(e){return async(s,r)=>{const a=r().folder,t=[];for(const s of a.permissions)s.inherited||s===e||t.push(m(s));await i.ae.post(`/api/folders/${a.uid}/permissions`,{items:t}),await s(f(a.uid))}}function v(e){return async(s,r)=>{const a=r().folder,t=[];for(const e of a.permissions)e.inherited||t.push(m(e));t.push({userId:e.userId,teamId:e.teamId,role:e.role,permission:e.permission}),await i.ae.post(`/api/folders/${a.uid}/permissions`,{items:t}),await s(f(a.uid))}}function g(e){return async()=>{const s=await(0,t.getBackendSrv)().post("/api/folders",{title:e});d.Z.emit(a.AppEvents.alertSuccess,["Folder Created","OK"]),t.locationService.push(a.locationUtil.stripBaseFromUrl(s.url))}}},"./public/app/features/folders/state/navModel.ts":(e,s,r)=>{function a(e){const s={icon:"folder",id:"manage-folder",subTitle:"Manage folder dashboards and permissions",url:"",text:e.title,breadcrumbs:[{title:"Dashboards",url:"dashboards"}],children:[{active:!1,icon:"apps",id:`folder-dashboards-${e.uid}`,text:"Dashboards",url:e.url}]};return s.children.push({active:!1,icon:"library-panel",id:`folder-library-panels-${e.uid}`,text:"Panels",url:`${e.url}/library-panels`}),e.canAdmin&&s.children.push({active:!1,icon:"lock",id:`folder-permissions-${e.uid}`,text:"Permissions",url:`${e.url}/permissions`}),e.canSave&&s.children.push({active:!1,icon:"cog",id:`folder-settings-${e.uid}`,text:"Settings",url:`${e.url}/settings`}),s}function t(e){const s=a({id:1,uid:"loading",title:"Loading",url:"url",canSave:!0,canEdit:!0,canAdmin:!0,version:0});return s.children[e].active=!0,{main:s,node:s.children[e]}}r.d(s,{B:()=>a,_:()=>t})}}]);
//# sourceMappingURL=NewDashboardsFolder.8128b05ac04b15cbf98d.js.map