Download web/src/artifacts/WorklistTable.tsx from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 3.71 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/artifacts/WorklistTable.tsx
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/artifacts/WorklistTable.tsx
-
curl -L -o WorklistTable.tsx https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/artifacts/WorklistTable.tsx
3.71 kB
| import type { ReactNode } from "react"; | |
| import { safeWorklistLink, worklistText } from "./worklistApi"; | |
| import type { WorklistCell, WorklistColumn, WorklistPage } from "./worklistApi"; | |
| export function worklistFigure(value: unknown, money = false): string { | |
| return typeof value === "number" && Number.isFinite(value) | |
| ? value.toLocaleString(undefined, money ? { minimumFractionDigits: 2, maximumFractionDigits: 2 } : { maximumFractionDigits: 20 }) | |
| : worklistText(value); | |
| } | |
| function Cell({ column, value }: { column: WorklistColumn; value: WorklistCell }) { | |
| if (value == null || value === "") return null; | |
| if (column.type === "link") { | |
| const href = safeWorklistLink(value); | |
| return href ? <a href={href} target="_blank" rel="noopener noreferrer">Open {worklistText(column.label)}</a> : <>Link unavailable.</>; | |
| } | |
| return <>{column.type === "money" || column.type === "number" ? worklistFigure(value, column.type === "money") : worklistText(value)}</>; | |
| } | |
| export default function WorklistTable({ page, details, loading, problem, onShowMore, onRetry }: { | |
| page: WorklistPage | null; details?: ReactNode; loading: boolean; problem: string; onShowMore: () => void; onRetry: () => void; | |
| }) { | |
| return <section className="ar-worklist" aria-label="Worklist" aria-busy={loading}> | |
| {details || page?.validation.length ? <details className="ar-details"> | |
| <summary>Details</summary><div className="ar-details-content">{details} | |
| {page?.validation.length ? <ul className="ar-validation" aria-label="Odoo validation"> | |
| {page.validation.map((check, index) => <li className={check.ok ? "ar-validation-pass" : "ar-validation-fail"} key={index}> | |
| <span className="ar-validation-check">{worklistText(check.check)}</span> | |
| <span className="ar-validation-figures">Worklist: {worklistFigure(check.a)} · Odoo: {worklistFigure(check.b)}</span> | |
| <span className="ar-validation-status">{check.ok ? "Ties to Odoo" : "Does not tie to Odoo"}</span> | |
| </li>)} | |
| </ul> : null} | |
| </div> | |
| </details> : null} | |
| {page ? <> | |
| {page.rows.length ? <> | |
| <p className="ar-worklist-count" role="status">{page.rows.length.toLocaleString()} of {page.total.toLocaleString()} rows</p> | |
| <div className="ar-worklist-scroll" tabIndex={0} role="region" aria-label="Worklist table"> | |
| <table className="ar-worklist-table" aria-label={worklistText(page.title)}> | |
| <thead><tr>{page.columns.map((column) => <th key={column.key} scope="col" | |
| className={column.type === "number" || column.type === "money" ? "ar-numeric" : undefined}>{worklistText(column.label)}</th>)}</tr></thead> | |
| <tbody>{page.rows.map((row, rowIndex) => <tr key={rowIndex}>{page.columns.map((column, index) => <td key={column.key} | |
| className={column.type === "number" || column.type === "money" ? "ar-numeric" : undefined}> | |
| <Cell column={column} value={Array.isArray(row) ? row[index] : row[column.key]} /> | |
| </td>)}</tr>)}</tbody> | |
| </table> | |
| </div> | |
| </> : <p className="ar-worklist-empty" role="status">Nothing found.</p>} | |
| </> : null} | |
| {loading ? <div className="ar-worklist-loading" role="status" aria-label="Loading worklist"><span /><span /></div> : null} | |
| {problem ? <p className="ar-worklist-problem" role="status"><span>{worklistText(problem)}</span>{" "} | |
| <button type="button" className="ar-retry" disabled={loading} onClick={onRetry}>Try again</button></p> : null} | |
| {page && page.rows.length < page.total ? <button className="ar-button ar-worklist-more" type="button" | |
| disabled={loading} onClick={onShowMore}>Show more</button> : null} | |
| </section>; | |
| } | |