import * as React from "react";
import { useQuery } from "react-query";
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict";
import {
useTable,
useFilters,
useGlobalFilter,
useSortBy,
usePagination
} from "react-table";
import { APIClient } from "../api/APIClient";
import { EmptyListState } from "../components/emptystates";
import { ReleaseStatusCell } from "./Releases";
export function Dashboard() {
return (
)
}
const StatsItem = ({ name, stat }: any) => (
{name}
{stat}
)
function Stats() {
const { isLoading, data } = useQuery(
'dash_release_stats',
() => APIClient.release.stats(),
{ refetchOnWindowFocus: false }
);
if (isLoading)
return null;
return (
Stats
{/* */}
)
}
// This is a custom filter UI for selecting
// a unique option from a list
export function SelectColumnFilter({
column: { filterValue, setFilter, preFilteredRows, id, render },
}: any) {
// Calculate the options for filtering
// using the preFilteredRows
const options = React.useMemo(() => {
const options: any = new Set()
preFilteredRows.forEach((row: { values: { [x: string]: unknown } }) => {
options.add(row.values[id])
})
return [...options.values()]
}, [id, preFilteredRows])
// Render a multi-select box
return (
)
}
export function StatusPill({ value }: any) {
const statusMap: any = {
"FILTER_APPROVED": Approved,
"FILTER_REJECTED": Rejected,
"PUSH_REJECTED": Rejected,
"PUSH_APPROVED": Approved,
"PENDING": PENDING,
"MIXED": MIXED,
}
return statusMap[value];
}
export function AgeCell({ value }: any) {
const formatDate = formatDistanceToNowStrict(
new Date(value),
{ addSuffix: true }
)
return (
{formatDate}
)
}
export function ReleaseCell({ value }: any) {
return (
{value}
)
}
export function IndexerCell({ value }: any) {
return (
{value}
)
}
function Table({ columns, data }: any) {
// Use the state and functions returned from useTable to build your UI
const {
getTableProps,
getTableBodyProps,
headerGroups,
prepareRow,
page, // Instead of using 'rows', we'll use page,
// which has only the rows for the active page
// The rest of these things are super handy, too ;)
// canPreviousPage,
// canNextPage,
// pageOptions,
// pageCount,
// gotoPage,
// nextPage,
// previousPage,
// setPageSize,
// state,
// preGlobalFilteredRows,
// setGlobalFilter,
} = useTable({
columns,
data,
},
useFilters, // useFilters!
useGlobalFilter,
useSortBy,
usePagination, // new
);
if (!page.length)
return ;
// Render the UI for your table
return (
{headerGroup.headers.map((column) => {
const { key: columnKey, ...columnRest } = column.getHeaderProps(column.getSortByToggleProps());
return (
// Add the sorting props to control sorting. For this example
// we can add them into the header props