@hrbolek/uoisfrontend-template 0.6.1 → 0.6.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 (70) hide show
  1. package/dist/cjs/index.js +447 -0
  2. package/dist/es/index.js +11062 -0
  3. package/dist/umd/index.js +447 -0
  4. package/package.json +5 -1
  5. package/src/Base/Components/Link.jsx +13 -8
  6. package/src/Base/Mutations/General.jsx +3 -1
  7. package/src/Base/Mutations/Update.jsx +5 -0
  8. package/src/EventGQLModel/Components/A4Plan/A4Plan.jsx +363 -0
  9. package/src/EventGQLModel/Components/A4Plan/index.js +1 -0
  10. package/src/EventGQLModel/Components/CardCapsule.jsx +43 -0
  11. package/src/EventGQLModel/Components/Children.jsx +31 -0
  12. package/src/EventGQLModel/Components/ConfirmEdit.jsx +61 -0
  13. package/src/EventGQLModel/Components/Filter.jsx +14 -0
  14. package/src/EventGQLModel/Components/LargeCard.jsx +54 -0
  15. package/src/EventGQLModel/Components/Link.jsx +55 -0
  16. package/src/EventGQLModel/Components/LiveEdit.jsx +111 -0
  17. package/src/EventGQLModel/Components/MediumCard.jsx +39 -0
  18. package/src/EventGQLModel/Components/MediumContent.jsx +96 -0
  19. package/src/EventGQLModel/Components/MediumEditableContent.jsx +35 -0
  20. package/src/EventGQLModel/Components/Plan/PlanRow.jsx +470 -0
  21. package/src/EventGQLModel/Components/Plan/_utils.js +971 -0
  22. package/src/EventGQLModel/Components/Plan/calendarReducer.js +535 -0
  23. package/src/EventGQLModel/Components/Plan/index.js +3 -0
  24. package/src/EventGQLModel/Components/Table.jsx +7 -0
  25. package/src/EventGQLModel/Components/index.js +15 -0
  26. package/src/EventGQLModel/Mutations/Create.jsx +202 -0
  27. package/src/EventGQLModel/Mutations/Delete.jsx +173 -0
  28. package/src/EventGQLModel/Mutations/InteractiveMutations.jsx +30 -0
  29. package/src/EventGQLModel/Mutations/Update.jsx +147 -0
  30. package/src/EventGQLModel/Mutations/helpers.jsx +7 -0
  31. package/src/EventGQLModel/Pages/PageBase.jsx +56 -0
  32. package/src/EventGQLModel/Pages/PageCreateItem.jsx +28 -0
  33. package/src/EventGQLModel/Pages/PageDeleteItem.jsx +16 -0
  34. package/src/EventGQLModel/Pages/PageNavbar.jsx +160 -0
  35. package/src/EventGQLModel/Pages/PagePlan.jsx +42 -0
  36. package/src/EventGQLModel/Pages/PageReadItem.jsx +11 -0
  37. package/src/EventGQLModel/Pages/PageReadItemEx.jsx +42 -0
  38. package/src/EventGQLModel/Pages/PageSubevents.jsx +43 -0
  39. package/src/EventGQLModel/Pages/PageUpdateItem.jsx +14 -0
  40. package/src/EventGQLModel/Pages/PageVector.jsx +80 -0
  41. package/src/EventGQLModel/Pages/RouterSegment.jsx +82 -0
  42. package/src/EventGQLModel/Pages/index.js +2 -0
  43. package/src/EventGQLModel/Queries/DeleteAsyncAction.jsx +32 -0
  44. package/src/EventGQLModel/Queries/Fragments.jsx +123 -0
  45. package/src/EventGQLModel/Queries/InsertAsyncAction.jsx +40 -0
  46. package/src/EventGQLModel/Queries/ReadAsyncAction.jsx +44 -0
  47. package/src/EventGQLModel/Queries/ReadPageAsyncAction.jsx +13 -0
  48. package/src/EventGQLModel/Queries/ReadSubEventsAsyncAction.jsx +44 -0
  49. package/src/EventGQLModel/Queries/SearchAsyncAction.jsx +16 -0
  50. package/src/EventGQLModel/Queries/UpdateAsyncAction.jsx +40 -0
  51. package/src/EventGQLModel/Queries/index.js +6 -0
  52. package/src/EventGQLModel/Scalars/ScalarAttribute.jsx +54 -0
  53. package/src/EventGQLModel/Scalars/TemplateScalarAttribute.jsx +88 -0
  54. package/src/EventGQLModel/Scalars/index.js +1 -0
  55. package/src/EventGQLModel/Vectors/TemplateVectorsAttribute.jsx +326 -0
  56. package/src/EventGQLModel/Vectors/VectorAttribute.jsx +56 -0
  57. package/src/EventGQLModel/Vectors/index.js +1 -0
  58. package/src/EventGQLModel/WhatToDo.md +44 -0
  59. package/src/EventGQLModel/index.js +71 -0
  60. package/src/GroupGQLModel/Mutations/Create.jsx +8 -2
  61. package/src/GroupGQLModel/Mutations/Delete.jsx +8 -2
  62. package/src/GroupGQLModel/Mutations/Update.jsx +8 -8
  63. package/src/GroupGQLModel/Queries/Fragments.jsx +17 -1
  64. package/src/GroupGQLModel/Scalars/RBACObject.jsx +17 -5
  65. package/src/GroupGQLModel/Vectors/GroupMemberships.jsx +1 -1
  66. package/src/UserGQLModel/Components/MediumContent.jsx +9 -3
  67. package/src/UserGQLModel/Queries/Fragments.jsx +6 -0
  68. package/src/_Template/WhatToDo.md +1 -1
  69. package/index.html +0 -104
  70. package/vite.config.js +0 -47
