synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
118 lines (117 loc) • 3.64 kB
JavaScript
import { jsx as t } from "react/jsx-runtime";
import D from "../layout/InfiniteTableLayout.js";
import { useSearchAccessApprovalsInfinite as R } from "../../synapse-queries/dataaccess/useAccessApprovals.js";
import { formatDate as m } from "../../utils/functions/DateFormatter.js";
import { PRODUCTION_ENDPOINT_CONFIG as I } from "../../utils/functions/getEndpoint.js";
import { AccessApprovalSortField as i, Direction as d } from "@sage-bionetworks/synapse-types";
import { useReactTable as C, getCoreRowModel as T, createColumnHelper as v } from "@tanstack/react-table";
import p from "dayjs";
import { upperFirst as M } from "lodash-es";
import { useState as V, useMemo as u } from "react";
import o from "../TanStackTable/ColumnHeader.js";
import E from "../TanStackTable/StyledTanStackTable.js";
import F from "../UserOrTeamBadge/UserOrTeamBadge.js";
const s = v(), P = [
s.accessor("accessRequirementId", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "AR ID" }),
enableSorting: !1,
cell: (e) => /* @__PURE__ */ t(
"a",
{
href: `${I.PORTAL}AccessRequirement:AR_ID=${e.getValue()}`,
target: "_blank",
children: e.getValue()
}
)
}),
s.accessor("accessRequirementName", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "Access Requirement Name" }),
enableSorting: !1
}),
s.accessor("submitterId", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "Submitter" }),
enableSorting: !1,
cell: (e) => /* @__PURE__ */ t(F, { principalId: e.getValue() })
}),
s.accessor("state", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "Status" }),
enableSorting: !1,
cell: (e) => M(e.getValue().toLocaleLowerCase())
}),
s.accessor("modifiedOn", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "Modified Date" }),
enableSorting: !0,
cell: (e) => m(p(e.getValue()))
}),
s.accessor("expiredOn", {
header: (e) => /* @__PURE__ */ t(o, { ...e, title: "Expires" }),
enableSorting: !0,
cell: (e) => /* @__PURE__ */ t(
"span",
{
className: `${e.getValue() ? /* @__PURE__ */ new Date() > new Date(e.getValue()) ? "expired" : "" : "non-expire"} remove-border`,
children: e.getValue() ? m(p(e.getValue())) : "Never"
}
)
})
];
function w(e) {
if (e.length === 0)
return;
const a = e[0];
let r = i.MODIFIED_ON;
return a.id === "modifiedOn" ? r = i.MODIFIED_ON : a.id === "expiredOn" && (r = i.EXPIRED_ON), [
{
field: r,
direction: a.desc ? d.DESC : d.ASC
}
];
}
function X({
accessorId: e,
accessRequirementId: a
}) {
const [r, g] = V([
{
desc: !0,
id: "modifiedOn"
}
]), f = u(
() => ({
accessorId: e,
accessRequirementId: a,
sort: w(r)
}),
[e, a, r]
), { data: l, hasNextPage: S, fetchNextPage: b, isLoading: n, isFetchingNextPage: h } = R(f), A = u(
() => l?.pages.flatMap((O) => O.results) ?? [],
[l?.pages]
), c = C({
data: A,
columns: P,
getCoreRowModel: T(),
manualSorting: !0,
onSortingChange: g,
state: {
sorting: r
},
columnResizeMode: "onChange"
}), N = !n && c.getRowModel().rows.length === 0;
return /* @__PURE__ */ t("div", { className: "AccessApprovalsTable", children: /* @__PURE__ */ t(
D,
{
table: /* @__PURE__ */ t(E, { table: c }),
isLoading: n,
isEmpty: N,
hasNextPage: S,
onFetchNextPageClicked: () => {
b();
},
isFetchingNextPage: h
}
) });
}
export {
X as AccessApprovalsTable
};
//# sourceMappingURL=AccessApprovalsTable.js.map