UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

237 lines (236 loc) 7.45 kB
import { jsx as r, Fragment as S, jsxs as R } from "react/jsx-runtime"; import "../../synapse-client/SynapseClient.js"; import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode"; import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse"; import "@sage-bionetworks/synapse-client/util/SynapseClientError"; import { TERMS_OF_USE_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as I, SELF_SIGN_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as F, MANAGED_ACT_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as h, ACT_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as U, LOCK_ACCESS_REQUIREMENT_CONCRETE_TYPE_VALUE as O, LOCK_ACCESS_REQUIREMENT_CONCRETE_TYPE_DISPLAY_VALUE as q, ACT_ACCESS_REQUIREMENT_CONCRETE_TYPE_DISPLAY_VALUE as w, MANAGED_ACT_ACCESS_REQUIREMENT_CONCRETE_TYPE_DISPLAY_VALUE as Q, SELF_SIGN_ACCESS_REQUIREMENT_CONCRETE_TYPE_DISPLAY_VALUE as v, TERMS_OF_USE_ACCESS_REQUIREMENT_CONCRETE_TYPE_DISPLAY_VALUE as x } from "@sage-bionetworks/synapse-types"; import "../../utils/functions/EntityTypeUtils.js"; import { PRODUCTION_ENDPOINT_CONFIG as G } from "../../utils/functions/getEndpoint.js"; import { noop as $ } from "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../utils/PermissionLevelToAccessType.js"; import { ACT_TEAM_ID as j } from "../../utils/SynapseConstants.js"; import { useState as k, useMemo as c, useCallback as H, Fragment as K } from "react"; import "../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; import { Link as z, Typography as B } from "@mui/material"; import "../../utils/hooks/useCookiePreferences.js"; import "../../utils/hooks/useSourceAppConfigs.js"; import "universal-cookie"; import "../../utils/AppUtils/session/ApplicationSessionContext.js"; import "../../utils/context/FullContextProvider.js"; import "../../utils/context/DocumentMetadataContext.js"; import '../../style/components/_spinner.css';/* empty css */ import "@tanstack/query-core"; import "lodash-es/isEmpty"; import "lodash-es/isEqual"; import "lodash-es/xorWith"; import "react-router"; import "@sage-bionetworks/synapse-client"; import "../../utils/types/IsType.js"; import { useSearchAccessRequirementsInfinite as J } from "../../synapse-queries/dataaccess/useAccessRequirements.js"; import { formatDate as f } from "../../utils/functions/DateFormatter.js"; import { useReactTable as W, getCoreRowModel as X, getFacetedUniqueValues as Z, createColumnHelper as ee } from "@tanstack/react-table"; import A from "dayjs"; import { EntityLink as te } from "../EntityLink.js"; import a from "../TanStackTable/ColumnHeader.js"; import g from "../UserOrTeamBadge/UserOrTeamBadge.js"; function N(e) { switch (e) { case I: return x; case F: return v; case h: return Q; case U: return w; case O: return q; default: return "Unknown"; } } const re = [ I, F, h, U, O ], ne = (e) => /^\d+$/.test(e), l = ee(), ie = [ l.accessor("id", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "AR ID" }), cell: ({ getValue: e }) => /* @__PURE__ */ r( z, { href: `${G.PORTAL}AccessRequirement:AR_ID=${e()}`, children: e() } ), enableSorting: !1, enableColumnFilter: !1 }), l.accessor("name", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Access Requirement Name" }), cell: ({ getValue: e }) => e(), enableSorting: !0, enableColumnFilter: !1 }), l.accessor("type", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Type" }), cell: ({ getValue: e }) => N(e()), enableSorting: !1, enableColumnFilter: !0, meta: { filterVariant: "enumeration", getDisplayText: N, enableMultipleSelect: !1 } }), l.accessor("relatedProjectIds", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Related to Projects" }), cell: ({ getValue: e }) => /* @__PURE__ */ r(S, { children: e().map((t) => /* @__PURE__ */ R(K, { children: [ /* @__PURE__ */ r(te, { entity: t }), " ", /* @__PURE__ */ R( B, { component: "span", variant: "smallText1", sx: { color: "grey.700" }, children: [ "(", t, ")" ] } ), /* @__PURE__ */ r("br", {}) ] }, t)) }), enableSorting: !1, enableColumnFilter: !1 }), l.accessor("reviewerIds", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Reviewer" }), cell: ({ getValue: e }) => /* @__PURE__ */ r(S, { children: e().length === 0 ? /* @__PURE__ */ r(g, { principalId: j }) : e().map((t) => /* @__PURE__ */ r(g, { principalId: t }, t)) }), enableSorting: !1, enableColumnFilter: !1 }), l.accessor("modifiedOn", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Last Modified" }), cell: ({ getValue: e }) => f(A(e())), enableSorting: !1, enableColumnFilter: !1 }), l.accessor("createdOn", { header: (e) => /* @__PURE__ */ r(a, { ...e, title: "Created On" }), cell: ({ getValue: e }) => f(A(e())), enableSorting: !0, enableColumnFilter: !1 }) ], oe = [ { desc: !0, id: "createdOn" } ]; function ae(e) { const t = e.desc ? "DESC" : "ASC"; if (e.id == "createdOn") return { field: "CREATED_ON", direction: t }; if (e.id == "name") return { field: "NAME", direction: t }; throw new Error( `Could not map sort field ${e.id} to AccessRequirementSortField` ); } function le(e) { const s = (e || []).find((m) => m.id === "type")?.value; if (s) return s[0]; } function Ke(e) { const { nameOrID: t, relatedProjectId: s, reviewerId: m, accessType: p, typeFilter: E, onTypeFilterChange: u = $ } = e, [C, L] = k( oe ), _ = c( () => E ? [{ id: "type", value: [E] }] : [], [E] ), M = H( (n) => { const i = typeof n == "function" ? n(_) : n, o = le(i); u(o); }, [_, u] ), T = c( () => C.map(ae), [C] ), P = c(() => { let n, i; if (t !== void 0) { const o = t.trim(); ne(o) ? i = [Number.parseInt(o)] : n = o; } return { ids: i, nameContains: n, relatedProjectId: s, reviewerId: m, accessType: p, sort: T, type: E }; }, [ t, s, m, p, T, E ]), { data: d, hasNextPage: b, fetchNextPage: y, isLoading: D, isFetchingNextPage: Y } = J(P), V = c( () => d?.pages.flatMap((n) => n.results) ?? [], [d] ); return { table: W({ data: V, columns: ie, state: { sorting: C, columnFilters: _ }, getFacetedUniqueValues: (n, i) => i === "type" ? () => new Map(re.map((o) => [o, 0])) : Z()( n, i ), onSortingChange: L, onColumnFiltersChange: M, getRowId: (n) => n.id, getCoreRowModel: X(), columnResizeMode: "onChange", manualSorting: !0, enableMultiSort: !1, // Sort is required for this API call, so prevent the user from removing the sort. enableSortingRemoval: !1, manualFiltering: !0 }), isLoading: D, hasNextPage: b, fetchNextPage: y, isFetchingNextPage: Y }; } export { N as accessRequirementConcreteTypeValueToDisplayValue, Ke as useAccessRequirementTable }; //# sourceMappingURL=UseAccessRequirementTable.js.map