"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9975],{33848:(e,a,t)=>{t.d(a,{H:()=>C});var l=t(76687),s=t(55324),n=t(10967),i=t(70534),r=t(97368),o=t.n(r),d=t(22260),c=t(52010);const u=e=>{let{onChange:a,value:t,width:l,isClearable:s=!1,invalid:n,disabled:r,id:u,optionLabel:p="label",excludedDashboards:m}=e;const h=o()((e=>async function(e,a,t){const l=(await d.ae.search({type:"dash-db",query:e,limit:100})).map((e=>{let{id:t,uid:l="",title:s,folderTitle:n}=e;const i={id:t,uid:l,[a]:`${null!=n?n:"General"}/${s}`};return{value:i,[a]:i[a]}}));if(t)return l.filter((e=>{let{value:a}=e;return!t.includes(a.uid)}));return l}(e||"",p,m)),300),v=t?{value:t,[p]:t[p]}:void 0;return(0,c.jsx)(i.AsyncSelect,{inputId:u,width:l,isClearable:s,defaultOptions:!0,loadOptions:h,onChange:e=>{a(null==e?void 0:e.value)},placeholder:"Select dashboard",noOptionsMessage:"No dashboards found",value:v,invalid:n,disabled:r,getOptionLabel:e=>e[p]})};var p=t(48833),m=t(36798),h=t(68490),v=t(63984);const g=e=>{let{item:a,onDelete:t,onMoveDown:l,onMoveUp:n,first:r,last:o}=e;const d=(0,i.useStyles)(b);return(0,c.jsxs)("tr",{"aria-label":s.wl.pages.PlaylistForm.itemRow,children:["dashboard_by_id"===a.type?(0,c.jsxs)("td",{className:(0,h.cx)(d.td,d.item),children:[(0,c.jsx)(i.Icon,{name:"apps","aria-label":s.wl.pages.PlaylistForm.itemIdType}),(0,c.jsx)("span",{children:a.title})]}):null,"dashboard_by_tag"===a.type?(0,c.jsxs)("td",{className:(0,h.cx)(d.td,d.item),children:[(0,c.jsx)(i.Icon,{name:"tag-alt","aria-label":s.wl.pages.PlaylistForm.itemTagType}),(0,c.jsx)(v.e,{label:a.title,removeIcon:!1,count:0},a.id)]}):null,(0,c.jsxs)("td",{className:(0,h.cx)(d.td,d.settings),children:[r?null:(0,c.jsx)(i.IconButton,{name:"arrow-up",size:"md",onClick:e=>{e.preventDefault(),n(a)},"aria-label":s.wl.pages.PlaylistForm.itemMoveUp,type:"button"}),o?null:(0,c.jsx)(i.IconButton,{name:"arrow-down",size:"md",onClick:e=>{e.preventDefault(),l(a)},"aria-label":s.wl.pages.PlaylistForm.itemMoveDown,type:"button"}),(0,c.jsx)(i.IconButton,{name:"times",size:"md",onClick:e=>{e.preventDefault(),t(a)},"aria-label":s.wl.pages.PlaylistForm.itemDelete,type:"button"})]})]},a.title)};function b(e){return{td:h.css`
      label: td;
      line-height: 28px;
      max-width: 335px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    `,item:h.css`
      label: item;
      span {
        margin-left: ${e.spacing.xs};
      }
    `,settings:h.css`
      label: settings;
      text-align: right;
    `}}var y;const x=e=>{let{items:a,onMoveUp:t,onMoveDown:l,onDelete:s}=e;return 0===a.length?y||(y=(0,c.jsx)("tr",{children:(0,c.jsx)("td",{children:(0,c.jsx)("em",{children:"Playlist is empty. Add dashboards below."})})})):(0,c.jsx)(c.Fragment,{children:a.map(((e,n)=>{const i=0===n,r=n===a.length-1;return(0,c.jsx)(g,{first:i,last:r,item:e,onDelete:s,onMoveDown:l,onMoveUp:t},e.title)}))})};var f;const j=e=>{let{items:a,onMoveUp:t,onMoveDown:l,onDelete:s}=e;return(0,c.jsxs)("div",{className:"gf-form-group",children:[f||(f=(0,c.jsx)("h3",{className:"page-headering",children:"Dashboards"})),(0,c.jsx)("table",{className:"filter-table",children:(0,c.jsx)("tbody",{children:(0,c.jsx)(x,{items:a,onMoveUp:t,onMoveDown:l,onDelete:s})})})]})};var w;const D=new m.i,C=e=>{var a,t;let{onSubmit:r,playlist:o}=e;const{name:d,interval:m,items:h}=o,{items:v,addById:g,addByTag:b,deleteItem:y,moveDown:x,moveUp:f}=function(e){const[a,t]=(0,l.useState)(null!=e?e:[]),s=(0,l.useCallback)((e=>{if(!e||a.find((a=>a.id===e.id)))return;const l={id:e.id,title:e.label,type:"dashboard_by_id",value:e.id.toString(10),order:a.length+1};t([...a,l])}),[a]),n=(0,l.useCallback)((e=>{const l=e[0];if(!l||a.find((e=>e.value===l)))return;const s={title:l,type:"dashboard_by_tag",value:l,order:a.length+1};t([...a,s])}),[a]),i=(0,l.useCallback)(((e,l)=>{const s=[...a],n=s.indexOf(e),i=n+l;i>=0&&i<s.length&&(s.splice(n,1),s.splice(i,0,e)),t(s)}),[a]),r=(0,l.useCallback)((e=>{i(e,-1)}),[i]),o=(0,l.useCallback)((e=>{i(e,1)}),[i]),d=(0,l.useCallback)((e=>{t(a.filter((a=>a!==e)))}),[a]);return{items:a,addById:s,addByTag:n,deleteItem:d,moveDown:o,moveUp:r}}(h);return(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(i.Form,{onSubmit:e=>r(Object.assign({},e,{items:v})),validateOn:"onBlur",children:e=>{var l,r;let{register:o,errors:h}=e;const C=0===v.length||Object.keys(h).length>0;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(i.Field,{label:"Name",invalid:!!h.name,error:null==h||null===(l=h.name)||void 0===l?void 0:l.message,children:(0,c.jsx)(i.Input,Object.assign({type:"text"},o("name",{required:"Name is required"}),{placeholder:"Name",defaultValue:d,"aria-label":s.wl.pages.PlaylistForm.name}))}),(0,c.jsx)(i.Field,{label:"Interval",invalid:!!h.interval,error:null==h||null===(r=h.interval)||void 0===r?void 0:r.message,children:(0,c.jsx)(i.Input,Object.assign({type:"text"},o("interval",{required:"Interval is required"}),{placeholder:"5m",defaultValue:null!=m?m:"5m","aria-label":s.wl.pages.PlaylistForm.interval}))}),a||(a=(0,c.jsx)(j,{items:v,onMoveUp:f,onMoveDown:x,onDelete:y})),(0,c.jsxs)("div",{className:"gf-form-group",children:[w||(w=(0,c.jsx)("h3",{className:"page-headering",children:"Add dashboards"})),t||(t=(0,c.jsx)(i.Field,{label:"Add by title",children:(0,c.jsx)(u,{onChange:g,id:"dashboard-picker",isClearable:!0})})),(0,c.jsx)(i.Field,{label:"Add by tag",children:(0,c.jsx)(p.D,{isClearable:!0,tags:[],hideValues:!0,tagOptions:D.getDashboardTags,onChange:b,placeholder:""})})]}),(0,c.jsxs)(i.HorizontalGroup,{children:[(0,c.jsx)(i.Button,{type:"submit",variant:"primary",disabled:C,children:"Save"}),(0,c.jsx)(i.LinkButton,{variant:"secondary",href:`${n.config.appSubUrl}/playlists`,children:"Cancel"})]})]})}})})}},22997:(e,a,t)=>{t.r(a),t.d(a,{PlaylistNewPage:()=>m,default:()=>h});t(76687);var l=t(46958),s=t(10967),n=t(70534),i=t(36131),r=t(3276),o=t(33848),d=t(37838),c=t(86222),u=t(38633),p=t(52010);const m=e=>{let{navModel:a}=e;const t=(0,n.useStyles2)(c.e),{playlist:l,loading:r}=(0,u.Z)();return(0,p.jsx)(i.Z,{navModel:a,children:(0,p.jsxs)(i.Z.Contents,{isLoading:r,children:[(0,p.jsx)("h3",{className:t.subHeading,children:"New Playlist"}),(0,p.jsx)("p",{className:t.description,children:"A playlist rotates through a pre-selected list of dashboards. A playlist can be a great way to build situational awareness, or just show off your metrics to your team or visitors."}),(0,p.jsx)(o.H,{onSubmit:async e=>{await(0,d.cg)(e),s.locationService.push("/playlists")},playlist:l})]})})},h=(0,l.connect)((e=>({navModel:(0,r.h)(e.navIndex,"playlists")})))(m)},37838:(e,a,t)=>{t.d(a,{A5:()=>c,CE:()=>o,Dv:()=>u,cg:()=>r,l8:()=>d});var l=t(10967),s=t(29877),n=t(94843),i=t(96572);async function r(e){await p((()=>(0,l.getBackendSrv)().post("/api/playlists",e)))}async function o(e,a){await p((()=>(0,l.getBackendSrv)().put(`/api/playlists/${e}`,a)))}async function d(e){await p((()=>(0,l.getBackendSrv)().delete(`/api/playlists/${e}`)),"Playlist deleted")}async function c(e){return await(0,l.getBackendSrv)().get(`/api/playlists/${e}`)}async function u(e){return await(0,l.getBackendSrv)().get("/api/playlists/",{query:e})}async function p(e){let a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Playlist saved";try{await e(),(0,i.WI)((0,s.$l)((0,n.AT)(a)))}catch(e){(0,i.WI)((0,s.$l)((0,n.t_)("Unable to save playlist",e)))}}},86222:(e,a,t)=>{t.d(a,{e:()=>s});var l=t(68490);function s(e){return{description:l.css`
      label: description;
      width: 555px;
      margin-bottom: 20px;
    `,subHeading:l.css`
      label: sub-heading;
      margin-bottom: ${e.spacing(2)};
    `}}},38633:(e,a,t)=>{t.d(a,{Z:()=>n});var l=t(76687),s=t(37838);function n(e){const[a,t]=(0,l.useState)({items:[],interval:"5m",name:"",uid:""}),[n,i]=(0,l.useState)(!0);return(0,l.useEffect)((()=>{(async()=>{if(!e)return void i(!1);const a=await(0,s.A5)(e);t(a),i(!1)})()}),[e]),{playlist:a,loading:n}}}}]);
//# sourceMappingURL=PlaylistNewPage.3303a85ce5368e421fe6.js.map