From a7382ebb98a5bfc2b4d4c25fe3842f90f5a5d097 Mon Sep 17 00:00:00 2001 From: Emma Segal-Grossman Date: Sat, 22 Jun 2024 01:40:56 -0400 Subject: [PATCH] Use internal rounded bar in `` for QA analysis meters (#1869) Closes #1851 This changes how we use the `` component: previously, we didn't set a `max` value on it, so it was drawing its internal (rounded) bar at 100% of the meter width, and then drawing the ``s inside that 100% width bar. This changes that, and instead it now does the following: - Draws the internal rounded bar to the width of the proportion of their counts to the total page count; - Adjusts the ``s to be proportional to the completed page count rather than the total page count - Uses the `"available"` slot in `` to draw the remaining "No data" bar & tooltip in the remaining space outside of the internal rounded bar This also includes a couple unrelated but adjacent changes: - Changes the page count text to say "Analysis starting" when the analysis run is starting, because there's no meaningful page count at that point. - Uses the pending state when the total page count is falsy (`undefined` or `0`), rather than just `undefined` --- .../pages/org/archived-item-detail/ui/qa.ts | 96 +++++++++++++------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/frontend/src/pages/org/archived-item-detail/ui/qa.ts b/frontend/src/pages/org/archived-item-detail/ui/qa.ts index 3747ec90..c1f6ee80 100644 --- a/frontend/src/pages/org/archived-item-detail/ui/qa.ts +++ b/frontend/src/pages/org/archived-item-detail/ui/qa.ts @@ -44,7 +44,7 @@ import { formatNumber, getLocale } from "@/utils/localization"; import { pluralOf } from "@/utils/pluralize"; type QAStatsThreshold = { - lowerBoundary: `${number}` | "No data"; + lowerBoundary: `${number}`; count: number; }; type QAStats = Record<"screenshotMatch" | "textMatch", QAStatsThreshold[]>; @@ -505,9 +505,7 @@ export class ArchivedItemDetailQA extends TailwindElement {
- ${when( - qaRun.stats, - (stats) => html` -
- ${formatNumber(stats.done)} / ${formatNumber(stats.found)} - ${pluralOf("pages", stats.found)} ${msg("analyzed")} -
- `, - )} +
+ ${qaRun.state === "starting" + ? msg("Analysis starting") + : `${formatNumber(qaRun.stats.done)}/${formatNumber(qaRun.stats.found)} + ${pluralOf("pages", qaRun.stats.found)} ${msg("analyzed")}`} +
+ @@ -585,6 +582,7 @@ export class ArchivedItemDetailQA extends TailwindElement { ? this.renderMeter( qaRun.stats.found, this.qaStats.value.textMatch, + isRunning, ) : this.renderMeter()} @@ -613,16 +611,39 @@ export class ArchivedItemDetailQA extends TailwindElement { `; } - private renderMeter(pageCount?: number, barData?: QAStatsThreshold[]) { - if (pageCount === undefined || !barData) { + private renderMeter(): TemplateResult<1>; + private renderMeter( + pageCount: number, + barData: QAStatsThreshold[], + qaIsRunning: boolean | undefined, + ): TemplateResult<1>; + private renderMeter( + pageCount?: number, + barData?: QAStatsThreshold[], + qaIsRunning?: boolean, + ) { + if (!pageCount || !barData) { return html``; } + barData = barData.filter( + (bar) => (bar.lowerBoundary as string) !== "No data", + ); + + const analyzedPageCount = barData.reduce( + (prev, cur) => prev + cur.count, + 0, + ); + + const remainingPageCount = pageCount - analyzedPageCount; + const remainderBarLabel = qaIsRunning ? msg("Pending") : msg("Incomplete"); + + console.log({ pageCount, barData, analyzedPageCount }); return html` - + ${barData.map((bar) => { const threshold = qaStatsThresholds.find( ({ lowerBoundary }) => bar.lowerBoundary === lowerBoundary, @@ -632,23 +653,20 @@ export class ArchivedItemDetailQA extends TailwindElement { return bar.count !== 0 ? html`
- ${bar.lowerBoundary === "No data" - ? msg("No Data") - : threshold?.label} + ${threshold?.label}
- ${bar.lowerBoundary !== "No data" - ? html`${idx === 0 - ? `<${+qaStatsThresholds[idx + 1].lowerBoundary * 100}%` - : idx === qaStatsThresholds.length - 1 - ? `>=${threshold ? +threshold.lowerBoundary * 100 : 0}%` - : `${threshold ? +threshold.lowerBoundary * 100 : 0}-${+qaStatsThresholds[idx + 1].lowerBoundary * 100 || 100}%`} - match
` - : nothing} + ${idx === 0 + ? `<${+qaStatsThresholds[idx + 1].lowerBoundary * 100}%` + : idx === qaStatsThresholds.length - 1 + ? `>=${threshold ? +threshold.lowerBoundary * 100 : 0}%` + : `${threshold ? +threshold.lowerBoundary * 100 : 0}-${+qaStatsThresholds[idx + 1].lowerBoundary * 100 || 100}%`} + ${msg("match", { desc: "label for match percentage" })} +
${formatNumber(bar.count)} ${pluralOf("pages", bar.count)}
@@ -656,6 +674,24 @@ export class ArchivedItemDetailQA extends TailwindElement { ` : nothing; })} + ${remainingPageCount > 0 + ? html` + +
+ ${remainderBarLabel} +
+ ${formatNumber(remainingPageCount)} + ${pluralOf("pages", remainingPageCount)} +
+
+
+ ` + : nothing}
`; }