"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9975],{34212:(B,f,a)=>{a.d(f,{H:()=>H});var e=a(68404),g=a(68183),p=a(35645),I=a(94270),c=a(24799),y=a(46967),C=a(52081),h=a(31403),D=a(99661),A=a(24357),N=a(64823),T=a(19677),b=a(52423),M=a(64681),O=a.n(M),S=a(72648),F=a(67487),x=a(39904),$=a(8180),R=a(21731);const L=({items:d,onDelete:l})=>{const r=(0,S.wW)(K);if(!d?.length)return e.createElement("div",null,e.createElement("em",null,"Playlist is empty. Add dashboards below."));const m=t=>{let i=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(R.e,{key:t.value,label:t.value,removeIcon:!1,count:0})),n?s.push(e.createElement("span",{key:"info"},"\xA0 ",O()("dashboard",t.dashboards.length,!0))):(i="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)):(i="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:i,className:r.rightMargin,key:"icon"}),s)};return e.createElement(e.Fragment,null,d.map((t,i)=>e.createElement(T._l,{key:`${i}/${t.value}`,draggableId:`${i}`,index:i},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(i),"aria-label":g.wl.pages.PlaylistForm.itemDelete,type:"button"}),e.createElement(x.J,{title:"Drag and drop to reorder",name:"draggabledots",size:"md"}))))))};function K(d){return{row:b.css`
      padding: 6px;
      background: ${d.colors.background.secondary};
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 3px;

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

//# sourceMappingURL=PlaylistNewPage.cd504b2301d8fc133dc1.js.map