@@ -0,0 +1,44 @@
1
+ import { createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared";
2
+ import { LargeFragment } from "./Fragments";
3
+ import { createAsyncGraphQLAction2 } from "../../../../dynamic/src/Core/createAsyncGraphQLAction2";
4
+
5
+ const ReadQueryStr = `
6
+ query eventById($id: UUID!) {
7
+ eventById(id: $id) {
8
+ ...Large
9
+ }
10
+ }
11
+ `
12
+
13
+ const ReadQuery = createQueryStrLazy(`${ReadQueryStr}`, LargeFragment)
14
+
15
+ /**
16
+ * An async action for executing a GraphQL query to read entities.
17
+ *
18
+ * This action is created using `createAsyncGraphQLAction` with a predefined `QueryRead` query.
19
+ * It can be dispatched with query variables to fetch data related to entities from the GraphQL API.
20
+ *
21
+ * @constant
22
+ * @type {Function}
23
+ *
24
+ * @param {Object} query_variables - The variables for the GraphQL query.
25
+ * @param {string|number} query_variables.id - The unique identifier for the entity to fetch.
26
+ *
27
+ * @returns {Function} A dispatchable async action that performs the GraphQL query, applies middleware, and dispatches the result.
28
+ *
29
+ * @throws {Error} If `query_variables` is not a valid JSON object.
30
+ *
31
+ * @example
32
+ * // Example usage:
33
+ * const queryVariables = { id: "12345" };
34
+ *
35
+ * dispatch(ReadAsyncAction(queryVariables))
36
+ * .then((result) => {
37
+ * console.log("Fetched data:", result);
38
+ * })
39
+ * .catch((error) => {
40
+ * console.error("Error fetching data:", error);
41
+ * });
42
+ */
43
+ // export const ReadAsyncAction = createAsyncGraphQLAction2(ReadQuery, reduceToFirstEntity("result"))
44
+ export const ReadAsyncAction = createAsyncGraphQLAction2(ReadQuery)
@@ -0,0 +1,13 @@
1
+ import { createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared";
2
+ import { LargeFragment } from "./Fragments";
3
+ import { createAsyncGraphQLAction2 } from "../../../../dynamic/src/Core/createAsyncGraphQLAction2";
4
+
5
+ const ReadPageQueryStr = `
6
+ query eventPage($skip: Int, $limit: Int, $orderby: String, $where: EventInputFilter) {
7
+ eventPage(skip: $skip, limit: $limit, orderby: $orderby, where: $where) {
8
+ ...Large
9
+ }
10
+ }
11
+ `
12
+ const ReadPageQuery = createQueryStrLazy(`${ReadPageQueryStr}`, LargeFragment)
13
+ export const ReadPageAsyncAction = createAsyncGraphQLAction2(ReadPageQuery)
@@ -0,0 +1,44 @@
1
+ import { createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared";
2
+ import { SubEventsFragment } from "./Fragments";
3
+ import { createAsyncGraphQLAction2 } from "../../../../dynamic/src/Core/createAsyncGraphQLAction2";
4
+
5
+ const ReadQueryStr = `
6
+ query eventById($id: UUID!, $limit: Int=1000, $skip: Int, $orderby: String, $where: EventInputFilter) {
7
+ eventById(id: $id) {
8
+ ...SubEvents
9
+ }
10
+ }
11
+ `
12
+
13
+ const ReadQuery = createQueryStrLazy(`${ReadQueryStr}`, SubEventsFragment)
14
+
15
+ /**
16
+ * An async action for executing a GraphQL query to read entities.
17
+ *
18
+ * This action is created using `createAsyncGraphQLAction` with a predefined `QueryRead` query.
19
+ * It can be dispatched with query variables to fetch data related to entities from the GraphQL API.
20
+ *
21
+ * @constant
22
+ * @type {Function}
23
+ *
24
+ * @param {Object} query_variables - The variables for the GraphQL query.
25
+ * @param {string|number} query_variables.id - The unique identifier for the entity to fetch.
26
+ *
27
+ * @returns {Function} A dispatchable async action that performs the GraphQL query, applies middleware, and dispatches the result.
28
+ *
29
+ * @throws {Error} If `query_variables` is not a valid JSON object.
30
+ *
31
+ * @example
32
+ * // Example usage:
33
+ * const queryVariables = { id: "12345" };
34
+ *
35
+ * dispatch(ReadAsyncAction(queryVariables))
36
+ * .then((result) => {
37
+ * console.log("Fetched data:", result);
38
+ * })
39
+ * .catch((error) => {
40
+ * console.error("Error fetching data:", error);
41
+ * });
42
+ */
43
+ // export const ReadAsyncAction = createAsyncGraphQLAction2(ReadQuery, reduceToFirstEntity("result"))
44
+ export const ReadSubEventsAsyncAction = createAsyncGraphQLAction2(ReadQuery)
@@ -0,0 +1,16 @@
1
+ import { createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared"
2
+ import { createAsyncGraphQLAction2 } from "../../../../dynamic/src/Core/createAsyncGraphQLAction2"
3
+ import { LargeFragment } from "./Fragments"
4
+ import { reduceToFirstEntity } from "../../../../dynamic/src/Store"
5
+
6
+ const SearchQueryStr = `
7
+ query SearchQuery($skip: Int, $limit: Int, $pattern: String) {
8
+ result: userPage(skip: $skip, limit: $limit, where: {email: {_ilike: $pattern}}) {
9
+ ...Large
10
+ }
11
+ }
12
+ `
13
+
14
+
15
+ export const SearchAsyncActionQuery = createQueryStrLazy(`${SearchQueryStr}`, LargeFragment)
16
+ export const SearchAsyncAction = createAsyncGraphQLAction2(SearchAsyncActionQuery)
@@ -0,0 +1,40 @@
1
+ import { createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared";
2
+ import { LargeFragment } from "./Fragments";
3
+ import { createAsyncGraphQLAction2 } from "../../../../dynamic/src/Core/createAsyncGraphQLAction2";
4
+ import { reduceToFirstEntity, updateItemsFromGraphQLResult } from "../../../../dynamic/src/Store";
5
+
6
+ const UpdateMutationStr = `
7
+ mutation roleTypeUpdate(
8
+ $id: UUID! # null,
9
+ $lastchange: DateTime! # null,
10
+ $name: String # null,
11
+ $nameEn: String # null
12
+ ) {
13
+ roleTypeUpdate(
14
+ roleType: {
15
+ id: $id,
16
+ lastchange: $lastchange,
17
+ name: $name,
18
+ nameEn: $nameEn}
19
+ ) {
20
+ ... on RoleTypeGQLModel { ...Large }
21
+ ... on RoleTypeGQLModelUpdateError { ...Error }
22
+ }
23
+ }
24
+
25
+ fragment Error on RoleTypeGQLModelUpdateError {
26
+ __typename
27
+ Entity {
28
+ ...Large
29
+ }
30
+ msg
31
+ failed
32
+ code
33
+ location
34
+ input
35
+ }
36
+ `
37
+
38
+ const UpdateMutation = createQueryStrLazy(`${UpdateMutationStr}`, LargeFragment)
39
+ export const UpdateAsyncAction = createAsyncGraphQLAction2(UpdateMutation,
40
+ updateItemsFromGraphQLResult, reduceToFirstEntity)
@@ -0,0 +1,6 @@
1
+
2
+ export { InsertAsyncAction } from './InsertAsyncAction'
3
+ export { UpdateAsyncAction } from './UpdateAsyncAction'
4
+ export { DeleteAsyncAction } from './DeleteAsyncAction'
5
+ export { ReadAsyncAction } from './ReadAsyncAction'
6
+ export { ReadPageAsyncAction } from './ReadPageAsyncAction'
@@ -0,0 +1,54 @@
1
+ import { useSelector } from "react-redux";
2
+
3
+ // import { selectItemById } from "../Store/ItemSlice"; // uprav cestu
4
+
5
+ import { CardCapsule } from "../Components/CardCapsule"
6
+ import { MediumCard } from "../Components/MediumCard"
7
+ import { Col } from "../../../../_template/src/Base/Components/Col"
8
+ import { Row } from "../../../../_template/src/Base/Components/Row"
9
+ import { selectItemById } from "../../../../dynamic/src/Store";
10
+ import { useMemo } from "react";
11
+
12
+ export const ScalarAttributeCapsule = ({ attribute_name, item, children }) => {
13
+ return (
14
+ <Row>
15
+ <Col className="col-2"><b>{attribute_name}</b></Col>
16
+ <Col className="col-10">
17
+ {children}
18
+ </Col>
19
+ </Row>
20
+ )
21
+ }
22
+
23
+ export const ScalarAttributeBase = ({ attribute_name, item }) => {
24
+ return (
25
+ <ScalarAttributeCapsule attribute_name={attribute_name} item={item}>
26
+ <MediumCard item={item} />
27
+ </ScalarAttributeCapsule>
28
+ )
29
+ }
30
+
31
+ export const ScalarAttributeBind = ({ attribute_name, item }) => {
32
+ const id = item?.[attribute_name]?.id
33
+ const storedItem = useSelector((rootState) => {
34
+ const result = id != null ? selectItemById(rootState, id) : null
35
+ return result
36
+ })
37
+ return (
38
+ <ScalarAttributeBase attribute_name={attribute_name} item={storedItem} />
39
+ )
40
+ }
41
+
42
+ export const MediumCardScalars = ({ item }) => {
43
+ const sureitem = item || {}
44
+ const noArrays = useMemo(() => Object.fromEntries(
45
+ Object.entries(sureitem).filter(([_, v]) => v && typeof v === "object" && !Array.isArray(v) && v.id != null)
46
+ ), [item]);
47
+ return (
48
+ <CardCapsule item={sureitem}>
49
+ {Object.keys(noArrays).map(
50
+ (attribute_name) => <ScalarAttributeBind key={attribute_name} item={item} attribute_name={attribute_name} />
51
+ )}
52
+ </CardCapsule>
53
+ )
54
+ }
@@ -0,0 +1,88 @@
1
+ import { createAsyncGraphQLAction, useAsyncAction } from "@hrbolek/uoisfrontend-gql-shared"
2
+ import { ErrorHandler, LoadingSpinner } from "@hrbolek/uoisfrontend-shared"
3
+
4
+ /**
5
+ * A component for displaying the `scalar` attribute of an template entity.
6
+ *
7
+ * This component checks if the `scalar` attribute exists on the `template` object. If `scalar` is undefined,
8
+ * the component returns `null` and renders nothing. Otherwise, it displays a placeholder message
9
+ * and a JSON representation of the `scalar` attribute.
10
+ *
11
+ * @component
12
+ * @param {Object} props - The props for the TemplateScalarAttribute component.
13
+ * @param {Object} props.template - The object representing the template entity.
14
+ * @param {*} [props.template.scalar] - The scalar attribute of the template entity to be displayed, if defined.
15
+ *
16
+ * @returns {JSX.Element|null} A JSX element displaying the `scalar` attribute or `null` if the attribute is undefined.
17
+ *
18
+ * @example
19
+ * // Example usage:
20
+ * const templateEntity = { scalar: { id: 1, name: "Sample Scalar" } };
21
+ *
22
+ * <TemplateScalarAttribute template={templateEntity} />
23
+ */
24
+ export const TemplateScalarAttribute = ({template}) => {
25
+ const {scalar} = template
26
+ if (typeof scalar === 'undefined') return null
27
+ return (
28
+ <>
29
+ {/* <ScalarMediumCard scalar={scalar} /> */}
30
+ {/* <ScalarLink scalar={scalar} /> */}
31
+ Probably {'<ScalarMediumCard scalar={scalar} />'} <br />
32
+ <pre>{JSON.stringify(scalar, null, 4)}</pre>
33
+ </>
34
+ )
35
+ }
36
+
37
+ const TemplateScalarAttributeQuery = `
38
+ query TemplateQueryRead($id: UUID!) {
39
+ result: templateById(id: $id) {
40
+ __typename
41
+ id
42
+ scalar {
43
+ __typename
44
+ id
45
+ }
46
+ }
47
+ }
48
+ `
49
+
50
+ const TemplateScalarAttributeAsyncAction = createAsyncGraphQLAction(
51
+ TemplateScalarAttributeQuery
52
+ )
53
+
54
+ /**
55
+ * A lazy-loading component for displaying filtered `scalar` from a `template` entity.
56
+ *
57
+ * This component uses the `TemplateScalarAttributeAsyncAction` to asynchronously fetch
58
+ * the `template.scalar` data. It shows a loading spinner while fetching, handles errors,
59
+ * and filters the resulting list using a custom `filter` function (defaults to `Boolean` to remove falsy values).
60
+ *
61
+ * Each vector item is rendered as a `<div>` with its `id` as both the `key` and the `id` attribute,
62
+ * and displays a formatted JSON preview using `<pre>`.
63
+ *
64
+ * @component
65
+ * @param {Object} props - The properties object.
66
+ * @param {Object} props.template - The template entity or identifying query variables used to fetch it.
67
+ * @param {Function} [props.filter=Boolean] - A filtering function applied to the `scalar` array before rendering.
68
+ *
69
+ * @returns {JSX.Element} A rendered list of filtered scalar or a loading/error placeholder.
70
+ *
71
+ * @example
72
+ * <TemplateScalarAttributeLazy template={{ id: "abc123" }} />
73
+ *
74
+ *
75
+ * @example
76
+ * <TemplateScalarAttributeLazy
77
+ * template={{ id: "abc123" }}
78
+ * filter={(v) => v.status === "active"}
79
+ * />
80
+ */
81
+ export const TemplateScalarAttributeLazy = ({template}) => {
82
+ const {loading, error, entity, fetch} = useAsyncAction(TemplateScalarAttributeAsyncAction, template)
83
+
84
+ if (loading) return <LoadingSpinner />
85
+ if (error) return <ErrorHandler errors={error} />
86
+
87
+ return <TemplateScalarAttribute template={entity} />
88
+ }
@@ -0,0 +1 @@
1
+ export * from './TemplateScalarAttribute'
@@ -0,0 +1,326 @@
1
+ import { useEffect } from "react";
2
+ import { Col } from "react-bootstrap";
3
+ import { useAsyncAction, createAsyncGraphQLAction, processVectorAttributeFromGraphQLResult, createQueryStrLazy } from "@hrbolek/uoisfrontend-gql-shared"
4
+ import { ErrorHandler, InfiniteScroll, LoadingSpinner } from "@hrbolek/uoisfrontend-shared"
5
+
6
+
7
+ /**
8
+ * Inserts a VectorGQLModel item into a template’s vectors array and dispatches an update.
9
+ *
10
+ * @param {Object} template - The current template object containing a `vectors` array.
11
+ * @param {Object} vectorItem - The item to insert; must have `__typename === "VectorGQLModel"`.
12
+ * @param {Function} dispatch - Redux dispatch function (or similar) to call the update action.
13
+ */
14
+ const followUpTemplateVectorItemInsert = (template, vectorItem, dispatch) => {
15
+ const { __typename } = vectorItem;
16
+ if (__typename === "VectorGQLModel") {
17
+ const { vectors, ...others } = template;
18
+ const newTemplateVectorItems = [...vectors, vectorItem];
19
+ const newTemplate = { ...others, vectors: newTemplateVectorItems };
20
+ dispatch(ItemActions.item_update(newTemplate));
21
+ }
22
+ };
23
+
24
+ /**
25
+ * Replaces an existing VectorGQLModel item in a template’s vectors array and dispatches an update.
26
+ *
27
+ * @param {Object} template - The current template object containing a `vectors` array.
28
+ * @param {Object} vectorItem - The updated item; must have `__typename === "VectorGQLModel"` and an `id` field matching an existing item.
29
+ * @param {Function} dispatch - Redux dispatch function (or similar) to call the update action.
30
+ */
31
+ const followUpTemplateVectorItemUpdate = (template, vectorItem, dispatch) => {
32
+ const { __typename } = vectorItem;
33
+ if (__typename === "VectorGQLModel") {
34
+ const { vectors, ...others } = template;
35
+ const newTemplateVectorItems = vectors.map(item =>
36
+ item.id === vectorItem.id ? vectorItem : item
37
+ );
38
+ const newTemplate = { ...others, vectors: newTemplateVectorItems };
39
+ dispatch(ItemActions.item_update(newTemplate));
40
+ }
41
+ };
42
+
43
+ /**
44
+ * Removes a VectorGQLModel item from a template’s vectors array by its `id` and dispatches an update.
45
+ *
46
+ * @param {Object} template - The current template object containing a `vectors` array.
47
+ * @param {Object} vectorItem - The item to delete; must have `__typename === "VectorGQLModel"` and an `id` field.
48
+ * @param {Function} dispatch - Redux dispatch function (or similar) to call the update action.
49
+ */
50
+ const followUpTemplateVectorItemDelete = (template, vectorItem, dispatch) => {
51
+ const { __typename } = vectorItem;
52
+ if (__typename === "VectorGQLModel") {
53
+ const { vectors, ...others } = template;
54
+ const newTemplateVectorItems = vectors.filter(
55
+ item => item.id !== vectorItem.id
56
+ );
57
+ const newTemplate = { ...others, vectors: newTemplateVectorItems };
58
+ dispatch(ItemActions.item_update(newTemplate));
59
+ }
60
+ };
61
+
62
+ const TemplateVectorsAttributeQuery = `
63
+ query TemplateQueryRead($id: UUID!, $where: VectorInputFilter, $skip: Int, $limit: Int) {
64
+ result: templateById(id: $id) {
65
+ __typename
66
+ id
67
+ vectors(skip: $skip, limit: $limit, where: $where) {
68
+ __typename
69
+ id
70
+ # ...VectorMedium
71
+ }
72
+ }
73
+ }
74
+ `
75
+
76
+ const TemplateVectorsAttributeAsyncAction = createAsyncGraphQLAction(
77
+ createQueryStrLazy(TemplateVectorsAttributeQuery,
78
+ //VectorMediumFragment
79
+ ),
80
+ processVectorAttributeFromGraphQLResult("vectors")
81
+ )
82
+
83
+
84
+ /**
85
+ * A component for displaying the `vectors` attribute of a template entity.
86
+ *
87
+ * This component checks if the `vectors` attribute exists on the `template` object. If `vectors` is undefined,
88
+ * the component returns `null` and renders nothing. Otherwise, it maps over the (optionally filtered) `vectors` array
89
+ * and displays a placeholder message and a JSON representation for each item.
90
+ *
91
+ * @component
92
+ * @param {Object} props - The props for the TemplateVectorsAttribute component.
93
+ * @param {Object} props.template - The object representing the template entity.
94
+ * @param {Array<Object>} [props.template.vectors] - An array of vector items associated with the template entity.
95
+ * Each item is expected to have a unique `id` property.
96
+ * @param {Function} [props.filter=Boolean] - (Optional) A function to filter the vectors array before rendering.
97
+ *
98
+ * @returns {JSX.Element|null} A JSX element displaying the (filtered) `vectors` items or `null` if the attribute is undefined or empty.
99
+ *
100
+ * @example
101
+ * // Basic usage:
102
+ * const templateEntity = {
103
+ * vectors: [
104
+ * { id: 1, name: "Vector Item 1" },
105
+ * { id: 2, name: "Vector Item 2" }
106
+ * ]
107
+ * };
108
+ * <TemplateVectorsAttribute template={templateEntity} />
109
+ *
110
+ * @example
111
+ * // With a custom filter:
112
+ * <TemplateVectorsAttribute
113
+ * template={templateEntity}
114
+ * filter={vector => vector.name.includes("1")}
115
+ * />
116
+ */
117
+ export const TemplateVectorsAttribute_old = ({template, filter=Boolean, Visualiser=TrivialVisualiserDiv}) => {
118
+ const { vectors: unfiltered } = template
119
+ if (typeof unfiltered === 'undefined') return null
120
+ const vectors = unfiltered.filter(filter)
121
+ if (vectors.length === 0) return null
122
+ return (
123
+ <>
124
+ {vectors.map(
125
+ vector => <Visualiser id={vector.id} key={vector.id} vector={vector} />
126
+ )}
127
+ </>
128
+ )
129
+ }
130
+
131
+ /**
132
+ * Visualiser component for displaying a list of vector items using `TemplateVectorsAttribute`.
133
+ *
134
+ * Wraps the `TemplateVectorsAttribute` component, passing the given `items` as the `vectors` attribute
135
+ * on a synthetic `template` object. All other props are forwarded.
136
+ *
137
+ * @component
138
+ * @param {Object} props - Component props.
139
+ * @param {Array<Object>} props.items - The array of vector items to be visualized.
140
+ * @param {...any} [props] - Additional props forwarded to `TemplateVectorsAttribute` (e.g., `filter`).
141
+ *
142
+ * @returns {JSX.Element|null} Rendered list of vectors or `null` if none are provided.
143
+ *
144
+ * @example
145
+ * <VectorsVisualiser
146
+ * items={[
147
+ * { id: 1, name: "Vector 1" },
148
+ * { id: 2, name: "Vector 2" }
149
+ * ]}
150
+ * filter={v => v.name.includes("1")}
151
+ * />
152
+ */
153
+ const VectorsVisualiser = ({ items, ...props }) =>
154
+ <TemplateVectorsAttribute_old {...props} template={{ vectors: items }} />
155
+
156
+ /**
157
+ * Infinite-scrolling component for the `vectors` attribute of a template entity.
158
+ *
159
+ * Uses the generic `InfiniteScroll` component to fetch, merge, and display the `vectors` array
160
+ * associated with the provided `template` object. It utilizes `VectorsVisualiser` for rendering,
161
+ * and handles pagination, lazy-loading, and merging of items as the user scrolls.
162
+ *
163
+ * @component
164
+ * @param {Object} props - Component props.
165
+ * @param {Object} props.template - The template entity containing the `vectors` array.
166
+ * @param {Array<Object>} [props.template.vectors] - (Optional) Preloaded vector items.
167
+ * @param {Object} [props.actionParams={}] - Optional extra parameters for the async fetch action (merged with pagination).
168
+ * @param {...any} [props] - Additional props passed to `InfiniteScroll` or `VectorsVisualiser`.
169
+ *
170
+ * @returns {JSX.Element} An infinite-scrolling list of vectors.
171
+ *
172
+ * @example
173
+ * <TemplateVectorsAttributeInfinite
174
+ * template={{
175
+ * vectors: [
176
+ * { id: 1, name: "Vector 1" },
177
+ * { id: 2, name: "Vector 2" }
178
+ * ]
179
+ * }}
180
+ * />
181
+ */
182
+ export const TemplateVectorsAttributeInfinite = ({template, actionParams={}, ...props}) => {
183
+ const {vectors} = template
184
+
185
+ return (
186
+ <InfiniteScroll
187
+ {...props}
188
+ Visualiser={VectorsVisualiser}
189
+ preloadedItems={vectors}
190
+ actionParams={{...actionParams, skip: 0, limit: 10}}
191
+ asyncAction={TemplateVectorsAttributeAsyncAction}
192
+ />
193
+ )
194
+ }
195
+
196
+ /**
197
+ * A lazy-loading component for displaying filtered `vectors` from a `template` entity.
198
+ *
199
+ * This component uses the `TemplateVectorsAttributeAsyncAction` to asynchronously fetch
200
+ * the `template.vectors` data. It shows a loading spinner while fetching, handles errors,
201
+ * and filters the resulting list using a custom `filter` function (defaults to `Boolean` to remove falsy values).
202
+ *
203
+ * Each vector item is rendered as a `<div>` with its `id` as both the `key` and the `id` attribute,
204
+ * and displays a formatted JSON preview using `<pre>`.
205
+ *
206
+ * @component
207
+ * @param {Object} props - The properties object.
208
+ * @param {Object} props.template - The template entity or identifying query variables used to fetch it.
209
+ * @param {Function} [props.filter=Boolean] - A filtering function applied to the `vectors` array before rendering.
210
+ *
211
+ * @returns {JSX.Element} A rendered list of filtered vectors or a loading/error placeholder.
212
+ *
213
+ * @example
214
+ * <TemplateVectorsAttributeLazy template={{ id: "abc123" }} />
215
+ *
216
+ *
217
+ * @example
218
+ * <TemplateVectorsAttributeLazy
219
+ * template={{ id: "abc123" }}
220
+ * filter={(v) => v.status === "active"}
221
+ * />
222
+ */
223
+ export const TemplateVectorsAttributeLazy = ({template, filter=Boolean, ...props}) => {
224
+ const {loading, error, entity, fetch} = useAsyncAction(TemplateVectorsAttributeAsyncAction, template, {deferred: true})
225
+ useEffect(() => {
226
+ fetch(template)
227
+ }, [template])
228
+
229
+ if (loading) return <LoadingSpinner />
230
+ if (error) return <ErrorHandler errors={error} />
231
+
232
+ return <TemplateVectorsAttribute_old template={entity} filter={filter} {...props}/>
233
+ }
234
+
235
+ const TrivialVisualiserDiv = ({vector, children}) => <div>
236
+ Probably {'<VectorMediumCard vector={vector} />'} <br />
237
+ <pre>{JSON.stringify(vector, null, 4)}</pre>
238
+ {children}
239
+ </div>
240
+
241
+ /**
242
+ * Component to render the filtered `vectors` attribute of a template entity.
243
+ *
244
+ * Applies an optional filter function to the vectors array before rendering.
245
+ * Supports infinite scrolling to load more items lazily.
246
+ *
247
+ * The `Layout` prop is used as a wrapper component for each rendered item and
248
+ * is consistently applied in both static and infinite scroll rendering modes.
249
+ * If different layouts are desired for infinite vs static modes,
250
+ * consider conditionally passing different `Layout` props.
251
+ *
252
+ * @param {object} props - Component props.
253
+ * @param {object} props.template - The template entity containing the `vectors` array.
254
+ * @param {Array<object>} [props.template.vectors] - Array of vector items to render.
255
+ * @param {React.ComponentType} [props.Visualiser=TrivialVisualiserDiv] - Component to render each vector item.
256
+ * Receives `vector` and optionally other props.
257
+ * @param {boolean} [props.infinite=true] - Whether to enable infinite scrolling.
258
+ * @param {React.ComponentType|string} [props.Layout=Col] - Wrapper component for each rendered item.
259
+ * This component is used consistently for both static rendering and infinite scroll loading.
260
+ * @param {Function} [props.filter=Boolean] - Filter function to apply on vectors before rendering.
261
+ * @param {...any} props - Additional props forwarded to `Visualiser` and `InfiniteScroll`.
262
+ *
263
+ * @returns {JSX.Element|null} Rendered list or infinite scroll component, or null if no vectors.
264
+ *
265
+ * @example
266
+ * <TemplateVectorsAttribute
267
+ * template={template}
268
+ * Visualiser={VectorMediumCard}
269
+ * Layout={Col}
270
+ * filter={(v) => v.active}
271
+ * infinite={true}
272
+ * />
273
+ */
274
+ export const TemplateVectorsAttribute = ({
275
+ template,
276
+ Visualiser = TrivialVisualiserDiv,
277
+ infinite = true,
278
+ Layout = Col, // 'list' | 'grid' | 'infinite'
279
+ filter = Boolean,
280
+ ...props
281
+ }) => {
282
+
283
+ const { vectors: unfiltered } = template
284
+ if (typeof unfiltered === 'undefined') return null
285
+ const vectors = unfiltered.filter(filter)
286
+ if (vectors.length === 0) return null
287
+
288
+
289
+
290
+ if (infinite) {
291
+ // Pro infinite scroll použijeme komponentu InfiniteScroll
292
+ // Visualiser zde je komponenta, která přijímá pole položek (items)
293
+ // a zobrazí je – proto vytvoříme wrapper, který předá Visualiser správně
294
+
295
+ const VisualiserWrapper = ({ items }) => (
296
+ <TemplateVectorsAttribute
297
+ {...props}
298
+ template={{vectors: items}}
299
+ Visualiser={Visualiser}
300
+ infinite={false}
301
+ Layout={Layout}
302
+ filter={filter}
303
+ />
304
+ );
305
+
306
+ return (
307
+ <InfiniteScroll
308
+ actionParams={{ ...template, skip: 0, limit: 10 }}
309
+ asyncAction={TemplateVectorsAttributeAsyncAction}
310
+ {...props}
311
+ Visualiser={VisualiserWrapper}
312
+ preloadedItems={vectors}
313
+ />
314
+ );
315
+ }
316
+
317
+ return (
318
+ <>
319
+ {vectors.map((vector) => (
320
+ <Layout key={vector.id}>
321
+ {vector && <Visualiser {...props} vector={vector} />}
322
+ </Layout>
323
+ ))}
324
+ </>
325
+ );
326
+ };