@vanillabp/bc-ui 0.0.3

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 (47) hide show
  1. package/README.md +1 -0
  2. package/dist/chunk-YH4NJHER.js +58 -0
  3. package/dist/components/ListCell.d.ts +27 -0
  4. package/dist/components/ListCell.js +123 -0
  5. package/dist/components/ListColumnHeader.d.ts +22 -0
  6. package/dist/components/ListColumnHeader.js +135 -0
  7. package/dist/components/ListOfTasks.d.ts +35 -0
  8. package/dist/components/ListOfTasks.js +1327 -0
  9. package/dist/components/ListOfWorkflows.d.ts +36 -0
  10. package/dist/components/ListOfWorkflows.js +974 -0
  11. package/dist/components/NoElementGivenByModule.d.ts +10 -0
  12. package/dist/components/NoElementGivenByModule.js +54 -0
  13. package/dist/components/NoUserTaskGiven.d.ts +10 -0
  14. package/dist/components/NoUserTaskGiven.js +23 -0
  15. package/dist/components/NoWorkflowGiven.d.ts +10 -0
  16. package/dist/components/NoWorkflowGiven.js +22 -0
  17. package/dist/components/SearchableAndSortableUpdatingList.d.ts +49 -0
  18. package/dist/components/SearchableAndSortableUpdatingList.js +200 -0
  19. package/dist/components/SnapScrolling.d.ts +15 -0
  20. package/dist/components/SnapScrolling.js +17 -0
  21. package/dist/components/SnapScrollingDataTable.d.ts +17 -0
  22. package/dist/components/SnapScrollingDataTable.js +113 -0
  23. package/dist/components/User.d.ts +11 -0
  24. package/dist/components/User.js +39 -0
  25. package/dist/components/UserAvatar.d.ts +12 -0
  26. package/dist/components/UserAvatar.js +133 -0
  27. package/dist/components/UserTaskPage.d.ts +24 -0
  28. package/dist/components/UserTaskPage.js +121 -0
  29. package/dist/components/WorkflowPage.d.ts +16 -0
  30. package/dist/components/WorkflowPage.js +124 -0
  31. package/dist/components/index.d.ts +25 -0
  32. package/dist/components/index.js +13 -0
  33. package/dist/index.d.ts +25 -0
  34. package/dist/index.js +3 -0
  35. package/dist/types/apis.d.ts +50 -0
  36. package/dist/types/apis.js +0 -0
  37. package/dist/types/index.d.ts +7 -0
  38. package/dist/types/index.js +3 -0
  39. package/dist/types/lists.d.ts +12 -0
  40. package/dist/types/lists.js +0 -0
  41. package/dist/types/navigate.d.ts +6 -0
  42. package/dist/types/navigate.js +0 -0
  43. package/dist/utils/index.d.ts +2 -0
  44. package/dist/utils/index.js +1 -0
  45. package/dist/utils/module-federation.d.ts +40 -0
  46. package/dist/utils/module-federation.js +182 -0
  47. package/package.json +66 -0
