"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2341],{79485:(M,P,a)=>{a.r(P),a.d(P,{PlaylistEditPage:()=>C,default:()=>D});var e=a(27702),v=a(25111),T=a(26129),I=a(44644),u=a(69e3),y=a(60086);const C=({match:p})=>{const c=(0,v.Z)(()=>(0,y.A5)(p.params.uid),[p.params]),O=async E=>{await(0,y.CE)(p.params.uid,E),T.E1.push("/playlists")},f={text:"Edit playlist",subTitle:"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."};return e.createElement(I.T,{navId:"dashboards/playlists",pageNav:f},e.createElement(I.T.Contents,{isLoading:c.loading},c.error&&e.createElement("div",null,"Error loading playlist: ",JSON.stringify(c.error)),c.value&&e.createElement(u.H,{onSubmit:O,playlist:c.value})))},D=C},69e3:(M,P,a)=>{a.d(P,{H:()=>H});var e=a(27702),v=a(74639),T=a(34667),I=a(23839),u=a(22209),y=a(1128),C=a(64022),D=a(66670),p=a(81290),c=a(1041),O=a(63064),f=a(85532),E=a(42844),B=a(6772),N=a.n(B),S=a(66310),F=a(62108),x=a(73453),$=a(67437),L=a(8311);const R=({items:i,onDelete:l})=>{const r=(0,S.wW)(K);if(!i?.length)return e.createElement("div",null,e.createElement("em",null,"Playlist is empty. Add dashboards below."));const m=t=>{let d=t.type==="dashboard_by_tag"?"apps":"tag-alt";const s=[],n=t.dashboards?.[0];return t.dashboards?t.type==="dashboard_by_tag"?(s.push(e.createElement(L.e,{key:t.value,label:t.value,removeIcon:!1,count:0})),n?s.push(e.createElement("span",{key:"info"},"\xA0 ",N()("dashboard",t.dashboards.length,!0))):(d="exclamation-triangle",s.push(e.createElement("span",{key:"info"},"\xA0 No dashboards found")))):n?s.push(t.dashboards.length>1?e.createElement("span",{key:"info"},"Multiple items found: $",t.value):e.createElement("span",{key:"info"},n.name??t.value)):(d="exclamation-triangle",s.push(e.createElement("span",{key:"info"},"\xA0 Not found: ",t.value))):s.push(e.createElement(F.$,{key:"spinner"})),e.createElement(e.Fragment,null,e.createElement(x.J,{name:d,className:r.rightMargin,key:"icon"}),s)};return e.createElement(e.Fragment,null,i.map((t,d)=>e.createElement(f._l,{key:`${d}/${t.value}`,draggableId:`${d}`,index:d},s=>e.createElement("div",{className:r.row,ref:s.innerRef,...s.draggableProps,...s.dragHandleProps,role:"row"},e.createElement("div",{className:r.actions,role:"cell","aria-label":`Playlist item, ${t.type}, ${t.value}`},m(t)),e.createElement("div",{className:r.actions},e.createElement($.h,{name:"times",size:"md",onClick:()=>l(d),tooltip:v.wl.pages.PlaylistForm.itemDelete}),e.createElement(x.J,{title:"Drag and drop to reorder",name:"draggabledots",size:"md"}))))))};function K(i){return{row:(0,E.css)`
      padding: 6px;
      background: ${i.colors.background.secondary};
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 3px;

      border: 1px solid ${i.colors.border.medium};
      &:hover {
        border: 1px solid ${i.colors.border.strong};
      }
    `,rightMargin:(0,E.css)`
      margin-right: 5px;
    `,actions:(0,E.css)`
      align-items: center;
      justify-content: center;
      display: flex;
    `,settings:(0,E.css)`
      label: settings;
      text-align: right;
    `}}const U=({items:i,deleteItem:l,moveItem:r})=>{const m=t=>{t.destination&&r(t.source.index,t.destination?.index)};return e.createElement("div",{className:"gf-form-group"},e.createElement("h3",{className:"page-headering"},"Dashboards"),e.createElement(f.Z5,{onDragEnd:m},e.createElement(f.bK,{droppableId:"playlist-list",direction:"vertical"},t=>e.createElement("div",{ref:t.innerRef,...t.droppableProps},e.createElement(R,{items:i,onDelete:l}),t.placeholder))))};var W=a(25111),j=a(60086);function z(i){const[l,r]=(0,e.useState)(i??[]);(0,W.Z)(async()=>{for(const n of l)if(!n.dashboards){r(await(0,j.jc)(l));return}},[l]);const m=(0,e.useCallback)(n=>{n&&r([...l,{type:"dashboard_by_uid",value:n.uid}])},[l]),t=(0,e.useCallback)(n=>{const o=n[0];if(!o||l.find(h=>h.value===o))return;const g={type:"dashboard_by_tag",value:o};r([...l,g])},[l]),d=(0,e.useCallback)((n,o)=>{if(n===o||!l[n])return;const g=Array.from(l),[h]=g.splice(n,1);g.splice(o,0,h),r(g)},[l]),s=(0,e.useCallback)(n=>{const o=l.slice();o.splice(n,1),r(o)},[l]);return{items:l,addById:m,addByTag:t,deleteItem:s,moveItem:d}}const H=({onSubmit:i,playlist:l})=>{const[r,m]=(0,e.useState)(!1),{name:t,interval:d,items:s}=l,n=(0,e.useMemo)(()=>()=>(0,O.getGrafanaSearcher)().tags({kind:["dashboard"]}),[]),{items:o,addById:g,addByTag:h,deleteItem:J,moveItem:V}=z(s),Z=A=>{m(!0),i({...A,items:o})};return e.createElement("div",null,e.createElement(I.l,{onSubmit:Z,validateOn:"onBlur"},({register:A,errors:b})=>{const G=o.length===0||Object.keys(b).length>0;return e.createElement(e.Fragment,null,e.createElement(u.g,{label:"Name",invalid:!!b.name,error:b?.name?.message},e.createElement(y.I,{type:"text",...A("name",{required:"Name is required"}),placeholder:"Name",defaultValue:t,"aria-label":v.wl.pages.PlaylistForm.name})),e.createElement(u.g,{label:"Interval",invalid:!!b.interval,error:b?.interval?.message},e.createElement(y.I,{type:"text",...A("interval",{required:"Interval is required"}),placeholder:"5m",defaultValue:d??"5m","aria-label":v.wl.pages.PlaylistForm.interval})),e.createElement(U,{items:o,deleteItem:J,moveItem:V}),e.createElement("div",{className:"gf-form-group"},e.createElement("h3",{className:"page-headering"},"Add dashboards"),e.createElement(u.g,{label:"Add by title"},e.createElement(p.o,{id:"dashboard-picker",onChange:g,key:o.length})),e.createElement(u.g,{label:"Add by tag"},e.createElement(c.D,{isClearable:!0,tags:[],hideValues:!0,tagOptions:n,onChange:h,placeholder:"Select a tag"}))),e.createElement(C.Lh,null,e.createElement(D.zx,{type:"submit",variant:"primary",disabled:G,icon:r?"fa fa-spinner":void 0},"Save"),e.createElement(D.Qj,{variant:"secondary",href:`${T.config.appSubUrl}/playlists`},"Cancel")))}))}}}]);

//# sourceMappingURL=PlaylistEditPage.fbe226ce3cd2b8cfcdee.js.map