@addsign/moje-agenda-shared-lib 1.0.60 → 2.0.0

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.
Files changed (128) hide show
  1. package/dist/Dialog-DZMfjbGC.js +421 -0
  2. package/dist/Dialog-DZMfjbGC.js.map +1 -0
  3. package/dist/assets/style.css +4369 -0
  4. package/dist/assets/tailwind.css +1365 -1193
  5. package/dist/check-B7dJm08z.js +12 -0
  6. package/dist/check-B7dJm08z.js.map +1 -0
  7. package/dist/components/Button.js +1 -1
  8. package/dist/components/datatable/DataTable.js +6 -2
  9. package/dist/components/datatable/DataTable.js.map +1 -1
  10. package/dist/components/datatable/DataTableServer.js +6 -2
  11. package/dist/components/datatable/DataTableServer.js.map +1 -1
  12. package/dist/components/form/AutocompleteSearchBar.js +6 -2
  13. package/dist/components/form/AutocompleteSearchBar.js.map +1 -1
  14. package/dist/components/form/AutocompleteSearchBarServer.js +6 -2
  15. package/dist/components/form/AutocompleteSearchBarServer.js.map +1 -1
  16. package/dist/components/form/FileInput.js +7 -3
  17. package/dist/components/form/FileInput.js.map +1 -1
  18. package/dist/components/form/FileInputMultiple.js +7 -3
  19. package/dist/components/form/FileInputMultiple.js.map +1 -1
  20. package/dist/components/form/FormField.js +6 -2
  21. package/dist/components/form/FormField.js.map +1 -1
  22. package/dist/components/form/PositionsSelectorSingle.js +6 -2
  23. package/dist/components/form/PositionsSelectorSingle.js.map +1 -1
  24. package/dist/components/form/SelectField.js +6 -2
  25. package/dist/components/form/SelectField.js.map +1 -1
  26. package/dist/components/profiles/ProfileOverview.js +6 -2
  27. package/dist/components/profiles/ProfileOverview.js.map +1 -1
  28. package/dist/components/ui/Combobox.d.ts +1 -0
  29. package/dist/components/ui/Combobox.js +138 -0
  30. package/dist/components/ui/Combobox.js.map +1 -0
  31. package/dist/components/ui/DateTimePicker.js +19 -5
  32. package/dist/components/ui/DateTimePicker.js.map +1 -1
  33. package/dist/components/ui/Dialog.js +15 -413
  34. package/dist/components/ui/Dialog.js.map +1 -1
  35. package/dist/components/ui/ScrollArea.js +2 -1
  36. package/dist/components/ui/ScrollArea.js.map +1 -1
  37. package/dist/components/ui/command.d.ts +80 -0
  38. package/dist/components/ui/command.js +643 -0
  39. package/dist/components/ui/command.js.map +1 -0
  40. package/dist/components/ui/datepicker.js +14 -1
  41. package/dist/components/ui/datepicker.js.map +1 -1
  42. package/dist/components/ui/popover.js +3 -2
  43. package/dist/components/ui/popover.js.map +1 -1
  44. package/dist/components/ui/radioGroup.d.ts +5 -0
  45. package/dist/components/ui/radioGroup.js +586 -0
  46. package/dist/components/ui/radioGroup.js.map +1 -0
  47. package/dist/components/ui/select.js +9 -144
  48. package/dist/components/ui/select.js.map +1 -1
  49. package/dist/index-BXrwe-_7.js +1395 -0
  50. package/dist/index-BXrwe-_7.js.map +1 -0
  51. package/dist/index-Bk8dRTPE.js +11 -0
  52. package/dist/index-Bk8dRTPE.js.map +1 -0
  53. package/dist/index-BlzC-wss.js +140 -0
  54. package/dist/index-BlzC-wss.js.map +1 -0
  55. package/dist/index-Bp9GiUkg.js +2266 -0
  56. package/dist/index-Bp9GiUkg.js.map +1 -0
  57. package/dist/index-BzVVosDl.js +57 -0
  58. package/dist/index-BzVVosDl.js.map +1 -0
  59. package/dist/index-CbAQSs_C.js +40 -0
  60. package/dist/index-CbAQSs_C.js.map +1 -0
  61. package/dist/index-Dz_fWpFA.js +2203 -0
  62. package/dist/index-Dz_fWpFA.js.map +1 -0
  63. package/dist/index-IXOTxK3N.js +7 -0
  64. package/dist/index-IXOTxK3N.js.map +1 -0
  65. package/dist/main.d.ts +3 -0
  66. package/dist/main.js +29 -12
  67. package/dist/main.js.map +1 -1
  68. package/dist/parse-D2yb8751.js +1727 -0
  69. package/dist/parse-D2yb8751.js.map +1 -0
  70. package/dist/tailwind-l0sNRNKZ.js +2 -0
  71. package/dist/tailwind-l0sNRNKZ.js.map +1 -0
  72. package/lib/components/Button.tsx +57 -0
  73. package/lib/components/Calendar.tsx +242 -0
  74. package/lib/components/ConfirmationModalDialog.tsx +115 -0
  75. package/lib/components/Modal.tsx +73 -0
  76. package/lib/components/ModalDialog.tsx +63 -0
  77. package/lib/components/Spinner.tsx +25 -0
  78. package/lib/components/SpinnerIcon.tsx +12 -0
  79. package/lib/components/datatable/DataTable.tsx +442 -0
  80. package/lib/components/datatable/DataTableServer.tsx +939 -0
  81. package/lib/components/datatable/DatatableSettings.tsx +48 -0
  82. package/lib/components/datatable/Resizable.tsx +99 -0
  83. package/lib/components/datatable/types.ts +33 -0
  84. package/lib/components/form/AutocompleteSearchBar.tsx +424 -0
  85. package/lib/components/form/AutocompleteSearchBarServer.tsx +257 -0
  86. package/lib/components/form/DateField.tsx +124 -0
  87. package/lib/components/form/DateRangeField.tsx +116 -0
  88. package/lib/components/form/FileInput.tsx +188 -0
  89. package/lib/components/form/FileInputMultiple.tsx +186 -0
  90. package/lib/components/form/FormField.tsx +371 -0
  91. package/lib/components/form/InputField.tsx +230 -0
  92. package/lib/components/form/PositionsSelectorSingle.tsx +266 -0
  93. package/lib/components/form/RadioGroup.tsx +64 -0
  94. package/lib/components/form/SelectField.tsx +267 -0
  95. package/lib/components/layout/IconInCircle.tsx +29 -0
  96. package/lib/components/layout/PageTitle.tsx +19 -0
  97. package/lib/components/layout/SectionTitle.tsx +22 -0
  98. package/lib/components/profiles/ProfileOverview.tsx +212 -0
  99. package/lib/components/ui/Calendar.tsx +68 -0
  100. package/lib/components/ui/Combobox.tsx +122 -0
  101. package/lib/components/ui/DatePicker.tsx +124 -0
  102. package/lib/components/ui/DateTimePicker.tsx +187 -0
  103. package/lib/components/ui/Dialog.tsx +118 -0
  104. package/lib/components/ui/ScrollArea.tsx +45 -0
  105. package/lib/components/ui/button.tsx +56 -0
  106. package/lib/components/ui/command.tsx +153 -0
  107. package/lib/components/ui/form.tsx +177 -0
  108. package/lib/components/ui/input.tsx +22 -0
  109. package/lib/components/ui/label.tsx +24 -0
  110. package/lib/components/ui/popover.tsx +31 -0
  111. package/lib/components/ui/radioGroup.tsx +44 -0
  112. package/lib/components/ui/select.tsx +158 -0
  113. package/lib/contexts/FederationContext.tsx +28 -0
  114. package/lib/contexts/useFederationContext.ts +4 -0
  115. package/lib/css/tailwind.css +10 -0
  116. package/lib/fonts/arial.ts +3 -0
  117. package/lib/fonts/arialBold.ts +4 -0
  118. package/lib/main.ts +64 -0
  119. package/lib/types.ts +492 -0
  120. package/lib/utils/PdfManager.ts +224 -0
  121. package/lib/utils/getFullName.tsx +83 -0
  122. package/lib/utils/getIntersectingDays.ts +28 -0
  123. package/lib/utils/handleErrors.ts +28 -0
  124. package/lib/utils/hasRightInModule.ts +17 -0
  125. package/lib/utils/hasRole.ts +12 -0
  126. package/lib/utils/utils.ts +6 -0
  127. package/lib/vite-env.d.ts +1 -0
  128. package/package.json +5 -2
