@e-llm-studio/federated-dashboard-components 2.2.9-rca-test-4 → 2.2.9-rca-test-5
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/ExecutiveDashboardWrapper.js +1 -1
- package/dist/ExecutiveDashboard/api/insightsApi.js +1 -1
- package/dist/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js +1 -1
- package/dist/ExecutiveDashboard/components/ExecutiveDashboard.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/AgCharts.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/AgReport.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/CommentsThread.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/DecisionAdvantageCard.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/DrillLevel.js +2 -0
- package/dist/ExecutiveDashboard/components/Insights/DrillLevel.js.map +1 -0
- package/dist/ExecutiveDashboard/components/Insights/DrillTable.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/InsightTabs.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/InsightsContext.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/L1Report.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/ReportDrawer.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/RowDetail.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/agPrimitives.js +1 -1
- package/dist/ExecutiveDashboard/components/Insights/insightsUtils.js +1 -1
- package/dist/ExecutiveDashboard/components/RcaDecisionComponent/RcaDecisionComponent.js +1 -1
- package/dist/cjs/ExecutiveDashboard/ExecutiveDashboardWrapper.js +1 -1
- package/dist/cjs/ExecutiveDashboard/api/insightsApi.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/ExecutiveDashboard.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/AgCharts.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/AgReport.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/DecisionAdvantageCard.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/DrillLevel.js +2 -0
- package/dist/cjs/ExecutiveDashboard/components/Insights/DrillLevel.js.map +1 -0
- package/dist/cjs/ExecutiveDashboard/components/Insights/DrillTable.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/InsightTabs.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/InsightsContext.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/L1Report.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/ReportDrawer.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/RowDetail.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/agPrimitives.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/Insights/insightsUtils.js +1 -1
- package/dist/cjs/ExecutiveDashboard/components/RcaDecisionComponent/RcaDecisionComponent.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/styles.css +1 -1
- package/dist/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/ExecutiveDashboard/ExecutiveDashboardWrapper.d.ts +1 -1
- package/dist/types/ExecutiveDashboard/ExecutiveDashboardWrapper.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/TestExecutiveDashboard.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/api/insightsApi.d.ts +26 -2
- package/dist/types/ExecutiveDashboard/api/insightsApi.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/DashboardGrid/buildDashboardWidgets.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/ExecutiveDashboard.d.ts +10 -4
- package/dist/types/ExecutiveDashboard/components/ExecutiveDashboard.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/AgCharts.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/AgReport.d.ts +5 -0
- package/dist/types/ExecutiveDashboard/components/Insights/AgReport.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/DecisionAdvantageCard.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/DrillLevel.d.ts +35 -0
- package/dist/types/ExecutiveDashboard/components/Insights/DrillLevel.d.ts.map +1 -0
- package/dist/types/ExecutiveDashboard/components/Insights/DrillTable.d.ts +25 -17
- package/dist/types/ExecutiveDashboard/components/Insights/DrillTable.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/InsightTabs.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/InsightsContext.d.ts +27 -4
- package/dist/types/ExecutiveDashboard/components/Insights/InsightsContext.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/L1Report.d.ts +6 -1
- package/dist/types/ExecutiveDashboard/components/Insights/L1Report.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/NeedsAttention.d.ts +4 -3
- package/dist/types/ExecutiveDashboard/components/Insights/NeedsAttention.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/ReportDrawer.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/RowDetail.d.ts +8 -1
- package/dist/types/ExecutiveDashboard/components/Insights/RowDetail.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/agPrimitives.d.ts +2 -1
- package/dist/types/ExecutiveDashboard/components/Insights/agPrimitives.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/insightsContextCore.d.ts +37 -3
- package/dist/types/ExecutiveDashboard/components/Insights/insightsContextCore.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/Insights/insightsUtils.d.ts +5 -4
- package/dist/types/ExecutiveDashboard/components/Insights/insightsUtils.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/components/RcaDecisionComponent/RcaDecisionComponent.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/types/index.d.ts +24 -4
- package/dist/types/ExecutiveDashboard/types/index.d.ts.map +1 -1
- package/dist/types/ExecutiveDashboard/types/insights.d.ts +205 -3
- package/dist/types/ExecutiveDashboard/types/insights.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -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("./agPrimitives.js"),u=require("./NeedsAttention.js"),g=10;function v(a){var t,r=this,d=a.entityKey,c=a.dataDay,u=o.useInsights(),g=i.useState(null),v=g[0],h=g[1],p=i.useState(null),_=p[0],m=p[1];if(l.useJob(v,null!==(t=null==u?void 0:u.api)&&void 0!==t?t:null,function(){h(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?h(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){var n=e.trim().toLowerCase();return n?/(s|x|ch|sh)$/.test(n)?"".concat(n,"es"):/[^aeiou]y$/.test(n)?"".concat(n.slice(0,-1),"ies"):"".concat(n,"s"):"rows"},p=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 AI report generated yet for this day.":null:null}function m(a){var r,s,o=a.report,d=a.movementType,u=a.direction,g=a.good,v=a.loading,h=a.error,p=i.useState(!1),m=p[0],f=p[1],y=i.useMemo(function(){return l.reportDecisioning(o)},[o]);if(i.useEffect(function(){return f(!1)},[null==o?void 0:o.reportId]),v)return n.jsx("div",e.__assign({className:"ag-summary"},{children:n.jsx(c.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=c.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?c.movementVerdictLabel(d,u):k||"Summary",I=w?"good"===x.tone||"bad"===x.tone?c.verdictToneHex(x.tone):c.movementColorHex(x.movementType,x.movementDirection,g):N?c.movementColorHex(d,u,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(c.VerdictSentence,{text:b,good:g}):null!==(s=_(o,h))&&void 0!==s?s:"Reports are written after each morning run.",j&&y?n.jsx("span",e.__assign({className:"ag-summary__brain"},{children:n.jsx(t.ReasoningTrigger,{open:m,onToggle:function(){return f(function(e){return!e})},label:"how the AI reached this summary"})})):null]})),m&&y?n.jsx("div",e.__assign({className:"ag-summary__reasoning"},{children:n.jsx(t.ReasoningPanel,{decisioning:y})})):null]}))}function f(e){var a=e.report,r=e.error,s=e.loading,o=!s&&"generated"===(null==a?void 0:a.status),d=i.useMemo(function(){return o?l.reportDecisioning(a,null==a?void 0:a.footer):null},[o,a]),u=l.useOpenRow();return n.jsx(t.RcaDecisionComponent,{className:"ag-decision",title:"Decision Advantage",score:o?null==a?void 0:a.score:null,decisioning:d,notice:s?null:_(a,r),afterSections:s?n.jsx(c.SkeletonLines,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:o?l.toRcaItems(null==a?void 0:a.rootCause,u):[],nextSteps:o?l.toRcaItems(null==a?void 0:a.nextSteps,u):[],width:"100%",maxWidth:"none"})}var y=[{key:"drivers",label:"Top Drivers",info:"What moved the day's number the same way."},{key:"headwinds",label:"Headwinds",info:"What moved against the day's number."},{key:"attention",label:"Needs attention",info:"The number moved, but activity doesn't explain it."}],x={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},b={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function j(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(g," 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 k(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 w(i){var a=i.label,t=i.rightLabel,r=void 0===t?"User Activity":t,s=i.children;return n.jsxs("div",e.__assign({className:"ag-drivers"},{children:[n.jsxs("div",e.__assign({className:"ag-drivers__head"},{children:[n.jsx("span",{children:a}),n.jsx("span",{children:r})]})),n.jsx("ol",{children:s})]}))}var N=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],D=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 I(t){var d,u,g,v,h,p,_,m,f=this,y=t.dataDay,x=t.nodeKey,j=void 0===x?"root":x,k=t.kpiId,w=t.dayGroup,I=o.useInsights(),S=null!==(d=null!=k?k:null==I?void 0:I.headlineKpi)&&void 0!==d?d:void 0,C=i.useState(""),K=C[0],A=C[1],T=i.useState([]),R=T[0],L=T[1],F=i.useState({}),M=F[0],P=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],X=z[1],J=i.useState(!1),$=J[0],Q=J[1],Y=i.useRef(null),ee=l.useInsightsFetch(I&&S&&y?function(n){return s.fetchInsightsCorrelation(I.api,j,e.__assign({kpiId:S,dataDay:y,startDate:s.toIsoDay(I.range.startDate),endDate:s.toIsoDay(I.range.endDate)},M),n)}:null,[null==I?void 0:I.api.configId,null==I?void 0:I.rangeKey,y,S,j,M.disregardBefore,null===(u=M.disregardDates)||void 0===u?void 0:u.join(","),null==I?void 0:I.revision]),ne=ee.data,ie=ee.error,ae=ee.loading,te=l.useInsightsFetch(I&&S&&y?function(n){return s.fetchInsightsCorrelationTrend(I.api,j,e.__assign({kpiId:S,startDate:s.toIsoDay(I.range.startDate),endDate:s.toIsoDay(I.range.endDate)},M),n)}:null,[null==I?void 0:I.api.configId,null==I?void 0:I.rangeKey,y,S,j,M.disregardBefore,null===(g=M.disregardDates)||void 0===g?void 0:g.join(","),null==I?void 0:I.revision]);l.useJob(U,null!==(v=null==I?void 0:I.api)&&void 0!==v?v:null,function(){W(null),O(""),null==I||I.refresh()}),i.useEffect(function(){if(Z){var e=function(e){Y.current&&!Y.current.contains(e.target)&&X(!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&&I?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:I.kpiLabel(e),color:N[n%N.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,I,le]);i.useEffect(function(){return oe(new Set(de.slice(2).map(function(e){return e.key})))},[de]);if(!I||!y||"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(c.ChartSkeleton,{height:220,label:"Loading correlation"});if(!ne)return null;var ce=null!==(h=ne.strength)&&void 0!==h?h:"none",ue=I.kpiLabel(ne.kpiId);return n.jsx(c.CollapsibleVisualSection,e.__assign({title:"Correlation",meta:"Usage vs. ".concat(ue),className:"ag-visual--card",action:I.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 X(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:$,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:b[ce]})),n.jsxs("p",e.__assign({className:"ag-corr__caption"},{children:[ue," vs. usage - % change from the first day shown"]})),(null===(p=ne.window)||void 0===p?void 0:p.source)?n.jsx("p",e.__assign({className:"ag-muted"},{children:"default"===ne.window.source?ne.window.startDate?"Using all days since ".concat(D(ne.window.startDate,"en-US")):"Using all available days":"row"===ne.window.source?"Saved window".concat(ne.window.startDate?" since ".concat(D(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:D(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:I.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||I.kpiLabel(i.kpiId)})),i.kpiId!==ne.kpiId?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(t)},{children:b[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)})})),I.viewer.isAdmin&&$?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 (",R.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":R.includes(i.x),className:R.includes(i.x)?"is-selected":void 0,onClick:function(){return n=i.x,L(function(i){return i.includes(n)?i.filter(function(e){return e!==n}):e.__spreadArray(e.__spreadArray([],i,!0),[n],!1)});var n}},{children:D(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 P({disregardBefore:K||void 0,disregardDates:R})}},{children:"Preview"})),n.jsx("button",e.__assign({type:"button",className:"ins-button",disabled:Boolean(U),onClick:function(){return e.__awaiter(f,void 0,void 0,function(){var n,i;return e.__generator(this,function(e){switch(e.label){case 0:if(!I||!S||!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(I.api,j,{kpiId:S,startDate:K||null,excludedDates:R,dataDay:y,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(""),L([]),P({})}},{children:"Clear"}))]}))]})):null]}))}))}var S=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function C(a){var t,d=a.entityKey,u=a.kpis,v=a.nodeKeys,h=a.workingDays,p=a.group,_=a.onOpenPoint,m=o.useInsights(),f=i.useState(null!==(t=u[0])&&void 0!==t?t:""),y=f[0],x=f[1];i.useEffect(function(){var e;u.includes(y)||x(null!==(e=u[0])&&void 0!==e?e:"")},[u,y]);var b=l.useInsightsFetch(m&&y&&null!==p&&0!==(null==v?void 0:v.length)?function(n){return s.fetchInsightsSeries(m.api,e.__assign(e.__assign({},m.range),{workingDaysOnly:h,group:p||void 0}),v?{kpiIds:[y],nodeKeys:v.slice(0,g)}:{kpiIds:[y],entityKey:d,topN:3},n)}:null,[null==m?void 0:m.api.configId,null==m?void 0:m.rangeKey,d,y,null==v?void 0:v.join(","),h,p,null==m?void 0:m.revision]),j=b.data,k=b.loading,w=b.error,N=i.useMemo(function(){var e;return 0===(null==v?void 0:v.length)?[]:(null!==(e=null==j?void 0:j.series)&&void 0!==e?e:[]).filter(function(e){return e.kpiId===y&&e.points.some(function(e){return Number.isFinite(e.y)})})},[j,v,y]),D=i.useState(new Set),I=D[0],S=D[1];i.useEffect(function(){return S(new Set)},[N]);var C=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:C.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:c.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,C,m,_]);if(!m)return null;var A=m.kpiLabel(y);return n.jsxs("div",e.__assign({className:"ag-row-trend"},{children:[u.length>1?n.jsx("div",e.__assign({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:u.map(function(i){return n.jsx("button",e.__assign({type:"button","aria-pressed":i===y,className:i===y?"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(c.ChartSkeleton,{height:240,label:"Loading trend"}):C.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 S(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,h=null==g?void 0:g.points.find(function(e){return e.x===String(v)});if(g&&h){var p=null!==(a=g.label)&&void 0!==a?a:g.nodeKey,f=null!==(s=null===(r=null===(t=h.meta)||void 0===t?void 0:t.marker)||void 0===r?void 0:r.reportId)&&void 0!==s?s:null;_?_({nodeKey:g.nodeKey,label:p,kpiId:g.kpiId,dataDay:h.x,reportId:f}):m.openReport(f?{reportId:f,title:"".concat(p," · ").concat(l.shortDay(h.x))}:{nodeKey:g.nodeKey,kpiId:g.kpiId,dataDay:h.x,title:"".concat(p," · ").concat(l.shortDay(h.x))})}},xAxis:{label:"Date",categories:C,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 S(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 K(a){var t,r=this,d=a.tab,u=a.partName,v=a.kpiIds,_=a.rankBy,m=a.search,f=a.graphed,y=a.onToggleGraph,x=a.onOpenRow,b=a.onFirstRow,N=a.onInitialGraph,D=a.fallbackDay,I=o.useInsights(),S=Math.min(200,Math.max(1,Number(d.pageSize)||5)),C=i.useState([]),K=C[0],A=C[1],T=i.useState(null),R=T[0],L=T[1],F=i.useState(!1),M=F[0],P=F[1],E=i.useState({loading:!0,error:null}),B=E[0],O=E[1],G=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:S,cursor:null!=n?n:void 0,includeChildren:3},i)];case 2:return a=r.sent(),(null==i?void 0:i.aborted)?[2]:(A(function(i){return n?e.__spreadArray(e.__spreadArray([],i,!0),a.rows,!0):a.rows}),L(a.nextCursor),P(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]}})})},V=null===(t=K[0])||void 0===t?void 0:t.nodeKey;i.useEffect(function(){return null==b?void 0:b(V)},[V]);var q=K.slice(0,3).map(function(e){return e.nodeKey}),H=q.join("\0");if(i.useEffect(function(){B.loading||null==N||N(q)},[B.loading,H]),i.useEffect(function(){var e=new AbortController;return G(null,e.signal),function(){return e.abort()}},[null==I?void 0:I.api.configId,null==I?void 0:I.rangeKey,d.entityKey,_,m,S,null==I?void 0:I.revision]),!I)return null;var U=I.goodDirection(_),W=v.filter(function(e){return e!==_}).slice(0,2),z=h(u);return n.jsx(c.ReportAccordion,e.__assign({title:"Top Drivers for ".concat(p(z))},{children:B.error?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):B.loading&&!K.length?n.jsx(c.SkeletonLines,{widths:[80,60,85,55,75],label:"Loading drivers"}):K.length?n.jsxs(n.Fragment,{children:[n.jsx(w,e.__assign({label:p(u),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[_],u=i.label||i.nodeKey,v=f.includes(i.nodeKey);return n.jsx(k,{rank:i.rank,name:u,chips:n.jsxs(n.Fragment,{children:[n.jsx(c.CriticalityChip,{criticality:null===(t=i.chip)||void 0===t?void 0:t.criticality}),n.jsx(c.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})]}),action:n.jsx(j,{on:v,disabled:!v&&f.length>=g,onClick:function(){return y(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(c.DayOverDayChange,{deltaPct:null==d?void 0:d.deltaPct,good:U,direction:null==d?void 0:d.direction,tone:null==d?void 0:d.tone,suffix:"vs previous period"})]})),cell:W.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:c.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,_,D||(null===(e=i.chip)||void 0===e?void 0:e.dataDay)||s.toIsoDay(I.range.endDate))}},i.nodeKey)})})),M?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:B.loading,onClick:function(){return G(R)}},{children:B.loading?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:m?"No ".concat(z," match “").concat(m,"”."):"No ".concat(z," for this period yet.")}))}))}exports.AddToGraph=j,exports.CorrelationSection=I,exports.DecisionCard=f,exports.DriverList=w,exports.DriverRow=k,exports.L2Report=function(t){var r,u,p,_,y,x,b,j,k,w,N,D,A,T,R=t.tab,L=t.title,F=t.partName,M=t.partKpis,P=t.search,E=t.onOpenRow,B=o.useInsights(),O=i.useState(Boolean(null==B?void 0:B.defaultWorkingDays)),G=O[0],V=O[1],q=l.useInsightsFetch(B?function(e){return s.fetchGraphGroups(B.api,e)}:null,[null==B?void 0:B.api.configId,null==B?void 0:B.revision]),H=i.useState(null),U=H[0],W=H[1];i.useEffect(function(){var e,n;null===U&&((null===(e=q.data)||void 0===e?void 0:e.groups.length)?W((null!==(n=q.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:q.data.groups[0]).groupKey):q.loading||W(""))},[U,q.data,q.loading]);var z=i.useState(null),Z=z[0],X=z[1],J=i.useState(),$=J[0],Q=J[1],Y=!1!==R.showSummary,ee=l.useInsightsFetch(B&&Y?function(e){return s.fetchLevelSummary(B.api,R.entityKey,B.range,e)}:null,[null==B?void 0:B.api.configId,null==B?void 0:B.rangeKey,R.entityKey,Y,null==B?void 0:B.revision]);if(!B)return null;var ne=(null===(r=R.listKpis)||void 0===r?void 0:r.length)?R.listKpis:M,ie=R.rankBy&&ne.includes(R.rankBy)?R.rankBy:null!==(u=ne[0])&&void 0!==u?u:"",ae=null===(p=ee.data)||void 0===p?void 0:p.report,te=S(null===(_=ee.data)||void 0===_?void 0:_.context),re=B.goodDirection(ie),se=null!==(y=R.tier1Kpis)&&void 0!==y?y:B.tierKpis[1],oe=null!==(x=R.tier2Kpis)&&void 0!==x?x:B.tierKpis[2],le=B.headlineKpi||ie||se[0]||"",de=function(e){var n=e.nodeKey,i=e.label,a=e.dataDay;return E({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:le},action:null,children:[]},le,a)};return n.jsxs("section",e.__assign({className:"ag-report","aria-label":"L2 Report · ".concat(L)},{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:L})),te?n.jsx("span",e.__assign({className:"ag-report__date"},{children:c.formatHeaderDate(te)})):null]})),n.jsxs("div",e.__assign({className:"ag-report__grid ag-report__grid--l2"},{children:[n.jsxs("div",e.__assign({className:"ag-stack"},{children:[Y?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(c.SectionHeader,{title:"Summary",action:n.jsx(v,{entityKey:R.entityKey,dataDay:te})}),n.jsx(m,{report:ae,loading:ee.loading,error:ee.error,good:re})]}),n.jsx(f,{report:ae,error:ee.error,loading:ee.loading})]}):null,ne.length?n.jsx(K,{tab:R,partName:F,kpiIds:ne,rankBy:ie,search:P,graphed:null!=Z?Z:[],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<g?e.__spreadArray(e.__spreadArray([],a,!0),[n],!1):a})},onOpenRow:E,onFirstRow:Q,onInitialGraph:function(e){return X(function(n){return null!=n?n:e})},fallbackDay:te}):null]})),n.jsxs("div",e.__assign({className:"ag-stack"},{children:[se.length?n.jsx(c.CollapsibleVisualSection,e.__assign({title:"Trend",action:n.jsx(c.DaysDropdown,{value:G,onChange:V,groups:q.error||null===(b=q.data)||void 0===b?void 0:b.groups,group:U,onGroupChange:W})},{children:n.jsx(C,{entityKey:R.entityKey,kpis:se,nodeKeys:Z,workingDays:G,group:U,onOpenPoint:de})})):null,oe.length?n.jsx(c.CollapsibleVisualSection,e.__assign({title:"User Activity",meta:Z?"Selected rows":"Top ".concat(3," ").concat(h(F))},{children:n.jsx(C,{entityKey:R.entityKey,kpis:oe,nodeKeys:Z,workingDays:G,group:U,onOpenPoint:de})})):null,n.jsx(I,{dataDay:te,nodeKey:null!==(j=null==Z?void 0:Z[0])&&void 0!==j?j:$,dayGroup:null===(w=null===(k=q.data)||void 0===k?void 0:k.groups.find(function(e){return e.groupKey===U}))||void 0===w?void 0:w.days}),(null===(N=B.insightsColumns)||void 0===N?void 0:N[R.entityKey])||!1!==(null===(D=R.drillTable)||void 0===D?void 0:D.enabled)?n.jsx(d.default,{entityKey:R.entityKey,dataDay:null!=te?te:void 0,pageSize:null!==(A=R.pageSize)&&void 0!==A?A:void 0,defaultSort:null===(T=R.drillTable)||void 0===T?void 0:T.defaultSort,onOpenRow:function(e){var n;return E(e,ie,te||(null===(n=e.chip)||void 0===n?void 0:n.dataDay)||s.toIsoDay(B.range.endDate))}}):null]}))]}))]}))},exports.MAX_SERIES=g,exports.RegenerateSummary=v,exports.RowDrivers=K,exports.RowTrend=C,exports.SummaryCard=m,exports.TopDriversSection=function(t){var r,d,v,_,m,f,N,D,I,S,C=t.dataDay,K=t.entityKey,A=t.parentNodeKey,T=t.kpiId,R=t.title,L=t.graphed,F=t.onToggleGraph,M=t.onOpenDriver,P=t.onDecisionSettled,E=t.initialTab,B=void 0===E?"drivers":E,O=o.useInsights(),G=i.useState(B),V=G[0],q=G[1],H=i.useState({drivers:1,headwinds:1,attention:1}),U=H[0],W=H[1],z=null!==(r=null!=T?T:null==O?void 0:O.headlineKpi)&&void 0!==r?r:void 0,Z=function(e){return O&&z&&e===V?function(n){return s.fetchInsightsDrivers(O.api,{dataDay:C,kpiId:z,entityKey:K,parentNodeKey:A,tab:e,limit:Math.min(10,(A?10:3)*U[e]),offset:0},n)}:null},X=function(e){return[null==O?void 0:O.api.configId,C,z,K,A,e,V,U[e],null==O?void 0:O.revision]},J={drivers:l.useInsightsFetch(Z("drivers"),X("drivers")),headwinds:l.useInsightsFetch(Z("headwinds"),X("headwinds")),attention:l.useInsightsFetch(Z("attention"),X("attention"))},$=J[V],Q=$.data,Y=$.error,ee=$.loading,ne=null!==(m=null!==(v=null===(d=J.drivers.data)||void 0===d?void 0:d.tabs)&&void 0!==v?v:null===(_=J.headwinds.data)||void 0===_?void 0:_.tabs)&&void 0!==m?m:null===(f=J.attention.data)||void 0===f?void 0:f.tabs,ie=null!==(N=null==O?void 0:O.entityOrder)&&void 0!==N?N:[],ae=u.useNeedsAttention(C,A,z),te=null!==(I=null===(D=ae.data)||void 0===D?void 0:D.counts.pending)&&void 0!==I?I:0;if(i.useEffect(function(){return W({drivers:1,headwinds:1,attention:1})},[C]),i.useEffect(function(){return q(B)},[B]),!O)return null;var re=O.goodDirection(null!=z?z:""),se=null!==(S=null==Q?void 0:Q.rows)&&void 0!==S?S:[],oe=Array.from(new Set(se.map(function(e){return e.entityKey}).filter(function(e){return Boolean(e)}))),le=Boolean(A)&&oe.length>1,de=e.__spreadArray([],oe,!0).sort(function(e,n){var i=Math.min.apply(Math,se.filter(function(n){return n.entityKey===e}).map(function(e){var n;return null!==(n=e.level)&&void 0!==n?n:99})),a=Math.min.apply(Math,se.filter(function(e){return e.entityKey===n}).map(function(e){var n;return null!==(n=e.level)&&void 0!==n?n:99})),t=ie.indexOf(e),r=ie.indexOf(n);return i-a||(t<0?Number.MAX_SAFE_INTEGER:t)-(r<0?Number.MAX_SAFE_INTEGER:r)});return n.jsxs(c.ReportAccordion,e.__assign({title:R},{children:[n.jsx("div",e.__assign({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:y.map(function(i){return n.jsxs("button",e.__assign({type:"button",role:"tab","aria-selected":V===i.key,className:V===i.key?"is-active":void 0,onClick:function(){return q(i.key)},title:i.info},{children:[i.label,(null==ne?void 0:ne[i.key])?" (".concat(ne[i.key].total,")"):"","attention"===i.key&&te?n.jsxs("span",e.__assign({className:"ag-na__tab-badge",title:"".concat(te," data points need a decision")},{children:[te,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"===V?n.jsx(u.default,{dataDay:C,nodeKey:A,kpiId:z,attention:ae,onDecisionSettled:P}):null,"attention"===V&&se.length?n.jsx("h4",e.__assign({className:"ag-na__subhead"},{children:"Rows that moved without a clear cause"})):null,Y?n.jsxs("p",e.__assign({className:"ag-muted"},{children:["Top drivers are unavailable right now: ",Y.message]})):ee&&!Q?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading drivers..."})):se.length?n.jsxs(n.Fragment,{children:[(le?de:[null]).map(function(a){return n.jsxs(i.Fragment,{children:[a?n.jsx("h4",e.__assign({className:"ag-driver-group"},{children:p(h(O.entityName(a)))})):null,n.jsx(w,e.__assign({label:a?p(O.entityName(a)):"Driver"},{children:(a?se.filter(function(e){return e.entityKey===a}):se).map(function(i,t){var r,s,o,d,u,v,h,p,_,m,f,y=i.deltaContributionPct,x=L.includes(i.nodeKey),w=(null===(r=i.decisionAdvantage)||void 0===r?void 0:r.correlationSentence)||(null===(s=i.decisionAdvantage)||void 0===s?void 0:s.firstCause)||(null===(o=i.decisionAdvantage)||void 0===o?void 0:o.headline);return n.jsx(k,{rank:a?t+1:i.rank,category:null===(d=i.path)||void 0===d?void 0:d.slice(0,-1).join(" › "),name:i.label,chips:n.jsxs(n.Fragment,{children:[n.jsx(c.CriticalityChip,{criticality:i.criticality}),n.jsx(c.MovementChip,{movementType:i.movementType,direction:i.changeDirection}),(null===(u=i.correlation)||void 0===u?void 0:u.strength)?n.jsx("span",e.__assign({className:"ag-driver__badge ag-driver__badge--".concat(i.correlation.strength)},{children:b[i.correlation.strength]})):null]}),action:F?n.jsx(j,{on:x,disabled:!x&&L.length>=g,onClick:function(){return F(i)}}):void 0,lines:n.jsxs(n.Fragment,{children:[null!=y?n.jsxs("span",e.__assign({className:"ag-driver__share"},{children:[Math.abs(y),"% of today's movement ·"," ","opposite"===i.direction?"in the opposite direction":"driving the ".concat(null!==(v=null==Q?void 0:Q.headlineDirection)&&void 0!==v?v:"change")]})):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(c.DayOverDayChange,{deltaPct:i.deltaPct,good:re,direction:i.changeDirection,tone:i.tone,suffix:l.previousDayLabel(C)})]})),w?n.jsx("p",e.__assign({className:"ag-driver__brief"},{children:n.jsx(c.VerdictSentence,{text:w,good:re,arrowsFollowVerdict:!0})})):null,(null===(h=i.decisionAdvantage)||void 0===h?void 0:h.nextStep)?n.jsxs("p",e.__assign({className:"ag-driver__brief"},{children:[n.jsx("strong",{children:"Next:"})," ",i.decisionAdvantage.nextStep]})):null]}),cell:n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",{children:l.formatValue(null!==(_=null===(p=i.drivingMetric)||void 0===p?void 0:p.value)&&void 0!==_?_:i.previous)}),n.jsx("span",{children:(null===(m=i.drivingMetric)||void 0===m?void 0:m.label)||((null===(f=i.drivingMetric)||void 0===f?void 0:f.kpiId)?O.kpiLabel(i.drivingMetric.kpiId):"opposite"===i.direction?"Moved opposite":"with"===i.direction?"Moved with":"Previous")})]})),onOpen:function(){var e;return M?M(i):O.openReport({reportId:null===(e=i.report)||void 0===e?void 0:e.reportId,nodeKey:i.nodeKey,kpiId:z,dataDay:C,title:i.label})}},i.nodeKey)})}))]},null!=a?a:"all")}),(null==Q?void 0:Q.hasMore)?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:ee,onClick:function(){return W(function(n){var i;return e.__assign(e.__assign({},n),((i={})[V]=n[V]+1,i))})}},{children:ee?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:x[V]}))]}))},exports.reportDayOf=S,exports.titleCase=p;
|
|
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("./agPrimitives.js"),u=require("./NeedsAttention.js"),g=10;function v(a){var t,r=this,d=a.entityKey,c=a.dataDay,u=o.useInsights(),g=i.useState(null),v=g[0],h=g[1],p=i.useState(null),_=p[0],m=p[1];if(l.useJob(v,null!==(t=null==u?void 0:u.api)&&void 0!==t?t:null,function(){h(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?h(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 p(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 AI report generated yet for this day.":null:null}function _(e,n,i){return i?null:p(e,n)}function m(e){return e.replace(/\{\{([^|}]*)\|[^}]*\}\}/g,"$1")}function y(a){var r,s,o=a.report,d=a.movementType,u=a.direction,g=a.good,v=a.loading,h=a.error,_=i.useState(!1),m=_[0],y=_[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(c.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=c.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?c.movementVerdictLabel(d,u):k||"Summary",I=w?"good"===x.tone||"bad"===x.tone?c.verdictToneHex(x.tone):c.movementColorHex(x.movementType,x.movementDirection,g):N?c.movementColorHex(d,u,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(c.VerdictSentence,{text:b,good:g}):null!==(s=p(o,h))&&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 f(e){var a,r,s,d=e.report,u=e.error,g=e.loading,v=o.useInsights(),h=!g&&"generated"===(null==d?void 0:d.status),p=i.useMemo(function(){return h?l.reportDecisioning(d,null==d?void 0:d.footer):null},[h,d]),m=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:h?null==d?void 0:d.score:null,decisioning:p,notice:_(d,u,g),afterSections:g?n.jsx(c.SkeletonLines,{widths:[22,92,84,66,22,88,74],label:"Loading Decision Advantage"}):null,rootCause:h?l.toRcaItems(null==d?void 0:d.rootCause,m):[],nextSteps:h?l.toRcaItems(null==d?void 0:d.nextSteps,m):[],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 x=[{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."}],b={drivers:"Nothing moved the day's way.",headwinds:"Nothing ran against the day.",attention:"No drivers for this day."},j={high:"High correlation",medium:"Medium correlation",low:"Low correlation",none:"No correlation"};function k(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(g," 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 w(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 N(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 D=["#4F46E5","#64748B","#0F766E","#7C3AED","#475569","#818CF8","#94A3B8"],I=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 C(t){var d,u,g,v,h,p,_,m,y=this,f=t.dataDay,x=t.nodeKey,b=void 0===x?"root":x,k=t.kpiId,w=t.dayGroup,N=o.useInsights(),C=null!==(d=null!=k?k: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&&C&&f?function(n){return s.fetchInsightsCorrelation(N.api,b,e.__assign({kpiId:C,dataDay:f,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate)},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,C,b,P.disregardBefore,null===(u=P.disregardDates)||void 0===u?void 0:u.join(","),null==N?void 0:N.revision]),ne=ee.data,ie=ee.error,ae=ee.loading,te=l.useInsightsFetch(N&&C&&f?function(n){return s.fetchInsightsCorrelationTrend(N.api,b,e.__assign({kpiId:C,startDate:s.toIsoDay(N.range.startDate),endDate:s.toIsoDay(N.range.endDate)},P),n)}:null,[null==N?void 0:N.api.configId,null==N?void 0:N.rangeKey,f,C,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:D[n%D.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(c.ChartSkeleton,{height:220,label:"Loading correlation"});if(!ne)return null;var ce=null!==(h=ne.strength)&&void 0!==h?h:"none",ue=N.kpiLabel(ne.kpiId);return n.jsx(c.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:j[ce]})),n.jsxs("p",e.__assign({className:"ag-corr__caption"},{children:[ue," vs. usage - % change from the first day shown"]})),(null===(p=ne.window)||void 0===p?void 0:p.source)?n.jsx("p",e.__assign({className:"ag-muted"},{children:"default"===ne.window.source?ne.window.startDate?"Using all days since ".concat(I(ne.window.startDate,"en-US")):"Using all available days":"row"===ne.window.source?"Saved window".concat(ne.window.startDate?" since ".concat(I(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:I(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:j[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:I(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||!C||!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:C,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 S=function(e){var n;return(null===(n=null==e?void 0:e.period)||void 0===n?void 0:n.end)||null};function K(a){var t,d=a.entityKey,u=a.kpis,v=a.nodeKeys,h=a.workingDays,p=a.group,_=a.onOpenPoint,m=o.useInsights(),y=i.useState(null!==(t=u[0])&&void 0!==t?t:""),f=y[0],x=y[1];i.useEffect(function(){var e;u.includes(f)||x(null!==(e=u[0])&&void 0!==e?e:"")},[u,f]);var b=l.useInsightsFetch(m&&f&&null!==p&&0!==(null==v?void 0:v.length)?function(n){return s.fetchInsightsSeries(m.api,e.__assign(e.__assign({},m.range),{workingDaysOnly:h,group:p||void 0}),v?{kpiIds:[f],nodeKeys:v.slice(0,g)}:{kpiIds:[f],entityKey:d,topN:3},n)}:null,[null==m?void 0:m.api.configId,null==m?void 0:m.rangeKey,d,f,null==v?void 0:v.join(","),h,p,null==m?void 0:m.revision]),j=b.data,k=b.loading,w=b.error,N=i.useMemo(function(){var e;return 0===(null==v?void 0:v.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,v,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:c.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:[u.length>1?n.jsx("div",e.__assign({className:"ag-chart__switch",role:"group","aria-label":"Number"},{children:u.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(c.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,h=null==g?void 0:g.points.find(function(e){return e.x===String(v)});if(g&&h){var p=null!==(a=g.label)&&void 0!==a?a:g.nodeKey,y=null!==(s=null===(r=null===(t=h.meta)||void 0===t?void 0:t.marker)||void 0===r?void 0:r.reportId)&&void 0!==s?s:null;_?_({nodeKey:g.nodeKey,label:p,kpiId:g.kpiId,dataDay:h.x,reportId:y}):m.openReport(y?{reportId:y,title:"".concat(p," · ").concat(l.shortDay(h.x))}:{nodeKey:g.nodeKey,kpiId:g.kpiId,dataDay:h.x,title:"".concat(p," · ").concat(l.shortDay(h.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 A(a){var t,r=this,d=a.tab,u=a.partName,v=a.kpiIds,p=a.rankBy,_=a.search,m=a.graphed,y=a.onToggleGraph,f=a.onOpenRow,x=a.onFirstRow,b=a.onInitialGraph,j=a.fallbackDay,D=o.useInsights(),I=Math.min(200,Math.max(1,Number(d.pageSize)||5)),C=i.useState([]),S=C[0],K=C[1],A=i.useState(null),T=A[0],L=A[1],R=i.useState(!1),F=R[0],P=R[1],M=i.useState({loading:!0,error:null}),E=M[0],B=M[1],O=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(!D)return[2];B({loading:!0,error:null}),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,s.fetchLevelRows(D.api,d.entityKey,D.range,{sort:p,order:"desc",search:_||void 0,pageSize:I,cursor:null!=n?n:void 0,includeChildren:3},i)];case 2:return a=r.sent(),(null==i?void 0:i.aborted)?[2]:(K(function(i){return n?e.__spreadArray(e.__spreadArray([],i,!0),a.rows,!0):a.rows}),L(a.nextCursor),P(a.hasNext),B({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]:(B({loading:!1,error:t.message||"Couldn't load the rows."}),[3,4]);case 4:return[2]}})})},G=null===(t=S[0])||void 0===t?void 0:t.nodeKey;i.useEffect(function(){return null==x?void 0:x(G)},[G]);var V=S.slice(0,3).map(function(e){return e.nodeKey}),q=V.join("\0");if(i.useEffect(function(){E.loading||null==b||b(V)},[E.loading,q]),i.useEffect(function(){var e=new AbortController;return O(null,e.signal),function(){return e.abort()}},[null==D?void 0:D.api.configId,null==D?void 0:D.rangeKey,d.entityKey,p,_,I,null==D?void 0:D.revision]),!D)return null;var H,U=D.goodDirection(p),W=v.filter(function(e){return e!==p}).slice(0,2),z=(H=u.trim().toLowerCase())?/(s|x|ch|sh)$/.test(H)?"".concat(H,"es"):/[^aeiou]y$/.test(H)?"".concat(H.slice(0,-1),"ies"):"".concat(H,"s"):"rows";return n.jsx(c.ReportAccordion,e.__assign({title:"Top Drivers for ".concat(h(z))},{children:E.error?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Top drivers are unavailable right now."})):E.loading&&!S.length?n.jsx(c.SkeletonLines,{widths:[80,60,85,55,75],label:"Loading drivers"}):S.length?n.jsxs(n.Fragment,{children:[n.jsx(N,e.__assign({label:h(u),rightLabel:"User Activity · selected dates"},{children:S.map(function(i){var a,t,r,o,d=null===(a=i.metrics)||void 0===a?void 0:a[p],u=i.label||i.nodeKey,v=m.includes(i.nodeKey);return n.jsx(w,{rank:i.rank,name:u,chips:n.jsxs(n.Fragment,{children:[n.jsx(c.CriticalityChip,{criticality:null===(t=i.chip)||void 0===t?void 0:t.criticality}),n.jsx(c.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:U})]}),action:n.jsx(k,{on:v,disabled:!v&&m.length>=g,onClick:function(){return y(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)," ",D.kpiLabel(p).toLowerCase()]})),null!=(null==d?void 0:d.deltaPct)?n.jsx("span",e.__assign({className:"ag-driver__sep"},{children:"|"})):null,n.jsx(c.DayOverDayChange,{deltaPct:null==d?void 0:d.deltaPct,good:U,direction:null==d?void 0:d.direction,tone:null==d?void 0:d.tone,suffix:"vs previous period"})]})),cell:W.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:c.toneOf(null==s?void 0:s.deltaPct,D.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:D.kpiLabel(a)})]}),a)}),onOpen:function(){var e;return f(i,p,j||(null===(e=i.chip)||void 0===e?void 0:e.dataDay)||s.toIsoDay(D.range.endDate))}},i.nodeKey)})})),F?n.jsx("div",e.__assign({className:"ag-more"},{children:n.jsx("button",e.__assign({type:"button",disabled:E.loading,onClick:function(){return O(T)}},{children:E.loading?"Loading...":"Show more"}))})):null]}):n.jsx("p",e.__assign({className:"ag-muted"},{children:_?"No ".concat(z," match “").concat(_,"”."):"No ".concat(z," for this period yet.")}))}))}exports.AddToGraph=k,exports.CorrelationSection=C,exports.DecisionCard=f,exports.DriverList=N,exports.DriverRow=w,exports.L2Report=function(t){var r,u,h,p,_,m,x,b,j,k,w,N,D,I=t.tab,T=t.title,L=t.partName,R=t.partKpis,F=t.search,P=t.onOpenRow,M=o.useInsights(),E=i.useState(Boolean(null==M?void 0:M.defaultWorkingDays)),B=E[0],O=E[1],G=l.useInsightsFetch(M?function(e){return s.fetchGraphGroups(M.api,e)}:null,[null==M?void 0:M.api.configId,null==M?void 0:M.revision]),V=i.useState(null),q=V[0],H=V[1];i.useEffect(function(){var e,n;null===q&&((null===(e=G.data)||void 0===e?void 0:e.groups.length)?H((null!==(n=G.data.groups.find(function(e){return e.isDefault}))&&void 0!==n?n:G.data.groups[0]).groupKey):G.loading||H(""))},[q,G.data,G.loading]);var U=i.useState(null),W=U[0],z=U[1],Z=i.useState(),$=Z[0],J=Z[1],X=!1!==I.showSummary,Q=l.useInsightsFetch(M&&X?function(e){return s.fetchLevelSummary(M.api,I.entityKey,M.range,e)}:null,[null==M?void 0:M.api.configId,null==M?void 0:M.rangeKey,I.entityKey,X,null==M?void 0:M.revision]);if(!M)return null;var Y=(null===(r=I.listKpis)||void 0===r?void 0:r.length)?I.listKpis:R,ee=I.rankBy&&Y.includes(I.rankBy)?I.rankBy:null!==(u=Y[0])&&void 0!==u?u:"",ne=null===(h=Q.data)||void 0===h?void 0:h.report,ie=S(null===(p=Q.data)||void 0===p?void 0:p.context),ae=M.goodDirection(ee),te=null!==(_=I.tier1Kpis)&&void 0!==_?_:M.tierKpis[1],re=null!==(m=I.tier2Kpis)&&void 0!==m?m:M.tierKpis[2],se=M.headlineKpi||ee||te[0]||"",oe=function(e){var n=e.nodeKey,i=e.label,a=e.dataDay;return P({rank:0,nodeKey:n,label:i,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:se},action:null,children:[]},se,a)},le=M.drill.tabTables[I.entityKey],de=le?n.jsx(d.default,{table:e.__assign(e.__assign({},le),{pageSize:null!==(b=null!==(x=le.pageSize)&&void 0!==x?x:I.pageSize)&&void 0!==b?b:void 0}),tabEntityKey:I.entityKey,context:{trail:[],day:ie},onRowClick:function(e,n){var i,a,t;return"report"===n?M.openReport({reportId:e.report.reportId,nodeKey:e.nodeKey,kpiId:ee,dataDay:ie||(null===(i=e.chip)||void 0===i?void 0:i.dataDay)||s.toIsoDay(M.range.endDate),title:null!==(a=e.label)&&void 0!==a?a:e.nodeKey}):"drill"===n?P(e,ee,ie||(null===(t=e.chip)||void 0===t?void 0:t.dataDay)||s.toIsoDay(M.range.endDate)):void 0}}):null;return n.jsxs("section",e.__assign({className:"ag-report","aria-label":"L2 Report · ".concat(T)},{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:T})),ie?n.jsx("span",e.__assign({className:"ag-report__date"},{children:c.formatHeaderDate(ie)})):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(T," analysis"),tabIndex:0},{children:n.jsxs("div",e.__assign({className:"ag-stack"},{children:[X?n.jsxs(n.Fragment,{children:[n.jsxs("div",{children:[n.jsx(c.SectionHeader,{title:"Summary",action:n.jsx(v,{entityKey:I.entityKey,dataDay:ie})}),n.jsx(y,{report:ne,loading:Q.loading,error:Q.error,good:ae})]}),n.jsx(f,{report:ne,error:Q.error,loading:Q.loading})]}):null,Y.length?n.jsx(A,{tab:I,partName:L,kpiIds:Y,rankBy:ee,search:F,graphed:null!=W?W:[],onToggleGraph:function(n){return z(function(i){var a=null!=i?i:[];return a.includes(n)?a.filter(function(e){return e!==n}):a.length<g?e.__spreadArray(e.__spreadArray([],a,!0),[n],!1):a})},onOpenRow:P,onFirstRow:J,onInitialGraph:function(e){return z(function(n){return null!=n?n:e})},fallbackDay:ie}):null]}))})),n.jsxs("div",e.__assign({className:"ag-stack"},{children:[te.length?n.jsx(c.CollapsibleVisualSection,e.__assign({title:"Trend",action:n.jsx(c.DaysDropdown,{value:B,onChange:O,groups:G.error||null===(j=G.data)||void 0===j?void 0:j.groups,group:q,onGroupChange:H})},{children:n.jsx(K,{entityKey:I.entityKey,kpis:te,nodeKeys:W,workingDays:B,group:q,onOpenPoint:oe})})):null,re.length?n.jsx(c.CollapsibleVisualSection,e.__assign({title:M.labels.activityTitle,meta:W?"Selected rows":"Top ".concat(3," ").concat(M.entityPluralName(I.entityKey))},{children:n.jsx(K,{entityKey:I.entityKey,kpis:re,nodeKeys:W,workingDays:B,group:q,onOpenPoint:oe})})):null,n.jsx(C,{dataDay:ie,nodeKey:null!==(k=null==W?void 0:W[0])&&void 0!==k?k:$,dayGroup:null===(N=null===(w=G.data)||void 0===w?void 0:w.groups.find(function(e){return e.groupKey===q}))||void 0===N?void 0:N.days}),"column"===(null==le?void 0:le.width)?de:null]}))]})),le&&"full"===(null!==(D=le.width)&&void 0!==D?D:"full")?de:null]}))},exports.MAX_SERIES=g,exports.RegenerateSummary=v,exports.RowDrivers=A,exports.RowTrend=K,exports.SummaryCard=y,exports.TopDriversSection=function(t){var r,d,v,h,p,_,y,f,D,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},n)}:null},z=function(e){return[null==E?void 0:E.api.configId,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!==(p=null!==(v=null===(d=Z.drivers.data)||void 0===d?void 0:d.tabs)&&void 0!==v?v:null===(h=Z.headwinds.data)||void 0===h?void 0:h.tabs)&&void 0!==p?p:null===(_=Z.attention.data)||void 0===_?void 0:_.tabs,ee=u.useNeedsAttention(I,S,U),ne=null!==(f=null===(y=ee.data)||void 0===y?void 0:y.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!==(D=null==J?void 0:J.rows)&&void 0!==D?D:[],te="attention"===O?ae:e.__spreadArray([],ae,!0).sort(function(e,n){var i,a;return Math.abs(null!==(i=n.deltaContributionPct)&&void 0!==i?i:0)-Math.abs(null!==(a=e.deltaContributionPct)&&void 0!==a?a:0)});return n.jsxs(c.ReportAccordion,e.__assign({title:A},{children:[n.jsx("div",e.__assign({className:"ag-driver-tabs",role:"tablist","aria-label":"Driver views"},{children:x.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(u.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(N,e.__assign({label:"Driver",rightLabel:E.labels.activityColumn},{children:te.map(function(i){var a,t,r,s,o,d,u,v,h,p=i.deltaContributionPct,_=T.includes(i.nodeKey),y=(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(w,{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(c.CriticalityChip,{criticality:i.criticality}),n.jsx(c.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:j[i.correlation.strength]})):null]}),action:L?n.jsx(k,{on:_,disabled:!_&&T.length>=g,onClick:function(){return L(i)}}):void 0,lines:n.jsxs(n.Fragment,{children:[null!=p?n.jsxs("span",e.__assign({className:"ag-driver__share"},{children:[E.labels.shareLine.replace("{share}",String(Math.abs(p)))," · ","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(c.DayOverDayChange,{deltaPct:i.deltaPct,good:ie,direction:i.changeDirection,tone:i.tone,suffix:l.previousDayLabel(I)})]})),y?n.jsx("p",e.__assign({className:"ag-driver__brief"},{children:n.jsx(c.VerdictSentence,{text:m(y),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:"})," ",m(i.decisionAdvantage.nextStep)]})):null]}),cell:n.jsxs("span",e.__assign({className:"ag-driver__activity"},{children:[n.jsx("strong",{children:l.formatValue(null!==(u=null===(d=i.drivingMetric)||void 0===d?void 0:d.value)&&void 0!==u?u:i.previous)}),n.jsx("span",{children:(null===(v=i.drivingMetric)||void 0===v?void 0:v.label)||((null===(h=i.drivingMetric)||void 0===h?void 0:h.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:b[O]}))]}))},exports.decisionCardNotice=_,exports.reportDayOf=S,exports.stripRowTags=m,exports.titleCase=h;
|
|
2
2
|
//# sourceMappingURL=AgReport.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"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),i=require("lucide-react"),t=require("../RcaDecisionComponent/RcaDecisionComponent.js"),s=require("../../api/insightsApi.js"),a=require("./insightsContextCore.js"),r=require("./insightsUtils.js");function l(e,n){var i,t=[];return e&&!e.matchesRange&&(null===(i=e.period)||void 0===i?void 0:i.end)&&t.push("Latest report: ".concat(r.formatReportDate(e.period),".")),"preliminary"===(null==e?void 0:e.runType)&&t.push("Preliminary: late data can still change it."),n&&t.push("Insights cover all data; sidebar filters don't apply here."),t.length?t.join(" "):null}function o(t){var s=t.title,a=t.icon,r=t.heading,l=t.text,o=t.action;return n.jsxs("article",e.__assign({className:"ins-state"},{children:[n.jsx("header",e.__assign({className:"ins-state__header"},{children:n.jsx("span",{children:s})})),n.jsxs("div",e.__assign({className:"ins-state__body"},{children:[n.jsx("span",e.__assign({className:"ins-state__icon"},{children:null!=a?a:n.jsx(i.Sparkles,{"aria-hidden":"true"})})),n.jsxs("div",{children:[n.jsx("p",e.__assign({className:"ins-state__heading"},{children:r})),l?n.jsx("p",e.__assign({className:"ins-state__text"},{children:l})):null,o]})]}))]}))}function d(t){var s=t.summary,a=t.onOpen,r="good"===s.tone?"#15803D":"bad"===s.tone?"#E11D48":void 0;return n.jsxs("div",e.__assign({className:"ins-summary","aria-label":"Significant change summary"},{children:[n.jsx("div",e.__assign({className:"ins-summary__title",style:{color:r}},{children:s.eyebrow||"Significant change"})),n.jsx("div",e.__assign({className:"ins-summary__text"},{children:s.headline?n.jsx("span",e.__assign({className:"ins-summary__lead",style:{color:r}},{children:s.headline})):"No summary yet"})),a?n.jsx("button",e.__assign({type:"button",className:"ins-summary__open",onClick:a,"aria-label":"Open the full report and comments"},{children:n.jsx(i.MessageSquare,{"aria-hidden":"true"})})):null]}))}function u(s){var o,u,c,h,m,p,g=s.title,v=void 0===g?"Decision Advantage":g,x=s.report,_=s.context,j=s.loading,y=s.error,f=s.onRetry,N=s.children,b=a.useInsights(),w=r.useOpenRow(),C="generated"===(null==x?void 0:x.status),I=(null==x?void 0:x.reportId)&&b?function(){return b.openReport({reportId:x.reportId,title:v})}:void 0,R=null;return R=y?n.jsxs(n.Fragment,{children:["Couldn't load Decision Advantage: ",y.message," ",f?n.jsxs("button",e.__assign({type:"button",className:"ins-link ins-link--inline",onClick:f},{children:[n.jsx(i.RefreshCw,{"aria-hidden":"true"})," Try again"]})):null]}):j&&!x?"Loading…":null!==(o=function(e,n){var i;return 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?(null===(i=null==n?void 0:n.period)||void 0===i?void 0:i.start)?"No report was written for ".concat(r.formatPeriod(n.period),". Reports are written after each morning run."):"No report yet. Reports are written after each morning run.":null:null}(x,_))&&void 0!==o?o:l(_,null==b?void 0:b.filtersActive),n.jsxs("div",e.__assign({className:"ins-dcol"},{children:[(null===(u=null==x?void 0:x.summary)||void 0===u?void 0:u.headline)?n.jsxs(n.Fragment,{children:[n.jsx("div",e.__assign({className:"ins-dcol__heading"},{children:"Summary"})),n.jsx(d,{summary:x.summary,onOpen:I})]}):null,n.jsx(t.RcaDecisionComponent,{className:"ins-dcol__card",title:v,score:C?null==x?void 0:x.score:null,notice:R,headerActions:C&&I?n.jsxs("button",e.__assign({type:"button",className:"ins-chip-button",onClick:I,"aria-label":"Open the full report and comments"},{children:[n.jsx(i.MessageSquare,{"aria-hidden":"true"}),(null==x?void 0:x.commentCount)||""]})):null,rootCause:C?r.toRcaItems(null==x?void 0:x.rootCause,w):[],nextSteps:C?r.toRcaItems(null==x?void 0:x.nextSteps,w):[],afterSections:N,width:"100%",maxWidth:"none"},"".concat(null!==(c=null==x?void 0:x.reportId)&&void 0!==c?c:v,":").concat(null!==(p=null!==(h=null==x?void 0:x.generatedAt)&&void 0!==h?h:null===(m=null==_?void 0:_.period)||void 0===m?void 0:m.end)&&void 0!==p?p:""))]}))}function c(i){var t=i.children,s=i.minHeight,a=void 0===s?520:s;return n.jsx("div",e.__assign({className:"ins-fill",style:{minHeight:a}},{children:n.jsx("div",e.__assign({className:"ins-fill__inner"},{children:t}))}))}exports.DecisionColumn=u,exports.FillHeight=c,exports.InsightsSkeleton=function(i){var t=i.title;return n.jsxs("article",e.__assign({className:"ins-state","aria-busy":"true","aria-label":"Loading ".concat(t)},{children:[n.jsx("header",e.__assign({className:"ins-state__header"},{children:n.jsx("span",{children:t})})),n.jsxs("div",e.__assign({className:"ins-skeleton"},{children:[n.jsx("span",{style:{width:"40%"}}),n.jsx("span",{style:{width:"85%"}}),n.jsx("span",{style:{width:"70%"}}),n.jsx("span",{style:{width:"78%"}})]}))]}))},exports.InsightsStateCard=o,exports.ReportView=function(s){var d,u,c,h,m,p=s.report,g=s.title,v=s.context,x=s.onComments,_=s.onRetry,j=a.useInsights(),y=r.useOpenRow(),f=p.title||g;return"waiting"===p.status?n.jsx(o,{title:f,icon:n.jsx(i.Clock3,{"aria-hidden":"true"}),heading:"The first run hasn't finished yet",text:"The AI checks yesterday's numbers every morning. This card fills in after its first run."}):"running"===p.status?n.jsx(o,{title:f,icon:n.jsx(i.Clock3,{"aria-hidden":"true"}),heading:"Being written",text:"The AI is writing this report. It usually takes a minute or two.",action:_?n.jsxs("button",e.__assign({type:"button",className:"ins-link",onClick:_},{children:[n.jsx(i.RefreshCw,{"aria-hidden":"true"})," Check again"]})):null}):"generated"!==p.status?n.jsx(o,{title:f,heading:"No report for this period",text:(null===(d=null==v?void 0:v.period)||void 0===d?void 0:d.start)?"Nothing was written for ".concat(r.formatPeriod(v.period),". Reports are written after each morning run."):"Reports are written after each morning run."}):n.jsx(t.RcaDecisionComponent,{title:f,score:p.score,summary:p.summary,notice:l(v,null==j?void 0:j.filtersActive),headerActions:x&&p.reportId?n.jsxs("button",e.__assign({type:"button",className:"ins-chip-button",onClick:x,"aria-label":"Open report and comments"},{children:[n.jsx(i.MessageSquare,{"aria-hidden":"true"}),p.commentCount||""]})):null,rootCause:r.toRcaItems(p.rootCause,y),nextSteps:r.toRcaItems(p.nextSteps,y),width:"100%",maxWidth:"none"},"".concat(null!==(u=p.reportId)&&void 0!==u?u:f,":").concat(null!==(m=null!==(c=p.generatedAt)&&void 0!==c?c:null===(h=null==v?void 0:v.period)||void 0===h?void 0:h.end)&&void 0!==m?m:""))},exports.SummaryBox=d,exports.default=function(e){var i,t,l,o,d=e.entityKey,h=e.title,m=void 0===h?"Decision Advantage":h,p=a.useInsights(),g=r.useInsightsFetch(p?function(e){return d?s.fetchLevelSummary(p.api,d,p.range,e):s.fetchInsightsSummary(p.api,p.range,e)}:null,[null==p?void 0:p.api.configId,null==p?void 0:p.api.baseUrl,null==p?void 0:p.api.accessToken,null==p?void 0:p.rangeKey,d,null==p?void 0:p.revision],"".concat(null!==(i=null==p?void 0:p.api.configId)&&void 0!==i?i:"",":").concat(null!==(t=null==p?void 0:p.api.baseUrl)&&void 0!==t?t:"",":").concat(null!==(l=null==p?void 0:p.api.accessToken)&&void 0!==l?l:"",":").concat(null!==(o=null==p?void 0:p.rangeKey)&&void 0!==o?o:"",":").concat(null!=d?d:"root")),v=g.data,x=g.error,_=g.loading,j=g.reload;return p?x&&"InsightsDisabled"===x.errorType?null:n.jsx(c,{children:n.jsx(u,{title:m,report:null==v?void 0:v.report,context:null==v?void 0:v.context,loading:_,error:x,onRetry:j})}):null},exports.reportNotice=l;
|
|
2
2
|
//# sourceMappingURL=DecisionAdvantageCard.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),i=require("../../api/insightsApi.js"),t=require("./agPrimitives.js"),a=require("./DrillTable.js"),l=require("./L1Report.js"),r=require("./RowDetail.js"),s=require("./insightsContextCore.js"),o=require("./insightsUtils.js"),d=function(e,n){var i,t;return{nodeKey:n.nodeKey,label:n.label||n.nodeKey,entityKey:n.entityKey||"",partName:(null==e?void 0:e.entityName(n.entityKey||""))||n.entityKey||"",reportId:null!==(t=null===(i=n.report)||void 0===i?void 0:i.reportId)&&void 0!==t?t:null,metrics:n.metrics}},u=function(e,n,i){var t,a,l,r,s;return{nodeKey:n.nodeKey,label:n.label,entityKey:null!==(a=n.entityKey)&&void 0!==a?a:"",partName:(null==e?void 0:e.entityName(null!==(l=n.entityKey)&&void 0!==l?l:""))||n.entityKey||"",reportId:null!==(s=null===(r=n.report)||void 0===r?void 0:r.reportId)&&void 0!==s?s:null,metrics:(t={},t[i]={value:n.value,previous:n.previous,deltaPct:n.deltaPct,direction:n.changeDirection,tone:n.tone},t)}};function c(a){var l,r,d,u,c=a.row,p=a.dataDay,y=a.kpiId,v=s.useInsights(),m=o.useInsightsFetch(v&&!c.metrics?function(e){return i.fetchRowDetail(v.api,c.nodeKey,{kpiId:y,dataDay:p},e)}:null,[null==v?void 0:v.api.configId,c.nodeKey,y,p,Boolean(c.metrics),null==v?void 0:v.revision],"".concat(null!==(l=null==v?void 0:v.api.configId)&&void 0!==l?l:"",":").concat(c.nodeKey,":").concat(y,":").concat(p));if(!v)return null;var g=null!==(u=null!==(r=c.metrics)&&void 0!==r?r:null===(d=m.data)||void 0===d?void 0:d.metrics)&&void 0!==u?u:{},_=Object.entries(g).filter(function(e){var n=e[1];return n&&null!=n.value});return n.jsxs("section",{children:[n.jsx(t.SectionHeader,{title:"Headline numbers"}),m.loading&&!_.length?n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading numbers…"})):null,m.loading||_.length?null:n.jsx("div",e.__assign({className:"ag-empty"},{children:"No numbers for this selection."})),_.length?n.jsx("dl",e.__assign({className:"ag-row-detail__metrics"},{children:_.map(function(e){var i=e[0],a=e[1];return n.jsxs("div",{children:[n.jsx("dt",{children:v.kpiLabel(i)}),n.jsxs("dd",{children:[o.formatValue(a.value)," ",n.jsx(t.DayOverDayChange,{deltaPct:a.deltaPct,direction:a.direction,tone:a.tone,good:v.goodDirection(i)})]})]},i)})})):null]})}exports.DEFAULT_LEVEL={id:"default",match:{entityKey:""},panels:["summary","decision","topDrivers","trend","activity","correlation"],tables:[]},exports.default=function(i){var t,o,p=i.trail,y=i.level,v=i.kpiId,m=i.dataDay,g=i.reportDay,_=i.onReportDay,h=i.tier2Kpis,j=i.onOpen,f=s.useInsights();if(!f||!p.length)return null;var x=p[p.length-1],b=g||m,K=new Set(null!==(t=y.panels)&&void 0!==t?t:[]),D=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.some(function(e){return K.has(e)})},I=p.map(function(e){return e.entityKey}),N=function(e,n){"drill"===n&&f.matchDrillLevel(e.entityKey,I)?j(e):f.openReport({reportId:e.reportId,nodeKey:e.nodeKey,kpiId:v,dataDay:b,title:e.label})},w=null!==(o=y.tables)&&void 0!==o?o:[],k=w.filter(function(e){return"column"===e.width}),q=w.filter(function(e){return"column"!==e.width}),R={trail:p,day:b},L=function(e,i,t){var l;return n.jsx(a.default,{table:e,context:R,className:t,onRowClick:function(e,n){return"none"===n?void 0:N(d(f,e),n)}},"".concat(x.nodeKey,":").concat(null!==(l=e.id)&&void 0!==l?l:i))},P=D("summary","decision","topDrivers"),O=D("trend","activity","correlation"),T=O||D("numbers")||k.length>0,C=P&&T;return n.jsxs("div",e.__assign({className:"ag-popup"},{children:[P?n.jsxs("section",e.__assign({className:"ag-popup__section".concat(C?" ag-popup__section--capped":"")},{children:[n.jsxs("div",e.__assign({className:"ag-popup__head"},{children:[n.jsx("p",e.__assign({className:"ag-popup__eyebrow"},{children:"Analysis"})),n.jsx("h3",e.__assign({className:"ag-popup__title"},{children:f.labels.analysisTitle}))]})),n.jsx("div",e.__assign({className:"ag-popup__scroll",role:"region","aria-label":"".concat(x.label," analysis"),tabIndex:C?0:void 0},{children:n.jsx(r.default,{embedded:!0,nodeKey:x.nodeKey,kpiId:v,dataDay:m,reportId:x.reportId,onReportDay:_,show:{summary:D("summary"),decision:D("decision"),topDrivers:D("topDrivers")},onOpenDriver:function(e){return N(u(f,e,v),"drill")}},x.nodeKey)}))]})):null,T?n.jsxs("section",e.__assign({className:"ag-popup__section"},{children:[O||D("numbers")?n.jsxs("div",e.__assign({className:"ag-popup__head"},{children:[n.jsx("p",e.__assign({className:"ag-popup__eyebrow"},{children:"Visuals"})),n.jsx("h3",e.__assign({className:"ag-popup__title"},{children:f.labels.visualsTitle}))]})):null,n.jsxs("div",e.__assign({className:"ag-stack"},{children:[D("numbers")?n.jsx(c,{row:x,dataDay:b,kpiId:v}):null,O?g||!P?n.jsx(l.EntityDetailVisuals,{nodeKey:x.nodeKey,label:x.label,kpiId:v,dataDay:b,tier2Kpis:h,show:{trend:D("trend"),activity:D("activity"),correlation:D("correlation")}},x.nodeKey):n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading report…"})):null,k.map(function(e,n){return L(e,n,P?void 0:"ag-drill--wide")})]}))]})):null,q.map(function(e,n){return L(e,k.length+n,"ag-drill--full")})]}))},exports.popupRowFromDriver=u,exports.popupRowFromTable=d;
|
|
2
|
+
//# sourceMappingURL=DrillLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DrillLevel.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),t=require("lucide-react"),i=require("react"),l=require("../../api/insightsApi.js"),r=require("./insightsContextCore.js"),a=function(e,n){return e instanceof Date?e:e?new Date("".concat(e.slice(0,10),"T00:00:00")):n},o=function(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})},s=function(e,n){var t,i,l,r;return{rank:e.rank,nodeKey:e.nodeKey,entityKey:e.entityKey,label:e.label,value:e.value,parent:null,metrics:n?(t={},t[n]={value:e.value,previous:e.previous,deltaPct:e.deltaPct,isRangeExact:!0,direction:e.changeDirection,tone:e.tone},t):{},barPct:null,chip:{criticality:e.criticality,movementType:e.movementType,direction:e.changeDirection,label:null},report:{reportId:null!==(l=null===(i=e.report)||void 0===i?void 0:i.reportId)&&void 0!==l?l:null,status:(null===(r=e.report)||void 0===r?void 0:r.reportId)?"generated":"none"},action:null,children:[]}};function c(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()}return"number"==typeof e?"percent"===n?"".concat(new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(e),"%"):new Intl.NumberFormat(void 0,{maximumFractionDigits:"rating"===n?2:1}).format(e):String(e).replace(/_/g," ")}exports.default=function(u){var d,v,h,_,g,f,p,y,m,b,x=this,w=u.entityKey,j=u.parentNodeKey,k=u.parts,N=u.columns,D=u.dataDay,K=u.startDate,S=u.endDate,C=u.pageSize,I=void 0===C?20:C,T=u.defaultSort,M=u.onOpenRow,L=r.useInsights(),E=null!==(d=null==k?void 0:k.filter(Boolean))&&void 0!==d?d:[],O=i.useState(null!==(v=E[0])&&void 0!==v?v:w),A=O[0],P=O[1],q=i.useState(""),B=q[0],R=q[1],F=i.useState(""),z=F[0],U=F[1],G=i.useState(T),H=G[0],J=G[1],Q=i.useState([]),V=Q[0],W=Q[1],X=i.useState(null),Y=X[0],Z=X[1],$=i.useState(0),ee=$[0],ne=$[1],te=i.useState(!1),ie=te[0],le=te[1],re=i.useState(0),ae=re[0],oe=re[1],se=i.useState(!1),ce=se[0],ue=se[1],de=i.useState(null),ve=de[0],he=de[1];i.useEffect(function(){var e;return P(null!==(e=E[0])&&void 0!==e?e:w)},[w,E.join("|")]),i.useEffect(function(){var e=setTimeout(function(){return U(B.trim())},300);return function(){return clearTimeout(e)}},[B]);var _e=null===(g=null===(_=null===(h=null==L?void 0:L.decisionAdvantage)||void 0===h?void 0:h.tabs)||void 0===_?void 0:_.items)||void 0===g?void 0:g.find(function(e){return e.entityKey===A}),ge=i.useMemo(function(){var e,n,t,i,l,r=null!==(n=null!=N?N:null===(e=null==L?void 0:L.insightsColumns)||void 0===e?void 0:e[A])&&void 0!==n?n:null===(t=null==_e?void 0:_e.drillTable)||void 0===t?void 0:t.columns;return(null==r?void 0:r.length)?r:((null===(i=null==_e?void 0:_e.listKpis)||void 0===i?void 0:i.length)?_e.listKpis:null!==(l=null==L?void 0:L.entityKpis(A))&&void 0!==l?l:[]).map(function(e){return{key:e,source:"kpi",show:"both",sortable:!0}})},[N,L,A,_e]),fe=null!=H?H:null===(f=null==_e?void 0:_e.drillTable)||void 0===f?void 0:f.defaultSort,pe=Boolean(j&&E.length&&A!==w&&!(null==L?void 0:L.isChildOf(A,w))),ye=null===(p=null==L?void 0:L.drillTable.clickableEntityKeys.includes(A))||void 0===p||p,me=null!==(b=null!==(m=null===(y=ge.find(function(e){return"kpi"===e.source}))||void 0===y?void 0:y.key)&&void 0!==m?m:null==L?void 0:L.headlineKpi)&&void 0!==b?b:"",be=ge.some(function(e){return"row"===e.source&&"children"===e.key})?20:void 0,xe=L?a(K,L.range.startDate):new Date,we=L?a(S,L.range.endDate):new Date,je="".concat(l.toIsoDay(xe),":").concat(l.toIsoDay(we));if(i.useEffect(function(){if(L){var n=new AbortController;ue(!0),he(null),W([]),Z(null),ne(0);var t=pe?l.fetchInsightsDrivers(L.api,{dataDay:null!=D?D:l.toIsoDay(we),kpiId:me,entityKey:A,parentNodeKey:j,tab:"drivers",limit:Math.min(10,I),offset:0},n.signal).then(function(e){var n,t,i,l;return{rows:e.rows.map(function(e){return s(e,me)}).filter(function(e){var n;return!z||(null!==(n=e.label)&&void 0!==n?n:"").toLowerCase().includes(z.toLowerCase())}),count:null!==(i=null===(t=null===(n=e.tabs)||void 0===n?void 0:n.drivers)||void 0===t?void 0:t.total)&&void 0!==i?i:e.rows.length,hasMore:e.hasMore,cursor:null,nextOffset:null!==(l=e.nextOffset)&&void 0!==l?l:e.rows.length}}):l.fetchLevelRows(L.api,A,e.__assign(e.__assign({},L.range),{startDate:xe,endDate:we}),{sort:null==fe?void 0:fe.key,order:null==fe?void 0:fe.order,search:z||void 0,parentNodeKey:j,pageSize:I,includeChildren:be},n.signal).then(function(e){return{rows:e.rows,count:e.count,hasMore:e.hasNext,cursor:e.nextCursor,nextOffset:0}});return t.then(function(e){var n;W(e.rows),oe(e.count),le(e.hasMore),Z(null!==(n=e.cursor)&&void 0!==n?n:null),ne(e.nextOffset)}).catch(function(e){"AbortError"!==(null==e?void 0:e.name)&&he(e instanceof Error?e.message:"The rows couldn't be loaded.")}).finally(function(){n.signal.aborted||ue(!1)}),function(){return n.abort()}}},[null==L?void 0:L.api,null==L?void 0:L.revision,A,j,pe,D,me,be,je,z,null==fe?void 0:fe.key,null==fe?void 0:fe.order,I]),!L)return null;var ke=function(t,i){var l,r=null===(l=L.renderInsightsCell)||void 0===l?void 0:l.call(L,{column:i,row:t,entityKey:A});if(void 0!==r)return r;if("custom"===i.source)return"—";if("kpi"===i.source){var a=t.metrics[i.key],o=c(null==a?void 0:a.value,i.format),s=null==(null==a?void 0:a.deltaPct)?"—":"".concat(a.deltaPct>0?"↑":a.deltaPct<0?"↓":""," ").concat(Math.abs(a.deltaPct),"%");return"delta"===i.show?n.jsx("span",e.__assign({className:(null==a?void 0:a.tone)?"ag-drill__change--".concat(a.tone):void 0},{children:s})):"both"!==i.show&&i.show?o:n.jsxs("span",e.__assign({className:"ag-drill__metric"},{children:[n.jsx("strong",{children:o}),n.jsx("small",e.__assign({className:(null==a?void 0:a.tone)?"ag-drill__change--".concat(a.tone):void 0},{children:s}))]}))}var u=c(function(e,n){var t,i;return"criticality"===n?null===(t=e.chip)||void 0===t?void 0:t.criticality:"movementType"===n||"change"===n?null===(i=e.chip)||void 0===i?void 0:i.movementType:"children"===n?e.children.reduce(function(e,n){return n.label&&!e.includes(n.label)&&e.push(n.label),e},[]).join(", "):e[n]}(t,i.key),i.format);return"children"===i.key?n.jsx("span",e.__assign({className:"ag-drill__contributors",title:"—"===u?void 0:u},{children:u})):"chip"===i.format?n.jsx("span",e.__assign({className:"ag-drill__chip"},{children:u})):u};return n.jsxs("section",e.__assign({className:"ag-drill","aria-labelledby":"ag-drill-title"},{children:[n.jsxs("header",e.__assign({className:"ag-drill__header"},{children:[n.jsxs("div",{children:[n.jsx("h3",e.__assign({id:"ag-drill-title"},{children:E.length?"Drill down in ".concat(L.entityName(w)):L.entityName(A)})),pe?n.jsx("span",{children:"Rows that moved"}):null]}),n.jsxs("label",e.__assign({className:"ag-drill__search"},{children:[n.jsx(t.Search,{"aria-hidden":"true"}),n.jsx("input",{type:"search",value:B,onChange:function(e){return R(e.target.value)},placeholder:"Search ".concat(L.entityName(A).toLowerCase(),"…"),"aria-label":"Search ".concat(L.entityName(A))})]}))]})),E.length?n.jsx("div",e.__assign({className:"ag-drill__tabs",role:"tablist","aria-label":"Drill-down parts"},{children:E.map(function(t){return n.jsx("button",e.__assign({type:"button",role:"tab","aria-selected":A===t,className:A===t?"is-active":void 0,onClick:function(){P(t),R(""),U(""),J(void 0)}},{children:L.entityName(t)}),t)})})):null,n.jsxs("div",e.__assign({className:"ag-drill__table-wrap","aria-live":"polite"},{children:[n.jsxs("table",e.__assign({className:"ag-drill__table"},{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:L.entityName(A)}),ge.map(function(t){var i,l,r,a,s=!pe&&(null!==(i=t.sortable)&&void 0!==i?i:"kpi"===t.source||["criticality","change"].includes(t.key));return n.jsx("th",e.__assign({className:"ag-drill__col--".concat(null!==(l=t.align)&&void 0!==l?l:"kpi"===t.source?"right":"left"," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):""),style:{width:t.width}},{children:s?n.jsxs("button",e.__assign({type:"button",onClick:function(){return function(e){var n;(null!==(n=e.sortable)&&void 0!==n?n:"kpi"===e.source||["criticality","change"].includes(e.key))&&!pe&&J(function(n){return{key:e.key,order:(null==n?void 0:n.key)===e.key&&"desc"===n.order?"asc":"desc"}})}(t)}},{children:[null!==(r=t.label)&&void 0!==r?r:"kpi"===t.source?L.kpiLabel(t.key):o(t.key),(null==fe?void 0:fe.key)===t.key?n.jsxs("span",e.__assign({"aria-hidden":"true"},{children:[" ","asc"===fe.order?"↑":"↓"]})):null]})):null!==(a=t.label)&&void 0!==a?a:"kpi"===t.source?L.kpiLabel(t.key):o(t.key)}),"".concat(t.source,":").concat(t.key))}),ye?n.jsx("th",{children:n.jsx("span",e.__assign({className:"ins-visually-hidden"},{children:"Open"}))}):null]})}),n.jsx("tbody",{children:V.map(function(i){return n.jsxs("tr",e.__assign({className:ye?void 0:"is-static",tabIndex:ye?0:void 0,onClick:ye?function(n){var t;n.target.closest("a,button,input,select,textarea")||M(e.__assign(e.__assign({},i),{entityKey:null!==(t=i.entityKey)&&void 0!==t?t:A}))}:void 0,onKeyDown:ye?function(n){return function(n,t){var i;ye&&("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),M(e.__assign(e.__assign({},t),{entityKey:null!==(i=t.entityKey)&&void 0!==i?i:A}))))}(n,i)}:void 0},{children:[n.jsx("th",e.__assign({scope:"row"},{children:i.label||i.nodeKey})),ge.map(function(t){var l;return n.jsx("td",e.__assign({className:"ag-drill__col--".concat(null!==(l=t.align)&&void 0!==l?l:"kpi"===t.source?"right":"left"," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):"")},{children:ke(i,t)}),"".concat(t.source,":").concat(t.key))}),ye?n.jsx("td",{children:n.jsx(t.ChevronRight,{className:"ag-drill__open","aria-hidden":"true"})}):null]}),i.nodeKey)})})]})),ce&&!V.length?n.jsx("p",e.__assign({className:"ag-drill__state"},{children:"Loading rows…"})):null,ce||V.length||ve?null:n.jsx("p",e.__assign({className:"ag-drill__state"},{children:"No rows found."})),ve?n.jsx("p",e.__assign({className:"ag-drill__state ag-drill__state--error"},{children:ve})):null]})),n.jsxs("footer",e.__assign({className:"ag-drill__footer"},{children:[n.jsx("span",{children:ae?"".concat(V.length," of ").concat(ae):""}),ie?n.jsx("button",e.__assign({type:"button",onClick:function(){return e.__awaiter(x,void 0,void 0,function(){var n,t,i,r;return e.__generator(this,function(a){switch(a.label){case 0:if(ce||!ie)return[2];ue(!0),he(null),a.label=1;case 1:return a.trys.push([1,6,7,8]),pe?[4,l.fetchInsightsDrivers(L.api,{dataDay:null!=D?D:l.toIsoDay(we),kpiId:me,entityKey:A,parentNodeKey:j,tab:"drivers",limit:Math.min(10,I),offset:ee})]:[3,3];case 2:return n=a.sent(),W(function(t){return e.__spreadArray(e.__spreadArray([],t,!0),n.rows.map(function(e){return s(e,me)}),!0)}),le(n.hasMore),ne(null!==(r=n.nextOffset)&&void 0!==r?r:ee+n.rows.length),[3,5];case 3:return[4,l.fetchLevelRows(L.api,A,e.__assign(e.__assign({},L.range),{startDate:xe,endDate:we}),{sort:null==fe?void 0:fe.key,order:null==fe?void 0:fe.order,search:z||void 0,parentNodeKey:j,pageSize:I,includeChildren:be,cursor:null!=Y?Y:void 0})];case 4:t=a.sent(),W(function(n){return e.__spreadArray(e.__spreadArray([],n,!0),t.rows,!0)}),le(t.hasNext),Z(t.nextCursor),a.label=5;case 5:return[3,8];case 6:return i=a.sent(),he(i instanceof Error?i.message:"More rows couldn't be loaded."),[3,8];case 7:return ue(!1),[7];case 8:return[2]}})})},disabled:ce},{children:ce?"Loading…":"Show more"})):null]}))]}))};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),t=require("lucide-react"),l=require("react"),r=require("../../api/insightsApi.js"),i=require("./agPrimitives.js"),o=require("./insightsContextCore.js"),a=/\{([^{}]+)\}/g,s=function(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,function(e){return e.toUpperCase()})},u=function(e,n){return n.split(".").reduce(function(e,n){return e&&"object"==typeof e?e[n]:void 0},e)};function c(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 d(e,n,t){var l,i,o,a,s,u=n.trail;return{record:t.record,context:{row:null!==(i=null===(l=u[u.length-1])||void 0===l?void 0:l.label)&&void 0!==i?i:"",parent:null!==(a=null===(o=u[u.length-2])||void 0===o?void 0:o.label)&&void 0!==a?a:"",day:null!==(s=n.day)&&void 0!==s?s:"",startDate:r.toIsoDay(e.range.startDate),endDate:r.toIsoDay(e.range.endDate),trail:Object.fromEntries(u.map(function(e){return[e.entityKey,e.label]}))}}}var v=function(e,n,t,l){return e.replace(a,function(e,r){var i=function(e,n,t){var l=t.trim();return l.startsWith("context.")?u(e.context,l.slice(8)):l.startsWith("input.")?n[l.slice(6)]:u(e.record,l)}(n,t,r),o=null==i?"":"object"==typeof i?JSON.stringify(i):String(i);return l?encodeURIComponent(o):o})},y=function(e,n,t){return"string"==typeof e?v(e,n,t,!1):Array.isArray(e)?e.map(function(e){return y(e,n,t)}):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).map(function(e){var l=e[0],r=e[1];return[l,y(r,n,t)]})):e},f=new Set,h=["good","warning","bad","info","neutral"],g=function(e){return String(null!=e?e:"").trim().toLowerCase().replace(/[\s_-]+/g," ")};function p(t){var l,r=t.text,i=t.value,o=t.colors,a=o?null===(l=Object.entries(o).find(function(e){var n=e[0];return g(n)===g(i)}))||void 0===l?void 0:l[1]:void 0;if(a&&"object"==typeof a)return n.jsx("span",e.__assign({className:"ag-drill__chip",style:e.__assign({background:a.background,color:a.color},a.border?{boxShadow:"inset 0 0 0 1px ".concat(a.border)}:{})},{children:r}));var s="string"==typeof a&&h.includes(a)?a:"neutral";return n.jsx("span",e.__assign({className:"ag-drill__chip ag-drill__chip--".concat(s)},{children:r}))}function _(r){var i,o=r.button,a=r.question,s=r.onCancel,u=r.onSubmit,c=l.useState({}),d=c[0],v=c[1],y=l.useRef(null);l.useEffect(function(){var e;return null===(e=y.current)||void 0===e?void 0:e.focus()},[]);var f=null!==(i=o.ask)&&void 0!==i?i:[],h=f.some(function(e){var n;return!(null===(n=d[e.key])||void 0===n?void 0:n.trim())});return n.jsx("div",e.__assign({className:"ag-drill__dialog",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&s()}},{children:n.jsxs("form",e.__assign({className:"ag-drill__dialog-box",role:"dialog","aria-modal":"true","aria-label":o.label,onSubmit:function(e){e.preventDefault(),h||u(d)},onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),s())}},{children:[n.jsxs("header",{children:[n.jsx("strong",{children:o.label}),n.jsx("button",e.__assign({type:"button","aria-label":"Cancel",onClick:s},{children:n.jsx(t.X,{"aria-hidden":"true"})}))]}),a?n.jsx("p",{children:a}):null,f.map(function(t,l){var r;return n.jsxs("label",{children:[n.jsx("span",{children:t.label}),n.jsx("input",{ref:0===l?function(e){y.current=e}:void 0,value:null!==(r=d[t.key])&&void 0!==r?r:"",onChange:function(n){return v(function(l){var r;return e.__assign(e.__assign({},l),((r={})[t.key]=n.target.value,r))})},required:!0})]},t.key)}),n.jsxs("footer",{children:[n.jsx("button",e.__assign({type:"button",onClick:s},{children:"Cancel"})),n.jsx("button",e.__assign({ref:f.length?void 0:function(e){y.current=e},type:"submit",disabled:h},{children:o.label}))]})]}))}))}exports.default=function(a){var h,g,b,m,x,w,j,k,K,N,S,C,D,T,E,A,I,B=this,O=a.table,P=a.tabEntityKey,M=a.context,R=a.onRowClick,q=a.className,L=o.useInsights(),z=M.trail.length>0,F=l.useMemo(function(){return function(n,t,l){var r,i,o,a,s,u={filterBy:l?"trail":"none",period:l?"day":"range"};return(null===(r=n.views)||void 0===r?void 0:r.length)?n.views.map(function(t){var l,r,i,o,a,s;return e.__assign(e.__assign({},t),{source:null!==(l=t.source)&&void 0!==l?l:"insights",filterBy:null!==(r=t.filterBy)&&void 0!==r?r:"row"===t.scope?"row":u.filterBy,period:null!==(i=t.period)&&void 0!==i?i:u.period,onRowClick:null!==(o=t.onRowClick)&&void 0!==o?o:n.onRowClick,buttons:null!==(s=null!==(a=t.buttons)&&void 0!==a?a:n.buttons)&&void 0!==s?s:[]})}):[{source:null!==(i=n.source)&&void 0!==i?i:"insights",entityKey:t,tableKey:n.tableKey,columns:n.columns,onRowClick:n.onRowClick,filterBy:l?null!==(o=n.filterBy)&&void 0!==o?o:u.filterBy:"none",period:l?null!==(a=n.period)&&void 0!==a?a:u.period:"range",buttons:null!==(s=n.buttons)&&void 0!==s?s:[]}]}(O,P,z)},[O,P,z]),H=F.map(function(e){var n;return"".concat(e.source,":").concat(null!==(n=e.entityKey)&&void 0!==n?n:e.tableKey)}).join("|"),J=l.useState(0),U=J[0],W=J[1],X=l.useState(""),G=X[0],Q=X[1],V=l.useState(""),Y=V[0],Z=V[1],$=l.useState(O.defaultSort),ee=$[0],ne=$[1],te=l.useState([]),le=te[0],re=te[1],ie=l.useState(null),oe=ie[0],ae=ie[1],se=l.useState(0),ue=se[0],ce=se[1],de=l.useState(!1),ve=de[0],ye=de[1],fe=l.useState(0),he=fe[0],ge=fe[1],pe=l.useState(!1),_e=pe[0],be=pe[1],me=l.useState(null),xe=me[0],we=me[1],je=l.useState(null),ke=je[0],Ke=je[1],Ne=l.useState(null),Se=Ne[0],Ce=Ne[1],De=l.useState(null),Te=De[0],Ee=De[1];l.useEffect(function(){return W(0)},[H]),l.useEffect(function(){var e=setTimeout(function(){return Z(G.trim())},300);return function(){return clearTimeout(e)}},[G]);var Ae=F[Math.min(U,F.length-1)],Ie=M.trail,Be=Ie[Ie.length-1],Oe=null!==(h=O.pageSize)&&void 0!==h?h:10,Pe=Ae&&"table"!==Ae.source?Be&&Ae.entityKey&&!(null==L?void 0:L.isChildOf(Ae.entityKey,Be.entityKey))?"movers":"rows":"table",Me="rows"===Pe&&Be?Be.nodeKey:void 0,Re=l.useMemo(function(){var n,t,l;if(!L||!Ae||"table"===Ae.source)return[];if(null===(n=Ae.columns)||void 0===n?void 0:n.length)return Ae.columns;var r=L.entityKpis(null!==(t=Ae.entityKey)&&void 0!==t?t:"").slice(0,4);return e.__spreadArray([{key:"label",source:"field",label:L.entityName(null!==(l=Ae.entityKey)&&void 0!==l?l:"")}],r.map(function(e){return{key:e,source:"kpi",show:"both",sortable:!0}}),!0)},[L,Ae]),qe=Re.find(function(e){return"children"===e.source}),Le=null!==(g=null==L?void 0:L.headlineKpi)&&void 0!==g?g:"",ze=l.useMemo(function(){return L?"day"===(null==Ae?void 0:Ae.period)&&M.day?{start:M.day,end:M.day}:{start:r.toIsoDay(L.range.startDate),end:r.toIsoDay(L.range.endDate)}:{start:"",end:""}},[L,null==Ae?void 0:Ae.period,M.day]),Fe=Ie.map(function(e){return"".concat(e.entityKey,":").concat(e.nodeKey)}).join("|"),He=l.useMemo(function(){if(!L||!Ae)return{};var n=e.__assign({},L.sidebarFilters);return("trail"===Ae.filterBy?Ie:"row"===Ae.filterBy?Ie.slice(-1):[]).forEach(function(e){var t=L.labelColumnOf(e.entityKey);t&&e.label&&(n[t]=[e.label])}),n},[L,Ae,Fe]),Je=JSON.stringify(He),Ue="chip.criticality"===(null==ee?void 0:ee.key)?"criticality":null==ee?void 0:ee.key,We="table"===Pe?"":Y,Xe=function(n,t){return e.__awaiter(B,void 0,void 0,function(){var l,i,o,a,s,u,c,d,v,y,f;return e.__generator(this,function(h){switch(h.label){case 0:if(!L||!Ae)return[2,void 0];if("table"!==Pe)return[3,2];if(!Ae.tableKey)throw new Error("Pick a Table Builder table for this list.");return[4,r.fetchDrillTableRows(L.api,{tableKey:Ae.tableKey,startDay:ze.start,endDay:ze.end,filters:He,pageSize:Oe,cursor:n?oe:null},t)];case 1:return l=h.sent(),i=n?le.length:0,[2,{rows:l.rows.map(function(e,n){return{id:"t".concat(i+n),record:e}}),count:l.count,hasMore:l.hasNext,cursor:l.nextCursor,offset:0}];case 2:return"movers"!==Pe?[3,4]:(o=n?ue:0,[4,r.fetchInsightsDrivers(L.api,{dataDay:null!==(d=M.day)&&void 0!==d?d:void 0,kpiId:Le,parentNodeKey:null==Be?void 0:Be.nodeKey,entityKey:Ae.entityKey,tab:"drivers",limit:Oe,offset:o},t)]);case 3:return a=h.sent(),s=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,Le)}),u=a,[2,{rows:s.map(function(e){return{id:e.nodeKey,record:e,insights:e}}),count:null!==(v=u.total)&&void 0!==v?v:o+s.length,hasMore:Boolean(u.hasMore),cursor:null,offset:o+s.length}];case 4:return[4,r.fetchLevelRows(L.api,null!==(y=Ae.entityKey)&&void 0!==y?y:"",e.__assign({},L.range),{sort:Ue,order:null==ee?void 0:ee.order,search:We||void 0,pageSize:Oe,parentNodeKey:Me,includeChildren:qe?null!==(f=qe.max)&&void 0!==f?f:3:void 0,childEntityKey:null==qe?void 0:qe.childEntityKey,cursor:n&&null!=oe?oe:void 0},t)];case 5:return[2,{rows:(c=h.sent()).rows.map(function(n){var t,l;return{id:n.nodeKey,record:n,insights:e.__assign(e.__assign({},n),{entityKey:null!==(l=null!==(t=n.entityKey)&&void 0!==t?t:Ae.entityKey)&&void 0!==l?l:null})}}),count:c.count,hasMore:c.hasNext,cursor:c.nextCursor,offset:0}]}})})};if(l.useEffect(function(){if(L&&Ae){var e=new AbortController;return be(!0),we(null),re([]),ae(null),ce(0),Ke(null),Xe(!1,e.signal).then(function(e){var n;e&&(re(e.rows),ge(e.count),ye(e.hasMore),ae(null!==(n=e.cursor)&&void 0!==n?n:null),ce(e.offset))}).catch(function(e){"AbortError"!==(null==e?void 0:e.name)&&we(e instanceof Error?e.message:"The rows couldn't be loaded.")}).finally(function(){e.signal.aborted||be(!1)}),function(){return e.abort()}}},[null==L?void 0:L.api,null==L?void 0:L.revision,null==L?void 0:L.rangeKey,H,U,Pe,Me,Fe,M.day,ze.start,ze.end,Je,We,Ue,null==ee?void 0:ee.order,Oe,null==qe?void 0:qe.childEntityKey]),!L||!Ae)return null;var Ge="table"===Pe?function(n,t,l){var r,i,o=t.tableKey?n.tableSource(t.tableKey):void 0,a=(null===(r=null==o?void 0:o.columns)||void 0===r?void 0:r.length)?o.columns:Object.keys(null!=l?l:{}).map(function(e){return{key:e,label:s(e)}}),u=null!==(i=t.columns)&&void 0!==i?i:[];return e.__spreadArray(e.__spreadArray([],u.filter(function(e){return e.key&&a.some(function(n){return n.key===e.key})}),!0),a.filter(function(e){return!u.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(n){var t,l,r,i;return e.__assign(e.__assign({},n),{source:"field",label:null!==(r=null!==(t=n.label)&&void 0!==t?t:null===(l=a.find(function(e){return e.key===n.key}))||void 0===l?void 0:l.label)&&void 0!==r?r:s(null!==(i=n.key)&&void 0!==i?i:"")})})}(L,Ae,null===(b=le[0])||void 0===b?void 0:b.record):Re,Qe=L.hostTables["table"===Ae.source?null!==(m=Ae.tableKey)&&void 0!==m?m:"":"insights.".concat(null!==(x=Ae.entityKey)&&void 0!==x?x:"")],Ve=(null===(w=null==Qe?void 0:Qe.columns)||void 0===w?void 0:w.length)?Qe.columns:null,Ye=function(n){return n.insights?function(e){var n,t,l,r,i,o,a,s,u,c,d,v,y,f,h,g,p,_={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!==(s=null===(a=e.chip)||void 0===a?void 0:a.movementType)&&void 0!==s?s:null,reportId:null!==(c=null===(u=e.report)||void 0===u?void 0:u.reportId)&&void 0!==c?c:null,reportStatus:null!==(v=null===(d=e.report)||void 0===d?void 0:d.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!==(g=null===(h=e.action)||void 0===h?void 0:h.assigneeName)&&void 0!==g?g:null,children:e.children.map(function(e){return e.label}).filter(Boolean),__row:e};return Object.entries(null!==(p=e.metrics)&&void 0!==p?p:{}).forEach(function(e){var n,t,l,r=e[0],i=e[1];_[r]=null!==(n=null==i?void 0:i.value)&&void 0!==n?n:null,_["".concat(r,"_delta")]=null!==(t=null==i?void 0:i.deltaPct)&&void 0!==t?t:null,_["".concat(r,"_previous")]=null!==(l=null==i?void 0:i.previous)&&void 0!==l?l:null}),_}(n.insights):e.__assign({id:n.id},n.record)},Ze="table"===Pe?"none":null!==(j=Ae.onRowClick)&&void 0!==j?j:"none",$e="none"!==Ze,en="table"===Pe?e.__spreadArray([],le,!0).filter(function(e){return!Y||(Ve?Ve.map(function(e){return e.key}):Ge.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(Y.toLowerCase())})}).sort(function(e,n){if(!(null==ee?void 0:ee.key))return 0;var t=e.record[ee.key],l=n.record[ee.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"===ee.order?o:-o}):le,nn=function(e){var n;return"movers"!==Pe&&("table"===Pe?!1!==e.sortable:null!==(n=e.sortable)&&void 0!==n?n:"kpi"===e.source||"chip.criticality"===e.key)},tn=function(e){var n;return(null===(n=L.tableSource(null!=e?e:""))||void 0===n?void 0:n.title)||s(null!=e?e:"")},ln="table"===Ae.source?tn(Ae.tableKey):L.entityName(null!==(k=Ae.entityKey)&&void 0!==k?k:""),rn="table"===Ae.source?ln:L.entityPluralName(null!==(K=Ae.entityKey)&&void 0!==K?K:""),on=function(e){var n;return e.title||("table"===e.source?tn(e.tableKey):L.entityPluralName(null!==(n=e.entityKey)&&void 0!==n?n:""))},an=F.length>1?"Drill down in {row}":z?"table"===Ae.source?"{part}":L.labels.drillTableTitle:"{parts}",sn=(null!==(N=O.title)&&void 0!==N?N:an).replace(/\{row\}/g,null!==(S=null==Be?void 0:Be.label)&&void 0!==S?S:"").replace(/\{parent\}/g,null!==(D=null===(C=Ie[Ie.length-2])||void 0===C?void 0:C.label)&&void 0!==D?D:"").replace(/\{day\}/g,M.day?i.formatHeaderDate(M.day):"").replace(/\{parts\}|\{plural\}/g,rn).replace(/\{part\}/g,ln).replace(/\s+/g," ").trim(),un=function(e){return Ae.buttons.filter(function(n){var t,l,r;if(n.adminOnly&&!L.viewer.isAdmin)return!1;if(!("host"!==n.type||n.handler&&L.actionHandlers[n.handler]))return f.has(null!==(t=n.handler)&&void 0!==t?t:"")||(f.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=u(e.record,n.when);if(null==i||""===i)return!1}return!0})},cn=function(n,t,l){return e.__awaiter(B,void 0,void 0,function(){var r,i,o,a,s,u,c,f,h,g,p,_,b,m,x,w,j,k,K,N,S,C;return e.__generator(this,function(e){switch(e.label){case 0:r=d(L,M,t),i="".concat(t.id,":").concat(null!==(m=n.id)&&void 0!==m?m:n.label),Ke(null),e.label=1;case 1:if(e.trys.push([1,9,10,11]),"open"===n.type){if(o=v(null!==(x=n.url)&&void 0!==x?x:"",r,l,!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 Ee(i),"host"!==n.type?[3,3]:[4,(0,L.actionHandlers[null!==(w=n.handler)&&void 0!==w?w:""])({button:n,row:t.record,context:r.context,inputs:l})];case 2:return a=e.sent(),Ke({tone:"ok",text:a&&a.message||"".concat(n.label,": done.")}),[2];case 3:if("https:"!==(s=new URL(v(null!==(j=n.url)&&void 0!==j?j:"",r,l,!0))).protocol)throw new Error("Only https APIs can be called.");return u=null!==(k=n.method)&&void 0!==k?k:"POST",c={Accept:"application/json"},Object.entries(null!==(K=n.headers)&&void 0!==K?K:{}).forEach(function(e){var n=e[0],t=e[1];c[n]=v(String(t),r,l,!1)}),L.api.accessToken&&L.approvedApiHosts.includes(s.host.toLowerCase())&&(c.Authorization="Bearer ".concat(L.api.accessToken)),(f="GET"!==u&&void 0!==n.body&&null!==n.body)&&(c["Content-Type"]="application/json"),[4,fetch(s.toString(),{method:u,headers:c,body:f?JSON.stringify(y(n.body,r,l)):void 0})];case 4:h=e.sent(),g="",e.label=5;case 5:return e.trys.push([5,7,,8]),[4,h.json()];case 6:return p=e.sent(),_=null==p?void 0:p.error,g=String(null!==(C=null!==(S=null!==(N=null==p?void 0:p.message)&&void 0!==N?N:null==_?void 0:_.errorMessage)&&void 0!==S?S:null==p?void 0:p.detail)&&void 0!==C?C:""),[3,8];case 7:return e.sent(),g="",[3,8];case 8:if(!h.ok)throw new Error(g||"".concat(n.label," failed (status ").concat(h.status,")."));return Ke({tone:"ok",text:g||"".concat(n.label,": done.")}),[3,11];case 9:return b=e.sent(),Ke({tone:"error",text:b instanceof Error?b.message:"".concat(n.label," failed.")}),[3,11];case 10:return Ee(null),[7];case 11:return[2]}})})},dn=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"===Ae.source?Ae.tableKey:Ae.entityKey;return null!==(l=i?L.cellRenderers["".concat(i,".").concat(r)]:void 0)&&void 0!==l?l:L.cellRenderers[r]},vn=function(t,l){var r,i,o,a,s,d,v,y,f=null!==(r=l.key)&&void 0!==r?r:"",h=dn(l),g="kpi"===l.source&&t.insights?null===(i=t.insights.metrics[f])||void 0===i?void 0:i.value:"children"===l.source&&t.insights?t.insights.children.map(function(e){return e.label}).filter(Boolean):"label"===f&&t.insights?t.insights.label||t.insights.nodeKey:u(t.record,f);if(null==h?void 0:h.render){var _=h.render({column:l,value:g,record:t.record,row:t.insights,entityKey:Ae.entityKey,tableKey:Ae.tableKey});if(void 0!==_)return _}if(t.insights){var b=null===(o=L.renderInsightsCell)||void 0===o?void 0:o.call(L,{column:l,row:t.insights,entityKey:null!==(a=Ae.entityKey)&&void 0!==a?a:""});if(void 0!==b)return b}if("custom"===l.source)return null!==(s=l.emptyText)&&void 0!==s?s:"—";if("kpi"===l.source&&t.insights&&!(null==h?void 0:h.as)){var m=t.insights.metrics[f],x=c(null==m?void 0:m.value,l.format),w=null==(null==m?void 0:m.deltaPct)?"—":"".concat(m.deltaPct>0?"↑":m.deltaPct<0?"↓":""," ").concat(Math.abs(m.deltaPct),"%");return"delta"===l.show?n.jsx("span",e.__assign({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w})):"value"===l.show?x:n.jsxs("span",e.__assign({className:"ag-drill__metric"},{children:[n.jsx("strong",{children:x}),n.jsx("small",e.__assign({className:(null==m?void 0:m.tone)?"ag-drill__change--".concat(m.tone):void 0},{children:w}))]}))}if("children"===l.source&&t.insights&&!(null==h?void 0:h.as)){var j=Array.from(new Set(g)),k=null!==(d=l.max)&&void 0!==d?d:3,K=j.length?"".concat(j.slice(0,k).join(", ")).concat(j.length>k?" +".concat(j.length-k):""):null!==(v=l.emptyText)&&void 0!==v?v:"—";return n.jsx("span",e.__assign({className:"ag-drill__contributors",title:j.join(", ")||void 0},{children:K}))}var N=null!==(y=null==h?void 0:h.as)&&void 0!==y?y:l.format;if("link"===N){var S="string"==typeof g?g:"";return/^https:\/\//i.test(S)?n.jsx("a",e.__assign({href:S,target:"_blank",rel:"noopener noreferrer"},{children:S})):c(g,"text")}var C=c(g,"chip"===N?"text":N);return"—"===C&&l.emptyText?l.emptyText:"chip"!==N&&!(null==h?void 0:h.colors)||"—"===C?C:n.jsx(p,{text:C.replace(/_/g," "),value:g,colors:null==h?void 0:h.colors})},yn=function(e){e.insights&&(null==R||R(e.insights,Ze))},fn=Ae.buttons.length>0,hn=function(e){var n;return null!==(n=e.align)&&void 0!==n?n:"kpi"===e.source?"right":"left"},gn="ag-drill-".concat(String(null!==(T=O.id)&&void 0!==T?T:sn).replace(/[^a-z0-9]+/gi,"-")),pn=!1!==O.search&&"movers"!==Pe;return n.jsxs("section",e.__assign({className:"ag-drill".concat(q?" ".concat(q):""),"aria-labelledby":gn,style:null===(E=null==Qe?void 0:Qe.card)||void 0===E?void 0:E.root},{children:[n.jsxs("header",e.__assign({className:"ag-drill__header",style:null===(A=null==Qe?void 0:Qe.card)||void 0===A?void 0:A.header},{children:[n.jsxs("div",{children:[n.jsx("h3",e.__assign({id:gn,style:null===(I=null==Qe?void 0:Qe.card)||void 0===I?void 0:I.title},{children:sn})),"movers"===Pe?n.jsxs("span",{children:["Rows that moved",M.day?" on ".concat(i.formatHeaderDate(M.day)):""]}):null]}),pn?n.jsxs("label",e.__assign({className:"ag-drill__search"},{children:[n.jsx(t.Search,{"aria-hidden":"true"}),n.jsx("input",{type:"search",value:G,onChange:function(e){return Q(e.target.value)},placeholder:"Search ".concat(rn.toLowerCase(),"…"),"aria-label":"Search ".concat(rn)})]})):null]})),F.length>1?n.jsx("div",e.__assign({className:"ag-drill__tabs",role:"tablist","aria-label":"What this table lists"},{children:F.map(function(t,l){var r;return n.jsx("button",e.__assign({type:"button",role:"tab","aria-selected":l===U,className:l===U?"is-active":void 0,onClick:function(){W(l),Q(""),Z(""),ne(O.defaultSort)}},{children:on(t)}),"".concat(t.source,":").concat(null!==(r=t.entityKey)&&void 0!==r?r:t.tableKey,":").concat(l))})})):null,ke?n.jsxs("p",e.__assign({className:"ag-drill__notice ag-drill__notice--".concat(ke.tone),role:"status"},{children:[ke.text,n.jsx("button",e.__assign({type:"button","aria-label":"Dismiss",onClick:function(){return Ke(null)}},{children:n.jsx(t.X,{"aria-hidden":"true"})}))]})):null,n.jsxs("div",e.__assign({className:"ag-drill__table-wrap","aria-live":"polite"},{children:[n.jsxs("table",e.__assign({className:"ag-drill__table"},{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[Ve?Ve.map(function(t){return n.jsx("th",e.__assign({className:t.headerClassName,style:e.__assign(e.__assign({},t.style),t.headerStyle)},{children:t.header}),t.key)}):Ge.map(function(t){var l,r,i,o,a,u=null!==(r=null!==(l=t.key)&&void 0!==l?l:t.id)&&void 0!==r?r:"",c=null!==(i=t.label)&&void 0!==i?i:"kpi"===t.source?L.kpiLabel(u):"children"===t.source?L.entityPluralName(null!==(o=t.childEntityKey)&&void 0!==o?o:""):s(null!==(a=u.split(".").pop())&&void 0!==a?a:u);return n.jsx("th",e.__assign({className:"ag-drill__col--".concat(hn(t)," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):""),style:{width:t.width},"aria-sort":(null==ee?void 0:ee.key)===u?"asc"===ee.order?"ascending":"descending":void 0},{children:nn(t)?n.jsxs("button",e.__assign({type:"button",onClick:function(){return function(e){var n;if(nn(e)){var t=null!==(n=e.key)&&void 0!==n?n:"";ne(function(e){return{key:t,order:(null==e?void 0:e.key)===t&&"desc"===e.order?"asc":"desc"}})}}(t)}},{children:[c,(null==ee?void 0:ee.key)===u?n.jsxs("span",e.__assign({"aria-hidden":"true"},{children:[" ","asc"===ee.order?"↑":"↓"]})):null]})):c}),"".concat(t.source,":").concat(u))}),fn?n.jsx("th",{children:n.jsx("span",e.__assign({className:"ins-visually-hidden"},{children:"Actions"}))}):null,$e?n.jsx("th",{children:n.jsx("span",e.__assign({className:"ins-visually-hidden"},{children:"Open"}))}):null]})}),n.jsx("tbody",{children:en.map(function(l){return n.jsxs("tr",e.__assign({className:$e?void 0:"is-static",tabIndex:$e?0:void 0,onClick:$e?function(e){e.target.closest("a,button,input,select,textarea")||yn(l)}:void 0,onKeyDown:$e?function(e){return function(e,n){$e&&e.target===e.currentTarget&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),yn(n)))}(e,l)}:void 0},{children:[Ve?(r=Ye(l),Ve.map(function(t){return n.jsx("td",e.__assign({className:t.bodyClassName,style:e.__assign(e.__assign({},t.style),t.bodyStyle)},{children:t.body(r)}),t.key)})):Ge.map(function(t,r){var i,o,a=0===r?"th":"td",s=null===(i=dn(t))||void 0===i?void 0:i.className;return n.jsx(a,e.__assign({scope:0===r?"row":void 0,className:"ag-drill__col--".concat(hn(t)," ").concat(t.hideBelow?"ag-drill__hide--".concat(t.hideBelow):"").concat(s?" ".concat(s):"")},{children:vn(l,t)}),"".concat(t.source,":").concat(null!==(o=t.key)&&void 0!==o?o:t.id))}),fn?n.jsx("td",e.__assign({className:"ag-drill__buttons"},{children:un(l).map(function(t){var r,i,o=Te==="".concat(l.id,":").concat(null!==(r=t.id)&&void 0!==r?r:t.label);return n.jsx("button",e.__assign({type:"button",disabled:o,"aria-busy":o||void 0,onClick:function(){return function(e,n){var t,l=e.confirm?v(e.confirm,d(L,M,n),{},!1):"";"call"!==e.type||!(null!==(t=e.ask)&&void 0!==t?t:[]).length&&!l?l&&!window.confirm(l)||cn(e,n,{}):Ce({button:e,row:n,question:l})}(t,l)}},{children:o?"…":t.label}),null!==(i=t.id)&&void 0!==i?i:t.label)})})):null,$e?n.jsx("td",{children:n.jsx(t.ChevronRight,{className:"ag-drill__open","aria-hidden":"true"})}):null]}),l.id);var r})})]})),_e&&!le.length?n.jsx("p",e.__assign({className:"ag-drill__state"},{children:"Loading rows…"})):null,_e||en.length||xe?null:n.jsx("p",e.__assign({className:"ag-drill__state"},{children:"No rows found."})),xe?n.jsx("p",e.__assign({className:"ag-drill__state ag-drill__state--error"},{children:xe})):null]})),n.jsxs("footer",e.__assign({className:"ag-drill__footer"},{children:[n.jsx("span",{children:"rows"===Pe&&he?"".concat(le.length," of ").concat(he):""}),ve?n.jsx("button",e.__assign({type:"button",onClick:function(){return e.__awaiter(B,void 0,void 0,function(){var n,t,l;return e.__generator(this,function(r){switch(r.label){case 0:if(_e||!ve)return[2];be(!0),we(null),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,Xe(!0)];case 2:return(n=r.sent())?(re(function(t){return e.__spreadArray(e.__spreadArray([],t,!0),n.rows,!0)}),ye(n.hasMore),ae(null!==(l=n.cursor)&&void 0!==l?l:null),ce(n.offset),[3,5]):[2];case 3:return t=r.sent(),we(t instanceof Error?t.message:"More rows couldn't be loaded."),[3,5];case 4:return be(!1),[7];case 5:return[2]}})})},disabled:_e},{children:_e?"Loading…":"Show more"})):null]})),Se?n.jsx(_,{button:Se.button,question:Se.question,onCancel:function(){return Ce(null)},onSubmit:function(e){var n=Se.button,t=Se.row;Ce(null),cn(n,t,e)}}):null]}))};
|
|
2
2
|
//# sourceMappingURL=DrillTable.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"),t=require("react"),a=require("lucide-react"),i=require("./AgReport.js"),r=require("./L1Report.js"),l=require("./RowDetail.js"),s=require("./DrillTable.js"),o=require("./agPrimitives.js"),d=require("./insightsContextCore.js"),u=require("./insightsUtils.js");function c(i){var u,c=i.target,_=i.onClose,y=i.onOpenL1,g=i.onOpenL2,v=t.useRef(null),m=d.useInsights(),h=c.kpiId,f=t.useState([]),b=f[0],N=f[1];t.useEffect(function(){return N([])},[c.row.nodeKey]);var x=b.length?b[b.length-1]:null,j=x?x.nodeKey:c.row.nodeKey,K=x?x.entityKey:c.l2.tab.entityKey,w=x?x.reportId:c.row.report.kpiId===h?c.row.report.reportId:null,E=t.useState(w?null:c.dataDay),k=E[0],D=E[1];t.useEffect(function(){return D(w?null:c.dataDay)},[w,c.dataDay,j]);t.useEffect(function(){var e,n=document.activeElement,t=document.body.style.overflow;document.body.style.overflow="hidden",null===(e=v.current)||void 0===e||e.focus();var a=function(e){return"Escape"===e.key&&_()};return document.addEventListener("keydown",a),function(){var e;document.removeEventListener("keydown",a),document.body.style.overflow=t,null===(e=null==n?void 0:n.focus)||void 0===e||e.call(n)}},[_]);var I=c.row.label||c.row.nodeKey,C=x?x.label:I;return n.jsx("div",e.__assign({className:"ag-modal",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&_()}},{children:n.jsxs("div",e.__assign({className:"ag-modal__dialog",role:"dialog","aria-modal":"true","aria-labelledby":"ag-l2-row-modal-title"},{children:[n.jsxs("header",e.__assign({className:"ag-modal__head"},{children:[n.jsxs("div",e.__assign({className:"ag-modal__detail-title"},{children:[n.jsxs("div",e.__assign({className:"ag-modal__breadcrumb"},{children:[n.jsx("button",e.__assign({type:"button",onClick:y},{children:"L1"})),n.jsx(a.ChevronRight,{"aria-hidden":"true"}),n.jsxs("button",e.__assign({type:"button",onClick:g},{children:["Top ",p(c.partName)]})),n.jsx(a.ChevronRight,{"aria-hidden":"true"}),b.length?n.jsx("button",e.__assign({type:"button",onClick:function(){return N([])}},{children:I})):n.jsx("strong",e.__assign({id:"ag-l2-row-modal-title"},{children:I})),b.map(function(t,i){return n.jsxs("span",e.__assign({className:"ag-modal__crumb"},{children:[n.jsx(a.ChevronRight,{"aria-hidden":"true"}),i===b.length-1?n.jsxs("strong",e.__assign({id:"ag-l2-row-modal-title",title:t.partName},{children:[t.partName?"".concat(t.partName,": "):"",t.label]})):n.jsxs("button",e.__assign({type:"button",title:t.partName,onClick:function(){return N(function(e){return e.slice(0,i+1)})}},{children:[t.partName?"".concat(t.partName,": "):"",t.label]}))]}),"".concat(t.nodeKey,"-").concat(i))})]})),n.jsx("span",e.__assign({className:"ag-modal__date"},{children:o.formatHeaderDate(k||c.dataDay)}))]})),n.jsx("button",e.__assign({ref:v,type:"button",className:"ag-modal__close","aria-label":"Close",onClick:_},{children:n.jsx(a.X,{"aria-hidden":"true"})}))]})),n.jsx("div",e.__assign({className:"ag-modal__body"},{children:n.jsxs("div",e.__assign({className:"ag-popup"},{children:[n.jsxs("section",e.__assign({className:"ag-popup__section"},{children:[n.jsxs("div",e.__assign({className:"ag-popup__head"},{children:[n.jsx("p",e.__assign({className:"ag-popup__eyebrow"},{children:"Analysis"})),n.jsx("h3",e.__assign({className:"ag-popup__title"},{children:"Summary, Drivers & RCA"}))]})),n.jsx(l.default,{embedded:!0,nodeKey:j,kpiId:h,dataDay:c.dataDay,reportId:w,onReportDay:D,onOpenDriver:function(n){return N(function(t){var a,i,r,l;return e.__spreadArray(e.__spreadArray([],t,!0),[{nodeKey:n.nodeKey,label:n.label,partName:(null==m?void 0:m.entityName(null!==(a=n.entityKey)&&void 0!==a?a:""))||n.entityKey||"",entityKey:null!==(i=n.entityKey)&&void 0!==i?i:"",reportId:null!==(l=null===(r=n.report)||void 0===r?void 0:r.reportId)&&void 0!==l?l:null}],!1)})}},j)]})),n.jsxs("section",e.__assign({className:"ag-popup__section"},{children:[n.jsxs("div",e.__assign({className:"ag-popup__head"},{children:[n.jsx("p",e.__assign({className:"ag-popup__eyebrow"},{children:"Visuals"})),n.jsx("h3",e.__assign({className:"ag-popup__title"},{children:"Trend & Usage Signals"}))]})),k?n.jsx(r.EntityDetailVisuals,{nodeKey:j,label:C,kpiId:h,dataDay:k,tier2Kpis:c.tier2Kpis},j):n.jsx("p",e.__assign({className:"ag-muted"},{children:"Loading report…"})),(null==m?void 0:m.drillTable.popupEntityKeys.includes(K))&&(null===(u=m.drillTable.parts[K])||void 0===u?void 0:u.length)?n.jsx(s.default,{entityKey:K,parentNodeKey:j,parts:m.drillTable.parts[K],dataDay:k||c.dataDay,onOpenRow:function(n){return N(function(t){var a,i;return e.__spreadArray(e.__spreadArray([],t,!0),[{nodeKey:n.nodeKey,label:n.label||n.nodeKey,entityKey:n.entityKey||"",partName:(null==m?void 0:m.entityName(n.entityKey||""))||n.entityKey||"",reportId:null!==(i=null===(a=n.report)||void 0===a?void 0:a.reportId)&&void 0!==i?i:null}],!1)})}}):null]}))]}))}))]}))}))}function _(r){var l=r.target,s=r.onClose,u=r.onOpenL1,c=r.onOpenRow,_=t.useRef(null),y=d.useInsights();return t.useEffect(function(){var e,n=document.activeElement,t=document.body.style.overflow;document.body.style.overflow="hidden",null===(e=_.current)||void 0===e||e.focus();var a=function(e){return"Escape"===e.key&&s()};return document.addEventListener("keydown",a),function(){var e;document.removeEventListener("keydown",a),document.body.style.overflow=t,null===(e=null==n?void 0:n.focus)||void 0===e||e.call(n)}},[s]),y?n.jsx("div",e.__assign({className:"ag-modal",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&s()}},{children:n.jsxs("div",e.__assign({className:"ag-modal__dialog",role:"dialog","aria-modal":"true","aria-labelledby":"ag-l2-overview-modal-title"},{children:[n.jsxs("header",e.__assign({className:"ag-modal__head"},{children:[n.jsxs("div",e.__assign({className:"ag-modal__detail-title"},{children:[n.jsxs("div",e.__assign({className:"ag-modal__breadcrumb"},{children:[n.jsx("button",e.__assign({type:"button",onClick:u},{children:"L1"})),n.jsx(a.ChevronRight,{"aria-hidden":"true"}),n.jsxs("strong",e.__assign({id:"ag-l2-overview-modal-title"},{children:["Top ",p(l.partName)]}))]})),n.jsx("span",e.__assign({className:"ag-modal__date"},{children:o.formatHeaderDate(l.dataDay)}))]})),n.jsx("button",e.__assign({ref:_,type:"button",className:"ag-modal__close","aria-label":"Close",onClick:s},{children:n.jsx(a.X,{"aria-hidden":"true"})}))]})),n.jsx("div",e.__assign({className:"ag-modal__body"},{children:n.jsx(i.L2Report,{tab:l.tab,title:l.title,partName:l.partName,partKpis:l.partKpis,search:"",onOpenRow:function(e,n,t){var a;return c({row:e,partName:l.partName,kpiId:y.headlineKpi||n,dataDay:t,tier2Kpis:null!==(a=l.tab.tier2Kpis)&&void 0!==a?a:y.tierKpis[2],l2:l})}})}))]}))})):null}var p=function(e){var n=e.trim().toLowerCase();return n?/(s|x|ch|sh)$/.test(n)?"".concat(n,"es"):/[^aeiou]y$/.test(n)?"".concat(n.slice(0,-1),"ies"):"".concat(n,"s"):"rows"};exports.default=function(l){var s,o,y,g,v,m=l.tabs,h=l.insightsConfig,f=d.useInsights(),b=t.useState(0),N=b[0],x=b[1],j=t.useState(!1),K=j[0],w=j[1],E=t.useState(""),k=E[0],D=E[1],I=t.useState(""),C=I[0],O=I[1],R=t.useState(null),S=R[0],L=R[1],T=t.useState(null),A=T[0],q=T[1],M=t.useState(null),P=M[0],G=M[1];t.useEffect(function(){var e=setTimeout(function(){return O(k.trim())},300);return function(){return clearTimeout(e)}},[k]),t.useEffect(function(){D(""),O("")},[N]);var X=t.useMemo(function(){var e,n={};return(null!==(e=null==h?void 0:h.hierarchy)&&void 0!==e?e:[]).forEach(function(e){var t;return(null!==(t=e.entities)&&void 0!==t?t:[]).forEach(function(e){var t,a;(null==e?void 0:e.entityKey)&&(n[e.entityKey]={name:null!==(t=e.name)&&void 0!==t?t:"",kpis:null!==(a=e.kpis)&&void 0!==a?a:[]})})}),n},[h]);if(t.useEffect(function(){if(f){var n=f.entityOrder.length?e.__spreadArray([],m,!0).sort(function(e,n){var t=f.entityOrder.indexOf(e.entityKey),a=f.entityOrder.indexOf(n.entityKey);return(t<0?Number.MAX_SAFE_INTEGER:t)-(a<0?Number.MAX_SAFE_INTEGER:a)}):m,t=function(e){var t,a,i,r,l,s,o=e,d=o.detail,u=(null==d?void 0:d.entityKey)?n.findIndex(function(e){return e.entityKey===d.entityKey}):-1;if(d&&!(u<0)){var c=n[u],_=(null===(t=X[c.entityKey])||void 0===t?void 0:t.name)||c.title||f.entityName(c.entityKey)||c.entityKey,p=f.headlineKpi||c.rankBy||(null===(a=c.listKpis)||void 0===a?void 0:a[0])||(null===(i=X[c.entityKey])||void 0===i?void 0:i.kpis[0])||"",y=d.dataDay||f.range.endDate.toISOString().slice(0,10),g={tab:c,title:c.title||_,partName:_,partKpis:null!==(l=null===(r=X[c.entityKey])||void 0===r?void 0:r.kpis)&&void 0!==l?l:[],dataDay:y};o.preventDefault(),G(null),q(null),x(u),L({row:{rank:0,nodeKey:d.nodeKey,label:d.label,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:p},action:null,children:[]},partName:_,kpiId:p,dataDay:y,tier2Kpis:null!==(s=c.tier2Kpis)&&void 0!==s?s:f.tierKpis[2],l2:g})}};return window.addEventListener(u.OPEN_INSIGHTS_ENTITY_REPORT,t),function(){return window.removeEventListener(u.OPEN_INSIGHTS_ENTITY_REPORT,t)}}},[f,m,X]),!f||!m.length)return null;var F=f.entityOrder.length?e.__spreadArray([],m,!0).sort(function(e,n){var t=f.entityOrder.indexOf(e.entityKey),a=f.entityOrder.indexOf(n.entityKey);return(t<0?Number.MAX_SAFE_INTEGER:t)-(a<0?Number.MAX_SAFE_INTEGER:a)}):m,H=Math.min(N,F.length-1),B=F[H],U=function(e){var n;return e.title||f.entityName(e.entityKey)||(null===(n=X[e.entityKey])||void 0===n?void 0:n.name)||e.entityKey},V=(null===(s=X[B.entityKey])||void 0===s?void 0:s.name)||U(B),Y=B.rankBy||(null===(o=B.listKpis)||void 0===o?void 0:o[0])||(null===(y=X[B.entityKey])||void 0===y?void 0:y.kpis[0])||"",$=Y?f.kpiLabel(Y).toLowerCase():"activity";return n.jsxs("div",e.__assign({className:"ag-tabs"},{children:[n.jsxs("div",e.__assign({className:"ag-tabs__head"},{children:[n.jsxs("div",e.__assign({className:"ag-tabs__bar"},{children:[n.jsx("div",e.__assign({className:"ag-tabs__list",role:"tablist","aria-label":"Insights"},{children:F.map(function(t,a){return n.jsx("button",e.__assign({id:"ag-tab-".concat(a),type:"button",role:"tab","aria-selected":a===H,"aria-controls":"ag-tabpanel",className:a===H?"is-active":void 0,onClick:function(){L(null),x(a)}},{children:U(t)}),"".concat(t.entityKey,"-").concat(a))})})),n.jsx("button",e.__assign({type:"button",className:"ag-icon-button","aria-label":K?"Expand insights":"Collapse insights","aria-expanded":!K,onClick:function(){return w(function(e){return!e})}},{children:n.jsx(a.ChevronDown,{"aria-hidden":"true",className:K?"is-closed":"is-open"})}))]})),K?null:n.jsxs(n.Fragment,{children:[n.jsx("p",e.__assign({className:"ag-tabs__desc"},{children:V?"".concat(p(V).replace(/^\w/,function(e){return e.toUpperCase()})," with the highest ").concat($,"."):null})),n.jsx("div",e.__assign({className:"ag-tabs__tools"},{children:n.jsxs("label",e.__assign({className:"ag-search"},{children:[n.jsx(a.Search,{"aria-hidden":"true"}),n.jsx("input",{type:"search",value:k,onChange:function(e){return D(e.target.value)},placeholder:"Search ".concat(V.toLowerCase(),"..."),"aria-label":"Search ".concat(p(V))})]}))}))]})]})),K?null:n.jsxs("div",e.__assign({className:"ag-tabs__body",role:"tabpanel",id:"ag-tabpanel","aria-labelledby":"ag-tab-".concat(H)},{children:[n.jsx(i.L2Report,{tab:B,title:U(B),partName:V,partKpis:null!==(v=null===(g=X[B.entityKey])||void 0===g?void 0:g.kpis)&&void 0!==v?v:[],search:C,onOpenRow:function(e,n,t){var a,i,r;return L({row:e,partName:V,kpiId:f.headlineKpi||n,dataDay:t,tier2Kpis:null!==(a=B.tier2Kpis)&&void 0!==a?a:f.tierKpis[2],l2:{tab:B,title:U(B),partName:V,partKpis:null!==(r=null===(i=X[B.entityKey])||void 0===i?void 0:i.kpis)&&void 0!==r?r:[],dataDay:t}})}},H),S?n.jsx(c,{target:S,onClose:function(){return L(null)},onOpenL1:function(){G(S.dataDay),L(null)},onOpenL2:function(){q(S.l2),L(null)}}):null,A?n.jsx(_,{target:A,onClose:function(){return q(null)},onOpenL1:function(){G(A.dataDay),q(null)},onOpenRow:function(e){L(e),q(null)}}):null,P?n.jsx(r.L1ReportModal,{day:P,workingDays:Boolean(f.defaultWorkingDays),onClose:function(){return G(null)}}):null]}))]}))};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react/jsx-runtime"),n=require("react"),a=require("lucide-react"),i=require("./AgReport.js"),r=require("./L1Report.js"),l=require("./DrillLevel.js"),s=require("./agPrimitives.js"),o=require("./insightsContextCore.js"),d=require("./insightsUtils.js");function u(i){var r,d,u,c=i.target,y=i.onClose,_=i.onOpenL1,p=i.onOpenL2,v=n.useRef(null),g=o.useInsights(),m=c.kpiId,h=n.useState([]),f=h[0],b=h[1];n.useEffect(function(){return b([])},[c.row.nodeKey]);var K=e.__assign(e.__assign({},l.popupRowFromTable(g,e.__assign(e.__assign({},c.row),{entityKey:null!==(r=c.row.entityKey)&&void 0!==r?r:c.l2.tab.entityKey}))),{reportId:c.row.report.kpiId===m?c.row.report.reportId:null}),N=e.__spreadArray([K],f,!0),x=N[N.length-1],j=n.useState(x.reportId?null:c.dataDay),E=j[0],w=j[1];n.useEffect(function(){return w(x.reportId?null:c.dataDay)},[x.reportId,c.dataDay,x.nodeKey]),n.useEffect(function(){var e,t=document.activeElement,n=document.body.style.overflow;document.body.style.overflow="hidden",null===(e=v.current)||void 0===e||e.focus();var a=function(e){return"Escape"===e.key&&y()};return document.addEventListener("keydown",a),function(){var e;document.removeEventListener("keydown",a),document.body.style.overflow=n,null===(e=null==t?void 0:t.focus)||void 0===e||e.call(t)}},[y]);var k=K.label,I=null!==(d=null==g?void 0:g.matchDrillLevel(x.entityKey,N.slice(0,-1).map(function(e){return e.entityKey})))&&void 0!==d?d:l.DEFAULT_LEVEL;return t.jsx("div",e.__assign({className:"ag-modal",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&y()}},{children:t.jsxs("div",e.__assign({className:"ag-modal__dialog",role:"dialog","aria-modal":"true","aria-labelledby":"ag-l2-row-modal-title"},{children:[t.jsxs("header",e.__assign({className:"ag-modal__head"},{children:[t.jsxs("div",e.__assign({className:"ag-modal__detail-title"},{children:[t.jsxs("div",e.__assign({className:"ag-modal__breadcrumb"},{children:[t.jsx("button",e.__assign({type:"button",onClick:_},{children:"L1"})),t.jsx(a.ChevronRight,{"aria-hidden":"true"}),t.jsxs("button",e.__assign({type:"button",onClick:p},{children:["Top ",null!==(u=null==g?void 0:g.entityPluralName(c.l2.tab.entityKey))&&void 0!==u?u:c.partName]})),t.jsx(a.ChevronRight,{"aria-hidden":"true"}),f.length?t.jsx("button",e.__assign({type:"button",onClick:function(){return b([])}},{children:k})):t.jsx("strong",e.__assign({id:"ag-l2-row-modal-title"},{children:k})),f.map(function(n,i){return t.jsxs("span",e.__assign({className:"ag-modal__crumb"},{children:[t.jsx(a.ChevronRight,{"aria-hidden":"true"}),i===f.length-1?t.jsxs("strong",e.__assign({id:"ag-l2-row-modal-title",title:n.partName},{children:[n.partName?"".concat(n.partName,": "):"",n.label]})):t.jsxs("button",e.__assign({type:"button",title:n.partName,onClick:function(){return b(function(e){return e.slice(0,i+1)})}},{children:[n.partName?"".concat(n.partName,": "):"",n.label]}))]}),"".concat(n.nodeKey,"-").concat(i))})]})),t.jsx("span",e.__assign({className:"ag-modal__date"},{children:s.formatHeaderDate(E||c.dataDay)}))]})),t.jsx("button",e.__assign({ref:v,type:"button",className:"ag-modal__close","aria-label":"Close",onClick:y},{children:t.jsx(a.X,{"aria-hidden":"true"})}))]})),t.jsx("div",e.__assign({className:"ag-modal__body"},{children:t.jsx(l.default,{trail:N,level:I,kpiId:m,dataDay:c.dataDay,reportDay:E,onReportDay:w,tier2Kpis:c.tier2Kpis,onOpen:function(t){return b(function(n){return e.__spreadArray(e.__spreadArray([],n,!0),[t],!1)})}})}))]}))}))}function c(r){var l=r.target,d=r.onClose,u=r.onOpenL1,c=r.onOpenRow,y=n.useRef(null),_=o.useInsights();return n.useEffect(function(){var e,t=document.activeElement,n=document.body.style.overflow;document.body.style.overflow="hidden",null===(e=y.current)||void 0===e||e.focus();var a=function(e){return"Escape"===e.key&&d()};return document.addEventListener("keydown",a),function(){var e;document.removeEventListener("keydown",a),document.body.style.overflow=n,null===(e=null==t?void 0:t.focus)||void 0===e||e.call(t)}},[d]),_?t.jsx("div",e.__assign({className:"ag-modal",role:"presentation",onMouseDown:function(e){return e.target===e.currentTarget&&d()}},{children:t.jsxs("div",e.__assign({className:"ag-modal__dialog",role:"dialog","aria-modal":"true","aria-labelledby":"ag-l2-overview-modal-title"},{children:[t.jsxs("header",e.__assign({className:"ag-modal__head"},{children:[t.jsxs("div",e.__assign({className:"ag-modal__detail-title"},{children:[t.jsxs("div",e.__assign({className:"ag-modal__breadcrumb"},{children:[t.jsx("button",e.__assign({type:"button",onClick:u},{children:"L1"})),t.jsx(a.ChevronRight,{"aria-hidden":"true"}),t.jsxs("strong",e.__assign({id:"ag-l2-overview-modal-title"},{children:["Top ",_.entityPluralName(l.tab.entityKey)]}))]})),t.jsx("span",e.__assign({className:"ag-modal__date"},{children:s.formatHeaderDate(l.dataDay)}))]})),t.jsx("button",e.__assign({ref:y,type:"button",className:"ag-modal__close","aria-label":"Close",onClick:d},{children:t.jsx(a.X,{"aria-hidden":"true"})}))]})),t.jsx("div",e.__assign({className:"ag-modal__body"},{children:t.jsx(i.L2Report,{tab:l.tab,title:l.title,partName:l.partName,partKpis:l.partKpis,search:"",onOpenRow:function(e,t,n){var a;return c({row:e,partName:l.partName,kpiId:_.headlineKpi||t,dataDay:n,tier2Kpis:null!==(a=l.tab.tier2Kpis)&&void 0!==a?a:_.tierKpis[2],l2:l})}})}))]}))})):null}exports.default=function(l){var s,y,_,p,v,g=l.tabs,m=l.insightsConfig,h=o.useInsights(),f=n.useState(0),b=f[0],K=f[1],N=n.useState(!1),x=N[0],j=N[1],E=n.useState(""),w=E[0],k=E[1],I=n.useState(""),D=I[0],C=I[1],L=n.useState(null),O=L[0],R=L[1],S=n.useState(null),T=S[0],A=S[1],P=n.useState(null),q=P[0],M=P[1];n.useEffect(function(){var e=setTimeout(function(){return C(w.trim())},300);return function(){return clearTimeout(e)}},[w]),n.useEffect(function(){k(""),C("")},[b]);var F=n.useMemo(function(){var e,t={};return(null!==(e=null==m?void 0:m.hierarchy)&&void 0!==e?e:[]).forEach(function(e){var n;return(null!==(n=e.entities)&&void 0!==n?n:[]).forEach(function(e){var n,a;(null==e?void 0:e.entityKey)&&(t[e.entityKey]={name:null!==(n=e.name)&&void 0!==n?n:"",kpis:null!==(a=e.kpis)&&void 0!==a?a:[]})})}),t},[m]);if(n.useEffect(function(){if(h){var t=h.entityOrder.length?e.__spreadArray([],g,!0).sort(function(e,t){var n=h.entityOrder.indexOf(e.entityKey),a=h.entityOrder.indexOf(t.entityKey);return(n<0?Number.MAX_SAFE_INTEGER:n)-(a<0?Number.MAX_SAFE_INTEGER:a)}):g,n=function(e){var n,a,i,r,l,s,o=e,d=o.detail,u=(null==d?void 0:d.entityKey)?t.findIndex(function(e){return e.entityKey===d.entityKey}):-1;if(d&&!(u<0)){var c=t[u],y=(null===(n=F[c.entityKey])||void 0===n?void 0:n.name)||c.title||h.entityName(c.entityKey)||c.entityKey,_=h.headlineKpi||c.rankBy||(null===(a=c.listKpis)||void 0===a?void 0:a[0])||(null===(i=F[c.entityKey])||void 0===i?void 0:i.kpis[0])||"",p=d.dataDay||h.range.endDate.toISOString().slice(0,10),v={tab:c,title:c.title||y,partName:y,partKpis:null!==(l=null===(r=F[c.entityKey])||void 0===r?void 0:r.kpis)&&void 0!==l?l:[],dataDay:p};o.preventDefault(),M(null),A(null),K(u),R({row:{rank:0,nodeKey:d.nodeKey,label:d.label,parent:null,metrics:{},barPct:null,chip:null,report:{reportId:null,status:"none",kpiId:_},action:null,children:[]},partName:y,kpiId:_,dataDay:p,tier2Kpis:null!==(s=c.tier2Kpis)&&void 0!==s?s:h.tierKpis[2],l2:v})}};return window.addEventListener(d.OPEN_INSIGHTS_ENTITY_REPORT,n),function(){return window.removeEventListener(d.OPEN_INSIGHTS_ENTITY_REPORT,n)}}},[h,g,F]),!h||!g.length)return null;var G=h.entityOrder.length?e.__spreadArray([],g,!0).sort(function(e,t){var n=h.entityOrder.indexOf(e.entityKey),a=h.entityOrder.indexOf(t.entityKey);return(n<0?Number.MAX_SAFE_INTEGER:n)-(a<0?Number.MAX_SAFE_INTEGER:a)}):g,X=Math.min(b,G.length-1),H=G[X],B=function(e){var t;return e.title||h.entityName(e.entityKey)||(null===(t=F[e.entityKey])||void 0===t?void 0:t.name)||e.entityKey},U=(null===(s=F[H.entityKey])||void 0===s?void 0:s.name)||B(H),Y=H.rankBy||(null===(y=H.listKpis)||void 0===y?void 0:y[0])||(null===(_=F[H.entityKey])||void 0===_?void 0:_.kpis[0])||"",V=Y?h.kpiLabel(Y).toLowerCase():"activity";return t.jsxs("div",e.__assign({className:"ag-tabs"},{children:[t.jsxs("div",e.__assign({className:"ag-tabs__head"},{children:[t.jsxs("div",e.__assign({className:"ag-tabs__bar"},{children:[t.jsx("div",e.__assign({className:"ag-tabs__list",role:"tablist","aria-label":"Insights"},{children:G.map(function(n,a){return t.jsx("button",e.__assign({id:"ag-tab-".concat(a),type:"button",role:"tab","aria-selected":a===X,"aria-controls":"ag-tabpanel",className:a===X?"is-active":void 0,onClick:function(){R(null),K(a)}},{children:B(n)}),"".concat(n.entityKey,"-").concat(a))})})),t.jsx("button",e.__assign({type:"button",className:"ag-icon-button","aria-label":x?"Expand insights":"Collapse insights","aria-expanded":!x,onClick:function(){return j(function(e){return!e})}},{children:t.jsx(a.ChevronDown,{"aria-hidden":"true",className:x?"is-closed":"is-open"})}))]})),x?null:t.jsxs(t.Fragment,{children:[t.jsx("p",e.__assign({className:"ag-tabs__desc"},{children:U?"".concat(h.entityPluralName(H.entityKey)," with the highest ").concat(V,"."):null})),t.jsx("div",e.__assign({className:"ag-tabs__tools"},{children:t.jsxs("label",e.__assign({className:"ag-search"},{children:[t.jsx(a.Search,{"aria-hidden":"true"}),t.jsx("input",{type:"search",value:w,onChange:function(e){return k(e.target.value)},placeholder:"Search ".concat(U.toLowerCase(),"..."),"aria-label":"Search ".concat(h.entityPluralName(H.entityKey))})]}))}))]})]})),x?null:t.jsxs("div",e.__assign({className:"ag-tabs__body",role:"tabpanel",id:"ag-tabpanel","aria-labelledby":"ag-tab-".concat(X)},{children:[t.jsx(i.L2Report,{tab:H,title:B(H),partName:U,partKpis:null!==(v=null===(p=F[H.entityKey])||void 0===p?void 0:p.kpis)&&void 0!==v?v:[],search:D,onOpenRow:function(t,n,a){var i,r,l,s,o,d,u=null!==(i=t.entityKey)&&void 0!==i?i:H.entityKey;h.matchDrillLevel(u,[])?R({row:e.__assign(e.__assign({},t),{entityKey:u}),partName:U,kpiId:h.headlineKpi||n,dataDay:a,tier2Kpis:null!==(s=H.tier2Kpis)&&void 0!==s?s:h.tierKpis[2],l2:{tab:H,title:B(H),partName:U,partKpis:null!==(d=null===(o=F[H.entityKey])||void 0===o?void 0:o.kpis)&&void 0!==d?d:[],dataDay:a}}):h.openReport({reportId:null===(r=t.report)||void 0===r?void 0:r.reportId,nodeKey:t.nodeKey,kpiId:h.headlineKpi||n,dataDay:a,title:null!==(l=t.label)&&void 0!==l?l:t.nodeKey})}},X),O?t.jsx(u,{target:O,onClose:function(){return R(null)},onOpenL1:function(){M(O.dataDay),R(null)},onOpenL2:function(){A(O.l2),R(null)}}):null,T?t.jsx(c,{target:T,onClose:function(){return A(null)},onOpenL1:function(){M(T.dataDay),A(null)},onOpenRow:function(e){R(e),A(null)}}):null,q?t.jsx(r.L1ReportModal,{day:q,workingDays:Boolean(h.defaultWorkingDays),onClose:function(){return M(null)}}):null]}))]}))};
|
|
2
2
|
//# sourceMappingURL=InsightTabs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),n=require("react/jsx-runtime"),i=require("react"),t=require("./ReportDrawer.js"),l=require("./insightsUtils.js"),r=require("./insightsContextCore.js"),o=require("../../api/insightsApi.js");function a(e){var n,i,t=null!==(i=null===(n=null==e?void 0:e.analysis)||void 0===n?void 0:n.movingAverageDays)&&void 0!==i?i:{},l=function(e,n){return Number.isFinite(Number(e))&&Number(e)>0?Number(e):n};return{fast:l(t.fast,3),slow:l(t.slow,7),long:l(t.long,30)}}exports.useInsights=r.useInsights,exports.InsightsProvider=function(u){var s,v,d,c,y=u.baseUrl,f=u.configId,p=u.accessToken,g=u.startDate,h=u.endDate,m=u.workingDaysOnly,b=u.filtersActive,T=u.insights,k=u.decisionAdvantage,w=u.insightsDrill,D=u.insightsLabels,K=u.renderInsightsCell,_=u.sidebarFilters,I=u.tableBuilder,A=u.approvedApiHosts,C=u.actionHandlers,N=u.cellRenderers,j=u.tables,E=u.headlineKpiId,O=u.defaultWorkingDays,x=void 0!==O&&O,M=u.reportTarget,R=u.onReportTargetChange,L=u.refreshRevision,U=void 0===L?0:L,q=u.children,S=i.useState(0),H=S[0],F=S[1],P=i.useMemo(function(){return{baseUrl:y,configId:null!=f?f:"",accessToken:p}},[y,f,p]),B=l.useInsightsFetch(f?function(e){return o.fetchHierarchy(P,e)}:null,[P,H,U]),W=o.toIsoDay(g),z=o.toIsoDay(h),G=i.useMemo(function(){var n,i,t,r,o,u,s,v,d,c,y,f,g,h,O,M,L,q,S,G,J,Q,V,X,Y,Z={},$={},ee={},ne={},ie={},te={};(null!==(n=null==T?void 0:T.hierarchy)&&void 0!==n?n:[]).forEach(function(e,n){var i;return(null!==(i=e.entities)&&void 0!==i?i:[]).forEach(function(i){var t,l,r,o,a;if(null==i?void 0:i.entityKey){Z[i.entityKey]=Number(e.level)||n+1,ne[i.entityKey]=null!==(t=i.parentEntityKeys)&&void 0!==t?t:[],ie[i.entityKey]=null!==(l=i.kpis)&&void 0!==l?l:[],$[i.entityKey]=null!==(r=i.name)&&void 0!==r?r:i.entityKey,ee[i.entityKey]=null!==(a=null!==(o=i.pluralName)&&void 0!==o?o:i.name)&&void 0!==a?a:i.entityKey;var u=i.labelColumn||i.splitBy;u&&(te[i.entityKey]=u)}})}),null===(i=B.data)||void 0===i||i.levels.forEach(function(e,n){e.entities.forEach(function(i){var t;Z[i.entityKey]=Number(e.level)||n+1,$[i.entityKey]=i.name,ee[i.entityKey]=null!==(t=i.pluralName)&&void 0!==t?t:i.name,i.parentEntityKeys&&(ne[i.entityKey]=i.parentEntityKeys),i.kpis&&(ie[i.entityKey]=i.kpis)})});var le={};(null!==(t=null==T?void 0:T.kpis)&&void 0!==t?t:[]).forEach(function(e){(null==e?void 0:e.kpiId)&&(le[e.kpiId]=e)});var re={1:[],2:[]};(null!==(r=null==T?void 0:T.kpis)&&void 0!==r?r:[]).forEach(function(e){!(null==e?void 0:e.kpiId)||1!==e.tier&&2!==e.tier||re[e.tier].push(e.kpiId)});var oe=null!==(s=null!==(u=null!==(o=E&&le[E]?E:null)&&void 0!==o?o:re[1][0])&&void 0!==u?u:re[2][0])&&void 0!==s?s:null,ae=null!==(d=null===(v=B.data)||void 0===v?void 0:v.levels.flatMap(function(e){return e.entities.map(function(e){return e.entityKey})}))&&void 0!==d?d:(null!==(c=null==T?void 0:T.hierarchy)&&void 0!==c?c:[]).flatMap(function(e){var n;return(null!==(n=e.entities)&&void 0!==n?n:[]).map(function(e){return e.entityKey})}),ue={activityTitle:"User Activity",activityColumn:"User Activity",platformScope:"Platform-wide",correlationTitle:"Usage vs. {kpi}",correlationSubtitle:"{kpi} vs. usage - % change",visualsTitle:"Trend & Usage Signals",analysisTitle:"Summary, Drivers & RCA",driverCategory:"Top {plural}",driversTab:"Top Drivers",headwindsTab:"Headwinds",attentionTab:"Needs attention",shareLine:"{share}% of today's movement",movedWith:"Moved with",movedOpposite:"Moved opposite",previousDay:{working:"vs previous working day",weekend:"vs previous weekend day"},drillTableTitle:"{plural} in {row}",decisionAdvantageTitle:"Decision Advantage"},se={tabTables:Object.fromEntries((null!==(f=null===(y=null==k?void 0:k.tabs)||void 0===y?void 0:y.items)&&void 0!==f?f:[]).map(function(e){return[e.entityKey,e.table]})),levels:null!==(g=null==k?void 0:k.drillLevels)&&void 0!==g?g:[]},ve="function"==typeof w?w(se):e.__assign(e.__assign({},se),null!=w?w:{}),de=null!==(h=ve.levels)&&void 0!==h?h:[],ce={};Object.entries(null!=_?_:{}).forEach(function(e){var n=e[0],i=e[1],t=(Array.isArray(i)?i:[i]).filter(function(e){return""!==e&&null!=e}).map(String);t.length&&(ce[n]=t)});var ye=new Map((null!=I?I:[]).filter(function(e){return null==e?void 0:e.key}).map(function(e){return[e.key,e]}));return{api:P,headlineKpi:oe,tierKpis:re,defaultWorkingDays:x,range:{startDate:new Date("".concat(W,"T00:00:00")),endDate:new Date("".concat(z,"T00:00:00")),workingDaysOnly:m},rangeKey:"".concat(W,":").concat(z,":").concat(m?1:0),filtersActive:Boolean(b),kpis:le,kpiLabel:function(e){var n;return(null===(n=le[e])||void 0===n?void 0:n.label)||e},goodDirection:function(e){var n;return"down"===(null===(n=le[e])||void 0===n?void 0:n.goodDirection)?"down":"up"},levelOf:function(e){return e&&Z[e]||1},entityName:function(e){return $[e]||e},entityPluralName:function(e){return ee[e]||$[e]||e},entityKpis:function(e){var n;return null!==(n=ie[e])&&void 0!==n?n:[]},entityOrder:ae,isChildOf:function(e,n){var i;return(null!==(i=ne[e])&&void 0!==i?i:[]).includes(n)},decisionAdvantage:k,labels:e.__assign(e.__assign(e.__assign(e.__assign({},ue),null!==(O=null==k?void 0:k.labels)&&void 0!==O?O:{}),null!=D?D:{}),{previousDay:e.__assign(e.__assign(e.__assign({},ue.previousDay),null!==(L=null===(M=null==k?void 0:k.labels)||void 0===M?void 0:M.previousDay)&&void 0!==L?L:{}),null!==(q=null==D?void 0:D.previousDay)&&void 0!==q?q:{})}),tierTitles:{1:null!==(G=null===(S=null==k?void 0:k.tierTitles)||void 0===S?void 0:S[1])&&void 0!==G?G:"Trend",2:null!==(Q=null===(J=null==k?void 0:k.tierTitles)||void 0===J?void 0:J[2])&&void 0!==Q?Q:"User Activity"},drill:{tabTables:null!==(V=ve.tabTables)&&void 0!==V?V:{},levels:de},matchDrillLevel:function(e,n){return de.filter(function(i){var t;return i.match.entityKey===e&&(null!==(t=i.match.within)&&void 0!==t?t:[]).every(function(e){return n.includes(e)})}).sort(function(e,n){var i,t,l,r;return(null!==(t=null===(i=n.match.within)||void 0===i?void 0:i.length)&&void 0!==t?t:0)-(null!==(r=null===(l=e.match.within)||void 0===l?void 0:l.length)&&void 0!==r?r:0)})[0]},labelColumnOf:function(e){var n;return null!==(n=te[e])&&void 0!==n?n:null},sidebarFilters:ce,tableSource:function(e){return ye.get(e)},approvedApiHosts:(null!=A?A:[]).map(function(e){return e.trim().toLowerCase()}).filter(Boolean),actionHandlers:null!=C?C:{},cellRenderers:null!=N?N:{},hostTables:null!=j?j:{},renderInsightsCell:K,windows:a(T),openReport:R,viewer:l.viewerFromToken(p),minReasonLength:Math.max(1,Number(null===(Y=null===(X=null==T?void 0:T.analysis)||void 0===X?void 0:X.outliers)||void 0===Y?void 0:Y.minReasonLength)||10),revision:H+U,refresh:function(){return F(function(e){return e+1})}}},[P,W,z,m,b,T,k,w,D,K,_,I,A,C,N,j,E,x,R,H,U,B.data]);return n.jsxs(r.InsightsContext.Provider,e.__assign({value:G},{children:[q,M?n.jsx(t.default,{target:M,onClose:function(){return R(null)}},"".concat(null!==(s=M.reportId)&&void 0!==s?s:"",":").concat(null!==(v=M.nodeKey)&&void 0!==v?v:"",":").concat(null!==(d=M.kpiId)&&void 0!==d?d:"",":").concat(null!==(c=M.dataDay)&&void 0!==c?c:"")):null]}))};
|
|
2
2
|
//# sourceMappingURL=InsightsContext.js.map
|