synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
81 lines (80 loc) • 2.36 kB
JavaScript
import { jsx as i, jsxs as g } from "react/jsx-runtime";
import { PaginationItem as x, Pagination as I, Typography as b, Select as z, MenuItem as O } from "@mui/material";
import { useCallback as C, forwardRef as M } from "react";
import { useQueryContext as T } from "../QueryContext/QueryContext.js";
import { useSuspenseGetQueryMetadata as w } from "../QueryWrapper/useGetQueryMetadata.js";
import { usePrefetchTableRows as R } from "./usePrefetchTableData.js";
const m = [10, 25, 100, 500], G = () => {
const { goToPage: a, pageSize: s, setPageSize: f, currentPage: l, currentQueryRequest: p } = T(), c = R(), {
data: { queryCount: n, maxRowsPerPage: r }
} = w(), u = p.query.limit ?? s;
let o = r ? m.filter((e) => e < r) : [...m];
if (n) {
const e = o.findIndex(
(t) => t >= n
);
e !== -1 && (o = o.slice(0, e + 1));
}
const d = o.includes(u) ? u : o[0], P = (e, t) => {
a(t);
}, h = (e) => {
const t = e.target.value;
f(t), a(1);
}, y = C(
(e) => {
const t = M(
function(v, S) {
return /* @__PURE__ */ i(
"button",
{
ref: S,
...v,
onMouseOver: () => {
e.page && c(e.page);
}
}
);
}
);
return /* @__PURE__ */ i(x, { ...e, component: t });
},
[c]
);
return l == 1 && n == 1 && s != 1 || n == null || r && r < 5 ? null : /* @__PURE__ */ g("div", { children: [
/* @__PURE__ */ i(
I,
{
page: l,
count: Math.ceil(n / d),
color: "secondary",
onChange: P,
shape: "rounded",
sx: {
display: "inline-block",
float: "left",
".MuiPaginationItem-root": { fontSize: "14px" }
},
renderItem: y
}
),
/* @__PURE__ */ i(b, { variant: "body1", style: { display: "inline-block" }, children: `${n?.toLocaleString()} total rows /` }),
/* @__PURE__ */ i(
z,
{
name: "page size",
value: d,
size: "small",
onChange: h,
sx: { ml: 0.5 },
children: o.map((e) => /* @__PURE__ */ g(O, { value: e, children: [
e,
" per page"
] }, e))
}
)
] });
};
export {
G as TablePagination
};
//# sourceMappingURL=TablePagination.js.map