@@ -0,0 +1,442 @@
1
+ import React, { useEffect, useState } from "react";
2
+
3
+ import { Button, FormField, Spinner } from "../../main";
4
+ import {
5
+ MdArrowBack,
6
+ MdArrowDownward,
7
+ MdArrowForward,
8
+ MdArrowUpward,
9
+ MdClose,
10
+ MdOutlineFilterAlt,
11
+ MdOutlineFilterAltOff,
12
+ MdSearch,
13
+ } from "react-icons/md";
14
+
15
+ export interface DataTableColumn<T> {
16
+ key: keyof T | "actions";
17
+ header: string;
18
+ render?: (item: T) => React.ReactNode;
19
+ actions?: DataTableAction<T>[];
20
+ filterType?: string;
21
+ classes?: string;
22
+ type?: "string" | "number" | "date";
23
+ filterOperator?: ">=" | "<=" | "==";
24
+ }
25
+ export interface DataTableAction<T> {
26
+ label: string;
27
+ onClick: (item: T) => void;
28
+ visible?: (item: T) => boolean;
29
+ icon?: React.ReactNode;
30
+ }
31
+ interface DataTableProps<T> {
32
+ items: T[];
33
+ columns: DataTableColumn<T | "actions">[];
34
+ itemsPerPage?: number;
35
+ title?: string;
36
+ subtitle?: string;
37
+ allowSearch?: boolean;
38
+ isLoading?: boolean;
39
+ }
40
+
41
+ type DataTableInternalItems = {
42
+ _isHighlighted?: boolean;
43
+ };
44
+
45
+ function DataTable<T extends DataTableInternalItems>({
46
+ items,
47
+ columns,
48
+ itemsPerPage = 10,
49
+ title,
50
+ subtitle,
51
+ allowSearch = true,
52
+ isLoading,
53
+ }: DataTableProps<T>) {
54
+ const [currentPage, setCurrentPage] = useState(0);
55
+ const [fulltextSearch, setFulltextSearch] = useState("");
56
+ const [filterOptions, setFilterOptions] = useState<Record<string, any[]>>({});
57
+ const [columnFilters, setColumnFilters] = useState<Record<string, string>>(
58
+ {}
59
+ );
60
+
61
+ const [showColFilters, setShowColFilters] = useState(false);
62
+
63
+ const [sortConfig, setSortConfig] = useState<{
64
+ key: keyof T | "actions";
65
+ direction: "ascending" | "descending" | null;
66
+ } | null>(null);
67
+
68
+ useEffect(() => {
69
+ const newFilterOptions: Record<string, any[]> = {};
70
+
71
+ columns.forEach((column) => {
72
+ if (column.filterType && items.length > 0) {
73
+ const uniqueOptions = new Set(
74
+ items.map((item) => item[column.key as keyof T])
75
+ );
76
+ // Convert Set to an array of { value, label } objects
77
+ let sortedOptions = Array.from(uniqueOptions).map((option) => ({
78
+ value: option,
79
+ label:
80
+ column.type === "date"
81
+ ? new Date(option as string)?.toLocaleDateString()
82
+ : option,
83
+ }));
84
+
85
+ // Sort the options array by label in ascending alphabetical order
86
+ if (column.type === "date") {
87
+ // Convert labels to timestamps and sort accordingly
88
+ sortedOptions = sortedOptions.sort((a, b) => {
89
+ const timestampA = new Date(a.value as string).getTime();
90
+ const timestampB = new Date(b.value as string).getTime();
91
+ return timestampA - timestampB;
92
+ });
93
+ } else {
94
+ // Sort alphabetically by label for non-date columns
95
+ sortedOptions = sortedOptions.sort((a, b) =>
96
+ (a.label as string)?.localeCompare(b.label as string)
97
+ );
98
+ }
99
+
100
+ // Add a default option if needed
101
+ newFilterOptions[column.key as string] = [
102
+ { value: "", label: "" },
103
+ ...sortedOptions,
104
+ ];
105
+ }
106
+ });
107
+
108
+ setFilterOptions(newFilterOptions);
109
+ }, [items, columns]);
110
+
111
+ const requestSort = (key: keyof T | "actions") => {
112
+ if (sortConfig?.key === key && sortConfig.direction !== null) {
113
+ setSortConfig({
114
+ key,
115
+ direction: sortConfig.direction === "ascending" ? "descending" : null,
116
+ });
117
+ } else {
118
+ setSortConfig({ key, direction: "ascending" });
119
+ }
120
+ };
121
+
122
+ const getSortIcon = (key: keyof T | "actions") => {
123
+ if (sortConfig?.key === key) {
124
+ return sortConfig.direction === "ascending" ? (
125
+ <MdArrowUpward fontSize="small" />
126
+ ) : sortConfig.direction === "descending" ? (
127
+ <MdArrowDownward fontSize="small" />
128
+ ) : (
129
+ <MdArrowUpward
130
+ fontSize="small"
131
+ className="text-gray-300 invisible group-hover:visible "
132
+ />
133
+ );
134
+ }
135
+ return (
136
+ <MdArrowUpward
137
+ fontSize="small"
138
+ className="text-gray-300 invisible group-hover:visible "
139
+ />
140
+ );
141
+ };
142
+
143
+ const sortedItems = sortConfig?.direction
144
+ ? [...items].sort((a, b) => {
145
+ const aValue = a[sortConfig.key as keyof T];
146
+ const bValue = b[sortConfig.key as keyof T];
147
+
148
+ // Check if values are Date objects
149
+ if (aValue instanceof Date && bValue instanceof Date) {
150
+ return sortConfig.direction === "ascending"
151
+ ? aValue.getTime() - bValue.getTime()
152
+ : bValue.getTime() - aValue.getTime();
153
+ }
154
+ if (typeof aValue === "number" && typeof bValue === "number") {
155
+ return sortConfig.direction === "ascending"
156
+ ? aValue - bValue
157
+ : bValue - aValue;
158
+ }
159
+ return sortConfig.direction === "ascending"
160
+ ? String(aValue).localeCompare(String(bValue))
161
+ : String(bValue).localeCompare(String(aValue));
162
+ })
163
+ : items;
164
+
165
+ // const searchableKeys = new Set(
166
+ // columns.filter((col) => !col.actions).map((col) => col.key)
167
+ // );
168
+
169
+ const filteredItems = sortedItems.filter((item: any) => {
170
+ const textSearchMatch = fulltextSearch
171
+ ? columns.some((column) => {
172
+ const value = item[column.key];
173
+ return (
174
+ (typeof value === "string" || typeof value === "number") &&
175
+ value
176
+ .toString()
177
+ .toLowerCase()
178
+ .includes(fulltextSearch.toLowerCase())
179
+ );
180
+ })
181
+ : true;
182
+
183
+ const columnFiltersMatch = columns.every((column) => {
184
+ // debugger;
185
+ const filterValue = columnFilters[column.key as string];
186
+ if (!filterValue) return true; // Ignore filter if 'None' is selected
187
+
188
+ const itemValue = item[column.key];
189
+ if ((column.type || typeof itemValue) === "string") {
190
+ if (column.filterOperator == ">=") {
191
+ return itemValue.toLowerCase() >= filterValue.toLowerCase();
192
+ } else if (column.filterOperator == "<=") {
193
+ return itemValue.toLowerCase() <= filterValue.toLowerCase();
194
+ }
195
+ if (column.filterType == "text") {
196
+ return itemValue.toLowerCase().includes(filterValue.toLowerCase());
197
+ } else {
198
+ return itemValue.toLowerCase() == filterValue.toLowerCase();
199
+ }
200
+ } else {
201
+ if (column.filterOperator == ">=") {
202
+ return itemValue >= filterValue;
203
+ } else if (column.filterOperator == "<=") {
204
+ return itemValue <= filterValue;
205
+ } else {
206
+ return itemValue == filterValue;
207
+ }
208
+ }
209
+ });
210
+
211
+ return textSearchMatch && columnFiltersMatch;
212
+ });
213
+
214
+ // Pagination logic
215
+ const indexOfLastItem = (currentPage + 1) * itemsPerPage;
216
+ const indexOfFirstItem = indexOfLastItem - itemsPerPage;
217
+ const currentItems = filteredItems.slice(indexOfFirstItem, indexOfLastItem);
218
+
219
+ const nextPage = () => {
220
+ setCurrentPage(currentPage + 1);
221
+ };
222
+
223
+ const prevPage = () => {
224
+ setCurrentPage(currentPage - 1);
225
+ };
226
+ const handleSearchChanged = (
227
+ e: React.ChangeEvent<
228
+ HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
229
+ >
230
+ ) => {
231
+ setFulltextSearch(e.target?.value);
232
+ setCurrentPage(0);
233
+ };
234
+
235
+ const totalPages = Math.max(
236
+ 1,
237
+ Math.ceil(filteredItems.length / itemsPerPage)
238
+ );
239
+
240
+ // Pagination display logic
241
+ const paginationDisplay = `Strana ${currentPage + 1} z ${totalPages}`;
242
+
243
+ const filterHandler = (key: keyof T, value: string) => {
244
+ setColumnFilters((prev) => ({ ...prev, [key]: value }));
245
+ setCurrentPage(0);
246
+ };
247
+
248
+ if (isLoading) return <Spinner />;
249
+ return (
250
+ <>
251
+ <div className="container shadow-lg border border-gray-200 rounded-xl overflow-hidden ">
252
+ {(title || subtitle || allowSearch) && (
253
+ <div className="p-5 leading-9 flex ">
254
+ <div className="flex-grow">
255
+ {title && (
256
+ <h1 className="font-semibold text-xl leading-[42px] ">
257
+ {title}
258
+ </h1>
259
+ )}
260
+ {subtitle && (
261
+ <p className="font-normal text-gray-600">{subtitle}</p>
262
+ )}
263
+ </div>
264
+ <div
265
+ className="flex items-center text-xl h-full p-3 mr-5 cursor-pointer text-gray-500 "
266
+ onClick={() => setShowColFilters(!showColFilters)}
267
+ >
268
+ {!showColFilters && <MdOutlineFilterAlt />}
269
+ {showColFilters && <MdOutlineFilterAltOff />}
270
+ </div>
271
+ {allowSearch && (
272
+ <div className="">
273
+ <FormField
274
+ placeholder="Vyhledávání"
275
+ name="search"
276
+ onInputChange={handleSearchChanged}
277
+ type="text"
278
+ value={fulltextSearch}
279
+ >
280
+ {" "}
281
+ <div className=" text-gray-500 leading-5 flex items-center h-full">
282
+ {!fulltextSearch && <MdSearch></MdSearch>}
283
+ {fulltextSearch && (
284
+ <MdClose onClick={() => setFulltextSearch("")}></MdClose>
285
+ )}
286
+ </div>
287
+ </FormField>
288
+ </div>
289
+ )}
290
+ </div>
291
+ )}
292
+ <div className="overflow-x-auto">
293
+ <table className="w-full leading-normal">
294
+ <thead>
295
+ {showColFilters &&
296
+ columns.findIndex((it) => it.filterType) > -1 && (
297
+ <tr>
298
+ {columns.map(({ key, header, filterType }) => (
299
+ <th
300
+ key={String(key) + "_filter"}
301
+ // className="cursor-pointer px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-sm font-medium text-gray-600 uppercase tracking-wider"
302
+ className={` font-medium cursor-pointer !leading-9 text-xs text-left pl-5 pb-5 text-gray-600 ${
303
+ !title && !subtitle ? "border-t-0" : ""
304
+ }`}
305
+ >
306
+ {filterType && (
307
+ <FormField
308
+ label={header}
309
+ name={String(key) + "_filter"}
310
+ onInputChange={(e) =>
311
+ filterHandler(key as keyof T, e.target.value)
312
+ }
313
+ type={filterType}
314
+ options={filterOptions[String(key)] || []}
315
+ value={columnFilters[String(key)]}
316
+ clearable
317
+ ></FormField>
318
+ )}
319
+ </th>
320
+ ))}
321
+ </tr>
322
+ )}
323
+ <tr>
324
+ {columns.map(({ key, header, actions }) => (
325
+ <th
326
+ key={String(key)}
327
+ // className="cursor-pointer px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-sm font-medium text-gray-600 uppercase tracking-wider"
328
+ className={`group font-medium cursor-pointer !leading-9 text-xs text-left px-5 text-gray-600 bg bg-gray-50 border-t border-b border-gray-200 ${
329
+ !title && !subtitle ? "border-t-0" : ""
330
+ }`}
331
+ onClick={() => requestSort(key)}
332
+ >
333
+ <span className="inline-flex items-center gap-2">
334
+ {header} {!actions ? getSortIcon(key) : ""}
335
+ </span>
336
+ </th>
337
+ ))}
338
+ </tr>
339
+ </thead>
340
+
341
+ <tbody>
342
+ {currentItems.map((item, rowIndex) => (
343
+ <tr
344
+ key={rowIndex}
345
+ className={`${
346
+ item._isHighlighted ? " bg-gray-200 " : " "
347
+ } hover:bg-gray-50 border-gray-200 border-b text-sm `}
348
+ >
349
+ {columns.map(({ render, actions, classes }, colIndex) => (
350
+ <td
351
+ key={`${rowIndex}-${colIndex}`}
352
+ className={`px-5 py-2
353
+ ${
354
+ colIndex == 0
355
+ ? " font-medium text-gray-900"
356
+ : " text-gray-700"
357
+ } ${classes}`}
358
+ >
359
+ {render ? render(item) : ""}
360
+ {actions &&
361
+ actions
362
+ .filter((it) => {
363
+ if (it.visible) {
364
+ return it.visible(item);
365
+ } else true;
366
+ })
367
+ .map((action, actionIndex) => (
368
+ <div
369
+ key={`${rowIndex}-${colIndex}-${actionIndex}`}
370
+ className="inline-flex align-middle"
371
+ >
372
+ {action.icon && (
373
+ <Button
374
+ variant="icon"
375
+ onClick={() => action.onClick(item)}
376
+ >
377
+ {" "}
378
+ {action.icon}
379
+ </Button>
380
+ )}
381
+ {!action.icon && (
382
+ <Button
383
+ variant="transparent"
384
+ onClick={() => action.onClick(item)}
385
+ >
386
+ {" "}
387
+ {action.label}
388
+ </Button>
389
+ )}
390
+ </div>
391
+ ))}
392
+ </td>
393
+ ))}
394
+ </tr>
395
+ ))}
396
+ {currentItems.length == 0 && (
397
+ <tr key="tr-nodata ">
398
+ <td
399
+ key="td-nodata"
400
+ className="px-5 py-3 border-b border-gray-200 bg-white text-sm items-center justify-center align-middle"
401
+ colSpan={columns.length}
402
+ >
403
+ Žádná data
404
+ </td>
405
+ </tr>
406
+ )}
407
+ </tbody>
408
+ </table>
409
+ </div>
410
+ <div className="w-full p-5 grid grid-cols-3">
411
+ <div className="text-left items-start justify-start">
412
+ {currentPage !== 0 && (
413
+ <Button
414
+ variant="secondary"
415
+ onClick={prevPage}
416
+ className="flex items-center float-left"
417
+ >
418
+ <MdArrowBack className="mr-1.5" /> Předchozí
419
+ </Button>
420
+ )}
421
+ </div>
422
+ <div className=" text-center text-xs text-gray-800">
423
+ {paginationDisplay} {/* Updated to use dynamic page numbers */}
424
+ </div>
425
+ <div className="text-right items-end justify-end">
426
+ {indexOfLastItem < filteredItems.length && (
427
+ <Button
428
+ variant="secondary"
429
+ onClick={nextPage}
430
+ className="flex items-center float-right"
431
+ >
432
+ Následující <MdArrowForward className="ml-2" size={20} />
433
+ </Button>
434
+ )}
435
+ </div>
436
+ </div>
437
+ </div>
438
+ </>
439
+ );
440
+ }
441
+
442
+ export default DataTable;