@coko/client
Version:
Client side common code for coko apps
160 lines (159 loc) • 4.33 kB
JavaScript
import { th as e } from "../../toolkit/themeHelper.js";
import "../../toolkit/index.js";
import t from "./InviteRowProp.js";
import { useState as n } from "react";
import r from "styled-components";
import { jsx as i } from "react/jsx-runtime";
import { Table as a } from "antd";
import { MenuOutlined as o } from "@ant-design/icons";
import { DndContext as s, PointerSensor as c, closestCenter as l, useSensor as u, useSensors as d } from "@dnd-kit/core";
import { SortableContext as f, arrayMove as p, useSortable as m, verticalListSortingStrategy as h } from "@dnd-kit/sortable";
import { CSS as g } from "@dnd-kit/utilities";
//#region src/ui/assignReviewers/ReviewerTable.tsx
var _ = r.div`
border: 1px solid grey;
padding: 16px;
`, v = r.div`
color: ${e("colorTextPlaceholder")};
font-size: ${e("fontSizeBaseSmall")};
font-style: italic;
`, y = r(a)`
/* Ensure table rows can be transformed for drag and drop */
.ant-table-tbody > tr {
&.ant-table-row {
position: relative;
}
}
`, b = r(o)`
cursor: grab;
touch-action: none;
`, x = (e) => {
let { attributes: t, listeners: n, setNodeRef: r, transform: a, isDragging: o } = m({ id: e["data-row-key"] }), s = !o && a !== null, c = {
...e.style,
transform: g.Translate.toString(a),
transition: s ? "transform 200ms ease" : void 0,
cursor: o ? "grabbing" : "grab",
...o ? {
position: "relative",
zIndex: 9999,
opacity: .8,
background: "white"
} : {}
};
return /* @__PURE__ */ i("tr", {
...e,
ref: r,
style: c,
...t,
...n
});
}, S = (e) => /* @__PURE__ */ i("tr", { ...e }), C = (e) => {
let { additionalColumns: r = [], canInviteMore: a, canDismissReviewer: o = !1, className: m, manualSorting: g = !1, onChange: C, onInvite: w, onRemoveRow: T, onRevokeInvitation: E, reviewers: D = [], showEmails: O = !1 } = e, [k, A] = n({}), j = g ? {} : k, M = d(u(c, { activationConstraint: { distance: 1 } })), N = ({ active: e, over: t }) => {
e.id !== t?.id && C(p(D, D.findIndex((t) => t.id === e.id), D.findIndex((e) => e.id === t?.id)));
};
if (D.length === 0) return /* @__PURE__ */ i(_, {
className: m,
children: /* @__PURE__ */ i(v, { children: "No reviewers have been added to the list" })
});
let P = (e, t, n, r) => {
C(r.currentDataSource);
let i = Array.isArray(n) ? n[0] : n;
A(g ? {} : i);
}, F = [
...g ? [{
key: "sort",
width: 40,
render: () => /* @__PURE__ */ i(b, {})
}] : [],
{
title: "Name",
dataIndex: "displayName",
key: "displayName",
sorter: (e, t) => e.displayName.toLowerCase().localeCompare(t.displayName.toLowerCase()),
sortDirections: ["ascend", "descend"]
},
{
title: "",
dataIndex: "inviteStatus",
key: "inviteStatus",
render: (e, n) => /* @__PURE__ */ i(t, {
className: m,
data: n,
type: "status"
})
},
...O ? [{
title: "Email",
dataIndex: "email",
key: "email",
sorter: (e, t) => (e.email ?? "").toLowerCase().localeCompare((t.email ?? "").toLowerCase()),
sortDirections: ["ascend", "descend"]
}] : [],
...r,
{
title: "",
dataIndex: "inviteAction",
key: "inviteAction",
render: (e, n) => /* @__PURE__ */ i(t, {
canInvite: a,
className: m,
data: n,
onClickInvite: w,
onClickRevokeInvitation: E,
type: "action"
}),
align: "right"
},
{
title: "",
dataIndex: "removeRow",
key: "removeRow",
render: (e, n) => /* @__PURE__ */ i(t, {
canDismissReviewer: o,
canInvite: a,
className: m,
data: n,
onClickRemove: T,
type: "remove"
})
}
].map((e) => {
let t = e;
if (g) {
let { sorter: e, ...n } = t;
return {
...n,
sortOrder: void 0
};
}
return {
...e,
sortOrder: j.columnKey === t.key ? j.order : void 0
};
}), I = D.map((e) => ({
...e,
key: e.id
})), L = I.map((e) => e.key), R = /* @__PURE__ */ i(y, {
columns: F,
components: g ? { body: { row: x } } : { body: { row: S } },
dataSource: I,
onChange: P,
pagination: !1,
rowKey: "key"
}, `manual-sorting-${g}`);
return /* @__PURE__ */ i(_, {
className: m,
children: g ? /* @__PURE__ */ i(s, {
collisionDetection: l,
onDragEnd: N,
sensors: M,
children: /* @__PURE__ */ i(f, {
items: L,
strategy: h,
children: R
})
}) : R
});
};
//#endregion
export { C as default };