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

195 lines (194 loc) 5.91 kB
import { jsxs as i, jsx as t, Fragment as b } from "react/jsx-runtime"; import { useRestoreEntities as E, usePurgeEntities as L, useGetItemsInTrashCanInfinite as N } from "../../synapse-queries/trash/useTrashCan.js"; import { formatDate as j } from "../../utils/functions/DateFormatter.js"; import { entityTypeToFriendlyName as z } from "../../utils/functions/EntityTypeUtils.js"; import { Typography as m, Alert as T, Box as V, Button as l } from "@mui/material"; import { useReactTable as F, getCoreRowModel as H, createColumnHelper as O } from "@tanstack/react-table"; import Y from "dayjs"; import { useState as h, useMemo as w } from "react"; import { CheckBoxCell as A, CheckBoxHeader as G } from "../EntityHeaderTable/EntityHeaderTableCellRenderers.js"; import { EntityLink as W } from "../EntityLink.js"; import { BlockingLoader as q, SynapseSpinner as J } from "../LoadingScreen/LoadingScreen.js"; import { WarningDialog as K } from "../SynapseForm/WarningDialog.js"; import Q from "../TanStackTable/StyledTanStackTable.js"; function U(o) { return o.filter( (e) => e.status === "rejected" ).map((e) => e.reason); } const r = O(); function X(o) { return [ { id: "select", header: G, cell: A, maxSize: 50 }, r.accessor("entityId", { header: "ID" }), r.accessor("entityName", { header: "Name" }), r.accessor("entityType", { header: "Entity Type", cell: (e) => z(e.getValue()) }), r.accessor("originalParentId", { header: "Location", cell: (e) => /* @__PURE__ */ i(b, { children: [ e.getValue() && /* @__PURE__ */ t(W, { entity: e.getValue() }), " (", e.getValue(), ")" ] }), size: 200 }), r.accessor("deletedOn", { header: "Deleted On", cell: (e) => j(Y(e.getValue())) }), { id: "restoreButton", header: "", cell: ({ row: e }) => /* @__PURE__ */ t( l, { size: "small", variant: "outlined", onClick: () => { o(e.original.entityId), e.toggleSelected(!1); }, children: "Restore" } ), maxSize: 100 } ]; } function de() { const [o, e] = h(!1), [u, g] = h([]), [R, f] = h({}); function y(n, x) { n ? g(U(n)) : x && g([x]), f({}); } const { mutate: s, isPending: v } = E({ onSettled: y }), { mutate: I, isPending: p } = L({ onSettled: y }), P = v || p, { data: C, isLoading: c, hasNextPage: k, fetchNextPage: D, isFetchingNextPage: B } = N({ throwOnError: !0 }), d = w( () => C?.pages.flatMap((n) => n.results) ?? [], [C] ), M = w( () => X((n) => { s(n); }), [s] ), S = F({ data: d, columns: M, state: { rowSelection: R }, getRowId: (n) => n.entityId, enableRowSelection: !0, onRowSelectionChange: f, getCoreRowModel: H(), columnResizeMode: "onChange" }), a = S.getSelectedRowModel().rows.map((n) => n.original.entityId); return /* @__PURE__ */ i("div", { children: [ /* @__PURE__ */ t( q, { show: P, headlineText: p ? "Deleting..." : "Restoring..." } ), /* @__PURE__ */ t(m, { variant: "body1", children: 'The trash can contains items that were recently deleted. You can recover deleted items in the trash can by clicking "Restore". Items will remain in the trash can for 30 days before being automatically purged.' }), /* @__PURE__ */ t( K, { title: "Delete selected items from your Trash?", content: /* @__PURE__ */ t(m, { variant: "body1", children: "You can't undo this action." }), confirmButtonText: "Delete", confirmButtonColor: "error", onConfirm: () => { I(a), e(!1); }, onCancel: () => { e(!1); }, open: o } ), c && /* @__PURE__ */ t(J, {}), !c && d.length === 0 && /* @__PURE__ */ t(T, { severity: "info", sx: { my: 2 }, children: /* @__PURE__ */ t(m, { variant: "body1", children: "Your trash can is currently empty." }) }), !c && d.length > 0 && /* @__PURE__ */ i(b, { children: [ /* @__PURE__ */ t( Q, { table: S, styledTableContainerProps: { sx: { my: 4 } } } ), u.length > 0 && /* @__PURE__ */ i(T, { severity: "error", sx: { mb: 1 }, children: [ "The following errors were encountered:", /* @__PURE__ */ t("ul", { style: { marginBottom: 0 }, children: u.map((n) => /* @__PURE__ */ t("li", { children: n.message }, n.message)) }) ] }), /* @__PURE__ */ i( V, { sx: { display: "flex", justifyContent: "flex-end", gap: 2 }, children: [ k && /* @__PURE__ */ t( l, { variant: "contained", disabled: B, onClick: () => { D(); }, children: "Load More" } ), /* @__PURE__ */ t("div", { style: { margin: "auto" } }), /* @__PURE__ */ t( l, { variant: "contained", color: "error", disabled: a.length === 0, onClick: () => { e(!0); }, children: "Delete Selected" } ), /* @__PURE__ */ t( l, { variant: "outlined", disabled: a.length === 0, onClick: () => { s(a); }, children: "Restore Selected" } ) ] } ) ] }) ] }); } export { de as TrashCanList, de as default }; //# sourceMappingURL=TrashCanList.js.map