@bahmni/admin-app 0.0.1-dev.451 → 0.0.1-dev.453

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,227 +0,0 @@
1
- import { jsx as d, jsxs as h, Fragment as Y } from "react/jsx-runtime";
2
- import { d as x, u as G, z as J, J as W, Y as X, h as Z, I as ee, a as te } from "./index-D408E2pe.js";
3
- import { useQuery as ae } from "@tanstack/react-query";
4
- import { useState as l, useCallback as _, useEffect as D, useMemo as p } from "react";
5
- const ne = "DocumentsTable-module_documentsTableBody__6iR3w", oe = "DocumentsTable-module_viewAttachmentsLink__aQ1on", de = "DocumentsTable-module_documentViewerContainer__F5m8D", re = "DocumentsTable-module_attachmentItem__17KA7", se = "DocumentsTable-module_attachmentCounter__WFiI3", me = "DocumentsTable-module_attachmentError__RI4U2", ce = "DocumentsTable-module_documentIframe__ptq5I", le = "DocumentsTable-module_documentImage__KQVgS", r = {
6
- documentsTableBody: ne,
7
- viewAttachmentsLink: oe,
8
- documentViewerContainer: de,
9
- attachmentItem: re,
10
- attachmentCounter: se,
11
- attachmentError: me,
12
- documentIframe: ce,
13
- documentImage: le
14
- }, ue = {
15
- documentIdentifier: "DOCUMENTS_DOCUMENT_IDENTIFIER",
16
- documentType: "DOCUMENTS_TYPE",
17
- uploadedOn: "DOCUMENTS_UPLOADED_ON",
18
- uploadedBy: "DOCUMENTS_UPLOADED_BY",
19
- attachments: "DOCUMENTS_ATTACHMENTS"
20
- };
21
- function R(a) {
22
- return !a || a.includes(":") ? "#" : `/openmrs/auth?requested_document=/document_images/${a}`;
23
- }
24
- function ie(a, E) {
25
- return a.map((s) => ({
26
- key: s,
27
- header: E(ue[s])
28
- }));
29
- }
30
- const Te = [
31
- "documentIdentifier",
32
- "documentType",
33
- "attachments",
34
- "uploadedOn",
35
- "uploadedBy"
36
- ], he = /\.(jpg|jpeg|png|gif|webp|bmp|svg)$/i, B = (a) => a.attachments.length > 0 ? a.attachments : a.documentUrl ? [{ url: a.documentUrl, contentType: a.contentType }] : [], Ie = ({ config: a, encounterUuids: E }) => {
37
- const [s, w] = l(!1), [o, U] = l(
38
- null
39
- ), [$, O] = l(
40
- /* @__PURE__ */ new Set()
41
- ), g = x(), { t: n } = G(), { addNotification: L } = J(), k = Number(a?.pageSize) || 5, [f, C] = l(1), [u, V] = l(k), [F, A] = l(void 0), M = _((e) => {
42
- U(e), w(!0);
43
- }, []), H = _(() => {
44
- w(!1), U(null), O(/* @__PURE__ */ new Set());
45
- }, []), v = _((e) => {
46
- O((t) => new Set(t).add(e));
47
- }, []), { data: i, isLoading: q, isError: y, error: b } = ae({
48
- queryKey: [
49
- "documents",
50
- g,
51
- E,
52
- f,
53
- u
54
- ],
55
- enabled: !!g,
56
- queryFn: () => W(
57
- g,
58
- E,
59
- u,
60
- f
61
- )
62
- });
63
- D(() => {
64
- i && A(i.total);
65
- }, [i]), D(() => {
66
- C(1), A(void 0);
67
- }, [g]), D(() => {
68
- y && L({
69
- title: n("ERROR_DEFAULT_TITLE"),
70
- message: b?.message ?? "",
71
- type: "error"
72
- });
73
- }, [y, b, L, n]), D(() => {
74
- const e = new AbortController();
75
- return (async () => {
76
- if (!s || !o) return;
77
- const t = /* @__PURE__ */ new Set(), m = B(o);
78
- for (let c = 0; c < m.length; c++) {
79
- const S = R(m[c].url);
80
- try {
81
- (await fetch(S, {
82
- method: "HEAD",
83
- signal: e.signal
84
- })).ok || t.add(c);
85
- } catch (N) {
86
- N instanceof Error && N.name !== "AbortError" && t.add(c);
87
- }
88
- }
89
- e.signal.aborted || O(t);
90
- })(), () => e.abort();
91
- }, [s, o]);
92
- const z = _(
93
- (e, t) => {
94
- t !== u ? (V(t), C(1), A(void 0)) : C(e);
95
- },
96
- [u]
97
- ), I = p(
98
- () => a?.fields ?? Te,
99
- [a?.fields]
100
- ), j = p(() => [...i?.documents ?? []].sort((e, t) => !e.uploadedOn && !t.uploadedOn ? 0 : e.uploadedOn ? t.uploadedOn ? new Date(t.uploadedOn).getTime() - new Date(e.uploadedOn).getTime() : -1 : 1), [i]), P = p(() => ie(I, n), [I, n]), K = p(
101
- () => I.map((e) => ({
102
- key: e,
103
- sortable: e !== "attachments"
104
- })),
105
- [I]
106
- ), T = p(
107
- () => o ? B(o) : [],
108
- [o]
109
- ), Q = _(
110
- (e, t) => {
111
- switch (t) {
112
- case "documentIdentifier":
113
- return /* @__PURE__ */ d("span", { children: e.documentIdentifier });
114
- case "documentType":
115
- return e.documentType ?? n("DOCUMENTS_NOT_AVAILABLE");
116
- case "uploadedOn":
117
- return Z(
118
- e.uploadedOn,
119
- n,
120
- !0
121
- ).formattedResult || n("DOCUMENTS_NOT_AVAILABLE");
122
- case "uploadedBy":
123
- return e.uploadedBy ?? n("DOCUMENTS_NOT_AVAILABLE");
124
- case "attachments":
125
- return e.attachments.length > 0 || e.documentUrl ? /* @__PURE__ */ d(
126
- X,
127
- {
128
- onClick: () => M(e),
129
- className: r.viewAttachmentsLink,
130
- "data-testid": `view-attachments-${e.id}`,
131
- children: n("DOCUMENTS_VIEW_ATTACHMENTS")
132
- }
133
- ) : "--";
134
- default:
135
- return null;
136
- }
137
- },
138
- [M, n]
139
- );
140
- return /* @__PURE__ */ h(Y, { children: [
141
- /* @__PURE__ */ d("div", { "data-testid": "documents-table", children: /* @__PURE__ */ d(
142
- ee,
143
- {
144
- headers: P,
145
- ariaLabel: n("DOCUMENTS_TABLE_HEADING"),
146
- rows: j,
147
- loading: q,
148
- errorStateMessage: y ? b?.message : null,
149
- sortable: K,
150
- emptyStateMessage: n("DOCUMENTS_NO_RECORDS"),
151
- renderCell: Q,
152
- className: r.documentsTableBody,
153
- dataTestId: "documents-table",
154
- pageSize: u,
155
- totalItems: F,
156
- page: f,
157
- onPageChange: z
158
- }
159
- ) }),
160
- s && o && /* @__PURE__ */ d(
161
- te,
162
- {
163
- id: "modalIdForActionAreaLayout",
164
- portalId: "main-display-area",
165
- open: s,
166
- onRequestClose: H,
167
- modalHeading: o.documentIdentifier,
168
- passiveModal: !0,
169
- size: "lg",
170
- testId: "document-view-modal",
171
- children: /* @__PURE__ */ d("div", { className: r.documentViewerContainer, children: T.map((e, t) => {
172
- const m = R(e.url), c = e.contentType?.toLowerCase().includes("pdf"), S = (e.contentType?.toLowerCase().includes("image") ?? !1) || he.test(e.url ?? ""), N = $.has(t);
173
- return m === "#" || N ? /* @__PURE__ */ h(
174
- "div",
175
- {
176
- className: r.attachmentError,
177
- "data-testid": `attachment-error-${t}`,
178
- children: [
179
- T.length > 1 && /* @__PURE__ */ h("p", { className: r.attachmentCounter, children: [
180
- t + 1,
181
- "/",
182
- T.length
183
- ] }),
184
- /* @__PURE__ */ d("p", { children: n("DOCUMENTS_ERROR_LOADING_ATTACHMENT") })
185
- ]
186
- },
187
- `${o.id}-${e.url}`
188
- ) : /* @__PURE__ */ h(
189
- "div",
190
- {
191
- className: r.attachmentItem,
192
- "data-testid": `attachment-item-${t}`,
193
- children: [
194
- T.length > 1 && /* @__PURE__ */ h("p", { className: r.attachmentCounter, children: [
195
- t + 1,
196
- "/",
197
- T.length
198
- ] }),
199
- S ? /* @__PURE__ */ d(
200
- "img",
201
- {
202
- src: m,
203
- alt: o.documentIdentifier,
204
- className: r.documentImage,
205
- onError: () => v(t)
206
- }
207
- ) : /* @__PURE__ */ d(
208
- "iframe",
209
- {
210
- src: c ? `${m}#toolbar=0` : m,
211
- className: r.documentIframe,
212
- title: o.documentIdentifier,
213
- onError: () => v(t)
214
- }
215
- )
216
- ]
217
- },
218
- `${o.id}-${e.url}`
219
- );
220
- }) })
221
- }
222
- )
223
- ] });
224
- };
225
- export {
226
- Ie as default
227
- };