@@ -0,0 +1,974 @@
1
+ import {
2
+ __async,
3
+ __objRest,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../chunk-YH4NJHER.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { useEffect, useMemo, useRef, useState } from "react";
9
+ import { Box, CheckBox, Grid, Text, TextInput, Tip } from "grommet";
10
+ import {
11
+ colorForEndedItemsOrUndefined,
12
+ colorRowAccordingToUpdateStatus,
13
+ debounce,
14
+ DefaultListCell,
15
+ ENDED_FONT_COLOR,
16
+ Link,
17
+ ListCell as StyledListCell,
18
+ useResponsiveScreen
19
+ } from "@vanillabp/bc-shared";
20
+ import {
21
+ ListCell,
22
+ SearchableAndSortableUpdatingList,
23
+ TypeOfItem,
24
+ useFederationModules
25
+ } from "../index.js";
26
+ import { ListColumnHeader } from "./ListColumnHeader.js";
27
+ import { Clear, Refresh, Search } from "grommet-icons";
28
+ const minWidthOfTitleColumn = "20rem";
29
+ const updateModuleDefinitions = (workflows, existingModuleDefinitions, setModulesOfWorkflows, existingWorkflowDefinitions, setDefinitionsOfWorkflows) => {
30
+ const newModuleDefinitions = workflows.filter((workflow) => workflow.workflowModuleId !== void 0).reduce((moduleDefinitions, workflow) => moduleDefinitions.includes(workflow) ? moduleDefinitions : moduleDefinitions.concat(workflow), existingModuleDefinitions || []);
31
+ if ((existingModuleDefinitions == null ? void 0 : existingModuleDefinitions.length) !== newModuleDefinitions.length) {
32
+ setModulesOfWorkflows(newModuleDefinitions);
33
+ const newWorkflowDefinitions = __spreadValues({}, existingWorkflowDefinitions);
34
+ workflows.forEach((workflow) => newWorkflowDefinitions[`${workflow.workflowModuleId}#${workflow.bpmnProcessId}`] = workflow);
35
+ if (existingWorkflowDefinitions === void 0 || Object.keys(existingWorkflowDefinitions).length !== Object.keys(newWorkflowDefinitions).length) {
36
+ setDefinitionsOfWorkflows(newWorkflowDefinitions);
37
+ }
38
+ }
39
+ };
40
+ const loadWorkflows = (workflowlistApi, setNumberOfWorkflows, existingModuleDefinitions, setModulesOfWorkflows, existingWorkflowDefinitions, setDefinitionsOfWorkflows, pageSize, pageNumber, initialTimestamp, searchQueries, sort, sortAscending, mapToBcWorkflow) => __async(void 0, null, function* () {
41
+ const result = yield workflowlistApi.getWorkflows((/* @__PURE__ */ new Date()).getTime().toString(), pageNumber, pageSize, sort, sortAscending, searchQueries, initialTimestamp);
42
+ setNumberOfWorkflows(result.page.totalElements);
43
+ updateModuleDefinitions(result.workflows, existingModuleDefinitions, setModulesOfWorkflows, existingWorkflowDefinitions, setDefinitionsOfWorkflows);
44
+ return {
45
+ serverTimestamp: result.serverTimestamp,
46
+ items: result.workflows.map((workflow) => mapToBcWorkflow(workflow))
47
+ };
48
+ });
49
+ const reloadWorkflows = (workflowlistApi, setNumberOfWorkflows, existingModuleDefinitions, setModulesOfWorkflows, existingWorkflowDefinitions, setDefinitionsOfWorkflows, numberOfItems, knownItemsIds, initialTimestamp, searchQueries, sort, sortAscending, mapToBcWorkflow) => __async(void 0, null, function* () {
50
+ const result = yield workflowlistApi.getWorkflowsUpdate(
51
+ (/* @__PURE__ */ new Date()).getTime().toString(),
52
+ numberOfItems,
53
+ knownItemsIds,
54
+ sort,
55
+ sortAscending,
56
+ searchQueries,
57
+ initialTimestamp
58
+ );
59
+ setNumberOfWorkflows(result.page.totalElements);
60
+ updateModuleDefinitions(result.workflows, existingModuleDefinitions, setModulesOfWorkflows, existingWorkflowDefinitions, setDefinitionsOfWorkflows);
61
+ return {
62
+ serverTimestamp: result.serverTimestamp,
63
+ items: result.workflows.map((workflow) => mapToBcWorkflow(workflow))
64
+ };
65
+ });
66
+ const FulltextSearch = ({
67
+ t,
68
+ initialQuery,
69
+ limitListToKwic,
70
+ kwic
71
+ // focus = false,
72
+ }) => {
73
+ const { isPhone } = useResponsiveScreen();
74
+ const textFieldRef = useRef(null);
75
+ const [query, setQuery] = useState(initialQuery);
76
+ const currentQuery = useRef(initialQuery(void 0));
77
+ const [suggestions, setSuggestions] = useState(void 0);
78
+ const ignoreKeyEnter = useRef(false);
79
+ const select = (value, suggestion) => {
80
+ if (suggestion) {
81
+ ignoreKeyEnter.current = true;
82
+ } else if (ignoreKeyEnter.current) {
83
+ ignoreKeyEnter.current = false;
84
+ return;
85
+ }
86
+ if (value === void 0)
87
+ return;
88
+ setSuggestions(void 0);
89
+ setQuery(value);
90
+ currentQuery.current = value;
91
+ limitListToKwic(void 0, value);
92
+ };
93
+ const kwicDebounced = useMemo(() => debounce(() => __async(void 0, null, function* () {
94
+ const result = yield kwic(void 0, currentQuery.current);
95
+ const newSuggestions = result.map((r) => ({
96
+ value: r.item,
97
+ label: /* @__PURE__ */ jsxs(
98
+ Box,
99
+ {
100
+ direction: "row",
101
+ justify: "between",
102
+ pad: "xsmall",
103
+ children: [
104
+ /* @__PURE__ */ jsx(
105
+ Text,
106
+ {
107
+ weight: "bold",
108
+ truncate: "tip",
109
+ children: r.item
110
+ }
111
+ ),
112
+ /* @__PURE__ */ jsx(
113
+ Box,
114
+ {
115
+ align: "right",
116
+ children: r.count
117
+ }
118
+ )
119
+ ]
120
+ }
121
+ )
122
+ }));
123
+ setSuggestions(
124
+ newSuggestions.length > 20 ? [...newSuggestions.slice(0, 20), { value: void 0, label: /* @__PURE__ */ jsx(Box, { pad: "xsmall", children: t("kwic_to-many-hits") }) }] : newSuggestions
125
+ );
126
+ }), 300), [currentQuery, setSuggestions]);
127
+ const updateResult = (newQuery) => {
128
+ currentQuery.current = newQuery;
129
+ setQuery(newQuery);
130
+ if (newQuery.length < 3) {
131
+ if (suggestions) {
132
+ setSuggestions(void 0);
133
+ }
134
+ return;
135
+ }
136
+ kwicDebounced();
137
+ };
138
+ const clear = () => {
139
+ currentQuery.current = "";
140
+ setQuery("");
141
+ setSuggestions(void 0);
142
+ textFieldRef.current.focus();
143
+ limitListToKwic(void 0, void 0);
144
+ };
145
+ return /* @__PURE__ */ jsx(
146
+ Box,
147
+ {
148
+ width: isPhone ? "100%" : "min(100%, 30rem)",
149
+ elevation: "small",
150
+ alignContent: "center",
151
+ hoverIndicator: "white",
152
+ focusIndicator: false,
153
+ round: { size: "0.4rem" },
154
+ border: { color: "dark-4" },
155
+ children: /* @__PURE__ */ jsxs(
156
+ Grid,
157
+ {
158
+ columns: ["auto", "2rem"],
159
+ fill: true,
160
+ children: [
161
+ /* @__PURE__ */ jsx(
162
+ Box,
163
+ {
164
+ pad: { horizontal: "0.4rem", vertical: "0.25rem" },
165
+ direction: "row",
166
+ justify: "center",
167
+ children: /* @__PURE__ */ jsx(
168
+ TextInput,
169
+ {
170
+ plain: "full",
171
+ ref: textFieldRef,
172
+ value: query,
173
+ placeholder: t("kwic_placeholder"),
174
+ onKeyDown: (event) => event.key === "Enter" ? select(query, false) : void 0,
175
+ onChange: (event) => updateResult(event.target.value),
176
+ suggestions: suggestions === void 0 ? [] : suggestions.length === 0 ? [{ value: void 0, label: /* @__PURE__ */ jsx(Box, { pad: "xsmall", children: t("kwic_no-hit") }) }] : suggestions,
177
+ onSuggestionSelect: (x) => select(x.suggestion.value, true),
178
+ focusIndicator: false,
179
+ reverse: true
180
+ }
181
+ )
182
+ }
183
+ ),
184
+ /* @__PURE__ */ jsx(
185
+ Tip,
186
+ {
187
+ content: t("kwic_tooltip"),
188
+ children: /* @__PURE__ */ jsx(
189
+ Box,
190
+ {
191
+ align: "center",
192
+ justify: "center",
193
+ children: Boolean(query) ? /* @__PURE__ */ jsx(
194
+ Clear,
195
+ {
196
+ onMouseUp: clear,
197
+ color: "dark-4"
198
+ }
199
+ ) : /* @__PURE__ */ jsx(
200
+ Search,
201
+ {
202
+ color: "dark-4"
203
+ }
204
+ )
205
+ }
206
+ )
207
+ }
208
+ )
209
+ ]
210
+ }
211
+ )
212
+ }
213
+ );
214
+ };
215
+ const RefreshButton = ({
216
+ t,
217
+ disabled,
218
+ refresh
219
+ }) => {
220
+ const color = disabled ? "light-4" : "dark-3";
221
+ const textColor = disabled ? "dark-4" : "dark-1";
222
+ return /* @__PURE__ */ jsx(
223
+ Box,
224
+ {
225
+ hoverIndicator: disabled ? "light-2" : "accent-1",
226
+ focusIndicator: false,
227
+ onClick: refresh,
228
+ direction: "row",
229
+ elevation: "small",
230
+ background: !disabled ? { color: "accent-1", opacity: "strong" } : void 0,
231
+ round: { size: "0.4rem" },
232
+ border: { color },
233
+ children: /* @__PURE__ */ jsx(
234
+ Tip,
235
+ {
236
+ content: t("refresh_workflows"),
237
+ children: /* @__PURE__ */ jsx(
238
+ Box,
239
+ {
240
+ height: "2rem",
241
+ pad: { horizontal: "0.4rem" },
242
+ align: "center",
243
+ direction: "row",
244
+ justify: "center",
245
+ children: /* @__PURE__ */ jsx(
246
+ Refresh,
247
+ {
248
+ size: "20rem",
249
+ color: textColor
250
+ }
251
+ )
252
+ }
253
+ )
254
+ }
255
+ )
256
+ }
257
+ );
258
+ };
259
+ const DefaultFooter = ({
260
+ t,
261
+ isPhone,
262
+ isTablet,
263
+ numberOfWorkflows
264
+ }) => {
265
+ const isNotPhone = !isPhone;
266
+ return /* @__PURE__ */ jsxs(
267
+ Box,
268
+ {
269
+ direction: "row",
270
+ justify: "between",
271
+ align: "center",
272
+ children: [
273
+ /* @__PURE__ */ jsxs(
274
+ Box,
275
+ {
276
+ pad: "xsmall",
277
+ children: [
278
+ t("total"),
279
+ " ",
280
+ numberOfWorkflows
281
+ ]
282
+ }
283
+ ),
284
+ /* @__PURE__ */ jsxs(
285
+ Box,
286
+ {
287
+ direction: "row",
288
+ gap: "medium",
289
+ pad: "xsmall",
290
+ align: "center",
291
+ children: [
292
+ /* @__PURE__ */ jsxs(
293
+ Box,
294
+ {
295
+ direction: "row",
296
+ align: "center",
297
+ gap: "xsmall",
298
+ children: [
299
+ /* @__PURE__ */ jsx(
300
+ Box,
301
+ {
302
+ direction: "row",
303
+ height: "1rem",
304
+ border: { color: "light-4", size: "1px" },
305
+ children: /* @__PURE__ */ jsx(
306
+ Box,
307
+ {
308
+ width: "1rem",
309
+ height: "100%",
310
+ align: "center",
311
+ justify: "center",
312
+ background: "white",
313
+ children: /* @__PURE__ */ jsx(Text, { size: "xsmall", children: "T" })
314
+ }
315
+ )
316
+ }
317
+ ),
318
+ isNotPhone ? /* @__PURE__ */ jsx(Box, { children: t("legend_unchanged") }) : void 0
319
+ ]
320
+ }
321
+ ),
322
+ /* @__PURE__ */ jsxs(
323
+ Box,
324
+ {
325
+ direction: "row",
326
+ align: "center",
327
+ gap: "xsmall",
328
+ children: [
329
+ /* @__PURE__ */ jsx(
330
+ Box,
331
+ {
332
+ direction: "row",
333
+ height: "1rem",
334
+ border: { color: "light-4", size: "1px" },
335
+ children: /* @__PURE__ */ jsx(
336
+ Box,
337
+ {
338
+ width: "1rem",
339
+ height: "100%",
340
+ align: "center",
341
+ justify: "center",
342
+ background: { color: "accent-3", opacity: 0.1 },
343
+ children: /* @__PURE__ */ jsx(Text, { size: "xsmall", children: "T" })
344
+ }
345
+ )
346
+ }
347
+ ),
348
+ isNotPhone ? /* @__PURE__ */ jsx(Box, { children: t("legend_new") }) : void 0
349
+ ]
350
+ }
351
+ ),
352
+ /* @__PURE__ */ jsxs(
353
+ Box,
354
+ {
355
+ direction: "row",
356
+ align: "center",
357
+ gap: "xsmall",
358
+ children: [
359
+ /* @__PURE__ */ jsx(
360
+ Box,
361
+ {
362
+ direction: "row",
363
+ height: "1rem",
364
+ border: { color: "light-4", size: "1px" },
365
+ children: /* @__PURE__ */ jsx(
366
+ Box,
367
+ {
368
+ width: "1rem",
369
+ height: "100%",
370
+ align: "center",
371
+ justify: "center",
372
+ background: { color: "accent-1", opacity: 0.35 },
373
+ children: /* @__PURE__ */ jsx(Text, { size: "xsmall", children: "T" })
374
+ }
375
+ )
376
+ }
377
+ ),
378
+ isNotPhone ? /* @__PURE__ */ jsx(Box, { children: t("legend_updated") }) : void 0
379
+ ]
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsxs(
383
+ Box,
384
+ {
385
+ direction: "row",
386
+ align: "center",
387
+ gap: "xsmall",
388
+ children: [
389
+ /* @__PURE__ */ jsx(
390
+ Box,
391
+ {
392
+ direction: "row",
393
+ height: "1rem",
394
+ border: { color: "light-4", size: "1px" },
395
+ children: /* @__PURE__ */ jsx(
396
+ Box,
397
+ {
398
+ width: "1rem",
399
+ height: "100%",
400
+ align: "center",
401
+ justify: "center",
402
+ background: { color: "light-2", opacity: 0.5 },
403
+ children: /* @__PURE__ */ jsx(Text, { size: "xsmall", color: ENDED_FONT_COLOR, children: "T" })
404
+ }
405
+ )
406
+ }
407
+ ),
408
+ isNotPhone ? /* @__PURE__ */ jsx(Box, { children: t("legend_completed") }) : void 0
409
+ ]
410
+ }
411
+ ),
412
+ /* @__PURE__ */ jsxs(
413
+ Box,
414
+ {
415
+ direction: "row",
416
+ align: "center",
417
+ gap: "xsmall",
418
+ children: [
419
+ /* @__PURE__ */ jsx(
420
+ Box,
421
+ {
422
+ direction: "row",
423
+ height: "1rem",
424
+ border: { color: "light-4", size: "1px" },
425
+ children: /* @__PURE__ */ jsx(
426
+ Box,
427
+ {
428
+ width: "1rem",
429
+ height: "100%",
430
+ align: "center",
431
+ justify: "center",
432
+ background: { color: "light-2", opacity: 0.5 },
433
+ children: /* @__PURE__ */ jsx(Text, { size: "xsmall", children: "T" })
434
+ }
435
+ )
436
+ }
437
+ ),
438
+ isNotPhone ? /* @__PURE__ */ jsx(Box, { children: t("legend_filtered") }) : void 0
439
+ ]
440
+ }
441
+ )
442
+ ]
443
+ }
444
+ )
445
+ ]
446
+ },
447
+ "footer"
448
+ );
449
+ };
450
+ const DefaultHeader = ({
451
+ t,
452
+ isPhone,
453
+ isTablet,
454
+ numberOfWorkflows,
455
+ selectAll,
456
+ allSelected,
457
+ refresh,
458
+ refreshDisabled,
459
+ initialKwicQuery,
460
+ limitListToKwic,
461
+ kwic
462
+ }) => {
463
+ return /* @__PURE__ */ jsxs(
464
+ Box,
465
+ {
466
+ fill: true,
467
+ background: "white",
468
+ direction: "row",
469
+ align: "center",
470
+ justify: "start",
471
+ gap: "small",
472
+ pad: { horizontal: "xsmall" },
473
+ children: [
474
+ /* @__PURE__ */ jsx(
475
+ FulltextSearch,
476
+ {
477
+ t,
478
+ initialQuery: initialKwicQuery,
479
+ limitListToKwic,
480
+ kwic
481
+ }
482
+ ),
483
+ /* @__PURE__ */ jsx(
484
+ RefreshButton,
485
+ {
486
+ t,
487
+ refresh,
488
+ disabled: refreshDisabled
489
+ }
490
+ )
491
+ ]
492
+ }
493
+ );
494
+ };
495
+ const SelectDefaultListCell = ({
496
+ item,
497
+ selectItem
498
+ }) => {
499
+ const background = colorRowAccordingToUpdateStatus(item);
500
+ return /* @__PURE__ */ jsx(
501
+ StyledListCell,
502
+ {
503
+ background,
504
+ align: "center",
505
+ children: /* @__PURE__ */ jsx(
506
+ CheckBox,
507
+ {
508
+ checked: item.selected,
509
+ onChange: (event) => selectItem(event.currentTarget.checked)
510
+ }
511
+ )
512
+ }
513
+ );
514
+ };
515
+ const TitleDefaultListCell = ({
516
+ item,
517
+ currentLanguage
518
+ }) => {
519
+ const titleLanguages = Object.keys(item.data["title"]);
520
+ let title;
521
+ if (titleLanguages.includes(currentLanguage)) {
522
+ title = item.data["title"][currentLanguage];
523
+ } else {
524
+ title = item.data["title"][titleLanguages[0]];
525
+ }
526
+ const background = colorRowAccordingToUpdateStatus(item);
527
+ return /* @__PURE__ */ jsx(
528
+ StyledListCell,
529
+ {
530
+ align: "left",
531
+ background,
532
+ children: /* @__PURE__ */ jsx(
533
+ Text,
534
+ {
535
+ color: colorForEndedItemsOrUndefined(item),
536
+ weight: item.read === void 0 ? "bold" : "normal",
537
+ truncate: "tip",
538
+ children: /* @__PURE__ */ jsx(
539
+ Link,
540
+ {
541
+ onClick: item.data.navigateToWorkflow,
542
+ children: title
543
+ }
544
+ )
545
+ }
546
+ )
547
+ }
548
+ );
549
+ };
550
+ const WorkflowDefaultListCell = (_a) => {
551
+ var _b = _a, { column } = _b, props = __objRest(_b, ["column"]);
552
+ let Cell;
553
+ if (column.path === "id") {
554
+ Cell = SelectDefaultListCell;
555
+ } else if (column.path === "title") {
556
+ Cell = TitleDefaultListCell;
557
+ } else {
558
+ Cell = DefaultListCell;
559
+ }
560
+ return /* @__PURE__ */ jsx(
561
+ Cell,
562
+ __spreadValues({
563
+ column
564
+ }, props)
565
+ );
566
+ };
567
+ const ListOfWorkflows = ({
568
+ showLoadingIndicator,
569
+ useGuiSse,
570
+ useWorkflowlistApi,
571
+ openTask,
572
+ navigateToWorkflow,
573
+ currentLanguage,
574
+ defaultSort,
575
+ defaultSortAscending,
576
+ name,
577
+ columns,
578
+ children,
579
+ headerHeight = "3rem",
580
+ footer,
581
+ footerHeight = "2rem",
582
+ t,
583
+ rowSeparator,
584
+ applyBackgroundColor = true,
585
+ showColumnHeaders = true,
586
+ excludeIdColumn = false,
587
+ columnHeader,
588
+ columnHeaderBackground = "dark-3",
589
+ columnHeaderSeparator,
590
+ defaultSearchQueries = []
591
+ }) => {
592
+ const { isPhone, isTablet, isNotPhone } = useResponsiveScreen();
593
+ const wakeupSseCallback = useRef(void 0);
594
+ const workflowlistApi = useWorkflowlistApi(wakeupSseCallback);
595
+ const [refreshIndicator, setRefreshIndicator] = useState(/* @__PURE__ */ new Date());
596
+ const [searchQueries, setSearchQueries] = useState(defaultSearchQueries);
597
+ const updateListRef = useRef(void 0);
598
+ const updateList = useMemo(() => (ev) => __async(void 0, null, function* () {
599
+ if (!updateListRef.current)
600
+ return;
601
+ const listOfUpdatedWorkflows = ev.data.map((workflowEvent) => workflowEvent.event.id);
602
+ updateListRef.current(listOfUpdatedWorkflows);
603
+ }), [updateListRef]);
604
+ wakeupSseCallback.current = useGuiSse(
605
+ updateList,
606
+ /^Workflow$/
607
+ );
608
+ const refreshItemRef = useRef(void 0);
609
+ const mapToBcWorkflow = (workflow) => {
610
+ const getUserTasksFunction = (activeOnly, limitListAccordingToCurrentUsersPermissions) => __async(void 0, null, function* () {
611
+ return (yield workflowlistApi.getUserTasksOfWorkflow(
612
+ workflow.id,
613
+ activeOnly,
614
+ limitListAccordingToCurrentUsersPermissions
615
+ )).map((userTask) => __spreadProps(__spreadValues({}, userTask), {
616
+ open: () => openTask(userTask),
617
+ navigateToWorkflow: () => {
618
+ }
619
+ // don't change view because workflow is already shown
620
+ }));
621
+ });
622
+ return __spreadProps(__spreadValues({}, workflow), {
623
+ navigateToWorkflow: () => navigateToWorkflow(workflow),
624
+ getUserTasks: getUserTasksFunction
625
+ });
626
+ };
627
+ const workflows = useRef(void 0);
628
+ const [numberOfWorkflows, setNumberOfWorkflows] = useState(-1);
629
+ const [modulesOfWorkflows, setModulesOfWorkflows] = useState(void 0);
630
+ const [languagesOfTitles, setLanguagesOfTitles] = useState([currentLanguage]);
631
+ const [definitionsOfWorkflows, setDefinitionsOfWorkflows] = useState(void 0);
632
+ useEffect(
633
+ () => {
634
+ const loadMetaInformation = () => __async(void 0, null, function* () {
635
+ const result = yield loadWorkflows(
636
+ workflowlistApi,
637
+ setNumberOfWorkflows,
638
+ modulesOfWorkflows,
639
+ setModulesOfWorkflows,
640
+ definitionsOfWorkflows,
641
+ setDefinitionsOfWorkflows,
642
+ 20,
643
+ 0,
644
+ void 0,
645
+ searchQueries,
646
+ effectiveSort,
647
+ sortAscending,
648
+ mapToBcWorkflow
649
+ );
650
+ const titleLanguages = result.items.flatMap((workflow) => Object.keys(workflow.title)).reduce((allLanguages, titleLanguage) => {
651
+ if (!allLanguages.includes(titleLanguage)) {
652
+ allLanguages.push(titleLanguage);
653
+ }
654
+ return allLanguages;
655
+ }, new Array(currentLanguage));
656
+ setLanguagesOfTitles(titleLanguages);
657
+ });
658
+ if (workflows.current === void 0) {
659
+ showLoadingIndicator(true);
660
+ loadMetaInformation();
661
+ }
662
+ },
663
+ // workflowlistApi is not part of dependency because it changes one time but this is irrelevant to the
664
+ // purpose of preloading modules used by workflows
665
+ [workflows, setNumberOfWorkflows, setModulesOfWorkflows, setDefinitionsOfWorkflows, showLoadingIndicator, refreshIndicator, setLanguagesOfTitles]
666
+ );
667
+ const [columnsOfWorkflows, setColumnsOfWorkflows] = useState(void 0);
668
+ const modules = useFederationModules(modulesOfWorkflows, "WorkflowList");
669
+ useEffect(() => {
670
+ if (modules === void 0) {
671
+ return;
672
+ }
673
+ if (definitionsOfWorkflows === void 0) {
674
+ return;
675
+ }
676
+ const totalColumns = Object.keys(definitionsOfWorkflows).map((definition) => definitionsOfWorkflows[definition]).map((definition) => {
677
+ const columnsOfWorkflow = modules.filter((m) => m !== void 0).filter((m) => m.workflowModuleId === definition.workflowModuleId).filter((m) => m.workflowListColumns !== void 0).map((module) => module.workflowListColumns(definition));
678
+ if (columnsOfWorkflow.length === 0)
679
+ return void 0;
680
+ return columnsOfWorkflow[0];
681
+ }).filter((columnsOfWorkflow) => columnsOfWorkflow !== void 0).reduce((totalColumns2, columnsOfWorkflow) => {
682
+ columnsOfWorkflow.forEach((column) => {
683
+ totalColumns2[column.path] = column;
684
+ });
685
+ return totalColumns2;
686
+ }, {});
687
+ if (totalColumns.id === void 0 && !excludeIdColumn) {
688
+ totalColumns.id = {
689
+ title: { [currentLanguage]: "id" },
690
+ path: "id",
691
+ width: "2.2rem",
692
+ priority: -1,
693
+ show: true,
694
+ sortable: false,
695
+ filterable: false,
696
+ resizeable: false
697
+ };
698
+ }
699
+ if (totalColumns.title === void 0) {
700
+ totalColumns.title = {
701
+ title: { [currentLanguage]: t("column_title") },
702
+ path: "title",
703
+ width: "",
704
+ priority: 0,
705
+ show: true,
706
+ sortable: true,
707
+ filterable: true,
708
+ resizeable: true
709
+ };
710
+ }
711
+ const existingColumnsSignature = columnsOfWorkflows === void 0 ? " " : columnsOfWorkflows.map((c) => c.path).join("|");
712
+ const columnsToShow = Object.values(totalColumns).sort((a, b) => a.priority - b.priority);
713
+ const newColumnsSignature = columnsToShow.map((c) => c.path).join("|");
714
+ if (existingColumnsSignature === newColumnsSignature) {
715
+ return;
716
+ }
717
+ setColumnsOfWorkflows(columnsToShow);
718
+ }, [modules, definitionsOfWorkflows, columnsOfWorkflows, setColumnsOfWorkflows, refreshIndicator]);
719
+ const [allSelected, setAllSelected] = useState(false);
720
+ const [anySelected, setAnySelected] = useState(false);
721
+ const [refreshNecessary, setRefreshNecessary] = useState(false);
722
+ const [effectiveSort, _setSort] = useState(defaultSort);
723
+ const sort = (effectiveSort == null ? void 0 : effectiveSort.startsWith("title.")) ? "title" : effectiveSort;
724
+ const [sortAscending, _setSortAscending] = useState(defaultSortAscending === void 0 ? true : defaultSortAscending);
725
+ const refreshList = () => {
726
+ workflows.current = void 0;
727
+ setRefreshNecessary(false);
728
+ setColumnsOfWorkflows(void 0);
729
+ setRefreshIndicator(/* @__PURE__ */ new Date());
730
+ };
731
+ const setSort = (column) => {
732
+ if (column) {
733
+ if (column.path === "title") {
734
+ _setSort("title." + languagesOfTitles.join(",title."));
735
+ } else {
736
+ _setSort(column.path);
737
+ }
738
+ } else {
739
+ _setSort(defaultSort);
740
+ }
741
+ _setSortAscending(defaultSortAscending === void 0 ? true : defaultSortAscending);
742
+ refreshList();
743
+ };
744
+ const setSortAscending = (sortAscending2) => {
745
+ _setSortAscending(sortAscending2);
746
+ refreshList();
747
+ };
748
+ const [columnWidthAdjustments, setColumnWidthAdjustments] = useState({});
749
+ const getColumnSize = (column) => {
750
+ return !column.resizeable ? column.width : column.width !== "" ? `max(4rem, calc(${column.width} + ${columnWidthAdjustments[column.path] ? columnWidthAdjustments[column.path] : 0}px))` : columnWidthAdjustments[column.path] ? `${columnWidthAdjustments[column.path]}px` : void 0;
751
+ };
752
+ const setColumnWidthAdjustment = (column, adjustment) => {
753
+ if (column.width === "") {
754
+ column.width = `${adjustment}px`;
755
+ return;
756
+ }
757
+ const current = columnWidthAdjustments[column.path];
758
+ if (current === adjustment)
759
+ return;
760
+ setColumnWidthAdjustments(__spreadProps(__spreadValues({}, columnWidthAdjustments), { [column.path]: adjustment }));
761
+ };
762
+ const selectAll = (select) => {
763
+ refreshItemRef.current(
764
+ workflows.current.reduce((allItemIds, item) => {
765
+ item.selected = select;
766
+ allItemIds.push(item.id);
767
+ return allItemIds;
768
+ }, new Array())
769
+ );
770
+ setAllSelected(select);
771
+ if (anySelected !== select) {
772
+ setAnySelected(select);
773
+ }
774
+ };
775
+ const selectItem = (item, select) => {
776
+ item.selected = select;
777
+ refreshItemRef.current([item.id]);
778
+ const currentlyAllSelected = workflows.current.reduce((allSelected2, userTask) => allSelected2 && userTask.selected, true);
779
+ if (currentlyAllSelected !== allSelected) {
780
+ setAllSelected(currentlyAllSelected);
781
+ }
782
+ const currentlyAnySelected = workflows.current.reduce((anySelected2, userTask) => anySelected2 || userTask.selected, false);
783
+ if (anySelected !== currentlyAnySelected) {
784
+ setAnySelected(currentlyAnySelected);
785
+ }
786
+ };
787
+ const columnsOfList = columnsOfWorkflows === void 0 ? [] : columnsOfWorkflows.filter((column) => column.show).filter((column) => columns === void 0 || columns.includes(column.path)).map((column, columnIndex, allColumns) => ({
788
+ property: column.path,
789
+ size: getColumnSize(column),
790
+ plain: true,
791
+ verticalAlign: "top",
792
+ header: /* @__PURE__ */ jsx(
793
+ ListColumnHeader,
794
+ {
795
+ t,
796
+ currentLanguage,
797
+ nameOfList: name,
798
+ columnHeader,
799
+ hasColumnWidthAdjustment: columnWidthAdjustments[column.path] !== void 0,
800
+ setColumnWidthAdjustment,
801
+ sort: sort === column.path,
802
+ setSort,
803
+ sortAscending,
804
+ setSortAscending,
805
+ column,
806
+ columnIndex,
807
+ numberOfAllColumns: allColumns.length,
808
+ allSelected,
809
+ selectAll
810
+ }
811
+ ),
812
+ render: (item) => /* @__PURE__ */ jsx(
813
+ ListCell,
814
+ {
815
+ modulesAvailable: modules,
816
+ column,
817
+ currentLanguage,
818
+ nameOfList: name,
819
+ typeOfItem: TypeOfItem.WorkflowList,
820
+ showUnreadAsBold: false,
821
+ t,
822
+ item,
823
+ selectItem,
824
+ defaultListCell: WorkflowDefaultListCell
825
+ }
826
+ )
827
+ }));
828
+ const initialKwicQuery = (columnPath) => {
829
+ const query = searchQueries.filter((query2) => query2.path === columnPath).map((query2) => query2.query);
830
+ if (query.length === 0)
831
+ return "";
832
+ return query[0];
833
+ };
834
+ const setKwic = (columnPath, value) => {
835
+ const newSearchQueries = searchQueries.filter((query) => query.path !== columnPath);
836
+ if (value !== void 0 && value.trim().length > 0) {
837
+ newSearchQueries.push({ path: columnPath, query: value });
838
+ }
839
+ setSearchQueries(newSearchQueries);
840
+ refreshList();
841
+ };
842
+ const kwic = (columnPath, query) => __async(void 0, null, function* () {
843
+ return yield workflowlistApi.kwicWorkflows(
844
+ query,
845
+ columnPath,
846
+ searchQueries
847
+ );
848
+ });
849
+ const defaultHeader = () => /* @__PURE__ */ jsx(
850
+ DefaultHeader,
851
+ {
852
+ t,
853
+ isPhone,
854
+ isTablet,
855
+ numberOfWorkflows,
856
+ selectAll: (select) => {
857
+ },
858
+ allSelected,
859
+ refresh: refreshList,
860
+ refreshDisabled: !refreshNecessary,
861
+ initialKwicQuery,
862
+ limitListToKwic: setKwic,
863
+ kwic
864
+ }
865
+ );
866
+ const defaultFooter = () => /* @__PURE__ */ jsx(
867
+ DefaultFooter,
868
+ {
869
+ isPhone,
870
+ isTablet,
871
+ numberOfWorkflows,
872
+ t
873
+ }
874
+ );
875
+ return /* @__PURE__ */ jsxs(
876
+ Grid,
877
+ {
878
+ rows: [headerHeight, "auto", footerHeight],
879
+ fill: true,
880
+ children: [
881
+ children !== void 0 ? children(
882
+ isPhone,
883
+ isTablet,
884
+ numberOfWorkflows,
885
+ columnsOfWorkflows,
886
+ sort,
887
+ setSort,
888
+ sortAscending,
889
+ setSortAscending,
890
+ selectAll,
891
+ allSelected,
892
+ refreshList,
893
+ !refreshNecessary,
894
+ initialKwicQuery,
895
+ setKwic,
896
+ kwic
897
+ ) : defaultHeader(),
898
+ columnsOfWorkflows === void 0 ? /* @__PURE__ */ jsx(Box, {}, "list") : /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
899
+ SearchableAndSortableUpdatingList,
900
+ {
901
+ rowSeparator,
902
+ applyBackgroundColor,
903
+ showLoadingIndicator,
904
+ minWidthOfAutoColumn: minWidthOfTitleColumn,
905
+ showColumnHeaders,
906
+ columnHeaderBackground,
907
+ columnHeaderSeparator,
908
+ columns: columnsOfList,
909
+ itemsRef: workflows,
910
+ updateListRef,
911
+ refreshItemRef,
912
+ refreshNecessaryCallback: () => setRefreshNecessary(true),
913
+ retrieveItems: (pageNumber, pageSize, initialTimestamp) => (
914
+ // @ts-ignore
915
+ loadWorkflows(
916
+ workflowlistApi,
917
+ setNumberOfWorkflows,
918
+ modulesOfWorkflows,
919
+ setModulesOfWorkflows,
920
+ definitionsOfWorkflows,
921
+ setDefinitionsOfWorkflows,
922
+ pageSize,
923
+ pageNumber,
924
+ initialTimestamp,
925
+ searchQueries,
926
+ effectiveSort,
927
+ sortAscending,
928
+ mapToBcWorkflow
929
+ )
930
+ ),
931
+ reloadItems: (numberOfItems, updatedItemsIds, initialTimestamp) => (
932
+ // @ts-ignore
933
+ reloadWorkflows(
934
+ workflowlistApi,
935
+ setNumberOfWorkflows,
936
+ modulesOfWorkflows,
937
+ setModulesOfWorkflows,
938
+ definitionsOfWorkflows,
939
+ setDefinitionsOfWorkflows,
940
+ numberOfItems,
941
+ updatedItemsIds,
942
+ initialTimestamp,
943
+ searchQueries,
944
+ effectiveSort,
945
+ sortAscending,
946
+ mapToBcWorkflow
947
+ )
948
+ )
949
+ }
950
+ ) }, "list"),
951
+ footer !== void 0 ? footer(
952
+ isPhone,
953
+ isTablet,
954
+ numberOfWorkflows,
955
+ columnsOfWorkflows,
956
+ sort,
957
+ setSort,
958
+ sortAscending,
959
+ setSortAscending,
960
+ selectAll,
961
+ allSelected,
962
+ refreshList,
963
+ !refreshNecessary,
964
+ initialKwicQuery,
965
+ setKwic,
966
+ kwic
967
+ ) : defaultFooter()
968
+ ]
969
+ }
970
+ );
971
+ };
972
+ export {
973
+ ListOfWorkflows
974
+ };