"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2715],{52770:(k,x,n)=>{n.r(x),n.d(x,{BannerSettingsPage:()=>y,default:()=>U});var e=n(74848),u=n(96540),b=n(14110),j=n(21780),i=n(49785),l=n(47232),E=n(26272),I=n(3591),v=n(67061),C=n(84167),o=n(88575),P=n(15292),Q=n(32372),T=n(63383),F=n(90182),V=n(55852),W=n(35339),a=n(8484),L=n(32196),Y=n(94753),J=n(40845),M=n(93197);function N({message:s,variant:d}){const h=(0,J.of)(O);return(0,e.jsxs)(v.B,{direction:"column",width:"100%",gap:2,children:[(0,e.jsx)(Y.E,{variant:"h3",children:(0,e.jsx)(a.x6,{i18nKey:"banner.preview.title",children:"Preview"})}),(0,e.jsx)("div",{className:h.container,children:(0,e.jsx)(M.l,{message:s||(0,a.t)("banner.preview.message.default","Update this preview by modifying the message field."),variant:d})})]})}const O=s=>({container:(0,L.css)({backgroundColor:s.colors.background.canvas})});var S=n(5477);function R(s){return s?{...s,startTime:s.startTime?(0,l.KQ)(s.startTime):(0,l.KQ)(),endTime:s.endTime?(0,l.KQ)(s.endTime):void 0}:{enabled:!1,message:"",variant:"info",visibility:"authenticated",startTime:(0,l.KQ)()}}function z({banner:s,name:d}){const[h,c]=(0,S.Q)(d),{register:$,control:f,handleSubmit:w,watch:A,reset:g,formState:{errors:p,isDirty:D},getValues:K}=(0,i.mN)({defaultValues:R(s)}),[B,G,H]=A(["startTime","message","variant"]);(0,u.useEffect)(()=>{const t=(0,I.J7)();if(c.isSuccess){const r=K();t.publish({type:E.r1.alertSuccess.name,payload:[(0,a.t)("banner.api.result.saved","Banner settings saved")]}),g({...r,startTime:r.startTime||null,endTime:r.endTime||null})}},[c.isSuccess,g,K]);const X=async t=>{(0,b.rR)("grafana_banner_saved",{enabled:t.enabled,endSelected:!!t.endTime,daysShown:t.endTime?t.startTime&&(0,l.KQ)(t.endTime).diff(t.startTime,"days"):void 0,visibility:t.visibility,variant:t.variant});const r={...t,startTime:t.startTime?t.startTime.toISOString():null,endTime:t.endTime?t.endTime.toISOString():null};h(r)};return(0,e.jsxs)(v.B,{direction:"column",gap:2,children:[(0,e.jsx)(N,{message:G,variant:H}),(0,e.jsx)("form",{onSubmit:w(X),style:{maxWidth:650},children:(0,e.jsxs)(C.n,{label:(0,a.t)("banner.form.title","Configure banner"),children:[(0,e.jsx)(W.F,{onDiscard:g,confirmRedirect:D}),(0,e.jsx)(o.D,{label:(0,a.t)("banner.form.enabled.label","Enabled"),children:(0,e.jsx)(P.d,{...$("enabled"),label:"Enabled"})}),(0,e.jsx)(o.D,{label:(0,a.t)("banner.form.message.label","Message"),description:(0,e.jsx)(a.x6,{i18nKey:"banner.form.message.description",children:"Text content of the banner. Supports markdown."}),children:(0,e.jsx)(i.xI,{name:"message",control:f,render:({field:{ref:t,...r}})=>(0,e.jsx)(Q.B,{...r,height:200,language:"markdown"})})}),(0,e.jsx)(o.D,{label:(0,a.t)("banner.form.start.label","Starts at"),description:(0,e.jsx)(a.x6,{i18nKey:"banner.form.start.description",children:"The banner will be shown starting from this date/time."}),children:(0,e.jsx)(i.xI,{name:"startTime",control:f,render:({field:{ref:t,value:r,...m}})=>(0,e.jsx)(T.K,{...m,date:r||void 0,showSeconds:!1,clearable:!0,minDate:new Date})})}),(0,e.jsx)(o.D,{label:(0,a.t)("banner.form.end.label","Ends at"),invalid:!!p?.endTime,error:p?.endTime?.message,description:(0,e.jsx)(a.x6,{i18nKey:"banner.form.end.description",children:"If no end date is selected, the banner is displayed indefinitely."}),children:(0,e.jsx)(i.xI,{name:"endTime",control:f,rules:{validate:t=>!B||!t||t>B?!0:(0,a.t)("banner.form.end.error","End time must be after start time")},render:({field:{ref:t,value:r,...m}})=>(0,e.jsx)(T.K,{...m,date:r||void 0,showSeconds:!1,clearable:!0})})}),(0,e.jsx)(v.B,{children:(0,e.jsx)(o.D,{label:(0,a.t)("banner.form.variant.label","Variant"),children:(0,e.jsx)(i.xI,{name:"variant",control:f,render:({field:{ref:t,onChange:r,...m}})=>(0,e.jsx)(F.l6,{...m,onChange:Z=>{r(Z.value)},placeholder:"Select banner type",options:[{label:(0,a.t)("banner.form.options.info","Info"),value:"info"},{label:(0,a.t)("banner.form.options.warning","Warning"),value:"warning"},{label:(0,a.t)("banner.form.options.error","Error"),value:"error"}]})})})}),(0,e.jsx)(V.$n,{type:"submit",disabled:!D||c.isLoading,children:c.isLoading?(0,e.jsx)(a.x6,{i18nKey:"banner.form.button-saving",children:"Saving..."}):(0,e.jsx)(a.x6,{i18nKey:"banner.form.button-save",children:"Save"})})]})})]})}function y(){const[s,d]=(0,S.Y)();return(0,u.useEffect)(()=>{(0,b.Jy)()},[]),(0,e.jsx)(j.YW,{navId:"banner-settings",children:(0,e.jsx)(j.YW.Contents,{isLoading:d,children:(0,e.jsx)(z,{banner:s?.spec,name:s?.metadata.name})})})}const U=y}}]);

//# sourceMappingURL=BannerSettingsPage.9dbdf942d37a3c8d0941.js.map