@e-llm-studio/federated-dashboard-components 2.2.9-rca-test-7 → 2.2.9-rca-test-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ExecutiveDashboard/components/Insights/AgReport.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/DrillTable.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/drillDay.js +2 -0
- package/dist/ExecutiveDashboard/components/Insights/drillDay.js.map +1 -0
- package/dist/ExecutiveDashboard/components/Table/FTable.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/AgReport.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/DrillTable.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/drillDay.js +2 -0
- package/dist/cjs/ExecutiveDashboard/components/Insights/drillDay.js.map +1 -0
- package/dist/cjs/ExecutiveDashboard/components/Table/FTable.js +1 -1
- package/dist/cjs/styles.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/ExecutiveDashboard/TestExecutiveDashboard.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/AgReport.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/DrillTable.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/drillDay.d.ts +12 -0
- package/dist/types/ExecutiveDashboard/components/Insights/drillDay.d.ts.map +1 -0
- package/dist/types/ExecutiveDashboard/components/Table/FTable.d.ts +2 -0
- package/dist/types/ExecutiveDashboard/components/Table/FTable.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/types/insights.d.ts +1 -0
- package/dist/types/ExecutiveDashboard/types/insights.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as e,__spreadArray as n,__awaiter as i,__generator as r}from"../../../_virtual/_tslib.js";import{jsx as t,jsxs as a,Fragment as l}from"react/jsx-runtime";import{useState as o,useMemo as d,useEffect as c,useRef as s}from"react";import{Info as u,Settings2 as v,Sparkles as p,TrendingUp as g,ArrowUpRight as h}from"lucide-react";import{ReasoningTrigger as m,ReasoningPanel as y,RcaDecisionComponent as f}from"../RcaDecisionComponent/RcaDecisionComponent.js";import b from"../Graph/LineChart.js";import{fetchInsightsCorrelation as k,toIsoDay as _,fetchInsightsCorrelationTrend as w,fetchGraphGroups as N,fetchLevelSummary as D,fetchInsightsDrivers as x,saveCorrelationWindow as K,fetchInsightsSeries as I,generateInsightsSummary as C,generateLevelSummary as T,fetchLevelRows as A}from"../../api/insightsApi.js";import{useInsights as S}from"./insightsContextCore.js";import{reportDecisioning as L,useOpenRow as P,toRcaItems as B,useInsightsFetch as R,formatValue as j,previousDayLabel as F,useJob as M,shortDay as O}from"./insightsUtils.js";import G from"./DrillTable.js";import E from"./FilterNotice.js";import{SkeletonLines as W,splitVerdict as z,movementVerdictLabel as U,verdictToneHex as H,movementColorHex as Z,VerdictSentence as $,ReportAccordion as q,CriticalityChip as V,MovementChip as J,DayOverDayChange as Q,ChartSkeleton as X,CollapsibleVisualSection as Y,formatHeaderDate as ee,SectionHeader as ne,DaysDropdown as ie,toneOf as re}from"./agPrimitives.js";import te,{useNeedsAttention as ae}from"./NeedsAttention.js";var le=10;function oe(n){var l,d=this,c=n.entityKey,s=n.dataDay,u=S(),v=o(null),p=v[0],g=v[1],h=o(null),m=h[0],y=h[1];if(M(p,null!==(l=null==u?void 0:u.api)&&void 0!==l?l:null,function(){g(null),null==u||u.refresh()}),!(null==u?void 0:u.viewer.isAdmin))return null;return a("span",{children:[t("button",e({type:"button",className:"ins-link",disabled:Boolean(p),onClick:function(){return i(d,void 0,void 0,function(){var e,n,i,t;return r(this,function(r){switch(r.label){case 0:y(null),r.label=1;case 1:return r.trys.push([1,6,,7]),e={dataDay:s||_(u.range.endDate),window:"both"},c?[4,T(u.api,c,e)]:[3,3];case 2:return i=r.sent(),[3,5];case 3:return[4,C(u.api,e)];case 4:i=r.sent(),r.label=5;case 5:return(n=i).jobId?g(n.jobId):u.refresh(),[3,7];case 6:return t=r.sent(),y(t.message||"The summary couldn't be regenerated."),[3,7];case 7:return[2]}})})}},{children:p?"Regenerating…":"Regenerate summary"})),m?t("span",e({className:"ins-error"},{children:m})):null]})}var de=function(e){return e.replace(/\b\w/g,function(e){return e.toUpperCase()})};function ce(e,n){return n?"Decision Advantage is unavailable right now: ".concat(n.message):e?"waiting"===e.status?"The first morning run hasn't finished yet. This fills in after it.":"running"===e.status?"The AI is writing this report. It usually takes a minute or two.":"generated"!==e.status?"No report generated for this day.":null:null}function se(e,n,i){return i?null:ce(e,n)}function ue(e){return e.replace(/\{\{([^|}]*)\|[^}]*\}\}/g,"$1")}function ve(n){var i,r,l=n.report,s=n.movementType,u=n.direction,v=n.good,p=n.loading,g=n.error,h=o(!1),f=h[0],b=h[1],k=d(function(){return L(l)},[l]);if(c(function(){return b(!1)},[null==l?void 0:l.reportId]),p)return t("div",e({className:"ag-summary"},{children:t(W,{widths:[28,96,72],label:"Loading summary"})}));var _=null==l?void 0:l.summary,w=null!==(i=null==_?void 0:_.headline)&&void 0!==i?i:"",N=Boolean(w),D=z(w).prefix,x=Boolean(null==_?void 0:_.eyebrow)&&"Movement unavailable"!==(null==_?void 0:_.eyebrow),K=void 0!==s,I=x?_.eyebrow:K?U(s,u):D||"Summary",C=x?"good"===_.tone||"bad"===_.tone?H(_.tone):Z(_.movementType,_.movementDirection,v):K?Z(s,u,v):"Good news"===D?"#15803D":"Bad news"===D?"#E11D48":"#5928ED";return a("div",e({className:"ag-summary"},{children:[t("p",e({className:"ag-summary__title",style:{color:N?C:"#64748b"}},{children:N?I:"No summary yet"})),a("div",e({className:"ag-summary__text"},{children:[N?t($,{text:w,good:v}):null!==(r=ce(l,g))&&void 0!==r?r:"Reports are written after each morning run.",N&&k?t("span",e({className:"ag-summary__brain"},{children:t(m,{open:f,onToggle:function(){return b(function(e){return!e})},label:"how the AI reached this summary"})})):null]})),f&&k?t("div",e({className:"ag-summary__reasoning"},{children:t(y,{decisioning:k})})):null]}))}function pe(e){var n,i,r,a=e.report,l=e.error,o=e.loading,c=S(),s=!o&&"generated"===(null==a?void 0:a.status),u=d(function(){return s?L(a,null==a?void 0:a.footer):null},[s,a]),v=P();return t(f,{className:"ag-decision",title:null!==(n=null==c?void 0:c.labels.decisionAdvantageTitle)&&void 0!==n?n:"Decision Advantage",score:s?null==a?void 0:a.score:null,decisioning:u,notice:se(a,l,o),afterSections:o?t(W,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:s?B(null==a?void 0:a.rootCause,v):[],nextSteps:s?B(null==a?void 0:a.nextSteps,v):[],width:"100%",maxWidth:"none"},"".concat(null!==(i=null==a?void 0:a.reportId)&&void 0!==i?i:"pending",":").concat(null!==(r=null==a?void 0:a.generatedAt)&&void 0!==r?r:""))}var ge=[{key:"drivers",label:"driversTab",info:"What moved the day's number the same way."},{key:"headwinds",label:"headwindsTab",info:"What moved against the day's number."},{key:"attention",label:"attentionTab",info:"The number moved, but activity doesn't explain it."}],he={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},me={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function ye(n){var i=n.on,r=n.onClick,l=n.disabled,o=void 0!==l&&l;return a("button",e({type:"button",className:"ag-graph-pill".concat(i?" is-on":""),disabled:o,title:o?"A graph can show up to ".concat(le," rows"):void 0,onClick:function(e){e.stopPropagation(),r()}},{children:[t(g,{"aria-hidden":"true"}),i?"In graph":o?"Graph full":"Add to graph"]}))}function fe(n){var i=n.rank,r=n.category,l=n.name,o=n.chips,d=n.action,c=n.lines,s=n.cell,u=n.onOpen;return t("li",{children:a("div",e({className:"ag-driver".concat(u?" is-clickable":""),role:u?"button":void 0,tabIndex:u?0:void 0,onClick:u,onKeyDown:u?function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u())}:void 0},{children:[a("div",e({className:"ag-driver__main"},{children:[a("span",e({className:"ag-driver__rank"},{children:[i,"."]})),a("div",e({className:"ag-driver__body"},{children:[r?a("span",e({className:"ag-driver__category"},{children:[r," >"]})):null,t("span",e({className:"ag-driver__name"},{children:l})),a("div",e({className:"ag-driver__chips"},{children:[o,d]})),c]}))]})),a("div",e({className:"ag-driver__cell"},{children:[s,u?t("span",e({className:"ag-driver__open","aria-hidden":"true"},{children:t(h,{})})):null]}))]}))})}function be(n){var i,r=n.label,l=n.rightLabel,o=n.children,d=S();return a("div",e({className:"ag-drivers"},{children:[a("div",e({className:"ag-drivers__head"},{children:[t("span",{children:r}),t("span",{children:null!==(i=null!=l?l:null==d?void 0:d.labels.activityColumn)&&void 0!==i?i:"User Activity"})]})),t("ol",{children:o})]}))}function ke(n){var i,r,d,s,v,p,g,h,m,y=n.dataDay,f=n.entityKey,b=n.parentNodeKey,k=n.kpiId,_=n.title,w=n.graphed,N=n.onToggleGraph,D=n.onOpenDriver,K=n.onDecisionSettled,I=n.initialTab,C=void 0===I?"drivers":I,T=S(),A=o(C),L=A[0],P=A[1],B=o({drivers:1,headwinds:1,attention:1}),M=B[0],O=B[1],G=null!==(i=null!=k?k:null==T?void 0:T.headlineKpi)&&void 0!==i?i:void 0,E=function(e){return T&&G&&e===L?function(n){return x(T.api,{dataDay:y,kpiId:G,entityKey:f,parentNodeKey:b,tab:e,limit:Math.min(10,(b?10:3)*M[e]),offset:0,filters:T.range.filters},n)}:null},W=function(e){return[null==T?void 0:T.api.configId,null==T?void 0:T.rangeKey,y,G,f,b,e,L,M[e],null==T?void 0:T.revision]},z={drivers:R(E("drivers"),W("drivers")),headwinds:R(E("headwinds"),W("headwinds")),attention:R(E("attention"),W("attention"))},U=z[L],H=U.data,Z=U.error,X=U.loading,Y=null!==(v=null!==(d=null===(r=z.drivers.data)||void 0===r?void 0:r.tabs)&&void 0!==d?d:null===(s=z.headwinds.data)||void 0===s?void 0:s.tabs)&&void 0!==v?v:null===(p=z.attention.data)||void 0===p?void 0:p.tabs,ee=ae(y,b,G),ne=null!==(h=null===(g=ee.data)||void 0===g?void 0:g.counts.pending)&&void 0!==h?h:0;if(c(function(){return O({drivers:1,headwinds:1,attention:1})},[y]),c(function(){return P(C)},[C]),!T)return null;var ie=T.goodDirection(null!=G?G:""),re=null!==(m=null==H?void 0:H.rows)&&void 0!==m?m:[];return a(q,e({title:_},{children:[t("div",e({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:ge.map(function(n){return t("button",e({type:"button",role:"tab","aria-selected":L===n.key,className:L===n.key?"is-active":void 0,onClick:function(){return P(n.key)},title:n.info},{children:a(l,{children:[T.labels[n.label],(null==Y?void 0:Y[n.key])?" (".concat(Y[n.key].total,")"):"","attention"===n.key&&ne?a("span",e({className:"ag-na__tab-badge",title:"".concat(ne," data points need a decision")},{children:[ne,t("span",e({className:"ins-visually-hidden"},{children:" data points need a decision"}))]})):null,t(u,{"aria-hidden":"true"})]})}),n.key)})})),"attention"===L?t(te,{dataDay:y,nodeKey:b,kpiId:G,attention:ee,onDecisionSettled:K}):null,"attention"===L&&re.length?t("h4",e({className:"ag-na__subhead"},{children:"Rows that moved without a clear cause"})):null,Z?a("p",e({className:"ag-muted"},{children:["Top drivers are unavailable right now: ",Z.message]})):X&&!H?t("p",e({className:"ag-muted"},{children:"Loading drivers..."})):re.length?a(l,{children:[t(be,e({label:"Driver",rightLabel:T.labels.activityColumn},{children:re.map(function(n){var i,r,o,d,c,s,u,v,p,g=n.deltaContributionPct,h=w.includes(n.nodeKey),m=(null===(i=n.decisionAdvantage)||void 0===i?void 0:i.correlationSentence)||(null===(r=n.decisionAdvantage)||void 0===r?void 0:r.firstCause)||(null===(o=n.decisionAdvantage)||void 0===o?void 0:o.headline);return t(fe,{rank:n.rank,category:T.labels.driverCategory.replace("{plural}",n.entityKey?T.entityPluralName(n.entityKey):""),name:n.label,chips:a(l,{children:[t(V,{criticality:n.criticality}),t(J,{movementType:n.movementType,direction:n.changeDirection,good:ie}),(null===(d=n.correlation)||void 0===d?void 0:d.strength)?t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(n.correlation.strength)},{children:me[n.correlation.strength]})):null]}),action:N?t(ye,{on:h,disabled:!h&&w.length>=le,onClick:function(){return N(n)}}):void 0,lines:a(l,{children:[null!=g?a("span",e({className:"ag-driver__share"},{children:[T.labels.shareLine.replace("{share}",String(Math.abs(g)))," · ","opposite"===n.direction?T.labels.movedOpposite:T.labels.movedWith]})):null,a("span",e({className:"ag-driver__cost"},{children:[t("span",e({className:"ag-driver__total"},{children:j(n.value)})),null!=n.deltaPct?t("span",e({className:"ag-driver__sep"},{children:"|"})):null,t(Q,{deltaPct:n.deltaPct,good:ie,direction:n.changeDirection,tone:n.tone,suffix:F(y)})]})),m?t("p",e({className:"ag-driver__brief"},{children:t($,{text:ue(m),good:ie,arrowsFollowVerdict:!0})})):null,(null===(c=n.decisionAdvantage)||void 0===c?void 0:c.nextStep)?a("p",e({className:"ag-driver__brief"},{children:[t("strong",{children:"Next:"})," ",ue(n.decisionAdvantage.nextStep)]})):null]}),cell:a("span",e({className:"ag-driver__activity"},{children:[t("strong",{children:j(null!==(u=null===(s=n.drivingMetric)||void 0===s?void 0:s.value)&&void 0!==u?u:n.previous)}),t("span",{children:(null===(v=n.drivingMetric)||void 0===v?void 0:v.label)||((null===(p=n.drivingMetric)||void 0===p?void 0:p.kpiId)?T.kpiLabel(n.drivingMetric.kpiId):"opposite"===n.direction?"Moved opposite":"with"===n.direction?"Moved with":"Previous")})]})),onOpen:function(){var e;return D?D(n):T.openReport({reportId:null===(e=n.report)||void 0===e?void 0:e.reportId,nodeKey:n.nodeKey,kpiId:G,dataDay:y,title:n.label})}},n.nodeKey)})})),(null==H?void 0:H.hasMore)?t("div",e({className:"ag-more"},{children:t("button",e({type:"button",disabled:X,onClick:function(){return O(function(n){var i;return e(e({},n),((i={})[L]=n[L]+1,i))})}},{children:X?"Loading...":"Show more"}))})):null]}):t("p",e({className:"ag-muted"},{children:he[L]}))]}))}var _e=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],we=function(e,n){void 0===n&&(n="en-GB");var i=e.slice(0,10).split("-").map(Number),r=i[0],t=i[1],a=i[2];return Number.isFinite(r)&&Number.isFinite(t)&&Number.isFinite(a)?new Intl.DateTimeFormat(n,{day:"numeric",month:"short"}).format(new Date(r,t-1,a)):e};function Ne(u){var p,g,h,m,y,f,N,D,x=this,I=u.dataDay,C=u.nodeKey,T=void 0===C?"root":C,A=u.kpiId,L=u.dayGroup,P=S(),B=null!==(p=null!=A?A:null==P?void 0:P.headlineKpi)&&void 0!==p?p:void 0,F=o(""),G=F[0],E=F[1],W=o([]),z=W[0],U=W[1],H=o({}),Z=H[0],$=H[1],q=o(""),V=q[0],J=q[1],Q=o(null),ee=Q[0],ne=Q[1],ie=o(null),re=ie[0],te=ie[1],ae=o(!1),le=ae[0],oe=ae[1],de=o(!1),ce=de[0],se=de[1],ue=s(null),ve=R(P&&B&&I?function(n){return k(P.api,T,e({kpiId:B,dataDay:I,startDate:_(P.range.startDate),endDate:_(P.range.endDate),filters:P.range.filters},Z),n)}:null,[null==P?void 0:P.api.configId,null==P?void 0:P.rangeKey,I,B,T,Z.disregardBefore,null===(g=Z.disregardDates)||void 0===g?void 0:g.join(","),null==P?void 0:P.revision]),pe=ve.data,ge=ve.error,he=ve.loading,ye=R(P&&B&&I?function(n){return w(P.api,T,e({kpiId:B,startDate:_(P.range.startDate),endDate:_(P.range.endDate),filters:P.range.filters},Z),n)}:null,[null==P?void 0:P.api.configId,null==P?void 0:P.rangeKey,I,B,T,Z.disregardBefore,null===(h=Z.disregardDates)||void 0===h?void 0:h.join(","),null==P?void 0:P.revision]);M(re,null!==(m=null==P?void 0:P.api)&&void 0!==m?m:null,function(){te(null),J(""),null==P||P.refresh()}),c(function(){if(le){var e=function(e){ue.current&&!ue.current.contains(e.target)&&oe(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[le]);var fe=o(new Set),be=fe[0],ke=fe[1],Ne=d(function(){if(!pe)return[];return pe.series.filter(function(e){return!(null==L?void 0:L.length)||L.map(Number).includes((n=e.x,new Date("".concat(n.slice(0,10),"T00:00:00")).getDay()||7));var n})},[pe,L]),De=d(function(){return pe&&P?n([pe.kpiId],pe.drivers.map(function(e){return e.kpiId}).filter(function(e){return e!==pe.kpiId}),!0).map(function(e,n){return{key:"corr_".concat(e.replace(/[^a-zA-Z0-9_]/g,"_")),label:P.kpiLabel(e),color:_e[n%_e.length],curve:"smooth",strokeWidth:2,pointRadius:2,data:Ne.map(function(n){var i,r;return{x:n.x,y:n.disregarded?null:null!==(r=null===(i=n.values)||void 0===i?void 0:i[e])&&void 0!==r?r:null}}),valueFormatter:function(e){return"".concat(e,"%")}}}):[]},[pe,P,Ne]);c(function(){return ke(new Set(De.slice(2).map(function(e){return e.key})))},[De]);if(!P||!I||"no_drivers"===(null==pe?void 0:pe.state)||pe&&!pe.verdictText)return null;if(ge)return a("div",e({className:"ag-empty"},{children:["Correlation is unavailable right now: ",ge.message]}));if(he&&!pe)return t(X,{height:220,label:"Loading correlation"});if(!pe)return null;var xe=null!==(y=pe.strength)&&void 0!==y?y:"none",Ke=P.kpiLabel(pe.kpiId);return t(Y,e({title:"Correlation",meta:"Usage vs. ".concat(Ke),className:"ag-visual--card",action:P.viewer.isAdmin?a("div",e({ref:ue,className:"ag-corr__settings"},{children:[t("button",e({type:"button",className:"ag-icon-button","aria-label":"Correlation settings","aria-expanded":le,onClick:function(){return oe(function(e){return!e})}},{children:t(v,{"aria-hidden":"true"})})),le?t("div",e({className:"ag-corr__settings-menu",role:"menu"},{children:a("label",{children:[t("input",{type:"checkbox",checked:ce,onChange:function(e){return se(e.target.checked)}}),"Show date controls"]})})):null]})):null},{children:a("div",e({className:"ag-corr"},{children:[t("p",e({className:"ag-corr__banner ag-corr__banner--".concat(xe)},{children:pe.verdictText})),t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(xe)},{children:me[xe]})),a("p",e({className:"ag-corr__caption"},{children:[Ke," vs. usage - % change from the first day shown"]})),(null===(f=pe.window)||void 0===f?void 0:f.source)?t("p",e({className:"ag-muted"},{children:"default"===pe.window.source?pe.window.startDate?"Using all days since ".concat(we(pe.window.startDate,"en-US")):"Using all available days":"row"===pe.window.source?"Saved window".concat(pe.window.startDate?" since ".concat(we(pe.window.startDate,"en-US")):"").concat((null===(N=pe.window.excludedDates)||void 0===N?void 0:N.length)?" · ".concat(pe.window.excludedDates.length," left out"):""):"Preview window".concat((null===(D=pe.window.excludedDates)||void 0===D?void 0:D.length)?" · ".concat(pe.window.excludedDates.length," left out"):"")})):null,t("div",e({className:"ag-chart"},{children:t("div",e({className:"ellm-graph"},{children:t(b,{tier:"decision-advantage-correlation",series:De,hiddenKeys:be,onToggleSeries:function(e){return ke(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i})},onPointClick:function(){},xAxis:{label:"Date",categories:Ne.map(function(e){return e.x}),formatTick:function(e){return O(e)}},yAxis:{label:"% change",beginAtZero:!1,formatTick:function(e){return"".concat(Math.round(Number(e)),"%")}},tooltip:{render:function(n){var i,r=n.x,l=n.points,o=String(r),d=null===(i=ye.data)||void 0===i?void 0:i.series.find(function(e){return e.x===o});return a("div",e({className:"ag-tip ag-tip--wide"},{children:[t("div",e({className:"ag-tip__head"},{children:we(o)})),l.filter(function(e){return null!=e.value}).map(function(n){return a("div",e({className:"ag-tip__line"},{children:[a("span",{children:[t("i",{style:{background:n.color}}),n.series.label]}),a("strong",{children:[n.value,"%"]})]}),n.series.key)}),d?Object.keys(d.r).map(function(n){var i,r;return a("div",e({className:"ag-tip__sub"},{children:[t("span",{children:P.kpiLabel(n)}),t("span",{children:null==d.r[n]?"No correlation":"r ".concat(d.r[n]," · ").concat(null!==(i=d.strength[n])&&void 0!==i?i:"none"," · ").concat(null!==(r=d.nObs[n])&&void 0!==r?r:0," days")})]}),n)}):null]}))}},legend:{position:"bottom",toggle:!0},style:{chartHeight:220,yAxisWidth:60,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}})}))})),t("div",e({className:"ag-corr__metrics"},{children:pe.drivers.map(function(n){var i,r=null!==(i=n.strength)&&void 0!==i?i:"none";return a("div",e({className:"ag-corr__metric"},{children:[t("span",e({className:"ag-corr__name"},{children:n.label||P.kpiLabel(n.kpiId)})),n.kpiId!==pe.kpiId?t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(r)},{children:me[r]})):null,t("strong",{children:j(n.value)}),t("span",e({className:"ag-corr__delta"},{children:null!=n.deltaPct?a(l,{children:[a("span",e({className:"ag-dod__value ag-dod__value--".concat(n.tone||"flat")},{children:["up"===n.direction?"↑":"down"===n.direction?"↓":"→"," ",Math.abs(n.deltaPct),"%"]}))," vs. ",j(n.previous)]}):"—"})),n.kpiId!==pe.kpiId?a("span",e({className:"ag-corr__r"},{children:[n.nObs," days used",n.lowHistory?" · Low history":"",t("br",{}),null==n.movedWithToday?"No comparison for today":n.movedWithToday?"Moved together with the headline today":"Moved opposite the headline today"]})):null]}),n.kpiId)})})),P.viewer.isAdmin&&ce?a("div",e({className:"ag-corr__window"},{children:[a("label",e({className:"ag-corr__start"},{children:["Ignore data before ",t("input",{type:"date",value:G,onChange:function(e){return E(e.target.value)}})]})),a("div",e({className:"ag-corr__days-label"},{children:["Or leave out individual dates (",z.length," selected)"]})),t("div",e({className:"ag-corr__days","aria-label":"Days to leave out"},{children:pe.series.map(function(i){return t("button",e({type:"button","aria-pressed":z.includes(i.x),className:z.includes(i.x)?"is-selected":void 0,onClick:function(){return e=i.x,U(function(i){return i.includes(e)?i.filter(function(n){return n!==e}):n(n([],i,!0),[e],!1)});var e}},{children:we(i.x)}),i.x)})})),t("input",{className:"ag-corr__reason",value:V,onChange:function(e){return J(e.target.value)},placeholder:"Reason required to apply"}),ee?t("p",e({className:"ins-error"},{children:ee})):null,a("div",e({className:"ag-corr__actions"},{children:[t("button",e({type:"button",className:"ins-link",onClick:function(){return $({disregardBefore:G||void 0,disregardDates:z})}},{children:"Preview"})),t("button",e({type:"button",className:"ins-button",disabled:Boolean(re),onClick:function(){return i(x,void 0,void 0,function(){var e,n;return r(this,function(i){switch(i.label){case 0:if(!P||!B||!V.trim())return ne("A reason is required."),[2];ne(null),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,K(P.api,T,{kpiId:B,startDate:G||null,excludedDates:z,dataDay:I,changeReason:V.trim(),regenerate:!0})];case 2:return e=i.sent(),te(e.jobId),[3,4];case 3:return n=i.sent(),ne(n.message||"The correlation window couldn't be saved."),[3,4];case 4:return[2]}})})}},{children:"Apply"})),t("button",e({type:"button",className:"ins-link",onClick:function(){E(""),U([]),$({})}},{children:"Clear"}))]}))]})):null]}))}))}var De=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function xe(n){var i,r=n.entityKey,l=n.kpis,s=n.nodeKeys,u=n.workingDays,v=n.group,p=n.onOpenPoint,g=S(),h=o(null!==(i=l[0])&&void 0!==i?i:""),m=h[0],y=h[1];c(function(){var e;l.includes(m)||y(null!==(e=l[0])&&void 0!==e?e:"")},[l,m]);var f=R(g&&m&&null!==v&&0!==(null==s?void 0:s.length)?function(n){return I(g.api,e(e({},g.range),{workingDaysOnly:u,group:v||void 0}),s?{kpiIds:[m],nodeKeys:s.slice(0,le)}:{kpiIds:[m],entityKey:r,topN:3},n)}:null,[null==g?void 0:g.api.configId,null==g?void 0:g.rangeKey,r,m,null==s?void 0:s.join(","),u,v,null==g?void 0:g.revision]),k=f.data,_=f.loading,w=f.error,N=d(function(){var e;return 0===(null==s?void 0:s.length)?[]:(null!==(e=null==k?void 0:k.series)&&void 0!==e?e:[]).filter(function(e){return e.kpiId===m&&e.points.some(function(e){return Number.isFinite(e.y)})})},[k,s,m]),D=o(new Set),x=D[0],K=D[1];c(function(){return K(new Set)},[N]);var C=d(function(){return Array.from(new Set(N.flatMap(function(e){return e.points.map(function(e){return e.x})}))).sort()},[N]),T=d(function(){return N.map(function(e,n){var i,r=new Map(e.points.map(function(e){return[e.x,e.y]})),t=null!==(i=null==g?void 0:g.goodDirection(e.kpiId))&&void 0!==i?i:"up";return{key:"row_".concat(n,"_").concat(e.nodeKey.replace(/[^a-zA-Z0-9_]/g,"_")),label:e.label||e.nodeKey,color:["#06B6D4","#10A66A","#8650FF","#F59E0B","#E94BBD","#4285FF","#64748B","#F04444","#14B8A6","#84CC16"][n%10],curve:"smooth",pointRadius:3,activePointRadius:3,fillPointsOnHover:!0,data:C.map(function(e){var n;return{x:e,y:null!==(n=r.get(e))&&void 0!==n?n:null}}),valueFormatter:function(e){return j(e)},markers:e.points.filter(function(e){var n;return null===(n=e.meta)||void 0===n?void 0:n.marker}).map(function(n){return{x:n.x,color:Z(n.meta.marker.movementType,n.meta.marker.direction,t),label:[n.meta.marker.criticality,n.meta.marker.headline].filter(Boolean).join(" · "),radius:3,haloRadius:3,onClick:function(){var i,r=null!==(i=e.label)&&void 0!==i?i:e.nodeKey;p?p({nodeKey:e.nodeKey,label:r,kpiId:e.kpiId,dataDay:n.x,reportId:n.meta.marker.reportId}):null==g||g.openReport(n.meta.marker.reportId?{reportId:n.meta.marker.reportId,title:"".concat(r," · ").concat(O(n.x))}:{nodeKey:e.nodeKey,kpiId:e.kpiId,dataDay:n.x,title:"".concat(r," · ").concat(O(n.x))})}}})}})},[N,C,g,p]);if(!g)return null;var A=g.kpiLabel(m);return a("div",e({className:"ag-row-trend"},{children:[l.length>1?t("div",e({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:l.map(function(n){return t("button",e({type:"button","aria-pressed":n===m,className:n===m?"is-active":void 0,onClick:function(){return y(n)}},{children:g.kpiLabel(n)}),n)})})):null,w?t("div",e({className:"ag-empty"},{children:"This chart is unavailable right now."})):_?t(X,{height:240,label:"Loading trend"}):C.length?t("div",e({className:"ag-chart"},{children:a("div",e({className:"ellm-graph"},{children:[t(b,{tier:"decision-advantage-".concat(r),series:T,hiddenKeys:x,onToggleSeries:function(e){return K(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.size<T.length-1&&i.add(e),i})},onPointClick:function(e){var n,i,r,t,a,l,o=e.series,d=e.point,c=e.index,s=T.findIndex(function(e){return e.key===o.key}),u=N[s],v=null!==(n=d.x)&&void 0!==n?n:null===(i=o.data[c])||void 0===i?void 0:i.x,h=null==u?void 0:u.points.find(function(e){return e.x===String(v)});if(u&&h){var m=null!==(r=u.label)&&void 0!==r?r:u.nodeKey,y=null!==(l=null===(a=null===(t=h.meta)||void 0===t?void 0:t.marker)||void 0===a?void 0:a.reportId)&&void 0!==l?l:null;p?p({nodeKey:u.nodeKey,label:m,kpiId:u.kpiId,dataDay:h.x,reportId:y}):g.openReport(y?{reportId:y,title:"".concat(m," · ").concat(O(h.x))}:{nodeKey:u.nodeKey,kpiId:u.kpiId,dataDay:h.x,title:"".concat(m," · ").concat(O(h.x))})}},xAxis:{label:"Date",categories:C,tickCount:8,minTickGap:24,formatTick:function(e){return O(e)}},yAxis:{label:A,beginAtZero:!0,formatTick:function(e){return j(Number(e))}},tooltip:{formatHeading:function(e){return String(e)}},legend:{show:!1},style:{chartHeight:240,yAxisWidth:70,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}}),t("div",e({className:"ellm-graph__legend ellm-chart__legend--bottom ellm-chart__legend--center"},{children:T.map(function(n){var i=x.has(n.key);return a("label",e({title:n.label,className:"ellm-graph__legend-item ag-legend-item".concat(i?" ellm-graph__legend-item--off":""),style:{cursor:"pointer","--checkbox-color":n.color,color:n.color}},{children:[t("input",{type:"checkbox",className:"ellm-graph__legend-checkbox",checked:!i,onChange:function(){return K(function(e){var i=new Set(e);return i.has(n.key)?i.delete(n.key):i.size<T.length-1&&i.add(n.key),i})},style:{borderColor:n.color,accentColor:n.color}}),t("span",{children:n.label})]}),n.key)})}))]}))})):t("div",e({className:"ag-empty"},{children:"Not enough history yet for a trend chart."}))]}))}function Ke(d){var s,u=this,v=d.tab,p=d.partName,g=d.kpiIds,h=d.rankBy,m=d.search,y=d.graphed,f=d.onToggleGraph,b=d.onOpenRow,k=d.onFirstRow,w=d.onInitialGraph,N=d.fallbackDay,D=S(),x=Math.min(200,Math.max(1,Number(v.pageSize)||5)),K=o([]),I=K[0],C=K[1],T=o(null),L=T[0],P=T[1],B=o(!1),R=B[0],F=B[1],M=o({loading:!0,error:null}),O=M[0],G=M[1],z=o(),U=z[0],H=z[1],Z=function(e,t){return i(u,void 0,void 0,function(){var i,a;return r(this,function(r){switch(r.label){case 0:if(!D)return[2];G({loading:!0,error:null}),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,A(D.api,v.entityKey,D.range,{sort:h,order:"desc",search:m||void 0,pageSize:x,cursor:null!=e?e:void 0,includeChildren:3},t)];case 2:return i=r.sent(),(null==t?void 0:t.aborted)?[2]:(H(i.context),C(function(r){return e?n(n([],r,!0),i.rows,!0):i.rows}),P(i.nextCursor),F(i.hasNext),G({loading:!1,error:null}),[3,4]);case 3:return a=r.sent(),(null==t?void 0:t.aborted)||"AbortError"===(null==a?void 0:a.name)?[2]:(G({loading:!1,error:a.message||"Couldn't load the rows."}),[3,4]);case 4:return[2]}})})},$=null===(s=I[0])||void 0===s?void 0:s.nodeKey;c(function(){return null==k?void 0:k($)},[$]);var X=I.slice(0,3).map(function(e){return e.nodeKey}),Y=X.join("\0");if(c(function(){O.loading||null==w||w(X)},[O.loading,Y]),c(function(){var e=new AbortController;return Z(null,e.signal),function(){return e.abort()}},[null==D?void 0:D.api.configId,null==D?void 0:D.rangeKey,v.entityKey,h,m,x,null==D?void 0:D.revision]),!D)return null;var ee,ne=D.goodDirection(h),ie=g.filter(function(e){return e!==h}).slice(0,2),te=(ee=p.trim().toLowerCase())?/(s|x|ch|sh)$/.test(ee)?"".concat(ee,"es"):/[^aeiou]y$/.test(ee)?"".concat(ee.slice(0,-1),"ies"):"".concat(ee,"s"):"rows";return t(q,e({title:"Top Drivers for ".concat(de(te))},{children:O.error?t("p",e({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):O.loading&&!I.length?t(W,{widths:[80,60,85,55,75],label:"Loading drivers"}):I.length?a(l,{children:[t(E,{context:U}),t(be,e({label:de(p),rightLabel:"User Activity · selected dates"},{children:I.map(function(n){var i,r,o,d,c=null===(i=n.metrics)||void 0===i?void 0:i[h],s=n.label||n.nodeKey,u=y.includes(n.nodeKey);return t(fe,{rank:n.rank,name:s,chips:a(l,{children:[t(V,{criticality:null===(r=n.chip)||void 0===r?void 0:r.criticality}),t(J,{movementType:null===(o=n.chip)||void 0===o?void 0:o.movementType,direction:null===(d=n.chip)||void 0===d?void 0:d.direction,good:ne})]}),action:t(ye,{on:u,disabled:!u&&y.length>=le,onClick:function(){return f(n.nodeKey)}}),lines:a("span",e({className:"ag-driver__cost"},{children:[a("span",e({className:"ag-driver__total"},{children:[j(null==c?void 0:c.value)," ",D.kpiLabel(h).toLowerCase()]})),null!=(null==c?void 0:c.deltaPct)?t("span",e({className:"ag-driver__sep"},{children:"|"})):null,t(Q,{deltaPct:null==c?void 0:c.deltaPct,good:ne,direction:null==c?void 0:c.direction,tone:null==c?void 0:c.tone,suffix:"vs previous period"})]})),cell:ie.map(function(i){var r,l,o=null===(r=n.metrics)||void 0===r?void 0:r[i],d=null!==(l=null==o?void 0:o.tone)&&void 0!==l?l:re(null==o?void 0:o.deltaPct,D.goodDirection(i)),c="up"===(null==o?void 0:o.direction)?"↑":"down"===(null==o?void 0:o.direction)?"↓":"flat"===(null==o?void 0:o.direction)?"→":null!=(null==o?void 0:o.deltaPct)&&o.deltaPct>0?"↑":null!=(null==o?void 0:o.deltaPct)&&o.deltaPct<0?"↓":"→";return a("span",e({className:"ag-driver__activity"},{children:[t("strong",e({className:"good"===d?"ag-text--good":"bad"===d?"ag-text--bad":void 0},{children:null==(null==o?void 0:o.deltaPct)?j(null==o?void 0:o.value):"".concat(c).concat(Math.abs(o.deltaPct),"%")})),t("span",{children:D.kpiLabel(i)})]}),i)}),onOpen:function(){var e;return b(n,h,N||(null===(e=n.chip)||void 0===e?void 0:e.dataDay)||_(D.range.endDate))}},n.nodeKey)})})),R?t("div",e({className:"ag-more"},{children:t("button",e({type:"button",disabled:O.loading,onClick:function(){return Z(L)}},{children:O.loading?"Loading...":"Show more"}))})):null]}):t("p",e({className:"ag-muted"},{children:m?"No ".concat(te," match “").concat(m,"”."):"No ".concat(te," for this period yet.")}))}))}function Ie(i){var r,d,s,u,v,g,h,m,y,f,b,k,w,x,K,I=i.tab,C=i.title,T=i.partName,A=i.partKpis,L=i.search,P=i.dataDay,B=i.onOpenRow,j=S(),F=o(Boolean(null==j?void 0:j.defaultWorkingDays)),M=F[0],O=F[1],W=R(j?function(e){return N(j.api,e)}:null,[null==j?void 0:j.api.configId,null==j?void 0:j.revision]),z=o(null),U=z[0],H=z[1];c(function(){var e,n;null===U&&((null===(e=W.data)||void 0===e?void 0:e.groups.length)?H((null!==(n=W.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:W.data.groups[0]).groupKey):W.loading||H(""))},[U,W.data,W.loading]);var Z=o(null),$=Z[0],q=Z[1],V=o(),J=V[0],Q=V[1],X=!1!==I.showSummary,re=R(j&&X?function(e){return D(j.api,I.entityKey,j.range,e)}:null,[null==j?void 0:j.api.configId,null==j?void 0:j.rangeKey,I.entityKey,X,null==j?void 0:j.revision]);if(!j)return null;var te=(null===(r=I.listKpis)||void 0===r?void 0:r.length)?I.listKpis:A,ae=I.rankBy&&te.includes(I.rankBy)?I.rankBy:null!==(d=te[0])&&void 0!==d?d:"",de=null===(s=re.data)||void 0===s?void 0:s.report,ce=De(null===(u=re.data)||void 0===u?void 0:u.context),se=null!==(v=null!=P?P:ce)&&void 0!==v?v:_(j.range.endDate),ue=function(n){return P?e(e({},n),{report:e(e({},n.report),{reportId:null})}):n},ge=j.goodDirection(ae),he=null!==(g=I.tier1Kpis)&&void 0!==g?g:j.tierKpis[1],me=null!==(h=I.tier2Kpis)&&void 0!==h?h:j.tierKpis[2],ye=j.headlineKpi||ae||he[0]||"",fe=function(e){var n=e.nodeKey,i=e.label,r=e.dataDay;return B({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:ye},action:null,children:[]},ye,r)},be=j.drill.tabTables[I.entityKey],ke=be?t(G,{table:e(e({},be),{pageSize:null!==(y=null!==(m=be.pageSize)&&void 0!==m?m:I.pageSize)&&void 0!==y?y:void 0}),tabEntityKey:I.entityKey,context:{trail:[],day:se},onRowClick:function(e,n){var i;return"report"===n?j.openReport({reportId:P?null:e.report.reportId,nodeKey:e.nodeKey,kpiId:ae,dataDay:se,title:null!==(i=e.label)&&void 0!==i?i:e.nodeKey}):"drill"===n?B(ue(e),ae,se):void 0}}):null;return a("section",e({className:"ag-report","aria-label":"L2 Report · ".concat(C)},{children:[a("div",e({className:"ag-report__header"},{children:[a("h2",e({className:"ag-report__title"},{children:[t(p,{"aria-hidden":"true"}),"L2 Report"]})),t("span",e({className:"ag-report__scope"},{children:C})),ce?t("span",e({className:"ag-report__date"},{children:ee(ce)})):null]})),a("div",e({className:"ag-report__grid ag-report__grid--l2"},{children:[t("div",e({className:"ag-report__analysis-scroll",role:"region","aria-label":"".concat(C," analysis"),tabIndex:0},{children:a("div",e({className:"ag-stack"},{children:[X?a(l,{children:[a("div",{children:[t(ne,{title:"Summary",action:t(oe,{entityKey:I.entityKey,dataDay:ce})}),t(ve,{report:de,loading:re.loading,error:re.error,good:ge})]}),t(pe,{report:de,error:re.error,loading:re.loading}),t(E,{context:null===(f=re.data)||void 0===f?void 0:f.context})]}):null,te.length?t(Ke,{tab:I,partName:T,kpiIds:te,rankBy:ae,search:L,graphed:null!=$?$:[],onToggleGraph:function(e){return q(function(i){var r=null!=i?i:[];return r.includes(e)?r.filter(function(n){return n!==e}):r.length<le?n(n([],r,!0),[e],!1):r})},onOpenRow:function(e,n,i){return B(ue(e),n,i)},onFirstRow:Q,onInitialGraph:function(e){return q(function(n){return null!=n?n:e})},fallbackDay:se}):null]}))})),a("div",e({className:"ag-stack"},{children:[he.length?t(Y,e({title:"Trend",action:t(ie,{value:M,onChange:O,groups:W.error||null===(b=W.data)||void 0===b?void 0:b.groups,group:U,onGroupChange:H})},{children:t(xe,{entityKey:I.entityKey,kpis:he,nodeKeys:$,workingDays:M,group:U,onOpenPoint:fe})})):null,me.length?t(Y,e({title:j.labels.activityTitle,meta:$?"Selected rows":"Top ".concat(3," ").concat(j.entityPluralName(I.entityKey))},{children:t(xe,{entityKey:I.entityKey,kpis:me,nodeKeys:$,workingDays:M,group:U,onOpenPoint:fe})})):null,t(Ne,{dataDay:ce,nodeKey:null!==(k=null==$?void 0:$[0])&&void 0!==k?k:J,dayGroup:null===(x=null===(w=W.data)||void 0===w?void 0:w.groups.find(function(e){return e.groupKey===U}))||void 0===x?void 0:x.days}),"column"===(null==be?void 0:be.width)?ke:null]}))]})),be&&"full"===(null!==(K=be.width)&&void 0!==K?K:"full")?ke:null]}))}export{ye as AddToGraph,Ne as CorrelationSection,pe as DecisionCard,be as DriverList,fe as DriverRow,Ie as L2Report,le as MAX_SERIES,oe as RegenerateSummary,Ke as RowDrivers,xe as RowTrend,ve as SummaryCard,ke as TopDriversSection,se as decisionCardNotice,De as reportDayOf,ue as stripRowTags,de as titleCase};
|
|
1
|
+
import{__assign as e,__spreadArray as n,__awaiter as i,__generator as r}from"../../../_virtual/_tslib.js";import{jsx as t,jsxs as a,Fragment as l}from"react/jsx-runtime";import{useState as o,useMemo as d,useEffect as c,useRef as s}from"react";import{Info as u,Settings2 as v,Sparkles as p,TrendingUp as g,ArrowUpRight as h}from"lucide-react";import{ReasoningTrigger as m,ReasoningPanel as y,RcaDecisionComponent as f}from"../RcaDecisionComponent/RcaDecisionComponent.js";import b from"../Graph/LineChart.js";import{fetchInsightsCorrelation as k,toIsoDay as _,fetchInsightsCorrelationTrend as w,fetchGraphGroups as N,fetchLevelSummary as D,fetchInsightsDrivers as x,saveCorrelationWindow as K,fetchInsightsSeries as I,generateInsightsSummary as C,generateLevelSummary as T,fetchLevelRows as A}from"../../api/insightsApi.js";import{useInsights as S}from"./insightsContextCore.js";import{reportDecisioning as L,useOpenRow as P,toRcaItems as B,useInsightsFetch as R,formatValue as j,previousDayLabel as F,useJob as M,shortDay as O}from"./insightsUtils.js";import G from"./DrillTable.js";import{resolveL2SummaryRange as E,resolveDrillDay as W}from"./drillDay.js";import z from"./FilterNotice.js";import{SkeletonLines as U,splitVerdict as H,movementVerdictLabel as Z,verdictToneHex as $,movementColorHex as q,VerdictSentence as V,ReportAccordion as J,CriticalityChip as Q,MovementChip as X,DayOverDayChange as Y,ChartSkeleton as ee,CollapsibleVisualSection as ne,formatHeaderDate as ie,SectionHeader as re,DaysDropdown as te,toneOf as ae}from"./agPrimitives.js";import le,{useNeedsAttention as oe}from"./NeedsAttention.js";var de=10;function ce(n){var l,d=this,c=n.entityKey,s=n.dataDay,u=S(),v=o(null),p=v[0],g=v[1],h=o(null),m=h[0],y=h[1];if(M(p,null!==(l=null==u?void 0:u.api)&&void 0!==l?l:null,function(){g(null),null==u||u.refresh()}),!(null==u?void 0:u.viewer.isAdmin))return null;return a("span",{children:[t("button",e({type:"button",className:"ins-link",disabled:Boolean(p),onClick:function(){return i(d,void 0,void 0,function(){var e,n,i,t;return r(this,function(r){switch(r.label){case 0:y(null),r.label=1;case 1:return r.trys.push([1,6,,7]),e={dataDay:s||_(u.range.endDate),window:"both"},c?[4,T(u.api,c,e)]:[3,3];case 2:return i=r.sent(),[3,5];case 3:return[4,C(u.api,e)];case 4:i=r.sent(),r.label=5;case 5:return(n=i).jobId?g(n.jobId):u.refresh(),[3,7];case 6:return t=r.sent(),y(t.message||"The summary couldn't be regenerated."),[3,7];case 7:return[2]}})})}},{children:p?"Regenerating…":"Regenerate summary"})),m?t("span",e({className:"ins-error"},{children:m})):null]})}var se=function(e){return e.replace(/\b\w/g,function(e){return e.toUpperCase()})};function ue(e,n){return n?"Decision Advantage is unavailable right now: ".concat(n.message):e?"waiting"===e.status?"The first morning run hasn't finished yet. This fills in after it.":"running"===e.status?"The AI is writing this report. It usually takes a minute or two.":"generated"!==e.status?"No report generated for this day.":null:null}function ve(e,n,i){return i?null:ue(e,n)}function pe(e){return e.replace(/\{\{([^|}]*)\|[^}]*\}\}/g,"$1")}function ge(n){var i,r,l=n.report,s=n.movementType,u=n.direction,v=n.good,p=n.loading,g=n.error,h=o(!1),f=h[0],b=h[1],k=d(function(){return L(l)},[l]);if(c(function(){return b(!1)},[null==l?void 0:l.reportId]),p)return t("div",e({className:"ag-summary"},{children:t(U,{widths:[28,96,72],label:"Loading summary"})}));var _=null==l?void 0:l.summary,w=null!==(i=null==_?void 0:_.headline)&&void 0!==i?i:"",N=Boolean(w),D=H(w).prefix,x=Boolean(null==_?void 0:_.eyebrow)&&"Movement unavailable"!==(null==_?void 0:_.eyebrow),K=void 0!==s,I=x?_.eyebrow:K?Z(s,u):D||"Summary",C=x?"good"===_.tone||"bad"===_.tone?$(_.tone):q(_.movementType,_.movementDirection,v):K?q(s,u,v):"Good news"===D?"#15803D":"Bad news"===D?"#E11D48":"#5928ED";return a("div",e({className:"ag-summary"},{children:[t("p",e({className:"ag-summary__title",style:{color:N?C:"#64748b"}},{children:N?I:"No summary yet"})),a("div",e({className:"ag-summary__text"},{children:[N?t(V,{text:w,good:v}):null!==(r=ue(l,g))&&void 0!==r?r:"Reports are written after each morning run.",N&&k?t("span",e({className:"ag-summary__brain"},{children:t(m,{open:f,onToggle:function(){return b(function(e){return!e})},label:"how the AI reached this summary"})})):null]})),f&&k?t("div",e({className:"ag-summary__reasoning"},{children:t(y,{decisioning:k})})):null]}))}function he(e){var n,i,r,a=e.report,l=e.error,o=e.loading,c=S(),s=!o&&"generated"===(null==a?void 0:a.status),u=d(function(){return s?L(a,null==a?void 0:a.footer):null},[s,a]),v=P();return t(f,{className:"ag-decision",title:null!==(n=null==c?void 0:c.labels.decisionAdvantageTitle)&&void 0!==n?n:"Decision Advantage",score:s?null==a?void 0:a.score:null,decisioning:u,notice:ve(a,l,o),afterSections:o?t(U,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:s?B(null==a?void 0:a.rootCause,v):[],nextSteps:s?B(null==a?void 0:a.nextSteps,v):[],width:"100%",maxWidth:"none"},"".concat(null!==(i=null==a?void 0:a.reportId)&&void 0!==i?i:"pending",":").concat(null!==(r=null==a?void 0:a.generatedAt)&&void 0!==r?r:""))}var me=[{key:"drivers",label:"driversTab",info:"What moved the day's number the same way."},{key:"headwinds",label:"headwindsTab",info:"What moved against the day's number."},{key:"attention",label:"attentionTab",info:"The number moved, but activity doesn't explain it."}],ye={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},fe={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function be(n){var i=n.on,r=n.onClick,l=n.disabled,o=void 0!==l&&l;return a("button",e({type:"button",className:"ag-graph-pill".concat(i?" is-on":""),disabled:o,title:o?"A graph can show up to ".concat(de," rows"):void 0,onClick:function(e){e.stopPropagation(),r()}},{children:[t(g,{"aria-hidden":"true"}),i?"In graph":o?"Graph full":"Add to graph"]}))}function ke(n){var i=n.rank,r=n.category,l=n.name,o=n.chips,d=n.action,c=n.lines,s=n.cell,u=n.onOpen;return t("li",{children:a("div",e({className:"ag-driver".concat(u?" is-clickable":""),role:u?"button":void 0,tabIndex:u?0:void 0,onClick:u,onKeyDown:u?function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u())}:void 0},{children:[a("div",e({className:"ag-driver__main"},{children:[a("span",e({className:"ag-driver__rank"},{children:[i,"."]})),a("div",e({className:"ag-driver__body"},{children:[r?a("span",e({className:"ag-driver__category"},{children:[r," >"]})):null,t("span",e({className:"ag-driver__name"},{children:l})),a("div",e({className:"ag-driver__chips"},{children:[o,d]})),c]}))]})),a("div",e({className:"ag-driver__cell"},{children:[s,u?t("span",e({className:"ag-driver__open","aria-hidden":"true"},{children:t(h,{})})):null]}))]}))})}function _e(n){var i,r=n.label,l=n.rightLabel,o=n.children,d=S();return a("div",e({className:"ag-drivers"},{children:[a("div",e({className:"ag-drivers__head"},{children:[t("span",{children:r}),t("span",{children:null!==(i=null!=l?l:null==d?void 0:d.labels.activityColumn)&&void 0!==i?i:"User Activity"})]})),t("ol",{children:o})]}))}function we(n){var i,r,d,s,v,p,g,h,m,y=n.dataDay,f=n.entityKey,b=n.parentNodeKey,k=n.kpiId,_=n.title,w=n.graphed,N=n.onToggleGraph,D=n.onOpenDriver,K=n.onDecisionSettled,I=n.initialTab,C=void 0===I?"drivers":I,T=S(),A=o(C),L=A[0],P=A[1],B=o({drivers:1,headwinds:1,attention:1}),M=B[0],O=B[1],G=null!==(i=null!=k?k:null==T?void 0:T.headlineKpi)&&void 0!==i?i:void 0,E=function(e){return T&&G&&e===L?function(n){return x(T.api,{dataDay:y,kpiId:G,entityKey:f,parentNodeKey:b,tab:e,limit:Math.min(10,(b?10:3)*M[e]),offset:0,filters:T.range.filters},n)}:null},W=function(e){return[null==T?void 0:T.api.configId,null==T?void 0:T.rangeKey,y,G,f,b,e,L,M[e],null==T?void 0:T.revision]},z={drivers:R(E("drivers"),W("drivers")),headwinds:R(E("headwinds"),W("headwinds")),attention:R(E("attention"),W("attention"))},U=z[L],H=U.data,Z=U.error,$=U.loading,q=null!==(v=null!==(d=null===(r=z.drivers.data)||void 0===r?void 0:r.tabs)&&void 0!==d?d:null===(s=z.headwinds.data)||void 0===s?void 0:s.tabs)&&void 0!==v?v:null===(p=z.attention.data)||void 0===p?void 0:p.tabs,ee=oe(y,b,G),ne=null!==(h=null===(g=ee.data)||void 0===g?void 0:g.counts.pending)&&void 0!==h?h:0;if(c(function(){return O({drivers:1,headwinds:1,attention:1})},[y]),c(function(){return P(C)},[C]),!T)return null;var ie=T.goodDirection(null!=G?G:""),re=null!==(m=null==H?void 0:H.rows)&&void 0!==m?m:[];return a(J,e({title:_},{children:[t("div",e({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:me.map(function(n){return t("button",e({type:"button",role:"tab","aria-selected":L===n.key,className:L===n.key?"is-active":void 0,onClick:function(){return P(n.key)},title:n.info},{children:a(l,{children:[T.labels[n.label],(null==q?void 0:q[n.key])?" (".concat(q[n.key].total,")"):"","attention"===n.key&&ne?a("span",e({className:"ag-na__tab-badge",title:"".concat(ne," data points need a decision")},{children:[ne,t("span",e({className:"ins-visually-hidden"},{children:" data points need a decision"}))]})):null,t(u,{"aria-hidden":"true"})]})}),n.key)})})),"attention"===L?t(le,{dataDay:y,nodeKey:b,kpiId:G,attention:ee,onDecisionSettled:K}):null,"attention"===L&&re.length?t("h4",e({className:"ag-na__subhead"},{children:"Rows that moved without a clear cause"})):null,Z?a("p",e({className:"ag-muted"},{children:["Top drivers are unavailable right now: ",Z.message]})):$&&!H?t("p",e({className:"ag-muted"},{children:"Loading drivers..."})):re.length?a(l,{children:[t(_e,e({label:"Driver",rightLabel:T.labels.activityColumn},{children:re.map(function(n){var i,r,o,d,c,s,u,v,p,g=n.deltaContributionPct,h=w.includes(n.nodeKey),m=(null===(i=n.decisionAdvantage)||void 0===i?void 0:i.correlationSentence)||(null===(r=n.decisionAdvantage)||void 0===r?void 0:r.firstCause)||(null===(o=n.decisionAdvantage)||void 0===o?void 0:o.headline);return t(ke,{rank:n.rank,category:T.labels.driverCategory.replace("{plural}",n.entityKey?T.entityPluralName(n.entityKey):""),name:n.label,chips:a(l,{children:[t(Q,{criticality:n.criticality}),t(X,{movementType:n.movementType,direction:n.changeDirection,good:ie}),(null===(d=n.correlation)||void 0===d?void 0:d.strength)?t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(n.correlation.strength)},{children:fe[n.correlation.strength]})):null]}),action:N?t(be,{on:h,disabled:!h&&w.length>=de,onClick:function(){return N(n)}}):void 0,lines:a(l,{children:[null!=g?a("span",e({className:"ag-driver__share"},{children:[T.labels.shareLine.replace("{share}",String(Math.abs(g)))," · ","opposite"===n.direction?T.labels.movedOpposite:T.labels.movedWith]})):null,a("span",e({className:"ag-driver__cost"},{children:[t("span",e({className:"ag-driver__total"},{children:j(n.value)})),null!=n.deltaPct?t("span",e({className:"ag-driver__sep"},{children:"|"})):null,t(Y,{deltaPct:n.deltaPct,good:ie,direction:n.changeDirection,tone:n.tone,suffix:F(y)})]})),m?t("p",e({className:"ag-driver__brief"},{children:t(V,{text:pe(m),good:ie,arrowsFollowVerdict:!0})})):null,(null===(c=n.decisionAdvantage)||void 0===c?void 0:c.nextStep)?a("p",e({className:"ag-driver__brief"},{children:[t("strong",{children:"Next:"})," ",pe(n.decisionAdvantage.nextStep)]})):null]}),cell:a("span",e({className:"ag-driver__activity"},{children:[t("strong",{children:j(null!==(u=null===(s=n.drivingMetric)||void 0===s?void 0:s.value)&&void 0!==u?u:n.previous)}),t("span",{children:(null===(v=n.drivingMetric)||void 0===v?void 0:v.label)||((null===(p=n.drivingMetric)||void 0===p?void 0:p.kpiId)?T.kpiLabel(n.drivingMetric.kpiId):"opposite"===n.direction?"Moved opposite":"with"===n.direction?"Moved with":"Previous")})]})),onOpen:function(){var e;return D?D(n):T.openReport({reportId:null===(e=n.report)||void 0===e?void 0:e.reportId,nodeKey:n.nodeKey,kpiId:G,dataDay:y,title:n.label})}},n.nodeKey)})})),(null==H?void 0:H.hasMore)?t("div",e({className:"ag-more"},{children:t("button",e({type:"button",disabled:$,onClick:function(){return O(function(n){var i;return e(e({},n),((i={})[L]=n[L]+1,i))})}},{children:$?"Loading...":"Show more"}))})):null]}):t("p",e({className:"ag-muted"},{children:ye[L]}))]}))}var Ne=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],De=function(e,n){void 0===n&&(n="en-GB");var i=e.slice(0,10).split("-").map(Number),r=i[0],t=i[1],a=i[2];return Number.isFinite(r)&&Number.isFinite(t)&&Number.isFinite(a)?new Intl.DateTimeFormat(n,{day:"numeric",month:"short"}).format(new Date(r,t-1,a)):e};function xe(u){var p,g,h,m,y,f,N,D,x=this,I=u.dataDay,C=u.nodeKey,T=void 0===C?"root":C,A=u.kpiId,L=u.dayGroup,P=S(),B=null!==(p=null!=A?A:null==P?void 0:P.headlineKpi)&&void 0!==p?p:void 0,F=o(""),G=F[0],E=F[1],W=o([]),z=W[0],U=W[1],H=o({}),Z=H[0],$=H[1],q=o(""),V=q[0],J=q[1],Q=o(null),X=Q[0],Y=Q[1],ie=o(null),re=ie[0],te=ie[1],ae=o(!1),le=ae[0],oe=ae[1],de=o(!1),ce=de[0],se=de[1],ue=s(null),ve=R(P&&B&&I?function(n){return k(P.api,T,e({kpiId:B,dataDay:I,startDate:_(P.range.startDate),endDate:_(P.range.endDate),filters:P.range.filters},Z),n)}:null,[null==P?void 0:P.api.configId,null==P?void 0:P.rangeKey,I,B,T,Z.disregardBefore,null===(g=Z.disregardDates)||void 0===g?void 0:g.join(","),null==P?void 0:P.revision]),pe=ve.data,ge=ve.error,he=ve.loading,me=R(P&&B&&I?function(n){return w(P.api,T,e({kpiId:B,startDate:_(P.range.startDate),endDate:_(P.range.endDate),filters:P.range.filters},Z),n)}:null,[null==P?void 0:P.api.configId,null==P?void 0:P.rangeKey,I,B,T,Z.disregardBefore,null===(h=Z.disregardDates)||void 0===h?void 0:h.join(","),null==P?void 0:P.revision]);M(re,null!==(m=null==P?void 0:P.api)&&void 0!==m?m:null,function(){te(null),J(""),null==P||P.refresh()}),c(function(){if(le){var e=function(e){ue.current&&!ue.current.contains(e.target)&&oe(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[le]);var ye=o(new Set),be=ye[0],ke=ye[1],_e=d(function(){if(!pe)return[];return pe.series.filter(function(e){return!(null==L?void 0:L.length)||L.map(Number).includes((n=e.x,new Date("".concat(n.slice(0,10),"T00:00:00")).getDay()||7));var n})},[pe,L]),we=d(function(){return pe&&P?n([pe.kpiId],pe.drivers.map(function(e){return e.kpiId}).filter(function(e){return e!==pe.kpiId}),!0).map(function(e,n){return{key:"corr_".concat(e.replace(/[^a-zA-Z0-9_]/g,"_")),label:P.kpiLabel(e),color:Ne[n%Ne.length],curve:"smooth",strokeWidth:2,pointRadius:2,data:_e.map(function(n){var i,r;return{x:n.x,y:n.disregarded?null:null!==(r=null===(i=n.values)||void 0===i?void 0:i[e])&&void 0!==r?r:null}}),valueFormatter:function(e){return"".concat(e,"%")}}}):[]},[pe,P,_e]);c(function(){return ke(new Set(we.slice(2).map(function(e){return e.key})))},[we]);if(!P||!I||"no_drivers"===(null==pe?void 0:pe.state)||pe&&!pe.verdictText)return null;if(ge)return a("div",e({className:"ag-empty"},{children:["Correlation is unavailable right now: ",ge.message]}));if(he&&!pe)return t(ee,{height:220,label:"Loading correlation"});if(!pe)return null;var xe=null!==(y=pe.strength)&&void 0!==y?y:"none",Ke=P.kpiLabel(pe.kpiId);return t(ne,e({title:"Correlation",meta:"Usage vs. ".concat(Ke),className:"ag-visual--card",action:P.viewer.isAdmin?a("div",e({ref:ue,className:"ag-corr__settings"},{children:[t("button",e({type:"button",className:"ag-icon-button","aria-label":"Correlation settings","aria-expanded":le,onClick:function(){return oe(function(e){return!e})}},{children:t(v,{"aria-hidden":"true"})})),le?t("div",e({className:"ag-corr__settings-menu",role:"menu"},{children:a("label",{children:[t("input",{type:"checkbox",checked:ce,onChange:function(e){return se(e.target.checked)}}),"Show date controls"]})})):null]})):null},{children:a("div",e({className:"ag-corr"},{children:[t("p",e({className:"ag-corr__banner ag-corr__banner--".concat(xe)},{children:pe.verdictText})),t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(xe)},{children:fe[xe]})),a("p",e({className:"ag-corr__caption"},{children:[Ke," vs. usage - % change from the first day shown"]})),(null===(f=pe.window)||void 0===f?void 0:f.source)?t("p",e({className:"ag-muted"},{children:"default"===pe.window.source?pe.window.startDate?"Using all days since ".concat(De(pe.window.startDate,"en-US")):"Using all available days":"row"===pe.window.source?"Saved window".concat(pe.window.startDate?" since ".concat(De(pe.window.startDate,"en-US")):"").concat((null===(N=pe.window.excludedDates)||void 0===N?void 0:N.length)?" · ".concat(pe.window.excludedDates.length," left out"):""):"Preview window".concat((null===(D=pe.window.excludedDates)||void 0===D?void 0:D.length)?" · ".concat(pe.window.excludedDates.length," left out"):"")})):null,t("div",e({className:"ag-chart"},{children:t("div",e({className:"ellm-graph"},{children:t(b,{tier:"decision-advantage-correlation",series:we,hiddenKeys:be,onToggleSeries:function(e){return ke(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i})},onPointClick:function(){},xAxis:{label:"Date",categories:_e.map(function(e){return e.x}),formatTick:function(e){return O(e)}},yAxis:{label:"% change",beginAtZero:!1,formatTick:function(e){return"".concat(Math.round(Number(e)),"%")}},tooltip:{render:function(n){var i,r=n.x,l=n.points,o=String(r),d=null===(i=me.data)||void 0===i?void 0:i.series.find(function(e){return e.x===o});return a("div",e({className:"ag-tip ag-tip--wide"},{children:[t("div",e({className:"ag-tip__head"},{children:De(o)})),l.filter(function(e){return null!=e.value}).map(function(n){return a("div",e({className:"ag-tip__line"},{children:[a("span",{children:[t("i",{style:{background:n.color}}),n.series.label]}),a("strong",{children:[n.value,"%"]})]}),n.series.key)}),d?Object.keys(d.r).map(function(n){var i,r;return a("div",e({className:"ag-tip__sub"},{children:[t("span",{children:P.kpiLabel(n)}),t("span",{children:null==d.r[n]?"No correlation":"r ".concat(d.r[n]," · ").concat(null!==(i=d.strength[n])&&void 0!==i?i:"none"," · ").concat(null!==(r=d.nObs[n])&&void 0!==r?r:0," days")})]}),n)}):null]}))}},legend:{position:"bottom",toggle:!0},style:{chartHeight:220,yAxisWidth:60,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}})}))})),t("div",e({className:"ag-corr__metrics"},{children:pe.drivers.map(function(n){var i,r=null!==(i=n.strength)&&void 0!==i?i:"none";return a("div",e({className:"ag-corr__metric"},{children:[t("span",e({className:"ag-corr__name"},{children:n.label||P.kpiLabel(n.kpiId)})),n.kpiId!==pe.kpiId?t("span",e({className:"ag-driver__badge ag-driver__badge--".concat(r)},{children:fe[r]})):null,t("strong",{children:j(n.value)}),t("span",e({className:"ag-corr__delta"},{children:null!=n.deltaPct?a(l,{children:[a("span",e({className:"ag-dod__value ag-dod__value--".concat(n.tone||"flat")},{children:["up"===n.direction?"↑":"down"===n.direction?"↓":"→"," ",Math.abs(n.deltaPct),"%"]}))," vs. ",j(n.previous)]}):"—"})),n.kpiId!==pe.kpiId?a("span",e({className:"ag-corr__r"},{children:[n.nObs," days used",n.lowHistory?" · Low history":"",t("br",{}),null==n.movedWithToday?"No comparison for today":n.movedWithToday?"Moved together with the headline today":"Moved opposite the headline today"]})):null]}),n.kpiId)})})),P.viewer.isAdmin&&ce?a("div",e({className:"ag-corr__window"},{children:[a("label",e({className:"ag-corr__start"},{children:["Ignore data before ",t("input",{type:"date",value:G,onChange:function(e){return E(e.target.value)}})]})),a("div",e({className:"ag-corr__days-label"},{children:["Or leave out individual dates (",z.length," selected)"]})),t("div",e({className:"ag-corr__days","aria-label":"Days to leave out"},{children:pe.series.map(function(i){return t("button",e({type:"button","aria-pressed":z.includes(i.x),className:z.includes(i.x)?"is-selected":void 0,onClick:function(){return e=i.x,U(function(i){return i.includes(e)?i.filter(function(n){return n!==e}):n(n([],i,!0),[e],!1)});var e}},{children:De(i.x)}),i.x)})})),t("input",{className:"ag-corr__reason",value:V,onChange:function(e){return J(e.target.value)},placeholder:"Reason required to apply"}),X?t("p",e({className:"ins-error"},{children:X})):null,a("div",e({className:"ag-corr__actions"},{children:[t("button",e({type:"button",className:"ins-link",onClick:function(){return $({disregardBefore:G||void 0,disregardDates:z})}},{children:"Preview"})),t("button",e({type:"button",className:"ins-button",disabled:Boolean(re),onClick:function(){return i(x,void 0,void 0,function(){var e,n;return r(this,function(i){switch(i.label){case 0:if(!P||!B||!V.trim())return Y("A reason is required."),[2];Y(null),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,K(P.api,T,{kpiId:B,startDate:G||null,excludedDates:z,dataDay:I,changeReason:V.trim(),regenerate:!0})];case 2:return e=i.sent(),te(e.jobId),[3,4];case 3:return n=i.sent(),Y(n.message||"The correlation window couldn't be saved."),[3,4];case 4:return[2]}})})}},{children:"Apply"})),t("button",e({type:"button",className:"ins-link",onClick:function(){E(""),U([]),$({})}},{children:"Clear"}))]}))]})):null]}))}))}var Ke=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function Ie(n){var i,r=n.entityKey,l=n.kpis,s=n.nodeKeys,u=n.workingDays,v=n.group,p=n.onOpenPoint,g=S(),h=o(null!==(i=l[0])&&void 0!==i?i:""),m=h[0],y=h[1];c(function(){var e;l.includes(m)||y(null!==(e=l[0])&&void 0!==e?e:"")},[l,m]);var f=R(g&&m&&null!==v&&0!==(null==s?void 0:s.length)?function(n){return I(g.api,e(e({},g.range),{workingDaysOnly:u,group:v||void 0}),s?{kpiIds:[m],nodeKeys:s.slice(0,de)}:{kpiIds:[m],entityKey:r,topN:3},n)}:null,[null==g?void 0:g.api.configId,null==g?void 0:g.rangeKey,r,m,null==s?void 0:s.join(","),u,v,null==g?void 0:g.revision]),k=f.data,_=f.loading,w=f.error,N=d(function(){var e;return 0===(null==s?void 0:s.length)?[]:(null!==(e=null==k?void 0:k.series)&&void 0!==e?e:[]).filter(function(e){return e.kpiId===m&&e.points.some(function(e){return Number.isFinite(e.y)})})},[k,s,m]),D=o(new Set),x=D[0],K=D[1];c(function(){return K(new Set)},[N]);var C=d(function(){return Array.from(new Set(N.flatMap(function(e){return e.points.map(function(e){return e.x})}))).sort()},[N]),T=d(function(){return N.map(function(e,n){var i,r=new Map(e.points.map(function(e){return[e.x,e.y]})),t=null!==(i=null==g?void 0:g.goodDirection(e.kpiId))&&void 0!==i?i:"up";return{key:"row_".concat(n,"_").concat(e.nodeKey.replace(/[^a-zA-Z0-9_]/g,"_")),label:e.label||e.nodeKey,color:["#06B6D4","#10A66A","#8650FF","#F59E0B","#E94BBD","#4285FF","#64748B","#F04444","#14B8A6","#84CC16"][n%10],curve:"smooth",pointRadius:3,activePointRadius:3,fillPointsOnHover:!0,data:C.map(function(e){var n;return{x:e,y:null!==(n=r.get(e))&&void 0!==n?n:null}}),valueFormatter:function(e){return j(e)},markers:e.points.filter(function(e){var n;return null===(n=e.meta)||void 0===n?void 0:n.marker}).map(function(n){return{x:n.x,color:q(n.meta.marker.movementType,n.meta.marker.direction,t),label:[n.meta.marker.criticality,n.meta.marker.headline].filter(Boolean).join(" · "),radius:3,haloRadius:3,onClick:function(){var i,r=null!==(i=e.label)&&void 0!==i?i:e.nodeKey;p?p({nodeKey:e.nodeKey,label:r,kpiId:e.kpiId,dataDay:n.x,reportId:n.meta.marker.reportId}):null==g||g.openReport(n.meta.marker.reportId?{reportId:n.meta.marker.reportId,title:"".concat(r," · ").concat(O(n.x))}:{nodeKey:e.nodeKey,kpiId:e.kpiId,dataDay:n.x,title:"".concat(r," · ").concat(O(n.x))})}}})}})},[N,C,g,p]);if(!g)return null;var A=g.kpiLabel(m);return a("div",e({className:"ag-row-trend"},{children:[l.length>1?t("div",e({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:l.map(function(n){return t("button",e({type:"button","aria-pressed":n===m,className:n===m?"is-active":void 0,onClick:function(){return y(n)}},{children:g.kpiLabel(n)}),n)})})):null,w?t("div",e({className:"ag-empty"},{children:"This chart is unavailable right now."})):_?t(ee,{height:240,label:"Loading trend"}):C.length?t("div",e({className:"ag-chart"},{children:a("div",e({className:"ellm-graph"},{children:[t(b,{tier:"decision-advantage-".concat(r),series:T,hiddenKeys:x,onToggleSeries:function(e){return K(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.size<T.length-1&&i.add(e),i})},onPointClick:function(e){var n,i,r,t,a,l,o=e.series,d=e.point,c=e.index,s=T.findIndex(function(e){return e.key===o.key}),u=N[s],v=null!==(n=d.x)&&void 0!==n?n:null===(i=o.data[c])||void 0===i?void 0:i.x,h=null==u?void 0:u.points.find(function(e){return e.x===String(v)});if(u&&h){var m=null!==(r=u.label)&&void 0!==r?r:u.nodeKey,y=null!==(l=null===(a=null===(t=h.meta)||void 0===t?void 0:t.marker)||void 0===a?void 0:a.reportId)&&void 0!==l?l:null;p?p({nodeKey:u.nodeKey,label:m,kpiId:u.kpiId,dataDay:h.x,reportId:y}):g.openReport(y?{reportId:y,title:"".concat(m," · ").concat(O(h.x))}:{nodeKey:u.nodeKey,kpiId:u.kpiId,dataDay:h.x,title:"".concat(m," · ").concat(O(h.x))})}},xAxis:{label:"Date",categories:C,tickCount:8,minTickGap:24,formatTick:function(e){return O(e)}},yAxis:{label:A,beginAtZero:!0,formatTick:function(e){return j(Number(e))}},tooltip:{formatHeading:function(e){return String(e)}},legend:{show:!1},style:{chartHeight:240,yAxisWidth:70,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}}),t("div",e({className:"ellm-graph__legend ellm-chart__legend--bottom ellm-chart__legend--center"},{children:T.map(function(n){var i=x.has(n.key);return a("label",e({title:n.label,className:"ellm-graph__legend-item ag-legend-item".concat(i?" ellm-graph__legend-item--off":""),style:{cursor:"pointer","--checkbox-color":n.color,color:n.color}},{children:[t("input",{type:"checkbox",className:"ellm-graph__legend-checkbox",checked:!i,onChange:function(){return K(function(e){var i=new Set(e);return i.has(n.key)?i.delete(n.key):i.size<T.length-1&&i.add(n.key),i})},style:{borderColor:n.color,accentColor:n.color}}),t("span",{children:n.label})]}),n.key)})}))]}))})):t("div",e({className:"ag-empty"},{children:"Not enough history yet for a trend chart."}))]}))}function Ce(d){var s,u=this,v=d.tab,p=d.partName,g=d.kpiIds,h=d.rankBy,m=d.search,y=d.graphed,f=d.onToggleGraph,b=d.onOpenRow,k=d.onFirstRow,w=d.onInitialGraph,N=d.fallbackDay,D=S(),x=Math.min(200,Math.max(1,Number(v.pageSize)||5)),K=o([]),I=K[0],C=K[1],T=o(null),L=T[0],P=T[1],B=o(!1),R=B[0],F=B[1],M=o({loading:!0,error:null}),O=M[0],G=M[1],E=o(),W=E[0],H=E[1],Z=function(e,t){return i(u,void 0,void 0,function(){var i,a;return r(this,function(r){switch(r.label){case 0:if(!D)return[2];G({loading:!0,error:null}),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,A(D.api,v.entityKey,D.range,{sort:h,order:"desc",search:m||void 0,pageSize:x,cursor:null!=e?e:void 0,includeChildren:3},t)];case 2:return i=r.sent(),(null==t?void 0:t.aborted)?[2]:(H(i.context),C(function(r){return e?n(n([],r,!0),i.rows,!0):i.rows}),P(i.nextCursor),F(i.hasNext),G({loading:!1,error:null}),[3,4]);case 3:return a=r.sent(),(null==t?void 0:t.aborted)||"AbortError"===(null==a?void 0:a.name)?[2]:(G({loading:!1,error:a.message||"Couldn't load the rows."}),[3,4]);case 4:return[2]}})})},$=null===(s=I[0])||void 0===s?void 0:s.nodeKey;c(function(){return null==k?void 0:k($)},[$]);var q=I.slice(0,3).map(function(e){return e.nodeKey}),V=q.join("\0");if(c(function(){O.loading||null==w||w(q)},[O.loading,V]),c(function(){var e=new AbortController;return Z(null,e.signal),function(){return e.abort()}},[null==D?void 0:D.api.configId,null==D?void 0:D.rangeKey,v.entityKey,h,m,x,null==D?void 0:D.revision]),!D)return null;var ee,ne=D.goodDirection(h),ie=g.filter(function(e){return e!==h}).slice(0,2),re=(ee=p.trim().toLowerCase())?/(s|x|ch|sh)$/.test(ee)?"".concat(ee,"es"):/[^aeiou]y$/.test(ee)?"".concat(ee.slice(0,-1),"ies"):"".concat(ee,"s"):"rows";return t(J,e({title:"Top Drivers for ".concat(se(re))},{children:O.error?t("p",e({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):O.loading&&!I.length?t(U,{widths:[80,60,85,55,75],label:"Loading drivers"}):I.length?a(l,{children:[t(z,{context:W}),t(_e,e({label:se(p),rightLabel:"User Activity · selected dates"},{children:I.map(function(n){var i,r,o,d,c=null===(i=n.metrics)||void 0===i?void 0:i[h],s=n.label||n.nodeKey,u=y.includes(n.nodeKey);return t(ke,{rank:n.rank,name:s,chips:a(l,{children:[t(Q,{criticality:null===(r=n.chip)||void 0===r?void 0:r.criticality}),t(X,{movementType:null===(o=n.chip)||void 0===o?void 0:o.movementType,direction:null===(d=n.chip)||void 0===d?void 0:d.direction,good:ne})]}),action:t(be,{on:u,disabled:!u&&y.length>=de,onClick:function(){return f(n.nodeKey)}}),lines:a("span",e({className:"ag-driver__cost"},{children:[a("span",e({className:"ag-driver__total"},{children:[j(null==c?void 0:c.value)," ",D.kpiLabel(h).toLowerCase()]})),null!=(null==c?void 0:c.deltaPct)?t("span",e({className:"ag-driver__sep"},{children:"|"})):null,t(Y,{deltaPct:null==c?void 0:c.deltaPct,good:ne,direction:null==c?void 0:c.direction,tone:null==c?void 0:c.tone,suffix:"vs previous period"})]})),cell:ie.map(function(i){var r,l,o=null===(r=n.metrics)||void 0===r?void 0:r[i],d=null!==(l=null==o?void 0:o.tone)&&void 0!==l?l:ae(null==o?void 0:o.deltaPct,D.goodDirection(i)),c="up"===(null==o?void 0:o.direction)?"↑":"down"===(null==o?void 0:o.direction)?"↓":"flat"===(null==o?void 0:o.direction)?"→":null!=(null==o?void 0:o.deltaPct)&&o.deltaPct>0?"↑":null!=(null==o?void 0:o.deltaPct)&&o.deltaPct<0?"↓":"→";return a("span",e({className:"ag-driver__activity"},{children:[t("strong",e({className:"good"===d?"ag-text--good":"bad"===d?"ag-text--bad":void 0},{children:null==(null==o?void 0:o.deltaPct)?j(null==o?void 0:o.value):"".concat(c).concat(Math.abs(o.deltaPct),"%")})),t("span",{children:D.kpiLabel(i)})]}),i)}),onOpen:function(){var e;return b(n,h,N||(null===(e=n.chip)||void 0===e?void 0:e.dataDay)||_(D.range.endDate))}},n.nodeKey)})})),R?t("div",e({className:"ag-more"},{children:t("button",e({type:"button",disabled:O.loading,onClick:function(){return Z(L)}},{children:O.loading?"Loading...":"Show more"}))})):null]}):t("p",e({className:"ag-muted"},{children:m?"No ".concat(re," match “").concat(m,"”."):"No ".concat(re," for this period yet.")}))}))}function Te(i){var r,d,s,u,v,g,h,m,y,f,b,k,_,w,x,K,I=i.tab,C=i.title,T=i.partName,A=i.partKpis,L=i.search,P=i.dataDay,B=i.onOpenRow,j=S(),F=o(Boolean(null==j?void 0:j.defaultWorkingDays)),M=F[0],O=F[1],U=R(j?function(e){return N(j.api,e)}:null,[null==j?void 0:j.api.configId,null==j?void 0:j.revision]),H=o(null),Z=H[0],$=H[1];c(function(){var e,n;null===Z&&((null===(e=U.data)||void 0===e?void 0:e.groups.length)?$((null!==(n=U.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:U.data.groups[0]).groupKey):U.loading||$(""))},[Z,U.data,U.loading]);var q=o(null),V=q[0],J=q[1],Q=o(),X=Q[0],Y=Q[1],ee=!1!==I.showSummary,ae=null===(d=null===(r=U.data)||void 0===r?void 0:r.groups.find(function(e){return e.groupKey===Z}))||void 0===d?void 0:d.days.map(Number),le=(null==ae?void 0:ae.length)?ae.every(function(e){return e>=1&&e<=5}):M||Boolean(null==j?void 0:j.range.workingDaysOnly),oe=j?E(j.range,le,P):null,se="".concat(null==j?void 0:j.api.configId,":").concat(null==j?void 0:j.rangeKey,":").concat(I.entityKey,":").concat(Z,":").concat(null==oe?void 0:oe.startDate.getTime(),":").concat(null==oe?void 0:oe.endDate.getTime(),":").concat(null==oe?void 0:oe.workingDaysOnly),ue=R(j&&oe&&ee&&null!==Z?function(e){return D(j.api,I.entityKey,oe,e)}:null,[se,ee,null==j?void 0:j.revision],se);if(!j)return null;var ve=(null===(s=I.listKpis)||void 0===s?void 0:s.length)?I.listKpis:A,pe=I.rankBy&&ve.includes(I.rankBy)?I.rankBy:null!==(u=ve[0])&&void 0!==u?u:"",me=null===(v=ue.data)||void 0===v?void 0:v.report,ye=Ke(null===(g=ue.data)||void 0===g?void 0:g.context),fe=W({endDate:j.range.endDate,workingDays:le,selectedDay:P,reportDay:ye}),be=function(n){return P||le?e(e({},n),{report:e(e({},n.report),{reportId:null})}):n},ke=j.goodDirection(pe),_e=null!==(h=I.tier1Kpis)&&void 0!==h?h:j.tierKpis[1],we=null!==(m=I.tier2Kpis)&&void 0!==m?m:j.tierKpis[2],Ne=j.headlineKpi||pe||_e[0]||"",De=function(e){var n=e.nodeKey,i=e.label,r=e.dataDay;return B({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:Ne},action:null,children:[]},Ne,r)},Te=j.drill.tabTables[I.entityKey],Ae=Te?t(G,{table:e(e({},Te),{pageSize:null!==(f=null!==(y=Te.pageSize)&&void 0!==y?y:I.pageSize)&&void 0!==f?f:void 0}),tabEntityKey:I.entityKey,context:{trail:[],day:fe},onRowClick:function(e,n){var i;return"report"===n?j.openReport({reportId:be(e).report.reportId,nodeKey:e.nodeKey,kpiId:pe,dataDay:fe,title:null!==(i=e.label)&&void 0!==i?i:e.nodeKey}):"drill"===n?B(be(e),pe,fe):void 0}}):null;return a("section",e({className:"ag-report","aria-label":"L2 Report · ".concat(C)},{children:[a("div",e({className:"ag-report__header"},{children:[a("h2",e({className:"ag-report__title"},{children:[t(p,{"aria-hidden":"true"}),"L2 Report"]})),t("span",e({className:"ag-report__scope"},{children:C})),ye?t("span",e({className:"ag-report__date"},{children:ie(ye)})):null]})),a("div",e({className:"ag-report__grid ag-report__grid--l2"},{children:[t("div",e({className:"ag-report__analysis-scroll",role:"region","aria-label":"".concat(C," analysis"),tabIndex:0},{children:a("div",e({className:"ag-stack"},{children:[ee?a(l,{children:[a("div",{children:[t(re,{title:"Summary",action:t(ce,{entityKey:I.entityKey,dataDay:ye})}),t(ge,{report:me,loading:ue.loading,error:ue.error,good:ke})]}),t(he,{report:me,error:ue.error,loading:ue.loading}),t(z,{context:null===(b=ue.data)||void 0===b?void 0:b.context})]}):null,ve.length?t(Ce,{tab:I,partName:T,kpiIds:ve,rankBy:pe,search:L,graphed:null!=V?V:[],onToggleGraph:function(e){return J(function(i){var r=null!=i?i:[];return r.includes(e)?r.filter(function(n){return n!==e}):r.length<de?n(n([],r,!0),[e],!1):r})},onOpenRow:function(e,n,i){return B(be(e),n,i)},onFirstRow:Y,onInitialGraph:function(e){return J(function(n){return null!=n?n:e})},fallbackDay:fe}):null]}))})),a("div",e({className:"ag-stack"},{children:[_e.length?t(ne,e({title:"Trend",action:t(te,{value:M,onChange:O,groups:U.error||null===(k=U.data)||void 0===k?void 0:k.groups,group:Z,onGroupChange:$})},{children:t(Ie,{entityKey:I.entityKey,kpis:_e,nodeKeys:V,workingDays:M,group:Z,onOpenPoint:De})})):null,we.length?t(ne,e({title:j.labels.activityTitle,meta:V?"Selected rows":"Top ".concat(3," ").concat(j.entityPluralName(I.entityKey))},{children:t(Ie,{entityKey:I.entityKey,kpis:we,nodeKeys:V,workingDays:M,group:Z,onOpenPoint:De})})):null,t(xe,{dataDay:ye,nodeKey:null!==(_=null==V?void 0:V[0])&&void 0!==_?_:X,dayGroup:null===(x=null===(w=U.data)||void 0===w?void 0:w.groups.find(function(e){return e.groupKey===Z}))||void 0===x?void 0:x.days}),"column"===(null==Te?void 0:Te.width)?Ae:null]}))]})),Te&&"full"===(null!==(K=Te.width)&&void 0!==K?K:"full")?Ae:null]}))}export{be as AddToGraph,xe as CorrelationSection,he as DecisionCard,_e as DriverList,ke as DriverRow,Te as L2Report,de as MAX_SERIES,ce as RegenerateSummary,Ce as RowDrivers,Ie as RowTrend,ge as SummaryCard,we as TopDriversSection,ve as decisionCardNotice,Ke as reportDayOf,pe as stripRowTags,se as titleCase};
|
|
2
2
|
//# sourceMappingURL=AgReport.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__spreadArray as e,__assign as n,__awaiter as t,__generator as l}from"../../../_virtual/_tslib.js";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Search as o,X as a,ChevronRight as u}from"lucide-react";import{useMemo as c,useState as d,useEffect as s,useRef as v}from"react";import{toIsoDay as y,fetchLevelRows as f,fetchInsightsDrivers as h,fetchDrillTableRows as p}from"../../api/insightsApi.js";import{formatHeaderDate as b}from"./agPrimitives.js";import{useInsights as m}from"./insightsContextCore.js";var g=/\{([^{}]+)\}/g,w=function(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})},k=function(e,n){return n.split(".").reduce(function(e,n){return e&&"object"==typeof e?e[n]:void 0},e)};function K(e,n){if(null==e||""===e)return"—";if("date"===n&&"string"==typeof e){var t=new Date("".concat(e.slice(0,10),"T00:00:00"));return Number.isNaN(t.getTime())?e:t.toLocaleDateString()}var l="number"==typeof e?e:"string"==typeof e&&""!==e.trim()&&!Number.isNaN(Number(e))&&n&&"text"!==n&&"chip"!==n?Number(e):null;return null!==l?"percent"===n?"".concat(new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(l),"%"):new Intl.NumberFormat(void 0,{maximumFractionDigits:"rating"===n?2:1}).format(l):"object"==typeof e?JSON.stringify(e):String(e)}function N(e,n,t){var l,r,i,o,a,u=n.trail;return{record:t.record,context:{row:null!==(r=null===(l=u[u.length-1])||void 0===l?void 0:l.label)&&void 0!==r?r:"",parent:null!==(o=null===(i=u[u.length-2])||void 0===i?void 0:i.label)&&void 0!==o?o:"",day:null!==(a=n.day)&&void 0!==a?a:"",startDate:y(e.range.startDate),endDate:y(e.range.endDate),trail:Object.fromEntries(u.map(function(e){return[e.entityKey,e.label]}))}}}var _=function(e,n,t,l){return e.replace(g,function(e,r){var i=function(e,n,t){var l=t.trim();return l.startsWith("context.")?k(e.context,l.slice(8)):l.startsWith("input.")?n[l.slice(6)]:k(e.record,l)}(n,t,r),o=null==i?"":"object"==typeof i?JSON.stringify(i):String(i);return l?encodeURIComponent(o):o})},C=function(e,n,t){return"string"==typeof e?_(e,n,t,!1):Array.isArray(e)?e.map(function(e){return C(e,n,t)}):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).map(function(e){var l=e[0],r=e[1];return[l,C(r,n,t)]})):e},S=new Set,x=["good","warning","bad","info","neutral"],T=function(e){return String(null!=e?e:"").trim().toLowerCase().replace(/[\s_-]+/g," ")};function j(e){var t,l=e.text,r=e.value,o=e.colors,a=o?null===(t=Object.entries(o).find(function(e){var n=e[0];return T(n)===T(r)}))||void 0===t?void 0:t[1]:void 0;if(a&&"object"==typeof a)return i("span",n({className:"ag-drill__chip",style:n({background:a.background,color:a.color},a.border?{boxShadow:"inset 0 0 0 1px ".concat(a.border)}:{})},{children:l}));var u="string"==typeof a&&x.includes(a)?a:"neutral";return i("span",n({className:"ag-drill__chip ag-drill__chip--".concat(u)},{children:l}))}function D(e){var t,l=e.button,o=e.question,u=e.onCancel,c=e.onSubmit,y=d({}),f=y[0],h=y[1],p=v(null);s(function(){var e;return null===(e=p.current)||void 0===e?void 0:e.focus()},[]);var b=null!==(t=l.ask)&&void 0!==t?t:[],m=b.some(function(e){var n;return!(null===(n=f[e.key])||void 0===n?void 0:n.trim())});return i("div",n({className:"ag-drill__dialog",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&u()}},{children:r("form",n({className:"ag-drill__dialog-box",role:"dialog","aria-modal":"true","aria-label":l.label,onSubmit:function(e){e.preventDefault(),m||c(f)},onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),u())}},{children:[r("header",{children:[i("strong",{children:l.label}),i("button",n({type:"button","aria-label":"Cancel",onClick:u},{children:i(a,{"aria-hidden":"true"})}))]}),o?i("p",{children:o}):null,b.map(function(e,t){var l;return r("label",{children:[i("span",{children:e.label}),i("input",{ref:0===t?function(e){p.current=e}:void 0,value:null!==(l=f[e.key])&&void 0!==l?l:"",onChange:function(t){return h(function(l){var r;return n(n({},l),((r={})[e.key]=t.target.value,r))})},required:!0})]},e.key)}),r("footer",{children:[i("button",n({type:"button",onClick:u},{children:"Cancel"})),i("button",n({ref:b.length?void 0:function(e){p.current=e},type:"submit",disabled:m},{children:l.label}))]})]}))}))}function E(v){var g,x,T,E,B,O,P,A,I,R,M,L,q,z,F,J,H,U=this,W=v.table,G=v.tabEntityKey,Q=v.context,V=v.onRowClick,X=v.className,Y=m(),Z=Q.trail.length>0,$=c(function(){return function(e,t,l){var r,i,o,a,u,c={filterBy:l?"trail":"none",period:l?"day":"range"};return(null===(r=e.views)||void 0===r?void 0:r.length)?e.views.map(function(t){var l,r,i,o,a,u;return n(n({},t),{source:null!==(l=t.source)&&void 0!==l?l:"insights",filterBy:null!==(r=t.filterBy)&&void 0!==r?r:"row"===t.scope?"row":c.filterBy,period:null!==(i=t.period)&&void 0!==i?i:c.period,onRowClick:null!==(o=t.onRowClick)&&void 0!==o?o:e.onRowClick,buttons:null!==(u=null!==(a=t.buttons)&&void 0!==a?a:e.buttons)&&void 0!==u?u:[]})}):[{source:null!==(i=e.source)&&void 0!==i?i:"insights",entityKey:t,tableKey:e.tableKey,columns:e.columns,onRowClick:e.onRowClick,filterBy:l?null!==(o=e.filterBy)&&void 0!==o?o:c.filterBy:"none",period:l?null!==(a=e.period)&&void 0!==a?a:c.period:"range",buttons:null!==(u=e.buttons)&&void 0!==u?u:[]}]}(W,G,Z)},[W,G,Z]),ee=$.map(function(e){var n;return"".concat(e.source,":").concat(null!==(n=e.entityKey)&&void 0!==n?n:e.tableKey)}).join("|"),ne=d(0),te=ne[0],le=ne[1],re=d(""),ie=re[0],oe=re[1],ae=d(""),ue=ae[0],ce=ae[1],de=d(W.defaultSort),se=de[0],ve=de[1],ye=d([]),fe=ye[0],he=ye[1],pe=d(null),be=pe[0],me=pe[1],ge=d(0),we=ge[0],ke=ge[1],Ke=d(!1),Ne=Ke[0],_e=Ke[1],Ce=d(0),Se=Ce[0],xe=Ce[1],Te=d(!1),je=Te[0],De=Te[1],Ee=d(null),Be=Ee[0],Oe=Ee[1],Pe=d(null),Ae=Pe[0],Ie=Pe[1],Re=d(null),Me=Re[0],Le=Re[1],qe=d(null),ze=qe[0],Fe=qe[1];s(function(){return le(0)},[ee]),s(function(){var e=setTimeout(function(){return ce(ie.trim())},300);return function(){return clearTimeout(e)}},[ie]);var Je=$[Math.min(te,$.length-1)],He=Q.trail,Ue=He[He.length-1],We=null!==(g=W.pageSize)&&void 0!==g?g:10,Ge=Je&&"table"!==Je.source?Ue&&Je.entityKey&&!(null==Y?void 0:Y.isChildOf(Je.entityKey,Ue.entityKey))?"movers":"rows":"table",Qe="rows"===Ge&&Ue?Ue.nodeKey:void 0,Ve=c(function(){var n,t,l;if(!Y||!Je||"table"===Je.source)return[];if(null===(n=Je.columns)||void 0===n?void 0:n.length)return Je.columns;var r=Y.entityKpis(null!==(t=Je.entityKey)&&void 0!==t?t:"").slice(0,4);return e([{key:"label",source:"field",label:Y.entityName(null!==(l=Je.entityKey)&&void 0!==l?l:"")}],r.map(function(e){return{key:e,source:"kpi",show:"both",sortable:!0}}),!0)},[Y,Je]),Xe=Ve.find(function(e){return"children"===e.source}),Ye=null!==(x=null==Y?void 0:Y.headlineKpi)&&void 0!==x?x:"",Ze=c(function(){return Y?"day"===(null==Je?void 0:Je.period)&&Q.day?{start:Q.day,end:Q.day}:{start:y(Y.range.startDate),end:y(Y.range.endDate)}:{start:"",end:""}},[Y,null==Je?void 0:Je.period,Q.day]),$e=He.map(function(e){return"".concat(e.entityKey,":").concat(e.nodeKey)}).join("|"),en=c(function(){if(!Y||!Je)return{};var e=n({},Y.sidebarFilters);return("trail"===Je.filterBy?He:"row"===Je.filterBy?He.slice(-1):[]).forEach(function(n){var t=Y.labelColumnOf(n.entityKey);t&&n.label&&(e[t]=[n.label])}),e},[Y,Je,$e]),nn=JSON.stringify(en),tn="chip.criticality"===(null==se?void 0:se.key)?"criticality":null==se?void 0:se.key,ln="table"===Ge?"":ue,rn=function(e,r){return t(U,void 0,void 0,function(){var t,i,o,a,u,c,d,s,v,y,b;return l(this,function(l){switch(l.label){case 0:if(!Y||!Je)return[2,void 0];if("table"!==Ge)return[3,2];if(!Je.tableKey)throw new Error("Pick a Table Builder table for this list.");return[4,p(Y.api,{tableKey:Je.tableKey,startDay:Ze.start,endDay:Ze.end,filters:en,pageSize:We,cursor:e?be:null},r)];case 1:return t=l.sent(),i=e?fe.length:0,[2,{rows:t.rows.map(function(e,n){return{id:"t".concat(i+n),record:e}}),count:t.count,hasMore:t.hasNext,cursor:t.nextCursor,offset:0}];case 2:return"movers"!==Ge?[3,4]:(o=e?we:0,[4,h(Y.api,{dataDay:null!==(s=Q.day)&&void 0!==s?s:void 0,kpiId:Ye,parentNodeKey:null==Ue?void 0:Ue.nodeKey,entityKey:Je.entityKey,tab:"drivers",limit:We,offset:o,filters:Y.range.filters},r)]);case 3:return a=l.sent(),u=a.rows.map(function(e){return function(e,n){var t,l,r,i,o;return{rank:e.rank,nodeKey:e.nodeKey,label:e.label,parent:null,metrics:(t={},t[n]={value:e.value,previous:e.previous,deltaPct:e.deltaPct,direction:e.changeDirection,tone:e.tone},t),barPct:null,chip:{criticality:e.criticality,movementType:e.movementType},report:{reportId:null!==(r=null===(l=e.report)||void 0===l?void 0:l.reportId)&&void 0!==r?r:null,status:(null===(i=e.report)||void 0===i?void 0:i.reportId)?"generated":"none",kpiId:n},action:null,children:[],entityKey:null!==(o=e.entityKey)&&void 0!==o?o:null}}(e,Ye)}),c=a,[2,{rows:u.map(function(e){return{id:e.nodeKey,record:e,insights:e}}),count:null!==(v=c.total)&&void 0!==v?v:o+u.length,hasMore:Boolean(c.hasMore),cursor:null,offset:o+u.length}];case 4:return[4,f(Y.api,null!==(y=Je.entityKey)&&void 0!==y?y:"",n({},Y.range),{sort:tn,order:null==se?void 0:se.order,search:ln||void 0,pageSize:We,parentNodeKey:Qe,includeChildren:Xe?null!==(b=Xe.max)&&void 0!==b?b:3:void 0,childEntityKey:null==Xe?void 0:Xe.childEntityKey,cursor:e&&null!=be?be:void 0},r)];case 5:return[2,{rows:(d=l.sent()).rows.map(function(e){var t,l;return{id:e.nodeKey,record:e,insights:n(n({},e),{entityKey:null!==(l=null!==(t=e.entityKey)&&void 0!==t?t:Je.entityKey)&&void 0!==l?l:null})}}),count:d.count,hasMore:d.hasNext,cursor:d.nextCursor,offset:0}]}})})};if(s(function(){if(Y&&Je){var e=new AbortController;return De(!0),Oe(null),he([]),me(null),ke(0),Ie(null),rn(!1,e.signal).then(function(e){var n;e&&(he(e.rows),xe(e.count),_e(e.hasMore),me(null!==(n=e.cursor)&&void 0!==n?n:null),ke(e.offset))}).catch(function(e){"AbortError"!==(null==e?void 0:e.name)&&Oe(e instanceof Error?e.message:"The rows couldn't be loaded.")}).finally(function(){e.signal.aborted||De(!1)}),function(){return e.abort()}}},[null==Y?void 0:Y.api,null==Y?void 0:Y.revision,null==Y?void 0:Y.rangeKey,ee,te,Ge,Qe,$e,Q.day,Ze.start,Ze.end,nn,ln,tn,null==se?void 0:se.order,We,null==Xe?void 0:Xe.childEntityKey]),!Y||!Je)return null;var on="table"===Ge?function(t,l,r){var i,o,a=l.tableKey?t.tableSource(l.tableKey):void 0,u=(null===(i=null==a?void 0:a.columns)||void 0===i?void 0:i.length)?a.columns:Object.keys(null!=r?r:{}).map(function(e){return{key:e,label:w(e)}}),c=null!==(o=l.columns)&&void 0!==o?o:[];return e(e([],c.filter(function(e){return e.key&&u.some(function(n){return n.key===e.key})}),!0),u.filter(function(e){return!c.some(function(n){return n.key===e.key})}).map(function(e){return{key:e.key,source:"field"}}),!0).filter(function(e){return!e.hidden}).map(function(e){var t,l,r,i;return n(n({},e),{source:"field",label:null!==(r=null!==(t=e.label)&&void 0!==t?t:null===(l=u.find(function(n){return n.key===e.key}))||void 0===l?void 0:l.label)&&void 0!==r?r:w(null!==(i=e.key)&&void 0!==i?i:"")})})}(Y,Je,null===(T=fe[0])||void 0===T?void 0:T.record):Ve,an=Y.hostTables["table"===Je.source?null!==(E=Je.tableKey)&&void 0!==E?E:"":"insights.".concat(null!==(B=Je.entityKey)&&void 0!==B?B:"")],un=(null===(O=null==an?void 0:an.columns)||void 0===O?void 0:O.length)?an.columns:null,cn=function(e){return e.insights?function(e){var n,t,l,r,i,o,a,u,c,d,s,v,y,f,h,p,b,m={id:e.nodeKey,nodeKey:e.nodeKey,label:null!==(n=e.label)&&void 0!==n?n:e.nodeKey,entityKey:null!==(t=e.entityKey)&&void 0!==t?t:null,parent:null!==(r=null===(l=e.parent)||void 0===l?void 0:l.label)&&void 0!==r?r:null,criticality:null!==(o=null===(i=e.chip)||void 0===i?void 0:i.criticality)&&void 0!==o?o:null,movementType:null!==(u=null===(a=e.chip)||void 0===a?void 0:a.movementType)&&void 0!==u?u:null,reportId:null!==(d=null===(c=e.report)||void 0===c?void 0:c.reportId)&&void 0!==d?d:null,reportStatus:null!==(v=null===(s=e.report)||void 0===s?void 0:s.status)&&void 0!==v?v:null,actionStatus:null!==(f=null===(y=e.action)||void 0===y?void 0:y.status)&&void 0!==f?f:null,assignee:null!==(p=null===(h=e.action)||void 0===h?void 0:h.assigneeName)&&void 0!==p?p:null,children:e.children.map(function(e){return e.label}).filter(Boolean),__row:e};return Object.entries(null!==(b=e.metrics)&&void 0!==b?b:{}).forEach(function(e){var n,t,l,r=e[0],i=e[1];m[r]=null!==(n=null==i?void 0:i.value)&&void 0!==n?n:null,m["".concat(r,"_delta")]=null!==(t=null==i?void 0:i.deltaPct)&&void 0!==t?t:null,m["".concat(r,"_previous")]=null!==(l=null==i?void 0:i.previous)&&void 0!==l?l:null}),m}(e.insights):n({id:e.id},e.record)},dn="table"===Ge?"none":null!==(P=Je.onRowClick)&&void 0!==P?P:"none",sn="none"!==dn,vn="table"===Ge?e([],fe,!0).filter(function(e){return!ue||(un?un.map(function(e){return e.key}):on.map(function(e){var n;return null!==(n=e.key)&&void 0!==n?n:""})).some(function(n){var t;return String(null!==(t=e.record[n])&&void 0!==t?t:"").toLowerCase().includes(ue.toLowerCase())})}).sort(function(e,n){if(!(null==se?void 0:se.key))return 0;var t=e.record[se.key],l=n.record[se.key],r=Number(t),i=Number(l),o=null==t||null==l||""===t||""===l||Number.isNaN(r)||Number.isNaN(i)?String(null!=t?t:"").localeCompare(String(null!=l?l:"")):r-i;return"asc"===se.order?o:-o}):fe,yn=function(e){var n;return"movers"!==Ge&&("table"===Ge?!1!==e.sortable:null!==(n=e.sortable)&&void 0!==n?n:"kpi"===e.source||"chip.criticality"===e.key)},fn=function(e){var n;return(null===(n=Y.tableSource(null!=e?e:""))||void 0===n?void 0:n.title)||w(null!=e?e:"")},hn="table"===Je.source?fn(Je.tableKey):Y.entityName(null!==(A=Je.entityKey)&&void 0!==A?A:""),pn="table"===Je.source?hn:Y.entityPluralName(null!==(I=Je.entityKey)&&void 0!==I?I:""),bn=function(e){var n;return e.title||("table"===e.source?fn(e.tableKey):Y.entityPluralName(null!==(n=e.entityKey)&&void 0!==n?n:""))},mn=$.length>1?"Drill down in {row}":Z?"table"===Je.source?"{part}":Y.labels.drillTableTitle:"{parts}",gn=(null!==(R=W.title)&&void 0!==R?R:mn).replace(/\{row\}/g,null!==(M=null==Ue?void 0:Ue.label)&&void 0!==M?M:"").replace(/\{parent\}/g,null!==(q=null===(L=He[He.length-2])||void 0===L?void 0:L.label)&&void 0!==q?q:"").replace(/\{day\}/g,Q.day?b(Q.day):"").replace(/\{parts\}|\{plural\}/g,pn).replace(/\{part\}/g,hn).replace(/\s+/g," ").trim(),wn=function(e){return Je.buttons.filter(function(n){var t,l,r;if(n.adminOnly&&!Y.viewer.isAdmin)return!1;if(!("host"!==n.type||n.handler&&Y.actionHandlers[n.handler]))return S.has(null!==(t=n.handler)&&void 0!==t?t:"")||(S.add(null!==(l=n.handler)&&void 0!==l?l:""),console.warn('Decision Advantage: no host handler named "'.concat(null!==(r=n.handler)&&void 0!==r?r:"",'" is registered, so its button is hidden.'))),!1;if(n.when){var i=k(e.record,n.when);if(null==i||""===i)return!1}return!0})},kn=function(e,n,r){return t(U,void 0,void 0,function(){var t,i,o,a,u,c,d,s,v,y,f,h,p,b,m,g,w,k,K,S,x,T;return l(this,function(l){switch(l.label){case 0:t=N(Y,Q,n),i="".concat(n.id,":").concat(null!==(b=e.id)&&void 0!==b?b:e.label),Ie(null),l.label=1;case 1:if(l.trys.push([1,9,10,11]),"open"===e.type){if(o=_(null!==(m=e.url)&&void 0!==m?m:"",t,r,!0),/^https:\/\//i.test(o))window.open(o,"_blank","noopener,noreferrer");else{if(!/^mailto:/i.test(o))throw new Error("This link isn't allowed: only https and mailto links open.");window.location.href=o}return[2]}return Fe(i),"host"!==e.type?[3,3]:[4,(0,Y.actionHandlers[null!==(g=e.handler)&&void 0!==g?g:""])({button:e,row:n.record,context:t.context,inputs:r})];case 2:return a=l.sent(),Ie({tone:"ok",text:a&&a.message||"".concat(e.label,": done.")}),[2];case 3:if("https:"!==(u=new URL(_(null!==(w=e.url)&&void 0!==w?w:"",t,r,!0))).protocol)throw new Error("Only https APIs can be called.");return c=null!==(k=e.method)&&void 0!==k?k:"POST",d={Accept:"application/json"},Object.entries(null!==(K=e.headers)&&void 0!==K?K:{}).forEach(function(e){var n=e[0],l=e[1];d[n]=_(String(l),t,r,!1)}),Y.api.accessToken&&Y.approvedApiHosts.includes(u.host.toLowerCase())&&(d.Authorization="Bearer ".concat(Y.api.accessToken)),(s="GET"!==c&&void 0!==e.body&&null!==e.body)&&(d["Content-Type"]="application/json"),[4,fetch(u.toString(),{method:c,headers:d,body:s?JSON.stringify(C(e.body,t,r)):void 0})];case 4:v=l.sent(),y="",l.label=5;case 5:return l.trys.push([5,7,,8]),[4,v.json()];case 6:return f=l.sent(),h=null==f?void 0:f.error,y=String(null!==(T=null!==(x=null!==(S=null==f?void 0:f.message)&&void 0!==S?S:null==h?void 0:h.errorMessage)&&void 0!==x?x:null==f?void 0:f.detail)&&void 0!==T?T:""),[3,8];case 7:return l.sent(),y="",[3,8];case 8:if(!v.ok)throw new Error(y||"".concat(e.label," failed (status ").concat(v.status,")."));return Ie({tone:"ok",text:y||"".concat(e.label,": done.")}),[3,11];case 9:return p=l.sent(),Ie({tone:"error",text:p instanceof Error?p.message:"".concat(e.label," failed.")}),[3,11];case 10:return Fe(null),[7];case 11:return[2]}})})},Kn=function(e){var n,t,l,r=null!==(t=null!==(n=e.key)&&void 0!==n?n:e.id)&&void 0!==t?t:"",i="table"===Je.source?Je.tableKey:Je.entityKey;return null!==(l=i?Y.cellRenderers["".concat(i,".").concat(r)]:void 0)&&void 0!==l?l:Y.cellRenderers[r]},Nn=function(e,t){var l,o,a,u,c,d,s,v,y=null!==(l=t.key)&&void 0!==l?l:"",f=Kn(t),h="kpi"===t.source&&e.insights?null===(o=e.insights.metrics[y])||void 0===o?void 0:o.value:"children"===t.source&&e.insights?e.insights.children.map(function(e){return e.label}).filter(Boolean):"label"===y&&e.insights?e.insights.label||e.insights.nodeKey:k(e.record,y);if(null==f?void 0:f.render){var p=f.render({column:t,value:h,record:e.record,row:e.insights,entityKey:Je.entityKey,tableKey:Je.tableKey});if(void 0!==p)return p}if(e.insights){var b=null===(a=Y.renderInsightsCell)||void 0===a?void 0:a.call(Y,{column:t,row:e.insights,entityKey:null!==(u=Je.entityKey)&&void 0!==u?u:""});if(void 0!==b)return b}if("custom"===t.source)return null!==(c=t.emptyText)&&void 0!==c?c:"—";if("kpi"===t.source&&e.insights&&!(null==f?void 0:f.as)){var m=e.insights.metrics[y],g=K(null==m?void 0:m.value,t.format),w=null==(null==m?void 0:m.deltaPct)?"—":"".concat(m.deltaPct>0?"↑":m.deltaPct<0?"↓":""," ").concat(Math.abs(m.deltaPct),"%");return"delta"===t.show?i("span",n({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w})):"value"===t.show?g:r("span",n({className:"ag-drill__metric"},{children:[i("strong",{children:g}),i("small",n({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w}))]}))}if("children"===t.source&&e.insights&&!(null==f?void 0:f.as)){var N=Array.from(new Set(h)),_=null!==(d=t.max)&&void 0!==d?d:3,C=N.length?"".concat(N.slice(0,_).join(", ")).concat(N.length>_?" +".concat(N.length-_):""):null!==(s=t.emptyText)&&void 0!==s?s:"—";return i("span",n({className:"ag-drill__contributors",title:N.join(", ")||void 0},{children:C}))}var S=null!==(v=null==f?void 0:f.as)&&void 0!==v?v:t.format;if("link"===S){var x="string"==typeof h?h:"";return/^https:\/\//i.test(x)?i("a",n({href:x,target:"_blank",rel:"noopener noreferrer"},{children:x})):K(h,"text")}var T=K(h,"chip"===S?"text":S);return"—"===T&&t.emptyText?t.emptyText:"chip"!==S&&!(null==f?void 0:f.colors)||"—"===T?T:i(j,{text:T.replace(/_/g," "),value:h,colors:null==f?void 0:f.colors})},_n=function(e){e.insights&&(null==V||V(e.insights,dn))},Cn=Je.buttons.length>0,Sn=function(e){var n;return null!==(n=e.align)&&void 0!==n?n:"kpi"===e.source?"right":"left"},xn="ag-drill-".concat(String(null!==(z=W.id)&&void 0!==z?z:gn).replace(/[^a-z0-9]+/gi,"-")),Tn=!1!==W.search&&"movers"!==Ge;return r("section",n({className:"ag-drill".concat(X?" ".concat(X):""),"aria-labelledby":xn,style:null===(F=null==an?void 0:an.card)||void 0===F?void 0:F.root},{children:[r("header",n({className:"ag-drill__header",style:null===(J=null==an?void 0:an.card)||void 0===J?void 0:J.header},{children:[r("div",{children:[i("h3",n({id:xn,style:null===(H=null==an?void 0:an.card)||void 0===H?void 0:H.title},{children:gn})),"movers"===Ge?r("span",{children:["Rows that moved",Q.day?" on ".concat(b(Q.day)):""]}):null]}),Tn?r("label",n({className:"ag-drill__search"},{children:[i(o,{"aria-hidden":"true"}),i("input",{type:"search",value:ie,onChange:function(e){return oe(e.target.value)},placeholder:"Search ".concat(pn.toLowerCase(),"…"),"aria-label":"Search ".concat(pn)})]})):null]})),$.length>1?i("div",n({className:"ag-drill__tabs",role:"tablist","aria-label":"What this table lists"},{children:$.map(function(e,t){var l;return i("button",n({type:"button",role:"tab","aria-selected":t===te,className:t===te?"is-active":void 0,onClick:function(){le(t),oe(""),ce(""),ve(W.defaultSort)}},{children:bn(e)}),"".concat(e.source,":").concat(null!==(l=e.entityKey)&&void 0!==l?l:e.tableKey,":").concat(t))})})):null,Ae?r("p",n({className:"ag-drill__notice ag-drill__notice--".concat(Ae.tone),role:"status"},{children:[Ae.text,i("button",n({type:"button","aria-label":"Dismiss",onClick:function(){return Ie(null)}},{children:i(a,{"aria-hidden":"true"})}))]})):null,r("div",n({className:"ag-drill__table-wrap","aria-live":"polite"},{children:[r("table",n({className:"ag-drill__table"},{children:[i("thead",{children:r("tr",{children:[un?un.map(function(e){return i("th",n({className:e.headerClassName,style:n(n({},e.style),e.headerStyle)},{children:e.header}),e.key)}):on.map(function(e){var t,l,o,a,u,c=null!==(l=null!==(t=e.key)&&void 0!==t?t:e.id)&&void 0!==l?l:"",d=null!==(o=e.label)&&void 0!==o?o:"kpi"===e.source?Y.kpiLabel(c):"children"===e.source?Y.entityPluralName(null!==(a=e.childEntityKey)&&void 0!==a?a:""):w(null!==(u=c.split(".").pop())&&void 0!==u?u:c);return i("th",n({className:"ag-drill__col--".concat(Sn(e)," ").concat(e.hideBelow?"ag-drill__hide--".concat(e.hideBelow):""),style:{width:e.width},"aria-sort":(null==se?void 0:se.key)===c?"asc"===se.order?"ascending":"descending":void 0},{children:yn(e)?r("button",n({type:"button",onClick:function(){return function(e){var n;if(yn(e)){var t=null!==(n=e.key)&&void 0!==n?n:"";ve(function(e){return{key:t,order:(null==e?void 0:e.key)===t&&"desc"===e.order?"asc":"desc"}})}}(e)}},{children:[d,(null==se?void 0:se.key)===c?r("span",n({"aria-hidden":"true"},{children:[" ","asc"===se.order?"↑":"↓"]})):null]})):d}),"".concat(e.source,":").concat(c))}),Cn?i("th",{children:i("span",n({className:"ins-visually-hidden"},{children:"Actions"}))}):null,sn?i("th",{children:i("span",n({className:"ins-visually-hidden"},{children:"Open"}))}):null]})}),i("tbody",{children:vn.map(function(e){return r("tr",n({className:sn?void 0:"is-static",tabIndex:sn?0:void 0,onClick:sn?function(n){n.target.closest("a,button,input,select,textarea")||_n(e)}:void 0,onKeyDown:sn?function(n){return function(e,n){sn&&e.target===e.currentTarget&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),_n(n)))}(n,e)}:void 0},{children:[un?(t=cn(e),un.map(function(e){return i("td",n({className:e.bodyClassName,style:n(n({},e.style),e.bodyStyle)},{children:e.body(t)}),e.key)})):on.map(function(t,l){var r,o,a=0===l?"th":"td",u=null===(r=Kn(t))||void 0===r?void 0:r.className;return i(a,n({scope:0===l?"row":void 0,className:"ag-drill__col--".concat(Sn(t)," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):"").concat(u?" ".concat(u):"")},{children:Nn(e,t)}),"".concat(t.source,":").concat(null!==(o=t.key)&&void 0!==o?o:t.id))}),Cn?i("td",n({className:"ag-drill__buttons"},{children:wn(e).map(function(t){var l,r,o=ze==="".concat(e.id,":").concat(null!==(l=t.id)&&void 0!==l?l:t.label);return i("button",n({type:"button",disabled:o,"aria-busy":o||void 0,onClick:function(){return function(e,n){var t,l=e.confirm?_(e.confirm,N(Y,Q,n),{},!1):"";"call"!==e.type||!(null!==(t=e.ask)&&void 0!==t?t:[]).length&&!l?l&&!window.confirm(l)||kn(e,n,{}):Le({button:e,row:n,question:l})}(t,e)}},{children:o?"…":t.label}),null!==(r=t.id)&&void 0!==r?r:t.label)})})):null,sn?i("td",{children:i(u,{className:"ag-drill__open","aria-hidden":"true"})}):null]}),e.id);var t})})]})),je&&!fe.length?i("p",n({className:"ag-drill__state"},{children:"Loading rows…"})):null,je||vn.length||Be?null:i("p",n({className:"ag-drill__state"},{children:"No rows found."})),Be?i("p",n({className:"ag-drill__state ag-drill__state--error"},{children:Be})):null]})),r("footer",n({className:"ag-drill__footer"},{children:[i("span",{children:"rows"===Ge&&Se?"".concat(fe.length," of ").concat(Se):""}),Ne?i("button",n({type:"button",onClick:function(){return t(U,void 0,void 0,function(){var n,t,r;return l(this,function(l){switch(l.label){case 0:if(je||!Ne)return[2];De(!0),Oe(null),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,rn(!0)];case 2:return(n=l.sent())?(he(function(t){return e(e([],t,!0),n.rows,!0)}),_e(n.hasMore),me(null!==(r=n.cursor)&&void 0!==r?r:null),ke(n.offset),[3,5]):[2];case 3:return t=l.sent(),Oe(t instanceof Error?t.message:"More rows couldn't be loaded."),[3,5];case 4:return De(!1),[7];case 5:return[2]}})})},disabled:je},{children:je?"Loading…":"Show more"})):null]})),Me?i(D,{button:Me.button,question:Me.question,onCancel:function(){return Le(null)},onSubmit:function(e){var n=Me.button,t=Me.row;Le(null),kn(n,t,e)}}):null]}))}export{E as default};
|
|
1
|
+
import{__spreadArray as e,__assign as n,__awaiter as t,__generator as l}from"../../../_virtual/_tslib.js";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Search as o,X as a,ChevronRight as u}from"lucide-react";import{useMemo as c,useState as d,useEffect as s,useRef as v}from"react";import{toIsoDay as y,fetchLevelRows as f,fetchInsightsDrivers as h,fetchDrillTableRows as p}from"../../api/insightsApi.js";import{formatHeaderDate as b}from"./agPrimitives.js";import{useInsights as m}from"./insightsContextCore.js";var g=/\{([^{}]+)\}/g,w=function(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})},k=function(e,n){return n.split(".").reduce(function(e,n){return e&&"object"==typeof e?e[n]:void 0},e)};function K(e,n){if(null==e||""===e)return"—";if("date"===n&&"string"==typeof e){var t=new Date("".concat(e.slice(0,10),"T00:00:00"));return Number.isNaN(t.getTime())?e:t.toLocaleDateString()}var l="number"==typeof e?e:"string"==typeof e&&""!==e.trim()&&!Number.isNaN(Number(e))&&n&&"text"!==n&&"chip"!==n?Number(e):null;return null!==l?"percent"===n?"".concat(new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(l),"%"):new Intl.NumberFormat(void 0,{maximumFractionDigits:"rating"===n?2:1}).format(l):"object"==typeof e?JSON.stringify(e):String(e)}function N(e,n,t){var l,r,i,o,a,u=n.trail;return{record:t.record,context:{row:null!==(r=null===(l=u[u.length-1])||void 0===l?void 0:l.label)&&void 0!==r?r:"",parent:null!==(o=null===(i=u[u.length-2])||void 0===i?void 0:i.label)&&void 0!==o?o:"",day:null!==(a=n.day)&&void 0!==a?a:"",startDate:y(e.range.startDate),endDate:y(e.range.endDate),trail:Object.fromEntries(u.map(function(e){return[e.entityKey,e.label]}))}}}var _=function(e,n,t,l){return e.replace(g,function(e,r){var i=function(e,n,t){var l=t.trim();return l.startsWith("context.")?k(e.context,l.slice(8)):l.startsWith("input.")?n[l.slice(6)]:k(e.record,l)}(n,t,r),o=null==i?"":"object"==typeof i?JSON.stringify(i):String(i);return l?encodeURIComponent(o):o})},C=function(e,n,t){return"string"==typeof e?_(e,n,t,!1):Array.isArray(e)?e.map(function(e){return C(e,n,t)}):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).map(function(e){var l=e[0],r=e[1];return[l,C(r,n,t)]})):e},S=new Set,x=["good","warning","bad","info","neutral"],T=function(e){return String(null!=e?e:"").trim().toLowerCase().replace(/[\s_-]+/g," ")};function j(e){var t,l=e.text,r=e.value,o=e.colors,a=o?null===(t=Object.entries(o).find(function(e){var n=e[0];return T(n)===T(r)}))||void 0===t?void 0:t[1]:void 0;if(a&&"object"==typeof a)return i("span",n({className:"ag-drill__chip",style:n({background:a.background,color:a.color},a.border?{boxShadow:"inset 0 0 0 1px ".concat(a.border)}:{})},{children:l}));var u="string"==typeof a&&x.includes(a)?a:"neutral";return i("span",n({className:"ag-drill__chip ag-drill__chip--".concat(u)},{children:l}))}function D(e){var t,l=e.button,o=e.question,u=e.onCancel,c=e.onSubmit,y=d({}),f=y[0],h=y[1],p=v(null);s(function(){var e;return null===(e=p.current)||void 0===e?void 0:e.focus()},[]);var b=null!==(t=l.ask)&&void 0!==t?t:[],m=b.some(function(e){var n;return!(null===(n=f[e.key])||void 0===n?void 0:n.trim())});return i("div",n({className:"ag-drill__dialog",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&u()}},{children:r("form",n({className:"ag-drill__dialog-box",role:"dialog","aria-modal":"true","aria-label":l.label,onSubmit:function(e){e.preventDefault(),m||c(f)},onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),u())}},{children:[r("header",{children:[i("strong",{children:l.label}),i("button",n({type:"button","aria-label":"Cancel",onClick:u},{children:i(a,{"aria-hidden":"true"})}))]}),o?i("p",{children:o}):null,b.map(function(e,t){var l;return r("label",{children:[i("span",{children:e.label}),i("input",{ref:0===t?function(e){p.current=e}:void 0,value:null!==(l=f[e.key])&&void 0!==l?l:"",onChange:function(t){return h(function(l){var r;return n(n({},l),((r={})[e.key]=t.target.value,r))})},required:!0})]},e.key)}),r("footer",{children:[i("button",n({type:"button",onClick:u},{children:"Cancel"})),i("button",n({ref:b.length?void 0:function(e){p.current=e},type:"submit",disabled:m},{children:l.label}))]})]}))}))}function E(v){var g,x,T,E,B,O,P,A,I,R,M,L,q,z,F,J,H,U=this,W=v.table,G=v.tabEntityKey,Q=v.context,V=v.onRowClick,X=v.className,Y=m(),Z=Q.trail.length>0,$=c(function(){return function(e,t,l){var r,i,o,a,u,c={filterBy:l?"trail":"none",period:l?"day":"range"};return(null===(r=e.views)||void 0===r?void 0:r.length)?e.views.map(function(t){var l,r,i,o,a,u;return n(n({},t),{source:null!==(l=t.source)&&void 0!==l?l:"insights",filterBy:null!==(r=t.filterBy)&&void 0!==r?r:"row"===t.scope?"row":c.filterBy,period:null!==(i=t.period)&&void 0!==i?i:c.period,onRowClick:null!==(o=t.onRowClick)&&void 0!==o?o:e.onRowClick,buttons:null!==(u=null!==(a=t.buttons)&&void 0!==a?a:e.buttons)&&void 0!==u?u:[]})}):[{source:null!==(i=e.source)&&void 0!==i?i:"insights",entityKey:t,tableKey:e.tableKey,columns:e.columns,onRowClick:e.onRowClick,filterBy:l?null!==(o=e.filterBy)&&void 0!==o?o:c.filterBy:"none",period:l?null!==(a=e.period)&&void 0!==a?a:c.period:"range",buttons:null!==(u=e.buttons)&&void 0!==u?u:[]}]}(W,G,Z)},[W,G,Z]),ee=$.map(function(e){var n;return"".concat(e.source,":").concat(null!==(n=e.entityKey)&&void 0!==n?n:e.tableKey)}).join("|"),ne=d(0),te=ne[0],le=ne[1],re=d(""),ie=re[0],oe=re[1],ae=d(""),ue=ae[0],ce=ae[1],de=d(W.defaultSort),se=de[0],ve=de[1],ye=d([]),fe=ye[0],he=ye[1],pe=d(null),be=pe[0],me=pe[1],ge=d(0),we=ge[0],ke=ge[1],Ke=d(!1),Ne=Ke[0],_e=Ke[1],Ce=d(0),Se=Ce[0],xe=Ce[1],Te=d(!1),je=Te[0],De=Te[1],Ee=d(null),Be=Ee[0],Oe=Ee[1],Pe=d(null),Ae=Pe[0],Ie=Pe[1],Re=d(null),Me=Re[0],Le=Re[1],qe=d(null),ze=qe[0],Fe=qe[1];s(function(){return le(0)},[ee]),s(function(){var e=setTimeout(function(){return ce(ie.trim())},300);return function(){return clearTimeout(e)}},[ie]);var Je=$[Math.min(te,$.length-1)],He=Q.trail,Ue=He[He.length-1],We=null!==(g=W.pageSize)&&void 0!==g?g:10,Ge=Je&&"table"!==Je.source?Ue&&Je.entityKey&&!(null==Y?void 0:Y.isChildOf(Je.entityKey,Ue.entityKey))?"movers":"rows":"table",Qe="rows"===Ge&&Ue?Ue.nodeKey:void 0,Ve=c(function(){var n,t,l;if(!Y||!Je||"table"===Je.source)return[];if(null===(n=Je.columns)||void 0===n?void 0:n.length)return Je.columns;var r=Y.entityKpis(null!==(t=Je.entityKey)&&void 0!==t?t:"").slice(0,4);return e([{key:"label",source:"field",label:Y.entityName(null!==(l=Je.entityKey)&&void 0!==l?l:"")}],r.map(function(e){return{key:e,source:"kpi",show:"both"}}),!0)},[Y,Je]),Xe=Ve.find(function(e){return"children"===e.source}),Ye=null!==(x=null==Y?void 0:Y.headlineKpi)&&void 0!==x?x:"",Ze=c(function(){return Y?"day"===(null==Je?void 0:Je.period)&&Q.day?{start:Q.day,end:Q.day}:{start:y(Y.range.startDate),end:y(Y.range.endDate)}:{start:"",end:""}},[Y,null==Je?void 0:Je.period,Q.day]),$e=He.map(function(e){return"".concat(e.entityKey,":").concat(e.nodeKey)}).join("|"),en=c(function(){if(!Y||!Je)return{};var e=n({},Y.sidebarFilters);return("trail"===Je.filterBy?He:"row"===Je.filterBy?He.slice(-1):[]).forEach(function(n){var t=Y.labelColumnOf(n.entityKey);t&&n.label&&(e[t]=[n.label])}),e},[Y,Je,$e]),nn=JSON.stringify(en),tn="table"===Ge?void 0:"chip.criticality"===(null==se?void 0:se.key)?"criticality":null==se?void 0:se.key,ln="table"===Ge||null==se?void 0:se.order,rn="table"===Ge?"":ue,on=function(e,r){return t(U,void 0,void 0,function(){var t,i,o,a,u,c,d,s,v,y,b;return l(this,function(l){switch(l.label){case 0:if(!Y||!Je)return[2,void 0];if("table"!==Ge)return[3,2];if(!Je.tableKey)throw new Error("Pick a Table Builder table for this list.");return[4,p(Y.api,{tableKey:Je.tableKey,startDay:Ze.start,endDay:Ze.end,filters:en,pageSize:We,cursor:e?be:null},r)];case 1:return t=l.sent(),i=e?fe.length:0,[2,{rows:t.rows.map(function(e,n){return{id:"t".concat(i+n),record:e}}),count:t.count,hasMore:t.hasNext,cursor:t.nextCursor,offset:0}];case 2:return"movers"!==Ge?[3,4]:(o=e?we:0,[4,h(Y.api,{dataDay:null!==(s=Q.day)&&void 0!==s?s:void 0,kpiId:Ye,parentNodeKey:null==Ue?void 0:Ue.nodeKey,entityKey:Je.entityKey,tab:"drivers",limit:We,offset:o,filters:Y.range.filters},r)]);case 3:return a=l.sent(),u=a.rows.map(function(e){return function(e,n){var t,l,r,i,o;return{rank:e.rank,nodeKey:e.nodeKey,label:e.label,parent:null,metrics:(t={},t[n]={value:e.value,previous:e.previous,deltaPct:e.deltaPct,direction:e.changeDirection,tone:e.tone},t),barPct:null,chip:{criticality:e.criticality,movementType:e.movementType},report:{reportId:null!==(r=null===(l=e.report)||void 0===l?void 0:l.reportId)&&void 0!==r?r:null,status:(null===(i=e.report)||void 0===i?void 0:i.reportId)?"generated":"none",kpiId:n},action:null,children:[],entityKey:null!==(o=e.entityKey)&&void 0!==o?o:null}}(e,Ye)}),c=a,[2,{rows:u.map(function(e){return{id:e.nodeKey,record:e,insights:e}}),count:null!==(v=c.total)&&void 0!==v?v:o+u.length,hasMore:Boolean(c.hasMore),cursor:null,offset:o+u.length}];case 4:return[4,f(Y.api,null!==(y=Je.entityKey)&&void 0!==y?y:"",n({},Y.range),{sort:tn,order:ln,search:rn||void 0,pageSize:We,parentNodeKey:Qe,includeChildren:Xe?null!==(b=Xe.max)&&void 0!==b?b:3:void 0,childEntityKey:null==Xe?void 0:Xe.childEntityKey,cursor:e&&null!=be?be:void 0},r)];case 5:return[2,{rows:(d=l.sent()).rows.map(function(e){var t,l;return{id:e.nodeKey,record:e,insights:n(n({},e),{entityKey:null!==(l=null!==(t=e.entityKey)&&void 0!==t?t:Je.entityKey)&&void 0!==l?l:null})}}),count:d.count,hasMore:d.hasNext,cursor:d.nextCursor,offset:0}]}})})};if(s(function(){if(Y&&Je){var e=new AbortController;return De(!0),Oe(null),he([]),me(null),ke(0),Ie(null),on(!1,e.signal).then(function(e){var n;e&&(he(e.rows),xe(e.count),_e(e.hasMore),me(null!==(n=e.cursor)&&void 0!==n?n:null),ke(e.offset))}).catch(function(e){"AbortError"!==(null==e?void 0:e.name)&&Oe(e instanceof Error?e.message:"The rows couldn't be loaded.")}).finally(function(){e.signal.aborted||De(!1)}),function(){return e.abort()}}},[null==Y?void 0:Y.api,null==Y?void 0:Y.revision,null==Y?void 0:Y.rangeKey,ee,te,Ge,Qe,$e,Q.day,Ze.start,Ze.end,nn,rn,tn,ln,We,null==Xe?void 0:Xe.childEntityKey]),!Y||!Je)return null;var an="table"===Ge?function(t,l,r){var i,o,a=l.tableKey?t.tableSource(l.tableKey):void 0,u=(null===(i=null==a?void 0:a.columns)||void 0===i?void 0:i.length)?a.columns:Object.keys(null!=r?r:{}).map(function(e){return{key:e,label:w(e)}}),c=null!==(o=l.columns)&&void 0!==o?o:[];return e(e([],c.filter(function(e){return e.key&&u.some(function(n){return n.key===e.key})}),!0),u.filter(function(e){return!c.some(function(n){return n.key===e.key})}).map(function(e){return n(n({},e),{source:"field"})}),!0).filter(function(e){return!e.hidden}).map(function(e){var t,l,r,i,o,a;return n(n({},e),{source:"field",sortable:null!==(t=e.sortable)&&void 0!==t?t:null===(l=u.find(function(n){return n.key===e.key}))||void 0===l?void 0:l.sortable,label:null!==(o=null!==(r=e.label)&&void 0!==r?r:null===(i=u.find(function(n){return n.key===e.key}))||void 0===i?void 0:i.label)&&void 0!==o?o:w(null!==(a=e.key)&&void 0!==a?a:"")})})}(Y,Je,null===(T=fe[0])||void 0===T?void 0:T.record):Ve,un=Y.hostTables["table"===Je.source?null!==(E=Je.tableKey)&&void 0!==E?E:"":"insights.".concat(null!==(B=Je.entityKey)&&void 0!==B?B:"")],cn=(null===(O=null==un?void 0:un.columns)||void 0===O?void 0:O.length)?un.columns:null,dn=function(e){return e.insights?function(e){var n,t,l,r,i,o,a,u,c,d,s,v,y,f,h,p,b,m={id:e.nodeKey,nodeKey:e.nodeKey,label:null!==(n=e.label)&&void 0!==n?n:e.nodeKey,entityKey:null!==(t=e.entityKey)&&void 0!==t?t:null,parent:null!==(r=null===(l=e.parent)||void 0===l?void 0:l.label)&&void 0!==r?r:null,criticality:null!==(o=null===(i=e.chip)||void 0===i?void 0:i.criticality)&&void 0!==o?o:null,movementType:null!==(u=null===(a=e.chip)||void 0===a?void 0:a.movementType)&&void 0!==u?u:null,reportId:null!==(d=null===(c=e.report)||void 0===c?void 0:c.reportId)&&void 0!==d?d:null,reportStatus:null!==(v=null===(s=e.report)||void 0===s?void 0:s.status)&&void 0!==v?v:null,actionStatus:null!==(f=null===(y=e.action)||void 0===y?void 0:y.status)&&void 0!==f?f:null,assignee:null!==(p=null===(h=e.action)||void 0===h?void 0:h.assigneeName)&&void 0!==p?p:null,children:e.children.map(function(e){return e.label}).filter(Boolean),__row:e};return Object.entries(null!==(b=e.metrics)&&void 0!==b?b:{}).forEach(function(e){var n,t,l,r=e[0],i=e[1];m[r]=null!==(n=null==i?void 0:i.value)&&void 0!==n?n:null,m["".concat(r,"_delta")]=null!==(t=null==i?void 0:i.deltaPct)&&void 0!==t?t:null,m["".concat(r,"_previous")]=null!==(l=null==i?void 0:i.previous)&&void 0!==l?l:null}),m}(e.insights):n({id:e.id},e.record)},sn="table"===Ge?"none":null!==(P=Je.onRowClick)&&void 0!==P?P:"none",vn="none"!==sn,yn="table"===Ge?e([],fe,!0).filter(function(e){return!ue||(cn?cn.map(function(e){return e.key}):an.map(function(e){var n;return null!==(n=e.key)&&void 0!==n?n:""})).some(function(n){var t;return String(null!==(t=e.record[n])&&void 0!==t?t:"").toLowerCase().includes(ue.toLowerCase())})}).sort(function(e,n){if(!(null==se?void 0:se.key))return 0;var t=e.record[se.key],l=n.record[se.key],r=Number(t),i=Number(l),o=null==t||null==l||""===t||""===l||Number.isNaN(r)||Number.isNaN(i)?String(null!=t?t:"").localeCompare(String(null!=l?l:"")):r-i;return"asc"===se.order?o:-o}):fe,fn=function(e){return"movers"!==Ge&&!0===e.sortable},hn=function(e){var n;if(fn(e)){var t=null!==(n=e.key)&&void 0!==n?n:"";ve(function(e){return{key:t,order:(null==e?void 0:e.key)===t&&"desc"===e.order?"asc":"desc"}})}},pn=function(e){var n;return(null===(n=Y.tableSource(null!=e?e:""))||void 0===n?void 0:n.title)||w(null!=e?e:"")},bn="table"===Je.source?pn(Je.tableKey):Y.entityName(null!==(A=Je.entityKey)&&void 0!==A?A:""),mn="table"===Je.source?bn:Y.entityPluralName(null!==(I=Je.entityKey)&&void 0!==I?I:""),gn=function(e){var n;return e.title||("table"===e.source?pn(e.tableKey):Y.entityPluralName(null!==(n=e.entityKey)&&void 0!==n?n:""))},wn=$.length>1?"Drill down in {row}":Z?"table"===Je.source?"{part}":Y.labels.drillTableTitle:"{parts}",kn=(null!==(R=W.title)&&void 0!==R?R:wn).replace(/\{row\}/g,null!==(M=null==Ue?void 0:Ue.label)&&void 0!==M?M:"").replace(/\{parent\}/g,null!==(q=null===(L=He[He.length-2])||void 0===L?void 0:L.label)&&void 0!==q?q:"").replace(/\{day\}/g,Q.day?b(Q.day):"").replace(/\{parts\}|\{plural\}/g,mn).replace(/\{part\}/g,bn).replace(/\s+/g," ").trim(),Kn=function(e){return Je.buttons.filter(function(n){var t,l,r;if(n.adminOnly&&!Y.viewer.isAdmin)return!1;if(!("host"!==n.type||n.handler&&Y.actionHandlers[n.handler]))return S.has(null!==(t=n.handler)&&void 0!==t?t:"")||(S.add(null!==(l=n.handler)&&void 0!==l?l:""),console.warn('Decision Advantage: no host handler named "'.concat(null!==(r=n.handler)&&void 0!==r?r:"",'" is registered, so its button is hidden.'))),!1;if(n.when){var i=k(e.record,n.when);if(null==i||""===i)return!1}return!0})},Nn=function(e,n,r){return t(U,void 0,void 0,function(){var t,i,o,a,u,c,d,s,v,y,f,h,p,b,m,g,w,k,K,S,x,T;return l(this,function(l){switch(l.label){case 0:t=N(Y,Q,n),i="".concat(n.id,":").concat(null!==(b=e.id)&&void 0!==b?b:e.label),Ie(null),l.label=1;case 1:if(l.trys.push([1,9,10,11]),"open"===e.type){if(o=_(null!==(m=e.url)&&void 0!==m?m:"",t,r,!0),/^https:\/\//i.test(o))window.open(o,"_blank","noopener,noreferrer");else{if(!/^mailto:/i.test(o))throw new Error("This link isn't allowed: only https and mailto links open.");window.location.href=o}return[2]}return Fe(i),"host"!==e.type?[3,3]:[4,(0,Y.actionHandlers[null!==(g=e.handler)&&void 0!==g?g:""])({button:e,row:n.record,context:t.context,inputs:r})];case 2:return a=l.sent(),Ie({tone:"ok",text:a&&a.message||"".concat(e.label,": done.")}),[2];case 3:if("https:"!==(u=new URL(_(null!==(w=e.url)&&void 0!==w?w:"",t,r,!0))).protocol)throw new Error("Only https APIs can be called.");return c=null!==(k=e.method)&&void 0!==k?k:"POST",d={Accept:"application/json"},Object.entries(null!==(K=e.headers)&&void 0!==K?K:{}).forEach(function(e){var n=e[0],l=e[1];d[n]=_(String(l),t,r,!1)}),Y.api.accessToken&&Y.approvedApiHosts.includes(u.host.toLowerCase())&&(d.Authorization="Bearer ".concat(Y.api.accessToken)),(s="GET"!==c&&void 0!==e.body&&null!==e.body)&&(d["Content-Type"]="application/json"),[4,fetch(u.toString(),{method:c,headers:d,body:s?JSON.stringify(C(e.body,t,r)):void 0})];case 4:v=l.sent(),y="",l.label=5;case 5:return l.trys.push([5,7,,8]),[4,v.json()];case 6:return f=l.sent(),h=null==f?void 0:f.error,y=String(null!==(T=null!==(x=null!==(S=null==f?void 0:f.message)&&void 0!==S?S:null==h?void 0:h.errorMessage)&&void 0!==x?x:null==f?void 0:f.detail)&&void 0!==T?T:""),[3,8];case 7:return l.sent(),y="",[3,8];case 8:if(!v.ok)throw new Error(y||"".concat(e.label," failed (status ").concat(v.status,")."));return Ie({tone:"ok",text:y||"".concat(e.label,": done.")}),[3,11];case 9:return p=l.sent(),Ie({tone:"error",text:p instanceof Error?p.message:"".concat(e.label," failed.")}),[3,11];case 10:return Fe(null),[7];case 11:return[2]}})})},_n=function(e){var n,t,l,r=null!==(t=null!==(n=e.key)&&void 0!==n?n:e.id)&&void 0!==t?t:"",i="table"===Je.source?Je.tableKey:Je.entityKey;return null!==(l=i?Y.cellRenderers["".concat(i,".").concat(r)]:void 0)&&void 0!==l?l:Y.cellRenderers[r]},Cn=function(e,t){var l,o,a,u,c,d,s,v,y=null!==(l=t.key)&&void 0!==l?l:"",f=_n(t),h="kpi"===t.source&&e.insights?null===(o=e.insights.metrics[y])||void 0===o?void 0:o.value:"children"===t.source&&e.insights?e.insights.children.map(function(e){return e.label}).filter(Boolean):"label"===y&&e.insights?e.insights.label||e.insights.nodeKey:k(e.record,y);if(null==f?void 0:f.render){var p=f.render({column:t,value:h,record:e.record,row:e.insights,entityKey:Je.entityKey,tableKey:Je.tableKey});if(void 0!==p)return p}if(e.insights){var b=null===(a=Y.renderInsightsCell)||void 0===a?void 0:a.call(Y,{column:t,row:e.insights,entityKey:null!==(u=Je.entityKey)&&void 0!==u?u:""});if(void 0!==b)return b}if("custom"===t.source)return null!==(c=t.emptyText)&&void 0!==c?c:"—";if("kpi"===t.source&&e.insights&&!(null==f?void 0:f.as)){var m=e.insights.metrics[y],g=K(null==m?void 0:m.value,t.format),w=null==(null==m?void 0:m.deltaPct)?"—":"".concat(m.deltaPct>0?"↑":m.deltaPct<0?"↓":""," ").concat(Math.abs(m.deltaPct),"%");return"delta"===t.show?i("span",n({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w})):"value"===t.show?g:r("span",n({className:"ag-drill__metric"},{children:[i("strong",{children:g}),i("small",n({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w}))]}))}if("children"===t.source&&e.insights&&!(null==f?void 0:f.as)){var N=Array.from(new Set(h)),_=null!==(d=t.max)&&void 0!==d?d:3,C=N.length?"".concat(N.slice(0,_).join(", ")).concat(N.length>_?" +".concat(N.length-_):""):null!==(s=t.emptyText)&&void 0!==s?s:"—";return i("span",n({className:"ag-drill__contributors",title:N.join(", ")||void 0},{children:C}))}var S=null!==(v=null==f?void 0:f.as)&&void 0!==v?v:t.format;if("link"===S){var x="string"==typeof h?h:"";return/^https:\/\//i.test(x)?i("a",n({href:x,target:"_blank",rel:"noopener noreferrer"},{children:x})):K(h,"text")}var T=K(h,"chip"===S?"text":S);return"—"===T&&t.emptyText?t.emptyText:"chip"!==S&&!(null==f?void 0:f.colors)||"—"===T?T:i(j,{text:T.replace(/_/g," "),value:h,colors:null==f?void 0:f.colors})},Sn=function(e){e.insights&&(null==V||V(e.insights,sn))},xn=Je.buttons.length>0,Tn=function(e){var n;return null!==(n=e.align)&&void 0!==n?n:"kpi"===e.source?"right":"left"},jn="ag-drill-".concat(String(null!==(z=W.id)&&void 0!==z?z:kn).replace(/[^a-z0-9]+/gi,"-")),Dn=!1!==W.search&&"movers"!==Ge;return r("section",n({className:"ag-drill".concat(X?" ".concat(X):""),"aria-labelledby":jn,style:null===(F=null==un?void 0:un.card)||void 0===F?void 0:F.root},{children:[r("header",n({className:"ag-drill__header",style:null===(J=null==un?void 0:un.card)||void 0===J?void 0:J.header},{children:[r("div",{children:[i("h3",n({id:jn,style:null===(H=null==un?void 0:un.card)||void 0===H?void 0:H.title},{children:kn})),"movers"===Ge?r("span",{children:["Rows that moved",Q.day?" on ".concat(b(Q.day)):""]}):null]}),Dn?r("label",n({className:"ag-drill__search"},{children:[i(o,{"aria-hidden":"true"}),i("input",{type:"search",value:ie,onChange:function(e){return oe(e.target.value)},placeholder:"Search ".concat(mn.toLowerCase(),"…"),"aria-label":"Search ".concat(mn)})]})):null]})),$.length>1?i("div",n({className:"ag-drill__tabs",role:"tablist","aria-label":"What this table lists"},{children:$.map(function(e,t){var l;return i("button",n({type:"button",role:"tab","aria-selected":t===te,className:t===te?"is-active":void 0,onClick:function(){le(t),oe(""),ce(""),ve(W.defaultSort)}},{children:gn(e)}),"".concat(e.source,":").concat(null!==(l=e.entityKey)&&void 0!==l?l:e.tableKey,":").concat(t))})})):null,Ae?r("p",n({className:"ag-drill__notice ag-drill__notice--".concat(Ae.tone),role:"status"},{children:[Ae.text,i("button",n({type:"button","aria-label":"Dismiss",onClick:function(){return Ie(null)}},{children:i(a,{"aria-hidden":"true"})}))]})):null,r("div",n({className:"ag-drill__table-wrap","aria-live":"polite"},{children:[r("table",n({className:"ag-drill__table"},{children:[i("thead",{children:r("tr",{children:[cn?cn.map(function(e){var t,l,o=an.find(function(n){return n.key===e.key}),a=n(n({},o),{key:e.key,source:null!==(t=null==o?void 0:o.source)&&void 0!==t?t:"field",sortable:null!==(l=e.sortable)&&void 0!==l?l:null==o?void 0:o.sortable});return i("th",n({className:e.headerClassName,style:n(n({},e.style),e.headerStyle),"aria-sort":(null==se?void 0:se.key)===e.key?"asc"===se.order?"ascending":"descending":void 0},{children:fn(a)?r("button",n({type:"button",onClick:function(){return hn(a)}},{children:[e.header,i("span",n({"aria-hidden":"true"},{children:(null==se?void 0:se.key)===e.key?"asc"===se.order?"↑":"↓":"↕"}))]})):e.header}),e.key)}):an.map(function(e){var t,l,o,a,u,c=null!==(l=null!==(t=e.key)&&void 0!==t?t:e.id)&&void 0!==l?l:"",d=null!==(o=e.label)&&void 0!==o?o:"kpi"===e.source?Y.kpiLabel(c):"children"===e.source?Y.entityPluralName(null!==(a=e.childEntityKey)&&void 0!==a?a:""):w(null!==(u=c.split(".").pop())&&void 0!==u?u:c);return i("th",n({className:"ag-drill__col--".concat(Tn(e)," ").concat(e.hideBelow?"ag-drill__hide--".concat(e.hideBelow):""),style:{width:e.width},"aria-sort":(null==se?void 0:se.key)===c?"asc"===se.order?"ascending":"descending":void 0},{children:fn(e)?r("button",n({type:"button",onClick:function(){return hn(e)}},{children:[d,i("span",n({"aria-hidden":"true"},{children:(null==se?void 0:se.key)===c?"asc"===se.order?"↑":"↓":"↕"}))]})):d}),"".concat(e.source,":").concat(c))}),xn?i("th",{children:i("span",n({className:"ins-visually-hidden"},{children:"Actions"}))}):null,vn?i("th",{children:i("span",n({className:"ins-visually-hidden"},{children:"Open"}))}):null]})}),i("tbody",{children:yn.map(function(e){return r("tr",n({className:vn?void 0:"is-static",tabIndex:vn?0:void 0,onClick:vn?function(n){n.target.closest("a,button,input,select,textarea")||Sn(e)}:void 0,onKeyDown:vn?function(n){return function(e,n){vn&&e.target===e.currentTarget&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Sn(n)))}(n,e)}:void 0},{children:[cn?(t=dn(e),cn.map(function(e){return i("td",n({className:e.bodyClassName,style:n(n({},e.style),e.bodyStyle)},{children:e.body(t)}),e.key)})):an.map(function(t,l){var r,o,a=0===l?"th":"td",u=null===(r=_n(t))||void 0===r?void 0:r.className;return i(a,n({scope:0===l?"row":void 0,className:"ag-drill__col--".concat(Tn(t)," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):"").concat(u?" ".concat(u):"")},{children:Cn(e,t)}),"".concat(t.source,":").concat(null!==(o=t.key)&&void 0!==o?o:t.id))}),xn?i("td",n({className:"ag-drill__buttons"},{children:Kn(e).map(function(t){var l,r,o=ze==="".concat(e.id,":").concat(null!==(l=t.id)&&void 0!==l?l:t.label);return i("button",n({type:"button",disabled:o,"aria-busy":o||void 0,onClick:function(){return function(e,n){var t,l=e.confirm?_(e.confirm,N(Y,Q,n),{},!1):"";"call"!==e.type||!(null!==(t=e.ask)&&void 0!==t?t:[]).length&&!l?l&&!window.confirm(l)||Nn(e,n,{}):Le({button:e,row:n,question:l})}(t,e)}},{children:o?"…":t.label}),null!==(r=t.id)&&void 0!==r?r:t.label)})})):null,vn?i("td",{children:i(u,{className:"ag-drill__open","aria-hidden":"true"})}):null]}),e.id);var t})})]})),je&&!fe.length?i("p",n({className:"ag-drill__state"},{children:"Loading rows…"})):null,je||yn.length||Be?null:i("p",n({className:"ag-drill__state"},{children:"No rows found."})),Be?i("p",n({className:"ag-drill__state ag-drill__state--error"},{children:Be})):null]})),r("footer",n({className:"ag-drill__footer"},{children:[i("span",{children:"rows"===Ge&&Se?"".concat(fe.length," of ").concat(Se):""}),Ne?i("button",n({type:"button",onClick:function(){return t(U,void 0,void 0,function(){var n,t,r;return l(this,function(l){switch(l.label){case 0:if(je||!Ne)return[2];De(!0),Oe(null),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,on(!0)];case 2:return(n=l.sent())?(he(function(t){return e(e([],t,!0),n.rows,!0)}),_e(n.hasMore),me(null!==(r=n.cursor)&&void 0!==r?r:null),ke(n.offset),[3,5]):[2];case 3:return t=l.sent(),Oe(t instanceof Error?t.message:"More rows couldn't be loaded."),[3,5];case 4:return De(!1),[7];case 5:return[2]}})})},disabled:je},{children:je?"Loading…":"Show more"})):null]})),Me?i(D,{button:Me.button,question:Me.question,onCancel:function(){return Le(null)},onSubmit:function(e){var n=Me.button,t=Me.row;Le(null),Nn(n,t,e)}}):null]}))}export{E as default};
|
|
2
2
|
//# sourceMappingURL=DrillTable.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__assign as t}from"../../../_virtual/_tslib.js";function e(t){var e=t.endDate,a=t.workingDays,r=t.selectedDay,n=t.reportDay,D=t.now,o=void 0===D?new Date:D;if(r)return r;var g=function(t){return"".concat(t.getFullYear(),"-").concat(String(t.getMonth()+1).padStart(2,"0"),"-").concat(String(t.getDate()).padStart(2,"0"))};if(!a)return n||g(e);var i=new Date(o.getFullYear(),o.getMonth(),o.getDate());i.setDate(i.getDate()-1);var s=new Date(e.getFullYear(),e.getMonth(),e.getDate());for(s<i&&i.setTime(s.getTime());0===i.getDay()||6===i.getDay();)i.setDate(i.getDate()-1);return g(i)}function a(a,r,n,D){if(!r&&!n)return t(t({},a),{workingDaysOnly:!1});var o=e({endDate:a.endDate,workingDays:r,selectedDay:n,now:D}),g=new Date("".concat(o,"T00:00:00"));return t(t({},a),{startDate:n||a.startDate>g?g:a.startDate,endDate:g,workingDaysOnly:!n&&r})}export{e as resolveDrillDay,a as resolveL2SummaryRange};
|
|
2
|
+
//# sourceMappingURL=drillDay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drillDay.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as l,__spreadArray as e,__assign as i}from"../../../_virtual/_tslib.js";import{jsx as o,jsxs as n}from"react/jsx-runtime";import{useRef as t,useState as r,useEffect as a}from"react";import{DataTable as d}from"primereact/datatable";import{Column as u}from"primereact/column";import{ColumnGroup as c}from"primereact/columngroup";import{Row as s}from"primereact/row";import{Skeleton as p}from"primereact/skeleton";import"primereact/resources/primereact.min.css";import"primeicons/primeicons.css";function m(m){var v,f,h,g,y=m.rows,w=void 0===y?[]:y,N=m.loading,
|
|
1
|
+
import{__rest as l,__spreadArray as e,__assign as i}from"../../../_virtual/_tslib.js";import{jsx as o,jsxs as n}from"react/jsx-runtime";import{useRef as t,useState as r,useEffect as a}from"react";import{DataTable as d}from"primereact/datatable";import{Column as u}from"primereact/column";import{ColumnGroup as c}from"primereact/columngroup";import{Row as s}from"primereact/row";import{Skeleton as p}from"primereact/skeleton";import"primereact/resources/primereact.min.css";import"primeicons/primeicons.css";function m(m){var v,f,h,g,y=m.rows,w=void 0===y?[]:y,N=m.loading,b=m.loadingMore,x=m.onLoadMore,C=m.hasMore,_=m.emptyState,k=m.columns,S=m.tableProps,R=m.onRowClick,E=m.rowDetail,j=m.scrollHeight,T=void 0===j?"flex":j,D=t(null);t(null);var H="function"==typeof(null==E?void 0:E.render),M=r({}),L=M[0],q=M[1],A=function(l){return!(!(null==l?void 0:l.id)||!L[l.id])},B=function(l){(null==l?void 0:l.id)&&q(function(e){var o,n;return(null==E?void 0:E.multiple)?i(i({},e),((o={})[l.id]=!0,o)):((n={})[l.id]=!0,n)})},z=function(l){(null==l?void 0:l.id)&&q(function(e){var o=i({},e);return delete o[l.id],o})},F=function(l){return A(l)?z(l):B(l)},G=null!=S?S:{},K=G.onRowClick,O=G.rowClassName,P=l(G,["onRowClick","rowClassName"]),W=e(e([],w,!0),b?[{id:"__loading-more",__loading:!0}]:[],!0),I=!b&&x&&!1===C&&(null!==(v=null==k?void 0:k.length)&&void 0!==v?v:0)>0?o(c,{children:o(s,{children:o(u,{colSpan:k.length,footer:n("span",i({className:"audit-paginationEndContent"},{children:[o("i",{className:"pi pi-check-circle","aria-hidden":"true"}),"No more records to load"]})),footerClassName:"audit-paginationEnd"})})}):void 0;return a(function(){var l,e=null===(l=D.current)||void 0===l?void 0:l.querySelector(".p-datatable-wrapper");if(e){var i=!1,o=function(){i||(i=!0,requestAnimationFrame(function(){var l=e.scrollTop;e.scrollHeight-l-e.clientHeight<100&&C&&!b&&(null==x||x()),i=!1}))};return e.addEventListener("scroll",o),function(){e.removeEventListener("scroll",o)}}},[w,C,b,x]),N?o("div",{children:e([],Array(5),!0).map(function(l,e){return n("div",i({className:"audit-skeletonRow"},{children:[o(p,{height:0===e?"55px":"25px",width:"25%"}),o(p,{height:0===e?"55px":"25px",width:"50%"}),o(p,{height:0===e?"55px":"25px",width:"25%"})]}),e)})}):w&&0!==w.length?o("div",i({className:"audit-tableWrap",ref:D},{children:o(d,i({value:W,className:"audit-table ".concat(null!==(g=null==S?void 0:S.className)&&void 0!==g?g:""),dataKey:"id",scrollable:!0,scrollHeight:T},P,{rowClassName:function(l,e){var o="function"==typeof O?O(l,e):O,n=!H&&!R||(null==l?void 0:l.__loading)?"":"audit-row--clickable";return o&&"object"==typeof o?i(i({},o),{"audit-row--clickable":!!n}):[o,n].filter(Boolean).join(" ")},expandedRows:L,onRowToggle:function(l){return q(l.data)},rowExpansionTemplate:H?function(l){var e;return!H||(null==l?void 0:l.__loading)?null:o("div",i({className:"audit-rowDetail ".concat(null!==(e=null==E?void 0:E.className)&&void 0!==e?e:""),style:null==E?void 0:E.style},{children:E.render(l,{close:function(){return z(l)}})}))}:void 0,onRowClick:function(l){var e,i,o=null==l?void 0:l.data;if(o&&!o.__loading){var n=null===(e=null==l?void 0:l.originalEvent)||void 0===e?void 0:e.target;(null===(i=null==n?void 0:n.closest)||void 0===i?void 0:i.call(n,"button, a, input, .audit-seeMore"))||(null==R||R(o,{isExpanded:A(o),expand:function(){return B(o)},collapse:function(){return z(o)},toggle:function(){return F(o)}}),H&&!1!==(null==E?void 0:E.expandOnRowClick)&&F(o)),null==K||K(l)}},footerColumnGroup:I},{children:null==k?void 0:k.map(function(l){return o(u,{field:l.key,sortable:l.sortable,header:null==l?void 0:l.header,body:function(e){return(null==e?void 0:e.__loading)?o(p,{height:"25px"}):null==l?void 0:l.body(e)},style:null==l?void 0:l.style,headerStyle:null==l?void 0:l.headerStyle,bodyStyle:null==l?void 0:l.bodyStyle,headerClassName:null==l?void 0:l.headerClassName,bodyClassName:null==l?void 0:l.bodyClassName,pt:{bodyCell:{style:{padding:"16px"}},headerCell:{style:{padding:"16px"}}}},null==l?void 0:l.key)})}))})):n("div",i({className:"audit-emptyState"},{children:[(null==_?void 0:_.icon)?_.icon:o("i",{className:"pi pi-file",style:{fontSize:"63px",marginBottom:"8px"}}),o("div",i({className:"audit-emptyTitle"},{children:null!==(f=null==_?void 0:_.title)&&void 0!==f?f:"No Data found"})),o("div",i({className:"audit-emptyDesc"},{children:null!==(h=null==_?void 0:_.description)&&void 0!==h?h:"Try adjusting your filters or search criteria."}))]}))}export{m as default};
|
|
2
2
|
//# sourceMappingURL=FTable.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),i=require("react"),a=require("lucide-react"),t=require("../RcaDecisionComponent/RcaDecisionComponent.js"),r=require("../Graph/LineChart.js"),s=require("../../api/insightsApi.js"),o=require("./insightsContextCore.js"),l=require("./insightsUtils.js"),d=require("./DrillTable.js"),c=require("./FilterNotice.js"),u=require("./agPrimitives.js"),g=require("./NeedsAttention.js"),v=10;function p(a){var t,r=this,d=a.entityKey,c=a.dataDay,u=o.useInsights(),g=i.useState(null),v=g[0],p=g[1],h=i.useState(null),_=h[0],m=h[1];if(l.useJob(v,null!==(t=null==u?void 0:u.api)&&void 0!==t?t:null,function(){p(null),null==u||u.refresh()}),!(null==u?void 0:u.viewer.isAdmin))return null;return n.jsxs("span",{children:[n.jsx("button",e.__assign({type:"button",className:"ins-link",disabled:Boolean(v),onClick:function(){return e.__awaiter(r,void 0,void 0,function(){var n,i,a,t;return e.__generator(this,function(e){switch(e.label){case 0:m(null),e.label=1;case 1:return e.trys.push([1,6,,7]),n={dataDay:c||s.toIsoDay(u.range.endDate),window:"both"},d?[4,s.generateLevelSummary(u.api,d,n)]:[3,3];case 2:return a=e.sent(),[3,5];case 3:return[4,s.generateInsightsSummary(u.api,n)];case 4:a=e.sent(),e.label=5;case 5:return(i=a).jobId?p(i.jobId):u.refresh(),[3,7];case 6:return t=e.sent(),m(t.message||"The summary couldn't be regenerated."),[3,7];case 7:return[2]}})})}},{children:v?"Regenerating…":"Regenerate summary"})),_?n.jsx("span",e.__assign({className:"ins-error"},{children:_})):null]})}var h=function(e){return e.replace(/\b\w/g,function(e){return e.toUpperCase()})};function _(e,n){return n?"Decision Advantage is unavailable right now: ".concat(n.message):e?"waiting"===e.status?"The first morning run hasn't finished yet. This fills in after it.":"running"===e.status?"The AI is writing this report. It usually takes a minute or two.":"generated"!==e.status?"No report generated for this day.":null:null}function m(e,n,i){return i?null:_(e,n)}function y(e){return e.replace(/\{\{([^|}]*)\|[^}]*\}\}/g,"$1")}function f(a){var r,s,o=a.report,d=a.movementType,c=a.direction,g=a.good,v=a.loading,p=a.error,h=i.useState(!1),m=h[0],y=h[1],f=i.useMemo(function(){return l.reportDecisioning(o)},[o]);if(i.useEffect(function(){return y(!1)},[null==o?void 0:o.reportId]),v)return n.jsx("div",e.__assign({className:"ag-summary"},{children:n.jsx(u.SkeletonLines,{widths:[28,96,72],label:"Loading summary"})}));var x=null==o?void 0:o.summary,b=null!==(r=null==x?void 0:x.headline)&&void 0!==r?r:"",j=Boolean(b),k=u.splitVerdict(b).prefix,w=Boolean(null==x?void 0:x.eyebrow)&&"Movement unavailable"!==(null==x?void 0:x.eyebrow),N=void 0!==d,D=w?x.eyebrow:N?u.movementVerdictLabel(d,c):k||"Summary",I=w?"good"===x.tone||"bad"===x.tone?u.verdictToneHex(x.tone):u.movementColorHex(x.movementType,x.movementDirection,g):N?u.movementColorHex(d,c,g):"Good news"===k?"#15803D":"Bad news"===k?"#E11D48":"#5928ED";return n.jsxs("div",e.__assign({className:"ag-summary"},{children:[n.jsx("p",e.__assign({className:"ag-summary__title",style:{color:j?I:"#64748b"}},{children:j?D:"No summary yet"})),n.jsxs("div",e.__assign({className:"ag-summary__text"},{children:[j?n.jsx(u.VerdictSentence,{text:b,good:g}):null!==(s=_(o,p))&&void 0!==s?s:"Reports are written after each morning run.",j&&f?n.jsx("span",e.__assign({className:"ag-summary__brain"},{children:n.jsx(t.ReasoningTrigger,{open:m,onToggle:function(){return y(function(e){return!e})},label:"how the AI reached this summary"})})):null]})),m&&f?n.jsx("div",e.__assign({className:"ag-summary__reasoning"},{children:n.jsx(t.ReasoningPanel,{decisioning:f})})):null]}))}function x(e){var a,r,s,d=e.report,c=e.error,g=e.loading,v=o.useInsights(),p=!g&&"generated"===(null==d?void 0:d.status),h=i.useMemo(function(){return p?l.reportDecisioning(d,null==d?void 0:d.footer):null},[p,d]),_=l.useOpenRow();return n.jsx(t.RcaDecisionComponent,{className:"ag-decision",title:null!==(a=null==v?void 0:v.labels.decisionAdvantageTitle)&&void 0!==a?a:"Decision Advantage",score:p?null==d?void 0:d.score:null,decisioning:h,notice:m(d,c,g),afterSections:g?n.jsx(u.SkeletonLines,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:p?l.toRcaItems(null==d?void 0:d.rootCause,_):[],nextSteps:p?l.toRcaItems(null==d?void 0:d.nextSteps,_):[],width:"100%",maxWidth:"none"},"".concat(null!==(r=null==d?void 0:d.reportId)&&void 0!==r?r:"pending",":").concat(null!==(s=null==d?void 0:d.generatedAt)&&void 0!==s?s:""))}var b=[{key:"drivers",label:"driversTab",info:"What moved the day's number the same way."},{key:"headwinds",label:"headwindsTab",info:"What moved against the day's number."},{key:"attention",label:"attentionTab",info:"The number moved, but activity doesn't explain it."}],j={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},k={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function w(i){var t=i.on,r=i.onClick,s=i.disabled,o=void 0!==s&&s;return n.jsxs("button",e.__assign({type:"button",className:"ag-graph-pill".concat(t?" is-on":""),disabled:o,title:o?"A graph can show up to ".concat(v," rows"):void 0,onClick:function(e){e.stopPropagation(),r()}},{children:[n.jsx(a.TrendingUp,{"aria-hidden":"true"}),t?"In graph":o?"Graph full":"Add to graph"]}))}function N(i){var t=i.rank,r=i.category,s=i.name,o=i.chips,l=i.action,d=i.lines,c=i.cell,u=i.onOpen;return n.jsx("li",{children:n.jsxs("div",e.__assign({className:"ag-driver".concat(u?" is-clickable":""),role:u?"button":void 0,tabIndex:u?0:void 0,onClick:u,onKeyDown:u?function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u())}:void 0},{children:[n.jsxs("div",e.__assign({className:"ag-driver__main"},{children:[n.jsxs("span",e.__assign({className:"ag-driver__rank"},{children:[t,"."]})),n.jsxs("div",e.__assign({className:"ag-driver__body"},{children:[r?n.jsxs("span",e.__assign({className:"ag-driver__category"},{children:[r," >"]})):null,n.jsx("span",e.__assign({className:"ag-driver__name"},{children:s})),n.jsxs("div",e.__assign({className:"ag-driver__chips"},{children:[o,l]})),d]}))]})),n.jsxs("div",e.__assign({className:"ag-driver__cell"},{children:[c,u?n.jsx("span",e.__assign({className:"ag-driver__open","aria-hidden":"true"},{children:n.jsx(a.ArrowUpRight,{})})):null]}))]}))})}function D(i){var a,t=i.label,r=i.rightLabel,s=i.children,l=o.useInsights();return n.jsxs("div",e.__assign({className:"ag-drivers"},{children:[n.jsxs("div",e.__assign({className:"ag-drivers__head"},{children:[n.jsx("span",{children:t}),n.jsx("span",{children:null!==(a=null!=r?r:null==l?void 0:l.labels.activityColumn)&&void 0!==a?a:"User Activity"})]})),n.jsx("ol",{children:s})]}))}var I=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],C=function(e,n){void 0===n&&(n="en-GB");var i=e.slice(0,10).split("-").map(Number),a=i[0],t=i[1],r=i[2];return Number.isFinite(a)&&Number.isFinite(t)&&Number.isFinite(r)?new Intl.DateTimeFormat(n,{day:"numeric",month:"short"}).format(new Date(a,t-1,r)):e};function S(t){var d,c,g,v,p,h,_,m,y=this,f=t.dataDay,x=t.nodeKey,b=void 0===x?"root":x,j=t.kpiId,w=t.dayGroup,N=o.useInsights(),D=null!==(d=null!=j?j:null==N?void 0:N.headlineKpi)&&void 0!==d?d:void 0,S=i.useState(""),K=S[0],A=S[1],T=i.useState([]),L=T[0],R=T[1],F=i.useState({}),P=F[0],M=F[1],E=i.useState(""),B=E[0],O=E[1],G=i.useState(null),V=G[0],q=G[1],H=i.useState(null),U=H[0],W=H[1],z=i.useState(!1),Z=z[0],$=z[1],J=i.useState(!1),X=J[0],Q=J[1],Y=i.useRef(null),ee=l.useInsightsFetch(N&&D&&f?function(n){return s.fetchInsightsCorrelation(N.api,b,e.__assign({kpiId:D,dataDay:f,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate),filters:N.range.filters},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,D,b,P.disregardBefore,null===(c=P.disregardDates)||void 0===c?void 0:c.join(","),null==N?void 0:N.revision]),ne=ee.data,ie=ee.error,ae=ee.loading,te=l.useInsightsFetch(N&&D&&f?function(n){return s.fetchInsightsCorrelationTrend(N.api,b,e.__assign({kpiId:D,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate),filters:N.range.filters},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,D,b,P.disregardBefore,null===(g=P.disregardDates)||void 0===g?void 0:g.join(","),null==N?void 0:N.revision]);l.useJob(U,null!==(v=null==N?void 0:N.api)&&void 0!==v?v:null,function(){W(null),O(""),null==N||N.refresh()}),i.useEffect(function(){if(Z){var e=function(e){Y.current&&!Y.current.contains(e.target)&&$(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[Z]);var re=i.useState(new Set),se=re[0],oe=re[1],le=i.useMemo(function(){if(!ne)return[];return ne.series.filter(function(e){return!(null==w?void 0:w.length)||w.map(Number).includes((n=e.x,new Date("".concat(n.slice(0,10),"T00:00:00")).getDay()||7));var n})},[ne,w]),de=i.useMemo(function(){return ne&&N?e.__spreadArray([ne.kpiId],ne.drivers.map(function(e){return e.kpiId}).filter(function(e){return e!==ne.kpiId}),!0).map(function(e,n){return{key:"corr_".concat(e.replace(/[^a-zA-Z0-9_]/g,"_")),label:N.kpiLabel(e),color:I[n%I.length],curve:"smooth",strokeWidth:2,pointRadius:2,data:le.map(function(n){var i,a;return{x:n.x,y:n.disregarded?null:null!==(a=null===(i=n.values)||void 0===i?void 0:i[e])&&void 0!==a?a:null}}),valueFormatter:function(e){return"".concat(e,"%")}}}):[]},[ne,N,le]);i.useEffect(function(){return oe(new Set(de.slice(2).map(function(e){return e.key})))},[de]);if(!N||!f||"no_drivers"===(null==ne?void 0:ne.state)||ne&&!ne.verdictText)return null;if(ie)return n.jsxs("div",e.__assign({className:"ag-empty"},{children:["Correlation is unavailable right now: ",ie.message]}));if(ae&&!ne)return n.jsx(u.ChartSkeleton,{height:220,label:"Loading correlation"});if(!ne)return null;var ce=null!==(p=ne.strength)&&void 0!==p?p:"none",ue=N.kpiLabel(ne.kpiId);return n.jsx(u.CollapsibleVisualSection,e.__assign({title:"Correlation",meta:"Usage vs. ".concat(ue),className:"ag-visual--card",action:N.viewer.isAdmin?n.jsxs("div",e.__assign({ref:Y,className:"ag-corr__settings"},{children:[n.jsx("button",e.__assign({type:"button",className:"ag-icon-button","aria-label":"Correlation settings","aria-expanded":Z,onClick:function(){return $(function(e){return!e})}},{children:n.jsx(a.Settings2,{"aria-hidden":"true"})})),Z?n.jsx("div",e.__assign({className:"ag-corr__settings-menu",role:"menu"},{children:n.jsxs("label",{children:[n.jsx("input",{type:"checkbox",checked:X,onChange:function(e){return Q(e.target.checked)}}),"Show date controls"]})})):null]})):null},{children:n.jsxs("div",e.__assign({className:"ag-corr"},{children:[n.jsx("p",e.__assign({className:"ag-corr__banner ag-corr__banner--".concat(ce)},{children:ne.verdictText})),n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(ce)},{children:k[ce]})),n.jsxs("p",e.__assign({className:"ag-corr__caption"},{children:[ue," vs. usage - % change from the first day shown"]})),(null===(h=ne.window)||void 0===h?void 0:h.source)?n.jsx("p",e.__assign({className:"ag-muted"},{children:"default"===ne.window.source?ne.window.startDate?"Using all days since ".concat(C(ne.window.startDate,"en-US")):"Using all available days":"row"===ne.window.source?"Saved window".concat(ne.window.startDate?" since ".concat(C(ne.window.startDate,"en-US")):"").concat((null===(_=ne.window.excludedDates)||void 0===_?void 0:_.length)?" · ".concat(ne.window.excludedDates.length," left out"):""):"Preview window".concat((null===(m=ne.window.excludedDates)||void 0===m?void 0:m.length)?" · ".concat(ne.window.excludedDates.length," left out"):"")})):null,n.jsx("div",e.__assign({className:"ag-chart"},{children:n.jsx("div",e.__assign({className:"ellm-graph"},{children:n.jsx(r.default,{tier:"decision-advantage-correlation",series:de,hiddenKeys:se,onToggleSeries:function(e){return oe(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i})},onPointClick:function(){},xAxis:{label:"Date",categories:le.map(function(e){return e.x}),formatTick:function(e){return l.shortDay(e)}},yAxis:{label:"% change",beginAtZero:!1,formatTick:function(e){return"".concat(Math.round(Number(e)),"%")}},tooltip:{render:function(i){var a,t=i.x,r=i.points,s=String(t),o=null===(a=te.data)||void 0===a?void 0:a.series.find(function(e){return e.x===s});return n.jsxs("div",e.__assign({className:"ag-tip ag-tip--wide"},{children:[n.jsx("div",e.__assign({className:"ag-tip__head"},{children:C(s)})),r.filter(function(e){return null!=e.value}).map(function(i){return n.jsxs("div",e.__assign({className:"ag-tip__line"},{children:[n.jsxs("span",{children:[n.jsx("i",{style:{background:i.color}}),i.series.label]}),n.jsxs("strong",{children:[i.value,"%"]})]}),i.series.key)}),o?Object.keys(o.r).map(function(i){var a,t;return n.jsxs("div",e.__assign({className:"ag-tip__sub"},{children:[n.jsx("span",{children:N.kpiLabel(i)}),n.jsx("span",{children:null==o.r[i]?"No correlation":"r ".concat(o.r[i]," · ").concat(null!==(a=o.strength[i])&&void 0!==a?a:"none"," · ").concat(null!==(t=o.nObs[i])&&void 0!==t?t:0," days")})]}),i)}):null]}))}},legend:{position:"bottom",toggle:!0},style:{chartHeight:220,yAxisWidth:60,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}})}))})),n.jsx("div",e.__assign({className:"ag-corr__metrics"},{children:ne.drivers.map(function(i){var a,t=null!==(a=i.strength)&&void 0!==a?a:"none";return n.jsxs("div",e.__assign({className:"ag-corr__metric"},{children:[n.jsx("span",e.__assign({className:"ag-corr__name"},{children:i.label||N.kpiLabel(i.kpiId)})),i.kpiId!==ne.kpiId?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(t)},{children:k[t]})):null,n.jsx("strong",{children:l.formatValue(i.value)}),n.jsx("span",e.__assign({className:"ag-corr__delta"},{children:null!=i.deltaPct?n.jsxs(n.Fragment,{children:[n.jsxs("span",e.__assign({className:"ag-dod__value ag-dod__value--".concat(i.tone||"flat")},{children:["up"===i.direction?"↑":"down"===i.direction?"↓":"→"," ",Math.abs(i.deltaPct),"%"]}))," vs. ",l.formatValue(i.previous)]}):"—"})),i.kpiId!==ne.kpiId?n.jsxs("span",e.__assign({className:"ag-corr__r"},{children:[i.nObs," days used",i.lowHistory?" · Low history":"",n.jsx("br",{}),null==i.movedWithToday?"No comparison for today":i.movedWithToday?"Moved together with the headline today":"Moved opposite the headline today"]})):null]}),i.kpiId)})})),N.viewer.isAdmin&&X?n.jsxs("div",e.__assign({className:"ag-corr__window"},{children:[n.jsxs("label",e.__assign({className:"ag-corr__start"},{children:["Ignore data before ",n.jsx("input",{type:"date",value:K,onChange:function(e){return A(e.target.value)}})]})),n.jsxs("div",e.__assign({className:"ag-corr__days-label"},{children:["Or leave out individual dates (",L.length," selected)"]})),n.jsx("div",e.__assign({className:"ag-corr__days","aria-label":"Days to leave out"},{children:ne.series.map(function(i){return n.jsx("button",e.__assign({type:"button","aria-pressed":L.includes(i.x),className:L.includes(i.x)?"is-selected":void 0,onClick:function(){return n=i.x,R(function(i){return i.includes(n)?i.filter(function(e){return e!==n}):e.__spreadArray(e.__spreadArray([],i,!0),[n],!1)});var n}},{children:C(i.x)}),i.x)})})),n.jsx("input",{className:"ag-corr__reason",value:B,onChange:function(e){return O(e.target.value)},placeholder:"Reason required to apply"}),V?n.jsx("p",e.__assign({className:"ins-error"},{children:V})):null,n.jsxs("div",e.__assign({className:"ag-corr__actions"},{children:[n.jsx("button",e.__assign({type:"button",className:"ins-link",onClick:function(){return M({disregardBefore:K||void 0,disregardDates:L})}},{children:"Preview"})),n.jsx("button",e.__assign({type:"button",className:"ins-button",disabled:Boolean(U),onClick:function(){return e.__awaiter(y,void 0,void 0,function(){var n,i;return e.__generator(this,function(e){switch(e.label){case 0:if(!N||!D||!B.trim())return q("A reason is required."),[2];q(null),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.saveCorrelationWindow(N.api,b,{kpiId:D,startDate:K||null,excludedDates:L,dataDay:f,changeReason:B.trim(),regenerate:!0})];case 2:return n=e.sent(),W(n.jobId),[3,4];case 3:return i=e.sent(),q(i.message||"The correlation window couldn't be saved."),[3,4];case 4:return[2]}})})}},{children:"Apply"})),n.jsx("button",e.__assign({type:"button",className:"ins-link",onClick:function(){A(""),R([]),M({})}},{children:"Clear"}))]}))]})):null]}))}))}var K=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function A(a){var t,d=a.entityKey,c=a.kpis,g=a.nodeKeys,p=a.workingDays,h=a.group,_=a.onOpenPoint,m=o.useInsights(),y=i.useState(null!==(t=c[0])&&void 0!==t?t:""),f=y[0],x=y[1];i.useEffect(function(){var e;c.includes(f)||x(null!==(e=c[0])&&void 0!==e?e:"")},[c,f]);var b=l.useInsightsFetch(m&&f&&null!==h&&0!==(null==g?void 0:g.length)?function(n){return s.fetchInsightsSeries(m.api,e.__assign(e.__assign({},m.range),{workingDaysOnly:p,group:h||void 0}),g?{kpiIds:[f],nodeKeys:g.slice(0,v)}:{kpiIds:[f],entityKey:d,topN:3},n)}:null,[null==m?void 0:m.api.configId,null==m?void 0:m.rangeKey,d,f,null==g?void 0:g.join(","),p,h,null==m?void 0:m.revision]),j=b.data,k=b.loading,w=b.error,N=i.useMemo(function(){var e;return 0===(null==g?void 0:g.length)?[]:(null!==(e=null==j?void 0:j.series)&&void 0!==e?e:[]).filter(function(e){return e.kpiId===f&&e.points.some(function(e){return Number.isFinite(e.y)})})},[j,g,f]),D=i.useState(new Set),I=D[0],C=D[1];i.useEffect(function(){return C(new Set)},[N]);var S=i.useMemo(function(){return Array.from(new Set(N.flatMap(function(e){return e.points.map(function(e){return e.x})}))).sort()},[N]),K=i.useMemo(function(){return N.map(function(e,n){var i,a=new Map(e.points.map(function(e){return[e.x,e.y]})),t=null!==(i=null==m?void 0:m.goodDirection(e.kpiId))&&void 0!==i?i:"up";return{key:"row_".concat(n,"_").concat(e.nodeKey.replace(/[^a-zA-Z0-9_]/g,"_")),label:e.label||e.nodeKey,color:["#06B6D4","#10A66A","#8650FF","#F59E0B","#E94BBD","#4285FF","#64748B","#F04444","#14B8A6","#84CC16"][n%10],curve:"smooth",pointRadius:3,activePointRadius:3,fillPointsOnHover:!0,data:S.map(function(e){var n;return{x:e,y:null!==(n=a.get(e))&&void 0!==n?n:null}}),valueFormatter:function(e){return l.formatValue(e)},markers:e.points.filter(function(e){var n;return null===(n=e.meta)||void 0===n?void 0:n.marker}).map(function(n){return{x:n.x,color:u.movementColorHex(n.meta.marker.movementType,n.meta.marker.direction,t),label:[n.meta.marker.criticality,n.meta.marker.headline].filter(Boolean).join(" · "),radius:3,haloRadius:3,onClick:function(){var i,a=null!==(i=e.label)&&void 0!==i?i:e.nodeKey;_?_({nodeKey:e.nodeKey,label:a,kpiId:e.kpiId,dataDay:n.x,reportId:n.meta.marker.reportId}):null==m||m.openReport(n.meta.marker.reportId?{reportId:n.meta.marker.reportId,title:"".concat(a," · ").concat(l.shortDay(n.x))}:{nodeKey:e.nodeKey,kpiId:e.kpiId,dataDay:n.x,title:"".concat(a," · ").concat(l.shortDay(n.x))})}}})}})},[N,S,m,_]);if(!m)return null;var A=m.kpiLabel(f);return n.jsxs("div",e.__assign({className:"ag-row-trend"},{children:[c.length>1?n.jsx("div",e.__assign({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:c.map(function(i){return n.jsx("button",e.__assign({type:"button","aria-pressed":i===f,className:i===f?"is-active":void 0,onClick:function(){return x(i)}},{children:m.kpiLabel(i)}),i)})})):null,w?n.jsx("div",e.__assign({className:"ag-empty"},{children:"This chart is unavailable right now."})):k?n.jsx(u.ChartSkeleton,{height:240,label:"Loading trend"}):S.length?n.jsx("div",e.__assign({className:"ag-chart"},{children:n.jsxs("div",e.__assign({className:"ellm-graph"},{children:[n.jsx(r.default,{tier:"decision-advantage-".concat(d),series:K,hiddenKeys:I,onToggleSeries:function(e){return C(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.size<K.length-1&&i.add(e),i})},onPointClick:function(e){var n,i,a,t,r,s,o=e.series,d=e.point,c=e.index,u=K.findIndex(function(e){return e.key===o.key}),g=N[u],v=null!==(n=d.x)&&void 0!==n?n:null===(i=o.data[c])||void 0===i?void 0:i.x,p=null==g?void 0:g.points.find(function(e){return e.x===String(v)});if(g&&p){var h=null!==(a=g.label)&&void 0!==a?a:g.nodeKey,y=null!==(s=null===(r=null===(t=p.meta)||void 0===t?void 0:t.marker)||void 0===r?void 0:r.reportId)&&void 0!==s?s:null;_?_({nodeKey:g.nodeKey,label:h,kpiId:g.kpiId,dataDay:p.x,reportId:y}):m.openReport(y?{reportId:y,title:"".concat(h," · ").concat(l.shortDay(p.x))}:{nodeKey:g.nodeKey,kpiId:g.kpiId,dataDay:p.x,title:"".concat(h," · ").concat(l.shortDay(p.x))})}},xAxis:{label:"Date",categories:S,tickCount:8,minTickGap:24,formatTick:function(e){return l.shortDay(e)}},yAxis:{label:A,beginAtZero:!0,formatTick:function(e){return l.formatValue(Number(e))}},tooltip:{formatHeading:function(e){return String(e)}},legend:{show:!1},style:{chartHeight:240,yAxisWidth:70,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}}),n.jsx("div",e.__assign({className:"ellm-graph__legend ellm-chart__legend--bottom ellm-chart__legend--center"},{children:K.map(function(i){var a=I.has(i.key);return n.jsxs("label",e.__assign({title:i.label,className:"ellm-graph__legend-item ag-legend-item".concat(a?" ellm-graph__legend-item--off":""),style:{cursor:"pointer","--checkbox-color":i.color,color:i.color}},{children:[n.jsx("input",{type:"checkbox",className:"ellm-graph__legend-checkbox",checked:!a,onChange:function(){return C(function(e){var n=new Set(e);return n.has(i.key)?n.delete(i.key):n.size<K.length-1&&n.add(i.key),n})},style:{borderColor:i.color,accentColor:i.color}}),n.jsx("span",{children:i.label})]}),i.key)})}))]}))})):n.jsx("div",e.__assign({className:"ag-empty"},{children:"Not enough history yet for a trend chart."}))]}))}function T(a){var t,r=this,d=a.tab,g=a.partName,p=a.kpiIds,_=a.rankBy,m=a.search,y=a.graphed,f=a.onToggleGraph,x=a.onOpenRow,b=a.onFirstRow,j=a.onInitialGraph,k=a.fallbackDay,I=o.useInsights(),C=Math.min(200,Math.max(1,Number(d.pageSize)||5)),S=i.useState([]),K=S[0],A=S[1],T=i.useState(null),L=T[0],R=T[1],F=i.useState(!1),P=F[0],M=F[1],E=i.useState({loading:!0,error:null}),B=E[0],O=E[1],G=i.useState(),V=G[0],q=G[1],H=function(n,i){return e.__awaiter(r,void 0,void 0,function(){var a,t;return e.__generator(this,function(r){switch(r.label){case 0:if(!I)return[2];O({loading:!0,error:null}),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,s.fetchLevelRows(I.api,d.entityKey,I.range,{sort:_,order:"desc",search:m||void 0,pageSize:C,cursor:null!=n?n:void 0,includeChildren:3},i)];case 2:return a=r.sent(),(null==i?void 0:i.aborted)?[2]:(q(a.context),A(function(i){return n?e.__spreadArray(e.__spreadArray([],i,!0),a.rows,!0):a.rows}),R(a.nextCursor),M(a.hasNext),O({loading:!1,error:null}),[3,4]);case 3:return t=r.sent(),(null==i?void 0:i.aborted)||"AbortError"===(null==t?void 0:t.name)?[2]:(O({loading:!1,error:t.message||"Couldn't load the rows."}),[3,4]);case 4:return[2]}})})},U=null===(t=K[0])||void 0===t?void 0:t.nodeKey;i.useEffect(function(){return null==b?void 0:b(U)},[U]);var W=K.slice(0,3).map(function(e){return e.nodeKey}),z=W.join("\0");if(i.useEffect(function(){B.loading||null==j||j(W)},[B.loading,z]),i.useEffect(function(){var e=new AbortController;return H(null,e.signal),function(){return e.abort()}},[null==I?void 0:I.api.configId,null==I?void 0:I.rangeKey,d.entityKey,_,m,C,null==I?void 0:I.revision]),!I)return null;var Z,$=I.goodDirection(_),J=p.filter(function(e){return e!==_}).slice(0,2),X=(Z=g.trim().toLowerCase())?/(s|x|ch|sh)$/.test(Z)?"".concat(Z,"es"):/[^aeiou]y$/.test(Z)?"".concat(Z.slice(0,-1),"ies"):"".concat(Z,"s"):"rows";return n.jsx(u.ReportAccordion,e.__assign({title:"Top Drivers for ".concat(h(X))},{children:B.error?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):B.loading&&!K.length?n.jsx(u.SkeletonLines,{widths:[80,60,85,55,75],label:"Loading drivers"}):K.length?n.jsxs(n.Fragment,{children:[n.jsx(c.default,{context:V}),n.jsx(D,e.__assign({label:h(g),rightLabel:"User Activity · selected dates"},{children:K.map(function(i){var a,t,r,o,d=null===(a=i.metrics)||void 0===a?void 0:a[_],c=i.label||i.nodeKey,g=y.includes(i.nodeKey);return n.jsx(N,{rank:i.rank,name:c,chips:n.jsxs(n.Fragment,{children:[n.jsx(u.CriticalityChip,{criticality:null===(t=i.chip)||void 0===t?void 0:t.criticality}),n.jsx(u.MovementChip,{movementType:null===(r=i.chip)||void 0===r?void 0:r.movementType,direction:null===(o=i.chip)||void 0===o?void 0:o.direction,good:$})]}),action:n.jsx(w,{on:g,disabled:!g&&y.length>=v,onClick:function(){return f(i.nodeKey)}}),lines:n.jsxs("span",e.__assign({className:"ag-driver__cost"},{children:[n.jsxs("span",e.__assign({className:"ag-driver__total"},{children:[l.formatValue(null==d?void 0:d.value)," ",I.kpiLabel(_).toLowerCase()]})),null!=(null==d?void 0:d.deltaPct)?n.jsx("span",e.__assign({className:"ag-driver__sep"},{children:"|"})):null,n.jsx(u.DayOverDayChange,{deltaPct:null==d?void 0:d.deltaPct,good:$,direction:null==d?void 0:d.direction,tone:null==d?void 0:d.tone,suffix:"vs previous period"})]})),cell:J.map(function(a){var t,r,s=null===(t=i.metrics)||void 0===t?void 0:t[a],o=null!==(r=null==s?void 0:s.tone)&&void 0!==r?r:u.toneOf(null==s?void 0:s.deltaPct,I.goodDirection(a)),d="up"===(null==s?void 0:s.direction)?"↑":"down"===(null==s?void 0:s.direction)?"↓":"flat"===(null==s?void 0:s.direction)?"→":null!=(null==s?void 0:s.deltaPct)&&s.deltaPct>0?"↑":null!=(null==s?void 0:s.deltaPct)&&s.deltaPct<0?"↓":"→";return n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",e.__assign({className:"good"===o?"ag-text--good":"bad"===o?"ag-text--bad":void 0},{children:null==(null==s?void 0:s.deltaPct)?l.formatValue(null==s?void 0:s.value):"".concat(d).concat(Math.abs(s.deltaPct),"%")})),n.jsx("span",{children:I.kpiLabel(a)})]}),a)}),onOpen:function(){var e;return x(i,_,k||(null===(e=i.chip)||void 0===e?void 0:e.dataDay)||s.toIsoDay(I.range.endDate))}},i.nodeKey)})})),P?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:B.loading,onClick:function(){return H(L)}},{children:B.loading?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:m?"No ".concat(X," match “").concat(m,"”."):"No ".concat(X," for this period yet.")}))}))}exports.AddToGraph=w,exports.CorrelationSection=S,exports.DecisionCard=x,exports.DriverList=D,exports.DriverRow=N,exports.L2Report=function(t){var r,g,h,_,m,y,b,j,k,w,N,D,I,C,L,R=t.tab,F=t.title,P=t.partName,M=t.partKpis,E=t.search,B=t.dataDay,O=t.onOpenRow,G=o.useInsights(),V=i.useState(Boolean(null==G?void 0:G.defaultWorkingDays)),q=V[0],H=V[1],U=l.useInsightsFetch(G?function(e){return s.fetchGraphGroups(G.api,e)}:null,[null==G?void 0:G.api.configId,null==G?void 0:G.revision]),W=i.useState(null),z=W[0],Z=W[1];i.useEffect(function(){var e,n;null===z&&((null===(e=U.data)||void 0===e?void 0:e.groups.length)?Z((null!==(n=U.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:U.data.groups[0]).groupKey):U.loading||Z(""))},[z,U.data,U.loading]);var $=i.useState(null),J=$[0],X=$[1],Q=i.useState(),Y=Q[0],ee=Q[1],ne=!1!==R.showSummary,ie=l.useInsightsFetch(G&&ne?function(e){return s.fetchLevelSummary(G.api,R.entityKey,G.range,e)}:null,[null==G?void 0:G.api.configId,null==G?void 0:G.rangeKey,R.entityKey,ne,null==G?void 0:G.revision]);if(!G)return null;var ae=(null===(r=R.listKpis)||void 0===r?void 0:r.length)?R.listKpis:M,te=R.rankBy&&ae.includes(R.rankBy)?R.rankBy:null!==(g=ae[0])&&void 0!==g?g:"",re=null===(h=ie.data)||void 0===h?void 0:h.report,se=K(null===(_=ie.data)||void 0===_?void 0:_.context),oe=null!==(m=null!=B?B:se)&&void 0!==m?m:s.toIsoDay(G.range.endDate),le=function(n){return B?e.__assign(e.__assign({},n),{report:e.__assign(e.__assign({},n.report),{reportId:null})}):n},de=G.goodDirection(te),ce=null!==(y=R.tier1Kpis)&&void 0!==y?y:G.tierKpis[1],ue=null!==(b=R.tier2Kpis)&&void 0!==b?b:G.tierKpis[2],ge=G.headlineKpi||te||ce[0]||"",ve=function(e){var n=e.nodeKey,i=e.label,a=e.dataDay;return O({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:ge},action:null,children:[]},ge,a)},pe=G.drill.tabTables[R.entityKey],he=pe?n.jsx(d.default,{table:e.__assign(e.__assign({},pe),{pageSize:null!==(k=null!==(j=pe.pageSize)&&void 0!==j?j:R.pageSize)&&void 0!==k?k:void 0}),tabEntityKey:R.entityKey,context:{trail:[],day:oe},onRowClick:function(e,n){var i;return"report"===n?G.openReport({reportId:B?null:e.report.reportId,nodeKey:e.nodeKey,kpiId:te,dataDay:oe,title:null!==(i=e.label)&&void 0!==i?i:e.nodeKey}):"drill"===n?O(le(e),te,oe):void 0}}):null;return n.jsxs("section",e.__assign({className:"ag-report","aria-label":"L2 Report · ".concat(F)},{children:[n.jsxs("div",e.__assign({className:"ag-report__header"},{children:[n.jsxs("h2",e.__assign({className:"ag-report__title"},{children:[n.jsx(a.Sparkles,{"aria-hidden":"true"}),"L2 Report"]})),n.jsx("span",e.__assign({className:"ag-report__scope"},{children:F})),se?n.jsx("span",e.__assign({className:"ag-report__date"},{children:u.formatHeaderDate(se)})):null]})),n.jsxs("div",e.__assign({className:"ag-report__grid ag-report__grid--l2"},{children:[n.jsx("div",e.__assign({className:"ag-report__analysis-scroll",role:"region","aria-label":"".concat(F," analysis"),tabIndex:0},{children:n.jsxs("div",e.__assign({className:"ag-stack"},{children:[ne?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(u.SectionHeader,{title:"Summary",action:n.jsx(p,{entityKey:R.entityKey,dataDay:se})}),n.jsx(f,{report:re,loading:ie.loading,error:ie.error,good:de})]}),n.jsx(x,{report:re,error:ie.error,loading:ie.loading}),n.jsx(c.default,{context:null===(w=ie.data)||void 0===w?void 0:w.context})]}):null,ae.length?n.jsx(T,{tab:R,partName:P,kpiIds:ae,rankBy:te,search:E,graphed:null!=J?J:[],onToggleGraph:function(n){return X(function(i){var a=null!=i?i:[];return a.includes(n)?a.filter(function(e){return e!==n}):a.length<v?e.__spreadArray(e.__spreadArray([],a,!0),[n],!1):a})},onOpenRow:function(e,n,i){return O(le(e),n,i)},onFirstRow:ee,onInitialGraph:function(e){return X(function(n){return null!=n?n:e})},fallbackDay:oe}):null]}))})),n.jsxs("div",e.__assign({className:"ag-stack"},{children:[ce.length?n.jsx(u.CollapsibleVisualSection,e.__assign({title:"Trend",action:n.jsx(u.DaysDropdown,{value:q,onChange:H,groups:U.error||null===(N=U.data)||void 0===N?void 0:N.groups,group:z,onGroupChange:Z})},{children:n.jsx(A,{entityKey:R.entityKey,kpis:ce,nodeKeys:J,workingDays:q,group:z,onOpenPoint:ve})})):null,ue.length?n.jsx(u.CollapsibleVisualSection,e.__assign({title:G.labels.activityTitle,meta:J?"Selected rows":"Top ".concat(3," ").concat(G.entityPluralName(R.entityKey))},{children:n.jsx(A,{entityKey:R.entityKey,kpis:ue,nodeKeys:J,workingDays:q,group:z,onOpenPoint:ve})})):null,n.jsx(S,{dataDay:se,nodeKey:null!==(D=null==J?void 0:J[0])&&void 0!==D?D:Y,dayGroup:null===(C=null===(I=U.data)||void 0===I?void 0:I.groups.find(function(e){return e.groupKey===z}))||void 0===C?void 0:C.days}),"column"===(null==pe?void 0:pe.width)?he:null]}))]})),pe&&"full"===(null!==(L=pe.width)&&void 0!==L?L:"full")?he:null]}))},exports.MAX_SERIES=v,exports.RegenerateSummary=p,exports.RowDrivers=T,exports.RowTrend=A,exports.SummaryCard=f,exports.TopDriversSection=function(t){var r,d,c,p,h,_,m,f,x,I=t.dataDay,C=t.entityKey,S=t.parentNodeKey,K=t.kpiId,A=t.title,T=t.graphed,L=t.onToggleGraph,R=t.onOpenDriver,F=t.onDecisionSettled,P=t.initialTab,M=void 0===P?"drivers":P,E=o.useInsights(),B=i.useState(M),O=B[0],G=B[1],V=i.useState({drivers:1,headwinds:1,attention:1}),q=V[0],H=V[1],U=null!==(r=null!=K?K:null==E?void 0:E.headlineKpi)&&void 0!==r?r:void 0,W=function(e){return E&&U&&e===O?function(n){return s.fetchInsightsDrivers(E.api,{dataDay:I,kpiId:U,entityKey:C,parentNodeKey:S,tab:e,limit:Math.min(10,(S?10:3)*q[e]),offset:0,filters:E.range.filters},n)}:null},z=function(e){return[null==E?void 0:E.api.configId,null==E?void 0:E.rangeKey,I,U,C,S,e,O,q[e],null==E?void 0:E.revision]},Z={drivers:l.useInsightsFetch(W("drivers"),z("drivers")),headwinds:l.useInsightsFetch(W("headwinds"),z("headwinds")),attention:l.useInsightsFetch(W("attention"),z("attention"))},$=Z[O],J=$.data,X=$.error,Q=$.loading,Y=null!==(h=null!==(c=null===(d=Z.drivers.data)||void 0===d?void 0:d.tabs)&&void 0!==c?c:null===(p=Z.headwinds.data)||void 0===p?void 0:p.tabs)&&void 0!==h?h:null===(_=Z.attention.data)||void 0===_?void 0:_.tabs,ee=g.useNeedsAttention(I,S,U),ne=null!==(f=null===(m=ee.data)||void 0===m?void 0:m.counts.pending)&&void 0!==f?f:0;if(i.useEffect(function(){return H({drivers:1,headwinds:1,attention:1})},[I]),i.useEffect(function(){return G(M)},[M]),!E)return null;var ie=E.goodDirection(null!=U?U:""),ae=null!==(x=null==J?void 0:J.rows)&&void 0!==x?x:[];return n.jsxs(u.ReportAccordion,e.__assign({title:A},{children:[n.jsx("div",e.__assign({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:b.map(function(i){return n.jsx("button",e.__assign({type:"button",role:"tab","aria-selected":O===i.key,className:O===i.key?"is-active":void 0,onClick:function(){return G(i.key)},title:i.info},{children:n.jsxs(n.Fragment,{children:[E.labels[i.label],(null==Y?void 0:Y[i.key])?" (".concat(Y[i.key].total,")"):"","attention"===i.key&&ne?n.jsxs("span",e.__assign({className:"ag-na__tab-badge",title:"".concat(ne," data points need a decision")},{children:[ne,n.jsx("span",e.__assign({className:"ins-visually-hidden"},{children:" data points need a decision"}))]})):null,n.jsx(a.Info,{"aria-hidden":"true"})]})}),i.key)})})),"attention"===O?n.jsx(g.default,{dataDay:I,nodeKey:S,kpiId:U,attention:ee,onDecisionSettled:F}):null,"attention"===O&&ae.length?n.jsx("h4",e.__assign({className:"ag-na__subhead"},{children:"Rows that moved without a clear cause"})):null,X?n.jsxs("p",e.__assign({className:"ag-muted"},{children:["Top drivers are unavailable right now: ",X.message]})):Q&&!J?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading drivers..."})):ae.length?n.jsxs(n.Fragment,{children:[n.jsx(D,e.__assign({label:"Driver",rightLabel:E.labels.activityColumn},{children:ae.map(function(i){var a,t,r,s,o,d,c,g,p,h=i.deltaContributionPct,_=T.includes(i.nodeKey),m=(null===(a=i.decisionAdvantage)||void 0===a?void 0:a.correlationSentence)||(null===(t=i.decisionAdvantage)||void 0===t?void 0:t.firstCause)||(null===(r=i.decisionAdvantage)||void 0===r?void 0:r.headline);return n.jsx(N,{rank:i.rank,category:E.labels.driverCategory.replace("{plural}",i.entityKey?E.entityPluralName(i.entityKey):""),name:i.label,chips:n.jsxs(n.Fragment,{children:[n.jsx(u.CriticalityChip,{criticality:i.criticality}),n.jsx(u.MovementChip,{movementType:i.movementType,direction:i.changeDirection,good:ie}),(null===(s=i.correlation)||void 0===s?void 0:s.strength)?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(i.correlation.strength)},{children:k[i.correlation.strength]})):null]}),action:L?n.jsx(w,{on:_,disabled:!_&&T.length>=v,onClick:function(){return L(i)}}):void 0,lines:n.jsxs(n.Fragment,{children:[null!=h?n.jsxs("span",e.__assign({className:"ag-driver__share"},{children:[E.labels.shareLine.replace("{share}",String(Math.abs(h)))," · ","opposite"===i.direction?E.labels.movedOpposite:E.labels.movedWith]})):null,n.jsxs("span",e.__assign({className:"ag-driver__cost"},{children:[n.jsx("span",e.__assign({className:"ag-driver__total"},{children:l.formatValue(i.value)})),null!=i.deltaPct?n.jsx("span",e.__assign({className:"ag-driver__sep"},{children:"|"})):null,n.jsx(u.DayOverDayChange,{deltaPct:i.deltaPct,good:ie,direction:i.changeDirection,tone:i.tone,suffix:l.previousDayLabel(I)})]})),m?n.jsx("p",e.__assign({className:"ag-driver__brief"},{children:n.jsx(u.VerdictSentence,{text:y(m),good:ie,arrowsFollowVerdict:!0})})):null,(null===(o=i.decisionAdvantage)||void 0===o?void 0:o.nextStep)?n.jsxs("p",e.__assign({className:"ag-driver__brief"},{children:[n.jsx("strong",{children:"Next:"})," ",y(i.decisionAdvantage.nextStep)]})):null]}),cell:n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",{children:l.formatValue(null!==(c=null===(d=i.drivingMetric)||void 0===d?void 0:d.value)&&void 0!==c?c:i.previous)}),n.jsx("span",{children:(null===(g=i.drivingMetric)||void 0===g?void 0:g.label)||((null===(p=i.drivingMetric)||void 0===p?void 0:p.kpiId)?E.kpiLabel(i.drivingMetric.kpiId):"opposite"===i.direction?"Moved opposite":"with"===i.direction?"Moved with":"Previous")})]})),onOpen:function(){var e;return R?R(i):E.openReport({reportId:null===(e=i.report)||void 0===e?void 0:e.reportId,nodeKey:i.nodeKey,kpiId:U,dataDay:I,title:i.label})}},i.nodeKey)})})),(null==J?void 0:J.hasMore)?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:Q,onClick:function(){return H(function(n){var i;return e.__assign(e.__assign({},n),((i={})[O]=n[O]+1,i))})}},{children:Q?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:j[O]}))]}))},exports.decisionCardNotice=m,exports.reportDayOf=K,exports.stripRowTags=y,exports.titleCase=h;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),i=require("react"),a=require("lucide-react"),t=require("../RcaDecisionComponent/RcaDecisionComponent.js"),r=require("../Graph/LineChart.js"),s=require("../../api/insightsApi.js"),o=require("./insightsContextCore.js"),l=require("./insightsUtils.js"),d=require("./DrillTable.js"),c=require("./drillDay.js"),u=require("./FilterNotice.js"),g=require("./agPrimitives.js"),v=require("./NeedsAttention.js"),p=10;function h(a){var t,r=this,d=a.entityKey,c=a.dataDay,u=o.useInsights(),g=i.useState(null),v=g[0],p=g[1],h=i.useState(null),_=h[0],m=h[1];if(l.useJob(v,null!==(t=null==u?void 0:u.api)&&void 0!==t?t:null,function(){p(null),null==u||u.refresh()}),!(null==u?void 0:u.viewer.isAdmin))return null;return n.jsxs("span",{children:[n.jsx("button",e.__assign({type:"button",className:"ins-link",disabled:Boolean(v),onClick:function(){return e.__awaiter(r,void 0,void 0,function(){var n,i,a,t;return e.__generator(this,function(e){switch(e.label){case 0:m(null),e.label=1;case 1:return e.trys.push([1,6,,7]),n={dataDay:c||s.toIsoDay(u.range.endDate),window:"both"},d?[4,s.generateLevelSummary(u.api,d,n)]:[3,3];case 2:return a=e.sent(),[3,5];case 3:return[4,s.generateInsightsSummary(u.api,n)];case 4:a=e.sent(),e.label=5;case 5:return(i=a).jobId?p(i.jobId):u.refresh(),[3,7];case 6:return t=e.sent(),m(t.message||"The summary couldn't be regenerated."),[3,7];case 7:return[2]}})})}},{children:v?"Regenerating…":"Regenerate summary"})),_?n.jsx("span",e.__assign({className:"ins-error"},{children:_})):null]})}var _=function(e){return e.replace(/\b\w/g,function(e){return e.toUpperCase()})};function m(e,n){return n?"Decision Advantage is unavailable right now: ".concat(n.message):e?"waiting"===e.status?"The first morning run hasn't finished yet. This fills in after it.":"running"===e.status?"The AI is writing this report. It usually takes a minute or two.":"generated"!==e.status?"No report generated for this day.":null:null}function y(e,n,i){return i?null:m(e,n)}function f(e){return e.replace(/\{\{([^|}]*)\|[^}]*\}\}/g,"$1")}function x(a){var r,s,o=a.report,d=a.movementType,c=a.direction,u=a.good,v=a.loading,p=a.error,h=i.useState(!1),_=h[0],y=h[1],f=i.useMemo(function(){return l.reportDecisioning(o)},[o]);if(i.useEffect(function(){return y(!1)},[null==o?void 0:o.reportId]),v)return n.jsx("div",e.__assign({className:"ag-summary"},{children:n.jsx(g.SkeletonLines,{widths:[28,96,72],label:"Loading summary"})}));var x=null==o?void 0:o.summary,b=null!==(r=null==x?void 0:x.headline)&&void 0!==r?r:"",j=Boolean(b),k=g.splitVerdict(b).prefix,w=Boolean(null==x?void 0:x.eyebrow)&&"Movement unavailable"!==(null==x?void 0:x.eyebrow),N=void 0!==d,D=w?x.eyebrow:N?g.movementVerdictLabel(d,c):k||"Summary",I=w?"good"===x.tone||"bad"===x.tone?g.verdictToneHex(x.tone):g.movementColorHex(x.movementType,x.movementDirection,u):N?g.movementColorHex(d,c,u):"Good news"===k?"#15803D":"Bad news"===k?"#E11D48":"#5928ED";return n.jsxs("div",e.__assign({className:"ag-summary"},{children:[n.jsx("p",e.__assign({className:"ag-summary__title",style:{color:j?I:"#64748b"}},{children:j?D:"No summary yet"})),n.jsxs("div",e.__assign({className:"ag-summary__text"},{children:[j?n.jsx(g.VerdictSentence,{text:b,good:u}):null!==(s=m(o,p))&&void 0!==s?s:"Reports are written after each morning run.",j&&f?n.jsx("span",e.__assign({className:"ag-summary__brain"},{children:n.jsx(t.ReasoningTrigger,{open:_,onToggle:function(){return y(function(e){return!e})},label:"how the AI reached this summary"})})):null]})),_&&f?n.jsx("div",e.__assign({className:"ag-summary__reasoning"},{children:n.jsx(t.ReasoningPanel,{decisioning:f})})):null]}))}function b(e){var a,r,s,d=e.report,c=e.error,u=e.loading,v=o.useInsights(),p=!u&&"generated"===(null==d?void 0:d.status),h=i.useMemo(function(){return p?l.reportDecisioning(d,null==d?void 0:d.footer):null},[p,d]),_=l.useOpenRow();return n.jsx(t.RcaDecisionComponent,{className:"ag-decision",title:null!==(a=null==v?void 0:v.labels.decisionAdvantageTitle)&&void 0!==a?a:"Decision Advantage",score:p?null==d?void 0:d.score:null,decisioning:h,notice:y(d,c,u),afterSections:u?n.jsx(g.SkeletonLines,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:p?l.toRcaItems(null==d?void 0:d.rootCause,_):[],nextSteps:p?l.toRcaItems(null==d?void 0:d.nextSteps,_):[],width:"100%",maxWidth:"none"},"".concat(null!==(r=null==d?void 0:d.reportId)&&void 0!==r?r:"pending",":").concat(null!==(s=null==d?void 0:d.generatedAt)&&void 0!==s?s:""))}var j=[{key:"drivers",label:"driversTab",info:"What moved the day's number the same way."},{key:"headwinds",label:"headwindsTab",info:"What moved against the day's number."},{key:"attention",label:"attentionTab",info:"The number moved, but activity doesn't explain it."}],k={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},w={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function N(i){var t=i.on,r=i.onClick,s=i.disabled,o=void 0!==s&&s;return n.jsxs("button",e.__assign({type:"button",className:"ag-graph-pill".concat(t?" is-on":""),disabled:o,title:o?"A graph can show up to ".concat(p," rows"):void 0,onClick:function(e){e.stopPropagation(),r()}},{children:[n.jsx(a.TrendingUp,{"aria-hidden":"true"}),t?"In graph":o?"Graph full":"Add to graph"]}))}function D(i){var t=i.rank,r=i.category,s=i.name,o=i.chips,l=i.action,d=i.lines,c=i.cell,u=i.onOpen;return n.jsx("li",{children:n.jsxs("div",e.__assign({className:"ag-driver".concat(u?" is-clickable":""),role:u?"button":void 0,tabIndex:u?0:void 0,onClick:u,onKeyDown:u?function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),u())}:void 0},{children:[n.jsxs("div",e.__assign({className:"ag-driver__main"},{children:[n.jsxs("span",e.__assign({className:"ag-driver__rank"},{children:[t,"."]})),n.jsxs("div",e.__assign({className:"ag-driver__body"},{children:[r?n.jsxs("span",e.__assign({className:"ag-driver__category"},{children:[r," >"]})):null,n.jsx("span",e.__assign({className:"ag-driver__name"},{children:s})),n.jsxs("div",e.__assign({className:"ag-driver__chips"},{children:[o,l]})),d]}))]})),n.jsxs("div",e.__assign({className:"ag-driver__cell"},{children:[c,u?n.jsx("span",e.__assign({className:"ag-driver__open","aria-hidden":"true"},{children:n.jsx(a.ArrowUpRight,{})})):null]}))]}))})}function I(i){var a,t=i.label,r=i.rightLabel,s=i.children,l=o.useInsights();return n.jsxs("div",e.__assign({className:"ag-drivers"},{children:[n.jsxs("div",e.__assign({className:"ag-drivers__head"},{children:[n.jsx("span",{children:t}),n.jsx("span",{children:null!==(a=null!=r?r:null==l?void 0:l.labels.activityColumn)&&void 0!==a?a:"User Activity"})]})),n.jsx("ol",{children:s})]}))}var C=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],S=function(e,n){void 0===n&&(n="en-GB");var i=e.slice(0,10).split("-").map(Number),a=i[0],t=i[1],r=i[2];return Number.isFinite(a)&&Number.isFinite(t)&&Number.isFinite(r)?new Intl.DateTimeFormat(n,{day:"numeric",month:"short"}).format(new Date(a,t-1,r)):e};function K(t){var d,c,u,v,p,h,_,m,y=this,f=t.dataDay,x=t.nodeKey,b=void 0===x?"root":x,j=t.kpiId,k=t.dayGroup,N=o.useInsights(),D=null!==(d=null!=j?j:null==N?void 0:N.headlineKpi)&&void 0!==d?d:void 0,I=i.useState(""),K=I[0],A=I[1],T=i.useState([]),L=T[0],R=T[1],F=i.useState({}),P=F[0],M=F[1],B=i.useState(""),E=B[0],O=B[1],q=i.useState(null),G=q[0],V=q[1],H=i.useState(null),U=H[0],W=H[1],z=i.useState(!1),Z=z[0],$=z[1],J=i.useState(!1),X=J[0],Q=J[1],Y=i.useRef(null),ee=l.useInsightsFetch(N&&D&&f?function(n){return s.fetchInsightsCorrelation(N.api,b,e.__assign({kpiId:D,dataDay:f,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate),filters:N.range.filters},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,D,b,P.disregardBefore,null===(c=P.disregardDates)||void 0===c?void 0:c.join(","),null==N?void 0:N.revision]),ne=ee.data,ie=ee.error,ae=ee.loading,te=l.useInsightsFetch(N&&D&&f?function(n){return s.fetchInsightsCorrelationTrend(N.api,b,e.__assign({kpiId:D,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate),filters:N.range.filters},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,D,b,P.disregardBefore,null===(u=P.disregardDates)||void 0===u?void 0:u.join(","),null==N?void 0:N.revision]);l.useJob(U,null!==(v=null==N?void 0:N.api)&&void 0!==v?v:null,function(){W(null),O(""),null==N||N.refresh()}),i.useEffect(function(){if(Z){var e=function(e){Y.current&&!Y.current.contains(e.target)&&$(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}},[Z]);var re=i.useState(new Set),se=re[0],oe=re[1],le=i.useMemo(function(){if(!ne)return[];return ne.series.filter(function(e){return!(null==k?void 0:k.length)||k.map(Number).includes((n=e.x,new Date("".concat(n.slice(0,10),"T00:00:00")).getDay()||7));var n})},[ne,k]),de=i.useMemo(function(){return ne&&N?e.__spreadArray([ne.kpiId],ne.drivers.map(function(e){return e.kpiId}).filter(function(e){return e!==ne.kpiId}),!0).map(function(e,n){return{key:"corr_".concat(e.replace(/[^a-zA-Z0-9_]/g,"_")),label:N.kpiLabel(e),color:C[n%C.length],curve:"smooth",strokeWidth:2,pointRadius:2,data:le.map(function(n){var i,a;return{x:n.x,y:n.disregarded?null:null!==(a=null===(i=n.values)||void 0===i?void 0:i[e])&&void 0!==a?a:null}}),valueFormatter:function(e){return"".concat(e,"%")}}}):[]},[ne,N,le]);i.useEffect(function(){return oe(new Set(de.slice(2).map(function(e){return e.key})))},[de]);if(!N||!f||"no_drivers"===(null==ne?void 0:ne.state)||ne&&!ne.verdictText)return null;if(ie)return n.jsxs("div",e.__assign({className:"ag-empty"},{children:["Correlation is unavailable right now: ",ie.message]}));if(ae&&!ne)return n.jsx(g.ChartSkeleton,{height:220,label:"Loading correlation"});if(!ne)return null;var ce=null!==(p=ne.strength)&&void 0!==p?p:"none",ue=N.kpiLabel(ne.kpiId);return n.jsx(g.CollapsibleVisualSection,e.__assign({title:"Correlation",meta:"Usage vs. ".concat(ue),className:"ag-visual--card",action:N.viewer.isAdmin?n.jsxs("div",e.__assign({ref:Y,className:"ag-corr__settings"},{children:[n.jsx("button",e.__assign({type:"button",className:"ag-icon-button","aria-label":"Correlation settings","aria-expanded":Z,onClick:function(){return $(function(e){return!e})}},{children:n.jsx(a.Settings2,{"aria-hidden":"true"})})),Z?n.jsx("div",e.__assign({className:"ag-corr__settings-menu",role:"menu"},{children:n.jsxs("label",{children:[n.jsx("input",{type:"checkbox",checked:X,onChange:function(e){return Q(e.target.checked)}}),"Show date controls"]})})):null]})):null},{children:n.jsxs("div",e.__assign({className:"ag-corr"},{children:[n.jsx("p",e.__assign({className:"ag-corr__banner ag-corr__banner--".concat(ce)},{children:ne.verdictText})),n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(ce)},{children:w[ce]})),n.jsxs("p",e.__assign({className:"ag-corr__caption"},{children:[ue," vs. usage - % change from the first day shown"]})),(null===(h=ne.window)||void 0===h?void 0:h.source)?n.jsx("p",e.__assign({className:"ag-muted"},{children:"default"===ne.window.source?ne.window.startDate?"Using all days since ".concat(S(ne.window.startDate,"en-US")):"Using all available days":"row"===ne.window.source?"Saved window".concat(ne.window.startDate?" since ".concat(S(ne.window.startDate,"en-US")):"").concat((null===(_=ne.window.excludedDates)||void 0===_?void 0:_.length)?" · ".concat(ne.window.excludedDates.length," left out"):""):"Preview window".concat((null===(m=ne.window.excludedDates)||void 0===m?void 0:m.length)?" · ".concat(ne.window.excludedDates.length," left out"):"")})):null,n.jsx("div",e.__assign({className:"ag-chart"},{children:n.jsx("div",e.__assign({className:"ellm-graph"},{children:n.jsx(r.default,{tier:"decision-advantage-correlation",series:de,hiddenKeys:se,onToggleSeries:function(e){return oe(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.add(e),i})},onPointClick:function(){},xAxis:{label:"Date",categories:le.map(function(e){return e.x}),formatTick:function(e){return l.shortDay(e)}},yAxis:{label:"% change",beginAtZero:!1,formatTick:function(e){return"".concat(Math.round(Number(e)),"%")}},tooltip:{render:function(i){var a,t=i.x,r=i.points,s=String(t),o=null===(a=te.data)||void 0===a?void 0:a.series.find(function(e){return e.x===s});return n.jsxs("div",e.__assign({className:"ag-tip ag-tip--wide"},{children:[n.jsx("div",e.__assign({className:"ag-tip__head"},{children:S(s)})),r.filter(function(e){return null!=e.value}).map(function(i){return n.jsxs("div",e.__assign({className:"ag-tip__line"},{children:[n.jsxs("span",{children:[n.jsx("i",{style:{background:i.color}}),i.series.label]}),n.jsxs("strong",{children:[i.value,"%"]})]}),i.series.key)}),o?Object.keys(o.r).map(function(i){var a,t;return n.jsxs("div",e.__assign({className:"ag-tip__sub"},{children:[n.jsx("span",{children:N.kpiLabel(i)}),n.jsx("span",{children:null==o.r[i]?"No correlation":"r ".concat(o.r[i]," · ").concat(null!==(a=o.strength[i])&&void 0!==a?a:"none"," · ").concat(null!==(t=o.nObs[i])&&void 0!==t?t:0," days")})]}),i)}):null]}))}},legend:{position:"bottom",toggle:!0},style:{chartHeight:220,yAxisWidth:60,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}})}))})),n.jsx("div",e.__assign({className:"ag-corr__metrics"},{children:ne.drivers.map(function(i){var a,t=null!==(a=i.strength)&&void 0!==a?a:"none";return n.jsxs("div",e.__assign({className:"ag-corr__metric"},{children:[n.jsx("span",e.__assign({className:"ag-corr__name"},{children:i.label||N.kpiLabel(i.kpiId)})),i.kpiId!==ne.kpiId?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(t)},{children:w[t]})):null,n.jsx("strong",{children:l.formatValue(i.value)}),n.jsx("span",e.__assign({className:"ag-corr__delta"},{children:null!=i.deltaPct?n.jsxs(n.Fragment,{children:[n.jsxs("span",e.__assign({className:"ag-dod__value ag-dod__value--".concat(i.tone||"flat")},{children:["up"===i.direction?"↑":"down"===i.direction?"↓":"→"," ",Math.abs(i.deltaPct),"%"]}))," vs. ",l.formatValue(i.previous)]}):"—"})),i.kpiId!==ne.kpiId?n.jsxs("span",e.__assign({className:"ag-corr__r"},{children:[i.nObs," days used",i.lowHistory?" · Low history":"",n.jsx("br",{}),null==i.movedWithToday?"No comparison for today":i.movedWithToday?"Moved together with the headline today":"Moved opposite the headline today"]})):null]}),i.kpiId)})})),N.viewer.isAdmin&&X?n.jsxs("div",e.__assign({className:"ag-corr__window"},{children:[n.jsxs("label",e.__assign({className:"ag-corr__start"},{children:["Ignore data before ",n.jsx("input",{type:"date",value:K,onChange:function(e){return A(e.target.value)}})]})),n.jsxs("div",e.__assign({className:"ag-corr__days-label"},{children:["Or leave out individual dates (",L.length," selected)"]})),n.jsx("div",e.__assign({className:"ag-corr__days","aria-label":"Days to leave out"},{children:ne.series.map(function(i){return n.jsx("button",e.__assign({type:"button","aria-pressed":L.includes(i.x),className:L.includes(i.x)?"is-selected":void 0,onClick:function(){return n=i.x,R(function(i){return i.includes(n)?i.filter(function(e){return e!==n}):e.__spreadArray(e.__spreadArray([],i,!0),[n],!1)});var n}},{children:S(i.x)}),i.x)})})),n.jsx("input",{className:"ag-corr__reason",value:E,onChange:function(e){return O(e.target.value)},placeholder:"Reason required to apply"}),G?n.jsx("p",e.__assign({className:"ins-error"},{children:G})):null,n.jsxs("div",e.__assign({className:"ag-corr__actions"},{children:[n.jsx("button",e.__assign({type:"button",className:"ins-link",onClick:function(){return M({disregardBefore:K||void 0,disregardDates:L})}},{children:"Preview"})),n.jsx("button",e.__assign({type:"button",className:"ins-button",disabled:Boolean(U),onClick:function(){return e.__awaiter(y,void 0,void 0,function(){var n,i;return e.__generator(this,function(e){switch(e.label){case 0:if(!N||!D||!E.trim())return V("A reason is required."),[2];V(null),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.saveCorrelationWindow(N.api,b,{kpiId:D,startDate:K||null,excludedDates:L,dataDay:f,changeReason:E.trim(),regenerate:!0})];case 2:return n=e.sent(),W(n.jobId),[3,4];case 3:return i=e.sent(),V(i.message||"The correlation window couldn't be saved."),[3,4];case 4:return[2]}})})}},{children:"Apply"})),n.jsx("button",e.__assign({type:"button",className:"ins-link",onClick:function(){A(""),R([]),M({})}},{children:"Clear"}))]}))]})):null]}))}))}var A=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function T(a){var t,d=a.entityKey,c=a.kpis,u=a.nodeKeys,v=a.workingDays,h=a.group,_=a.onOpenPoint,m=o.useInsights(),y=i.useState(null!==(t=c[0])&&void 0!==t?t:""),f=y[0],x=y[1];i.useEffect(function(){var e;c.includes(f)||x(null!==(e=c[0])&&void 0!==e?e:"")},[c,f]);var b=l.useInsightsFetch(m&&f&&null!==h&&0!==(null==u?void 0:u.length)?function(n){return s.fetchInsightsSeries(m.api,e.__assign(e.__assign({},m.range),{workingDaysOnly:v,group:h||void 0}),u?{kpiIds:[f],nodeKeys:u.slice(0,p)}:{kpiIds:[f],entityKey:d,topN:3},n)}:null,[null==m?void 0:m.api.configId,null==m?void 0:m.rangeKey,d,f,null==u?void 0:u.join(","),v,h,null==m?void 0:m.revision]),j=b.data,k=b.loading,w=b.error,N=i.useMemo(function(){var e;return 0===(null==u?void 0:u.length)?[]:(null!==(e=null==j?void 0:j.series)&&void 0!==e?e:[]).filter(function(e){return e.kpiId===f&&e.points.some(function(e){return Number.isFinite(e.y)})})},[j,u,f]),D=i.useState(new Set),I=D[0],C=D[1];i.useEffect(function(){return C(new Set)},[N]);var S=i.useMemo(function(){return Array.from(new Set(N.flatMap(function(e){return e.points.map(function(e){return e.x})}))).sort()},[N]),K=i.useMemo(function(){return N.map(function(e,n){var i,a=new Map(e.points.map(function(e){return[e.x,e.y]})),t=null!==(i=null==m?void 0:m.goodDirection(e.kpiId))&&void 0!==i?i:"up";return{key:"row_".concat(n,"_").concat(e.nodeKey.replace(/[^a-zA-Z0-9_]/g,"_")),label:e.label||e.nodeKey,color:["#06B6D4","#10A66A","#8650FF","#F59E0B","#E94BBD","#4285FF","#64748B","#F04444","#14B8A6","#84CC16"][n%10],curve:"smooth",pointRadius:3,activePointRadius:3,fillPointsOnHover:!0,data:S.map(function(e){var n;return{x:e,y:null!==(n=a.get(e))&&void 0!==n?n:null}}),valueFormatter:function(e){return l.formatValue(e)},markers:e.points.filter(function(e){var n;return null===(n=e.meta)||void 0===n?void 0:n.marker}).map(function(n){return{x:n.x,color:g.movementColorHex(n.meta.marker.movementType,n.meta.marker.direction,t),label:[n.meta.marker.criticality,n.meta.marker.headline].filter(Boolean).join(" · "),radius:3,haloRadius:3,onClick:function(){var i,a=null!==(i=e.label)&&void 0!==i?i:e.nodeKey;_?_({nodeKey:e.nodeKey,label:a,kpiId:e.kpiId,dataDay:n.x,reportId:n.meta.marker.reportId}):null==m||m.openReport(n.meta.marker.reportId?{reportId:n.meta.marker.reportId,title:"".concat(a," · ").concat(l.shortDay(n.x))}:{nodeKey:e.nodeKey,kpiId:e.kpiId,dataDay:n.x,title:"".concat(a," · ").concat(l.shortDay(n.x))})}}})}})},[N,S,m,_]);if(!m)return null;var A=m.kpiLabel(f);return n.jsxs("div",e.__assign({className:"ag-row-trend"},{children:[c.length>1?n.jsx("div",e.__assign({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:c.map(function(i){return n.jsx("button",e.__assign({type:"button","aria-pressed":i===f,className:i===f?"is-active":void 0,onClick:function(){return x(i)}},{children:m.kpiLabel(i)}),i)})})):null,w?n.jsx("div",e.__assign({className:"ag-empty"},{children:"This chart is unavailable right now."})):k?n.jsx(g.ChartSkeleton,{height:240,label:"Loading trend"}):S.length?n.jsx("div",e.__assign({className:"ag-chart"},{children:n.jsxs("div",e.__assign({className:"ellm-graph"},{children:[n.jsx(r.default,{tier:"decision-advantage-".concat(d),series:K,hiddenKeys:I,onToggleSeries:function(e){return C(function(n){var i=new Set(n);return i.has(e)?i.delete(e):i.size<K.length-1&&i.add(e),i})},onPointClick:function(e){var n,i,a,t,r,s,o=e.series,d=e.point,c=e.index,u=K.findIndex(function(e){return e.key===o.key}),g=N[u],v=null!==(n=d.x)&&void 0!==n?n:null===(i=o.data[c])||void 0===i?void 0:i.x,p=null==g?void 0:g.points.find(function(e){return e.x===String(v)});if(g&&p){var h=null!==(a=g.label)&&void 0!==a?a:g.nodeKey,y=null!==(s=null===(r=null===(t=p.meta)||void 0===t?void 0:t.marker)||void 0===r?void 0:r.reportId)&&void 0!==s?s:null;_?_({nodeKey:g.nodeKey,label:h,kpiId:g.kpiId,dataDay:p.x,reportId:y}):m.openReport(y?{reportId:y,title:"".concat(h," · ").concat(l.shortDay(p.x))}:{nodeKey:g.nodeKey,kpiId:g.kpiId,dataDay:p.x,title:"".concat(h," · ").concat(l.shortDay(p.x))})}},xAxis:{label:"Date",categories:S,tickCount:8,minTickGap:24,formatTick:function(e){return l.shortDay(e)}},yAxis:{label:A,beginAtZero:!0,formatTick:function(e){return l.formatValue(Number(e))}},tooltip:{formatHeading:function(e){return String(e)}},legend:{show:!1},style:{chartHeight:240,yAxisWidth:70,gridColor:"#e2e8f0",axisColor:"#cbd5e1",axisLabelColor:"#64748b",tickColor:"#64748b"}}),n.jsx("div",e.__assign({className:"ellm-graph__legend ellm-chart__legend--bottom ellm-chart__legend--center"},{children:K.map(function(i){var a=I.has(i.key);return n.jsxs("label",e.__assign({title:i.label,className:"ellm-graph__legend-item ag-legend-item".concat(a?" ellm-graph__legend-item--off":""),style:{cursor:"pointer","--checkbox-color":i.color,color:i.color}},{children:[n.jsx("input",{type:"checkbox",className:"ellm-graph__legend-checkbox",checked:!a,onChange:function(){return C(function(e){var n=new Set(e);return n.has(i.key)?n.delete(i.key):n.size<K.length-1&&n.add(i.key),n})},style:{borderColor:i.color,accentColor:i.color}}),n.jsx("span",{children:i.label})]}),i.key)})}))]}))})):n.jsx("div",e.__assign({className:"ag-empty"},{children:"Not enough history yet for a trend chart."}))]}))}function L(a){var t,r=this,d=a.tab,c=a.partName,v=a.kpiIds,h=a.rankBy,m=a.search,y=a.graphed,f=a.onToggleGraph,x=a.onOpenRow,b=a.onFirstRow,j=a.onInitialGraph,k=a.fallbackDay,w=o.useInsights(),C=Math.min(200,Math.max(1,Number(d.pageSize)||5)),S=i.useState([]),K=S[0],A=S[1],T=i.useState(null),L=T[0],R=T[1],F=i.useState(!1),P=F[0],M=F[1],B=i.useState({loading:!0,error:null}),E=B[0],O=B[1],q=i.useState(),G=q[0],V=q[1],H=function(n,i){return e.__awaiter(r,void 0,void 0,function(){var a,t;return e.__generator(this,function(r){switch(r.label){case 0:if(!w)return[2];O({loading:!0,error:null}),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,s.fetchLevelRows(w.api,d.entityKey,w.range,{sort:h,order:"desc",search:m||void 0,pageSize:C,cursor:null!=n?n:void 0,includeChildren:3},i)];case 2:return a=r.sent(),(null==i?void 0:i.aborted)?[2]:(V(a.context),A(function(i){return n?e.__spreadArray(e.__spreadArray([],i,!0),a.rows,!0):a.rows}),R(a.nextCursor),M(a.hasNext),O({loading:!1,error:null}),[3,4]);case 3:return t=r.sent(),(null==i?void 0:i.aborted)||"AbortError"===(null==t?void 0:t.name)?[2]:(O({loading:!1,error:t.message||"Couldn't load the rows."}),[3,4]);case 4:return[2]}})})},U=null===(t=K[0])||void 0===t?void 0:t.nodeKey;i.useEffect(function(){return null==b?void 0:b(U)},[U]);var W=K.slice(0,3).map(function(e){return e.nodeKey}),z=W.join("\0");if(i.useEffect(function(){E.loading||null==j||j(W)},[E.loading,z]),i.useEffect(function(){var e=new AbortController;return H(null,e.signal),function(){return e.abort()}},[null==w?void 0:w.api.configId,null==w?void 0:w.rangeKey,d.entityKey,h,m,C,null==w?void 0:w.revision]),!w)return null;var Z,$=w.goodDirection(h),J=v.filter(function(e){return e!==h}).slice(0,2),X=(Z=c.trim().toLowerCase())?/(s|x|ch|sh)$/.test(Z)?"".concat(Z,"es"):/[^aeiou]y$/.test(Z)?"".concat(Z.slice(0,-1),"ies"):"".concat(Z,"s"):"rows";return n.jsx(g.ReportAccordion,e.__assign({title:"Top Drivers for ".concat(_(X))},{children:E.error?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):E.loading&&!K.length?n.jsx(g.SkeletonLines,{widths:[80,60,85,55,75],label:"Loading drivers"}):K.length?n.jsxs(n.Fragment,{children:[n.jsx(u.default,{context:G}),n.jsx(I,e.__assign({label:_(c),rightLabel:"User Activity · selected dates"},{children:K.map(function(i){var a,t,r,o,d=null===(a=i.metrics)||void 0===a?void 0:a[h],c=i.label||i.nodeKey,u=y.includes(i.nodeKey);return n.jsx(D,{rank:i.rank,name:c,chips:n.jsxs(n.Fragment,{children:[n.jsx(g.CriticalityChip,{criticality:null===(t=i.chip)||void 0===t?void 0:t.criticality}),n.jsx(g.MovementChip,{movementType:null===(r=i.chip)||void 0===r?void 0:r.movementType,direction:null===(o=i.chip)||void 0===o?void 0:o.direction,good:$})]}),action:n.jsx(N,{on:u,disabled:!u&&y.length>=p,onClick:function(){return f(i.nodeKey)}}),lines:n.jsxs("span",e.__assign({className:"ag-driver__cost"},{children:[n.jsxs("span",e.__assign({className:"ag-driver__total"},{children:[l.formatValue(null==d?void 0:d.value)," ",w.kpiLabel(h).toLowerCase()]})),null!=(null==d?void 0:d.deltaPct)?n.jsx("span",e.__assign({className:"ag-driver__sep"},{children:"|"})):null,n.jsx(g.DayOverDayChange,{deltaPct:null==d?void 0:d.deltaPct,good:$,direction:null==d?void 0:d.direction,tone:null==d?void 0:d.tone,suffix:"vs previous period"})]})),cell:J.map(function(a){var t,r,s=null===(t=i.metrics)||void 0===t?void 0:t[a],o=null!==(r=null==s?void 0:s.tone)&&void 0!==r?r:g.toneOf(null==s?void 0:s.deltaPct,w.goodDirection(a)),d="up"===(null==s?void 0:s.direction)?"↑":"down"===(null==s?void 0:s.direction)?"↓":"flat"===(null==s?void 0:s.direction)?"→":null!=(null==s?void 0:s.deltaPct)&&s.deltaPct>0?"↑":null!=(null==s?void 0:s.deltaPct)&&s.deltaPct<0?"↓":"→";return n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",e.__assign({className:"good"===o?"ag-text--good":"bad"===o?"ag-text--bad":void 0},{children:null==(null==s?void 0:s.deltaPct)?l.formatValue(null==s?void 0:s.value):"".concat(d).concat(Math.abs(s.deltaPct),"%")})),n.jsx("span",{children:w.kpiLabel(a)})]}),a)}),onOpen:function(){var e;return x(i,h,k||(null===(e=i.chip)||void 0===e?void 0:e.dataDay)||s.toIsoDay(w.range.endDate))}},i.nodeKey)})})),P?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:E.loading,onClick:function(){return H(L)}},{children:E.loading?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:m?"No ".concat(X," match “").concat(m,"”."):"No ".concat(X," for this period yet.")}))}))}exports.AddToGraph=N,exports.CorrelationSection=K,exports.DecisionCard=b,exports.DriverList=I,exports.DriverRow=D,exports.L2Report=function(t){var r,v,_,m,y,f,j,k,w,N,D,I,C,S,R,F,P=t.tab,M=t.title,B=t.partName,E=t.partKpis,O=t.search,q=t.dataDay,G=t.onOpenRow,V=o.useInsights(),H=i.useState(Boolean(null==V?void 0:V.defaultWorkingDays)),U=H[0],W=H[1],z=l.useInsightsFetch(V?function(e){return s.fetchGraphGroups(V.api,e)}:null,[null==V?void 0:V.api.configId,null==V?void 0:V.revision]),Z=i.useState(null),$=Z[0],J=Z[1];i.useEffect(function(){var e,n;null===$&&((null===(e=z.data)||void 0===e?void 0:e.groups.length)?J((null!==(n=z.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:z.data.groups[0]).groupKey):z.loading||J(""))},[$,z.data,z.loading]);var X=i.useState(null),Q=X[0],Y=X[1],ee=i.useState(),ne=ee[0],ie=ee[1],ae=!1!==P.showSummary,te=null===(v=null===(r=z.data)||void 0===r?void 0:r.groups.find(function(e){return e.groupKey===$}))||void 0===v?void 0:v.days.map(Number),re=(null==te?void 0:te.length)?te.every(function(e){return e>=1&&e<=5}):U||Boolean(null==V?void 0:V.range.workingDaysOnly),se=V?c.resolveL2SummaryRange(V.range,re,q):null,oe="".concat(null==V?void 0:V.api.configId,":").concat(null==V?void 0:V.rangeKey,":").concat(P.entityKey,":").concat($,":").concat(null==se?void 0:se.startDate.getTime(),":").concat(null==se?void 0:se.endDate.getTime(),":").concat(null==se?void 0:se.workingDaysOnly),le=l.useInsightsFetch(V&&se&&ae&&null!==$?function(e){return s.fetchLevelSummary(V.api,P.entityKey,se,e)}:null,[oe,ae,null==V?void 0:V.revision],oe);if(!V)return null;var de=(null===(_=P.listKpis)||void 0===_?void 0:_.length)?P.listKpis:E,ce=P.rankBy&&de.includes(P.rankBy)?P.rankBy:null!==(m=de[0])&&void 0!==m?m:"",ue=null===(y=le.data)||void 0===y?void 0:y.report,ge=A(null===(f=le.data)||void 0===f?void 0:f.context),ve=c.resolveDrillDay({endDate:V.range.endDate,workingDays:re,selectedDay:q,reportDay:ge}),pe=function(n){return q||re?e.__assign(e.__assign({},n),{report:e.__assign(e.__assign({},n.report),{reportId:null})}):n},he=V.goodDirection(ce),_e=null!==(j=P.tier1Kpis)&&void 0!==j?j:V.tierKpis[1],me=null!==(k=P.tier2Kpis)&&void 0!==k?k:V.tierKpis[2],ye=V.headlineKpi||ce||_e[0]||"",fe=function(e){var n=e.nodeKey,i=e.label,a=e.dataDay;return G({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:ye},action:null,children:[]},ye,a)},xe=V.drill.tabTables[P.entityKey],be=xe?n.jsx(d.default,{table:e.__assign(e.__assign({},xe),{pageSize:null!==(N=null!==(w=xe.pageSize)&&void 0!==w?w:P.pageSize)&&void 0!==N?N:void 0}),tabEntityKey:P.entityKey,context:{trail:[],day:ve},onRowClick:function(e,n){var i;return"report"===n?V.openReport({reportId:pe(e).report.reportId,nodeKey:e.nodeKey,kpiId:ce,dataDay:ve,title:null!==(i=e.label)&&void 0!==i?i:e.nodeKey}):"drill"===n?G(pe(e),ce,ve):void 0}}):null;return n.jsxs("section",e.__assign({className:"ag-report","aria-label":"L2 Report · ".concat(M)},{children:[n.jsxs("div",e.__assign({className:"ag-report__header"},{children:[n.jsxs("h2",e.__assign({className:"ag-report__title"},{children:[n.jsx(a.Sparkles,{"aria-hidden":"true"}),"L2 Report"]})),n.jsx("span",e.__assign({className:"ag-report__scope"},{children:M})),ge?n.jsx("span",e.__assign({className:"ag-report__date"},{children:g.formatHeaderDate(ge)})):null]})),n.jsxs("div",e.__assign({className:"ag-report__grid ag-report__grid--l2"},{children:[n.jsx("div",e.__assign({className:"ag-report__analysis-scroll",role:"region","aria-label":"".concat(M," analysis"),tabIndex:0},{children:n.jsxs("div",e.__assign({className:"ag-stack"},{children:[ae?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(g.SectionHeader,{title:"Summary",action:n.jsx(h,{entityKey:P.entityKey,dataDay:ge})}),n.jsx(x,{report:ue,loading:le.loading,error:le.error,good:he})]}),n.jsx(b,{report:ue,error:le.error,loading:le.loading}),n.jsx(u.default,{context:null===(D=le.data)||void 0===D?void 0:D.context})]}):null,de.length?n.jsx(L,{tab:P,partName:B,kpiIds:de,rankBy:ce,search:O,graphed:null!=Q?Q:[],onToggleGraph:function(n){return Y(function(i){var a=null!=i?i:[];return a.includes(n)?a.filter(function(e){return e!==n}):a.length<p?e.__spreadArray(e.__spreadArray([],a,!0),[n],!1):a})},onOpenRow:function(e,n,i){return G(pe(e),n,i)},onFirstRow:ie,onInitialGraph:function(e){return Y(function(n){return null!=n?n:e})},fallbackDay:ve}):null]}))})),n.jsxs("div",e.__assign({className:"ag-stack"},{children:[_e.length?n.jsx(g.CollapsibleVisualSection,e.__assign({title:"Trend",action:n.jsx(g.DaysDropdown,{value:U,onChange:W,groups:z.error||null===(I=z.data)||void 0===I?void 0:I.groups,group:$,onGroupChange:J})},{children:n.jsx(T,{entityKey:P.entityKey,kpis:_e,nodeKeys:Q,workingDays:U,group:$,onOpenPoint:fe})})):null,me.length?n.jsx(g.CollapsibleVisualSection,e.__assign({title:V.labels.activityTitle,meta:Q?"Selected rows":"Top ".concat(3," ").concat(V.entityPluralName(P.entityKey))},{children:n.jsx(T,{entityKey:P.entityKey,kpis:me,nodeKeys:Q,workingDays:U,group:$,onOpenPoint:fe})})):null,n.jsx(K,{dataDay:ge,nodeKey:null!==(C=null==Q?void 0:Q[0])&&void 0!==C?C:ne,dayGroup:null===(R=null===(S=z.data)||void 0===S?void 0:S.groups.find(function(e){return e.groupKey===$}))||void 0===R?void 0:R.days}),"column"===(null==xe?void 0:xe.width)?be:null]}))]})),xe&&"full"===(null!==(F=xe.width)&&void 0!==F?F:"full")?be:null]}))},exports.MAX_SERIES=p,exports.RegenerateSummary=h,exports.RowDrivers=L,exports.RowTrend=T,exports.SummaryCard=x,exports.TopDriversSection=function(t){var r,d,c,u,h,_,m,y,x,b=t.dataDay,C=t.entityKey,S=t.parentNodeKey,K=t.kpiId,A=t.title,T=t.graphed,L=t.onToggleGraph,R=t.onOpenDriver,F=t.onDecisionSettled,P=t.initialTab,M=void 0===P?"drivers":P,B=o.useInsights(),E=i.useState(M),O=E[0],q=E[1],G=i.useState({drivers:1,headwinds:1,attention:1}),V=G[0],H=G[1],U=null!==(r=null!=K?K:null==B?void 0:B.headlineKpi)&&void 0!==r?r:void 0,W=function(e){return B&&U&&e===O?function(n){return s.fetchInsightsDrivers(B.api,{dataDay:b,kpiId:U,entityKey:C,parentNodeKey:S,tab:e,limit:Math.min(10,(S?10:3)*V[e]),offset:0,filters:B.range.filters},n)}:null},z=function(e){return[null==B?void 0:B.api.configId,null==B?void 0:B.rangeKey,b,U,C,S,e,O,V[e],null==B?void 0:B.revision]},Z={drivers:l.useInsightsFetch(W("drivers"),z("drivers")),headwinds:l.useInsightsFetch(W("headwinds"),z("headwinds")),attention:l.useInsightsFetch(W("attention"),z("attention"))},$=Z[O],J=$.data,X=$.error,Q=$.loading,Y=null!==(h=null!==(c=null===(d=Z.drivers.data)||void 0===d?void 0:d.tabs)&&void 0!==c?c:null===(u=Z.headwinds.data)||void 0===u?void 0:u.tabs)&&void 0!==h?h:null===(_=Z.attention.data)||void 0===_?void 0:_.tabs,ee=v.useNeedsAttention(b,S,U),ne=null!==(y=null===(m=ee.data)||void 0===m?void 0:m.counts.pending)&&void 0!==y?y:0;if(i.useEffect(function(){return H({drivers:1,headwinds:1,attention:1})},[b]),i.useEffect(function(){return q(M)},[M]),!B)return null;var ie=B.goodDirection(null!=U?U:""),ae=null!==(x=null==J?void 0:J.rows)&&void 0!==x?x:[];return n.jsxs(g.ReportAccordion,e.__assign({title:A},{children:[n.jsx("div",e.__assign({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:j.map(function(i){return n.jsx("button",e.__assign({type:"button",role:"tab","aria-selected":O===i.key,className:O===i.key?"is-active":void 0,onClick:function(){return q(i.key)},title:i.info},{children:n.jsxs(n.Fragment,{children:[B.labels[i.label],(null==Y?void 0:Y[i.key])?" (".concat(Y[i.key].total,")"):"","attention"===i.key&&ne?n.jsxs("span",e.__assign({className:"ag-na__tab-badge",title:"".concat(ne," data points need a decision")},{children:[ne,n.jsx("span",e.__assign({className:"ins-visually-hidden"},{children:" data points need a decision"}))]})):null,n.jsx(a.Info,{"aria-hidden":"true"})]})}),i.key)})})),"attention"===O?n.jsx(v.default,{dataDay:b,nodeKey:S,kpiId:U,attention:ee,onDecisionSettled:F}):null,"attention"===O&&ae.length?n.jsx("h4",e.__assign({className:"ag-na__subhead"},{children:"Rows that moved without a clear cause"})):null,X?n.jsxs("p",e.__assign({className:"ag-muted"},{children:["Top drivers are unavailable right now: ",X.message]})):Q&&!J?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading drivers..."})):ae.length?n.jsxs(n.Fragment,{children:[n.jsx(I,e.__assign({label:"Driver",rightLabel:B.labels.activityColumn},{children:ae.map(function(i){var a,t,r,s,o,d,c,u,v,h=i.deltaContributionPct,_=T.includes(i.nodeKey),m=(null===(a=i.decisionAdvantage)||void 0===a?void 0:a.correlationSentence)||(null===(t=i.decisionAdvantage)||void 0===t?void 0:t.firstCause)||(null===(r=i.decisionAdvantage)||void 0===r?void 0:r.headline);return n.jsx(D,{rank:i.rank,category:B.labels.driverCategory.replace("{plural}",i.entityKey?B.entityPluralName(i.entityKey):""),name:i.label,chips:n.jsxs(n.Fragment,{children:[n.jsx(g.CriticalityChip,{criticality:i.criticality}),n.jsx(g.MovementChip,{movementType:i.movementType,direction:i.changeDirection,good:ie}),(null===(s=i.correlation)||void 0===s?void 0:s.strength)?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(i.correlation.strength)},{children:w[i.correlation.strength]})):null]}),action:L?n.jsx(N,{on:_,disabled:!_&&T.length>=p,onClick:function(){return L(i)}}):void 0,lines:n.jsxs(n.Fragment,{children:[null!=h?n.jsxs("span",e.__assign({className:"ag-driver__share"},{children:[B.labels.shareLine.replace("{share}",String(Math.abs(h)))," · ","opposite"===i.direction?B.labels.movedOpposite:B.labels.movedWith]})):null,n.jsxs("span",e.__assign({className:"ag-driver__cost"},{children:[n.jsx("span",e.__assign({className:"ag-driver__total"},{children:l.formatValue(i.value)})),null!=i.deltaPct?n.jsx("span",e.__assign({className:"ag-driver__sep"},{children:"|"})):null,n.jsx(g.DayOverDayChange,{deltaPct:i.deltaPct,good:ie,direction:i.changeDirection,tone:i.tone,suffix:l.previousDayLabel(b)})]})),m?n.jsx("p",e.__assign({className:"ag-driver__brief"},{children:n.jsx(g.VerdictSentence,{text:f(m),good:ie,arrowsFollowVerdict:!0})})):null,(null===(o=i.decisionAdvantage)||void 0===o?void 0:o.nextStep)?n.jsxs("p",e.__assign({className:"ag-driver__brief"},{children:[n.jsx("strong",{children:"Next:"})," ",f(i.decisionAdvantage.nextStep)]})):null]}),cell:n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",{children:l.formatValue(null!==(c=null===(d=i.drivingMetric)||void 0===d?void 0:d.value)&&void 0!==c?c:i.previous)}),n.jsx("span",{children:(null===(u=i.drivingMetric)||void 0===u?void 0:u.label)||((null===(v=i.drivingMetric)||void 0===v?void 0:v.kpiId)?B.kpiLabel(i.drivingMetric.kpiId):"opposite"===i.direction?"Moved opposite":"with"===i.direction?"Moved with":"Previous")})]})),onOpen:function(){var e;return R?R(i):B.openReport({reportId:null===(e=i.report)||void 0===e?void 0:e.reportId,nodeKey:i.nodeKey,kpiId:U,dataDay:b,title:i.label})}},i.nodeKey)})})),(null==J?void 0:J.hasMore)?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:Q,onClick:function(){return H(function(n){var i;return e.__assign(e.__assign({},n),((i={})[O]=n[O]+1,i))})}},{children:Q?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:k[O]}))]}))},exports.decisionCardNotice=y,exports.reportDayOf=A,exports.stripRowTags=f,exports.titleCase=_;
|
|
2
2
|
//# sourceMappingURL=AgReport.js.map
|