@arrai-innovations/reactive-helpers 18.0.0 → 18.0.2

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 (216) hide show
  1. package/package.json +20 -6
  2. package/types/config/listCrud.d.ts +153 -0
  3. package/types/config/listCrud.d.ts.map +1 -0
  4. package/types/config/objectCrud.d.ts +171 -0
  5. package/types/config/objectCrud.d.ts.map +1 -0
  6. package/types/index.d.ts +37 -0
  7. package/types/index.d.ts.map +1 -0
  8. package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
  9. package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
  10. package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
  11. package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
  12. package/types/tests/unit/crudPromise.d.ts +25 -0
  13. package/types/tests/unit/crudPromise.d.ts.map +1 -0
  14. package/types/tests/unit/expectHelpers.d.ts +2 -0
  15. package/types/tests/unit/expectHelpers.d.ts.map +1 -0
  16. package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
  17. package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
  18. package/types/tests/unit/poll.d.ts +2 -0
  19. package/types/tests/unit/poll.d.ts.map +1 -0
  20. package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
  21. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
  22. package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
  23. package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
  24. package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
  25. package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
  26. package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
  27. package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
  28. package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
  29. package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
  30. package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
  31. package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
  32. package/types/tests/unit/use/listSort.spec.d.ts +2 -0
  33. package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
  34. package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
  35. package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
  36. package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
  37. package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
  38. package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
  39. package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
  40. package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
  41. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
  42. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
  43. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
  44. package/types/tests/unit/use/search.spec.d.ts +2 -0
  45. package/types/tests/unit/use/search.spec.d.ts.map +1 -0
  46. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
  47. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
  48. package/types/tests/unit/utils/classes.spec.d.ts +2 -0
  49. package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
  50. package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
  51. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
  52. package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
  53. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
  54. package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
  55. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
  56. package/types/tests/unit/utils/set.spec.d.ts +2 -0
  57. package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
  58. package/types/tests/unit/utils/watches.spec.d.ts +2 -0
  59. package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
  60. package/types/use/cancellableIntent.d.ts +129 -0
  61. package/types/use/cancellableIntent.d.ts.map +1 -0
  62. package/types/use/combineClasses.d.ts +43 -0
  63. package/types/use/combineClasses.d.ts.map +1 -0
  64. package/types/use/list.d.ts +176 -0
  65. package/types/use/list.d.ts.map +1 -0
  66. package/types/use/listCalculated.d.ts +192 -0
  67. package/types/use/listCalculated.d.ts.map +1 -0
  68. package/types/use/listFilter.d.ts +203 -0
  69. package/types/use/listFilter.d.ts.map +1 -0
  70. package/types/use/listInstance.d.ts +357 -0
  71. package/types/use/listInstance.d.ts.map +1 -0
  72. package/types/use/listKeys.d.ts +15 -0
  73. package/types/use/listKeys.d.ts.map +1 -0
  74. package/types/use/listRelated.d.ts +239 -0
  75. package/types/use/listRelated.d.ts.map +1 -0
  76. package/types/use/listSearch.d.ts +298 -0
  77. package/types/use/listSearch.d.ts.map +1 -0
  78. package/types/use/listSort.d.ts +235 -0
  79. package/types/use/listSort.d.ts.map +1 -0
  80. package/types/use/listSubscription.d.ts +218 -0
  81. package/types/use/listSubscription.d.ts.map +1 -0
  82. package/types/use/loadingError.d.ts +81 -0
  83. package/types/use/loadingError.d.ts.map +1 -0
  84. package/types/use/object.d.ts +67 -0
  85. package/types/use/object.d.ts.map +1 -0
  86. package/types/use/objectCalculated.d.ts +215 -0
  87. package/types/use/objectCalculated.d.ts.map +1 -0
  88. package/types/use/objectInstance.d.ts +289 -0
  89. package/types/use/objectInstance.d.ts.map +1 -0
  90. package/types/use/objectRelated.d.ts +264 -0
  91. package/types/use/objectRelated.d.ts.map +1 -0
  92. package/types/use/objectSubscription.d.ts +249 -0
  93. package/types/use/objectSubscription.d.ts.map +1 -0
  94. package/types/use/paginatedListInstance.d.ts +51 -0
  95. package/types/use/paginatedListInstance.d.ts.map +1 -0
  96. package/types/use/proxyLoadingError.d.ts +36 -0
  97. package/types/use/proxyLoadingError.d.ts.map +1 -0
  98. package/types/use/search.d.ts +144 -0
  99. package/types/use/search.d.ts.map +1 -0
  100. package/types/use/watchesRunning.d.ts +63 -0
  101. package/types/use/watchesRunning.d.ts.map +1 -0
  102. package/types/utils/assignReactiveObject.d.ts +115 -0
  103. package/types/utils/assignReactiveObject.d.ts.map +1 -0
  104. package/types/utils/classes.d.ts +22 -0
  105. package/types/utils/classes.d.ts.map +1 -0
  106. package/types/utils/compact.d.ts +4 -0
  107. package/types/utils/compact.d.ts.map +1 -0
  108. package/types/utils/deleteKey.d.ts +16 -0
  109. package/types/utils/deleteKey.d.ts.map +1 -0
  110. package/types/utils/flattenPaths.d.ts +23 -0
  111. package/types/utils/flattenPaths.d.ts.map +1 -0
  112. package/types/utils/getFakePk.d.ts +13 -0
  113. package/types/utils/getFakePk.d.ts.map +1 -0
  114. package/types/utils/keepAliveTry.d.ts +15 -0
  115. package/types/utils/keepAliveTry.d.ts.map +1 -0
  116. package/types/utils/keyDiff.d.ts +63 -0
  117. package/types/utils/keyDiff.d.ts.map +1 -0
  118. package/types/utils/loadingCombine.d.ts +9 -0
  119. package/types/utils/loadingCombine.d.ts.map +1 -0
  120. package/types/utils/proxyRunning.d.ts +9 -0
  121. package/types/utils/proxyRunning.d.ts.map +1 -0
  122. package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
  123. package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
  124. package/types/utils/set.d.ts +7 -0
  125. package/types/utils/set.d.ts.map +1 -0
  126. package/types/utils/transformWalk.d.ts +2 -0
  127. package/types/utils/transformWalk.d.ts.map +1 -0
  128. package/types/utils/watches.d.ts +155 -0
  129. package/types/utils/watches.d.ts.map +1 -0
  130. package/use/loadingError.js +1 -1
  131. package/.circleci/config.yml +0 -88
  132. package/.commitlintrc.json +0 -25
  133. package/.editorconfig +0 -5
  134. package/.husky/commit-msg +0 -3
  135. package/.husky/pre-commit +0 -3
  136. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  137. package/.idea/encodings.xml +0 -6
  138. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  139. package/.idea/modules.xml +0 -8
  140. package/.idea/prettier.xml +0 -8
  141. package/.idea/reactive-helpers.iml +0 -15
  142. package/.prettierignore +0 -5
  143. package/.prettierrc.cjs +0 -5
  144. package/.vscode/extensions.json +0 -3
  145. package/docs/README.md +0 -45
  146. package/docs/config/listCrud.md +0 -422
  147. package/docs/config/objectCrud.md +0 -427
  148. package/docs/use/cancellableIntent.md +0 -165
  149. package/docs/use/combineClasses.md +0 -62
  150. package/docs/use/list.md +0 -361
  151. package/docs/use/listCalculated.md +0 -794
  152. package/docs/use/listFilter.md +0 -897
  153. package/docs/use/listInstance.md +0 -559
  154. package/docs/use/listKeys.md +0 -91
  155. package/docs/use/listRelated.md +0 -706
  156. package/docs/use/listSearch.md +0 -903
  157. package/docs/use/listSort.md +0 -1171
  158. package/docs/use/listSubscription.md +0 -393
  159. package/docs/use/loadingError.md +0 -115
  160. package/docs/use/object.md +0 -668
  161. package/docs/use/objectCalculated.md +0 -741
  162. package/docs/use/objectInstance.md +0 -685
  163. package/docs/use/objectRelated.md +0 -723
  164. package/docs/use/objectSubscription.md +0 -538
  165. package/docs/use/paginatedListInstance.md +0 -155
  166. package/docs/use/proxyLoadingError.md +0 -51
  167. package/docs/use/search.md +0 -321
  168. package/docs/use/watchesRunning.md +0 -84
  169. package/docs/utils/assignReactiveObject.md +0 -413
  170. package/docs/utils/classes.md +0 -139
  171. package/docs/utils/compact.md +0 -67
  172. package/docs/utils/deleteKey.md +0 -61
  173. package/docs/utils/flattenPaths.md +0 -53
  174. package/docs/utils/getFakePk.md +0 -39
  175. package/docs/utils/keepAliveTry.md +0 -59
  176. package/docs/utils/keyDiff.md +0 -117
  177. package/docs/utils/loadingCombine.md +0 -30
  178. package/docs/utils/proxyRunning.md +0 -39
  179. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  180. package/docs/utils/set.md +0 -223
  181. package/docs/utils/transformWalk.md +0 -68
  182. package/docs/utils/watches.md +0 -489
  183. package/eslint.config.js +0 -125
  184. package/lint-staged.config.js +0 -10
  185. package/makeTypeDoc.sh +0 -25
  186. package/make_type_doc.js +0 -59
  187. package/tests/unit/config/listCrud.spec.js +0 -114
  188. package/tests/unit/config/objectCrud.spec.js +0 -160
  189. package/tests/unit/crudPromise.js +0 -40
  190. package/tests/unit/expectHelpers.js +0 -6
  191. package/tests/unit/mockOnUnmounted.js +0 -9
  192. package/tests/unit/poll.js +0 -50
  193. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  194. package/tests/unit/use/listCalculated.spec.js +0 -135
  195. package/tests/unit/use/listFilter.spec.js +0 -484
  196. package/tests/unit/use/listInstance.spec.js +0 -1166
  197. package/tests/unit/use/listRelated.spec.js +0 -260
  198. package/tests/unit/use/listSearch.spec.js +0 -586
  199. package/tests/unit/use/listSort.spec.js +0 -418
  200. package/tests/unit/use/listSubscription.spec.js +0 -845
  201. package/tests/unit/use/loadingError.spec.js +0 -43
  202. package/tests/unit/use/objectInstance.spec.js +0 -1525
  203. package/tests/unit/use/objectSubscription.spec.js +0 -849
  204. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  205. package/tests/unit/use/search.spec.js +0 -248
  206. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  207. package/tests/unit/utils/classes.spec.js +0 -427
  208. package/tests/unit/utils/deleteKey.spec.js +0 -265
  209. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  210. package/tests/unit/utils/keyDiff.spec.js +0 -110
  211. package/tests/unit/utils/set.spec.js +0 -81
  212. package/tests/unit/utils/watches.spec.js +0 -276
  213. package/tsconfig.json +0 -19
  214. package/typedoc-local-plugins/customize-output.js +0 -13
  215. package/typedoc.json +0 -11
  216. package/vitest.config.js +0 -11
@@ -1,484 +0,0 @@
1
- import { doAwaitNot } from "../../../utils/watches.js";
2
- import { reactive, ref, unref } from "vue";
3
- import { deepUnref } from "vue-deepunref";
4
-
5
- describe("use/listFilter", () => {
6
- let useListInstance, useListFilter, useListCalculated, useListRelated, useListFilters, useListSort;
7
- beforeEach(async () => {
8
- const listInstanceModule = await import("../../../use/listInstance.js");
9
- useListInstance = listInstanceModule.useListInstance;
10
- const listFilterModule = await import("../../../use/listFilter.js");
11
- useListFilter = listFilterModule.useListFilter;
12
- useListFilters = listFilterModule.useListFilters;
13
- const listRelatedModule = await import("../../../use/listRelated.js");
14
- useListRelated = listRelatedModule.useListRelated;
15
- const listCalculatedModule = await import("../../../use/listCalculated.js");
16
- useListCalculated = listCalculatedModule.useListCalculated;
17
- const listSortModule = await import("../../../use/listSort.js");
18
- useListSort = listSortModule.useListSort;
19
- });
20
-
21
- it("should match an allowed filter function", async () => {
22
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
23
- const filter = useListFilter({
24
- parentState: list.state,
25
- allowedFilter: (object) => object.id === 1 || object.id === 3,
26
- });
27
- expect(filter.state.objects).toEqual({});
28
- list.addListObject({ id: 1, name: "one", has_things: true });
29
- await doAwaitNot({
30
- obj: filter.state,
31
- prop: "running",
32
- timeout: 100,
33
- });
34
- expect(filter.state.objects).toEqual({
35
- 1: { id: 1, name: "one", has_things: true },
36
- });
37
- list.addListObject({ id: 2, name: "two", has_things: true });
38
- await doAwaitNot({
39
- obj: filter.state,
40
- prop: "running",
41
- timeout: 100,
42
- });
43
- expect(filter.state.objects).toEqual({
44
- 1: { id: 1, name: "one", has_things: true },
45
- });
46
- list.addListObject({ id: 3, name: "three", has_things: true });
47
- await doAwaitNot({
48
- obj: filter.state,
49
- prop: "running",
50
- timeout: 100,
51
- });
52
- expect(filter.state.objects).toEqual({
53
- 1: { id: 1, name: "one", has_things: true },
54
- 3: { id: 3, name: "three", has_things: true },
55
- });
56
- list.addListObject({ id: 4, name: "four", has_things: true });
57
- await doAwaitNot({
58
- obj: filter.state,
59
- prop: "running",
60
- timeout: 100,
61
- });
62
- expect(filter.state.objects).toEqual({
63
- 1: { id: 1, name: "one", has_things: true },
64
- 3: { id: 3, name: "three", has_things: true },
65
- });
66
- });
67
- it("should match an excluded filter function", async () => {
68
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
69
- const filter = useListFilter({
70
- parentState: list.state,
71
- excludedFilter: (object) => object.id == 2 || object.id == 4,
72
- });
73
- expect(filter.state.objects).toEqual({});
74
- list.addListObject({ id: 1, name: "one", has_things: true });
75
- await doAwaitNot({
76
- obj: filter.state,
77
- prop: "running",
78
- timeout: 100,
79
- });
80
- expect(filter.state.objects).toEqual({
81
- 1: { id: 1, name: "one", has_things: true },
82
- });
83
- list.addListObject({ id: 2, name: "two", has_things: true });
84
- await doAwaitNot({
85
- obj: filter.state,
86
- prop: "running",
87
- timeout: 100,
88
- });
89
- expect(filter.state.objects).toEqual({
90
- 1: { id: 1, name: "one", has_things: true },
91
- });
92
- list.addListObject({ id: 3, name: "three", has_things: true });
93
- await doAwaitNot({
94
- obj: filter.state,
95
- prop: "running",
96
- timeout: 100,
97
- });
98
- expect(filter.state.objects).toEqual({
99
- 1: { id: 1, name: "one", has_things: true },
100
- 3: { id: 3, name: "three", has_things: true },
101
- });
102
- list.addListObject({ id: 4, name: "four", has_things: true });
103
- await doAwaitNot({
104
- obj: filter.state,
105
- prop: "running",
106
- timeout: 100,
107
- });
108
- expect(filter.state.objects).toEqual({
109
- 1: { id: 1, name: "one", has_things: true },
110
- 3: { id: 3, name: "three", has_things: true },
111
- });
112
- });
113
- it("no args: returns objects unfiltered", async () => {
114
- const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
115
- const listItems = [
116
- { id: 4, name: "four", has_things: true },
117
- { id: 2, name: "two", has_things: true },
118
- { id: 3, name: "three", has_things: true },
119
- { id: 1, name: "one", has_things: true },
120
- ];
121
- for (const item of listItems) {
122
- listInstance.addListObject(item);
123
- }
124
- const filter = useListFilter({
125
- parentState: listInstance.state,
126
- });
127
- await doAwaitNot({
128
- obj: filter.state,
129
- prop: "running",
130
- });
131
- expect(filter.state.objects).toEqual(listInstance.state.objects);
132
- });
133
- describe("useListFilter operates on parentState modified by useListSort", () => {
134
- it("computes state.order and state.objects in order", async () => {
135
- vi.resetAllMocks();
136
- const orderByRules = [{ key: "name", desc: true, localeCompare: false }];
137
- const sortThrottleWait = 0;
138
- const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
139
- const listItems = [
140
- { id: 4, name: "four", has_things: true },
141
- { id: 2, name: "two", has_things: true },
142
- { id: 3, name: "three", has_things: true },
143
- { id: 1, name: "one", has_things: true },
144
- ];
145
- const expectedOrder = ["2", "3", "1", "4"];
146
- const orderedObjects = [
147
- { id: 2, name: "two", has_things: true },
148
- { id: 3, name: "three", has_things: true },
149
- { id: 1, name: "one", has_things: true },
150
- { id: 4, name: "four", has_things: true },
151
- ];
152
- const listSort = useListSort({ parentState: listInstance.state, orderByRules, sortThrottleWait });
153
- for (const item of listItems) {
154
- listInstance.addListObject(item);
155
- }
156
- const filter = useListFilter({
157
- parentState: listSort.state,
158
- });
159
- await doAwaitNot({
160
- obj: filter.state,
161
- prop: "running",
162
- });
163
- expect(filter.state.order).toEqual(expectedOrder);
164
- expect(filter.state.objectsInOrder).toEqual(orderedObjects);
165
- });
166
- });
167
- describe("useListFilters accepts args and parentInstances", () => {
168
- it("returns filtered objects", async () => {
169
- vi.resetAllMocks();
170
- const fields = ["id", "__str__", "name"];
171
- const listInstanceA = useListInstance({
172
- props: {
173
- crudArgs: { stream: "test_streamA" },
174
- listArgs: { user: 1 },
175
- pkKey: "id",
176
- retrieveArgs: {
177
- fields,
178
- },
179
- },
180
- keepOldPages: false,
181
- });
182
- const listInstanceB = useListInstance({
183
- props: {
184
- crudArgs: { stream: "test_streamB" },
185
- listArgs: { user: 2 },
186
- retrieveArgs: {
187
- fields,
188
- },
189
- },
190
- keepOldPages: false,
191
- });
192
- const excludedFilter = (object) => object.id === 1 || object.name === "three";
193
- const allowedFilter = (object) => object.id === 2 || object.name === "four";
194
- const listFilterA = useListFilter({
195
- parentState: listInstanceA.state,
196
- excludedFilter,
197
- });
198
- const listFilterB = useListFilter({
199
- parentState: listInstanceB.state,
200
- allowedFilter,
201
- });
202
- const listFilterArgs = {
203
- A: {
204
- parentState: listInstanceA.state,
205
- excludedFilter,
206
- },
207
- B: {
208
- parentState: listInstanceB.state,
209
- allowedFilter,
210
- },
211
- };
212
- const listInstances = {
213
- A: listInstanceA,
214
- B: listInstanceB,
215
- };
216
- const listFilters = useListFilters(listFilterArgs);
217
-
218
- expect(listFilters.A.state.excludedFilter).toEqual(listFilterArgs.A.excludedFilter);
219
- expect(listFilters.B.state.allowedFilter).toEqual(listFilterArgs.B.allowedFilter);
220
- expect(unref(listFilters.A.parentState)).toEqual(unref(listFilterA.parentState));
221
- expect(unref(listFilters.B.parentState)).toEqual(unref(listFilterB.parentState));
222
- expect(deepUnref(listFilters.A.state)).toEqual(deepUnref(listFilterA.state));
223
- expect(deepUnref(listFilters.B.state)).toEqual(deepUnref(listFilterB.state));
224
- });
225
- });
226
- describe("useListFilters updates index when", () => {
227
- it("parentInstance.objects is updated", async () => {
228
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
229
- const filter = useListFilter({
230
- parentState: list.state,
231
- allowedFilter: (object) => !!object.allowed?.every((e) => e),
232
- });
233
- await doAwaitNot({
234
- obj: filter.state,
235
- prop: "running",
236
- timeout: 100,
237
- });
238
- expect(filter.state.objects).toEqual({});
239
- list.addListObject({ id: 1, name: "one", has_things: true, allowed: [true, true] });
240
- await doAwaitNot({
241
- obj: filter.state,
242
- prop: "running",
243
- timeout: 100,
244
- });
245
- expect(filter.state.objects).toEqual({
246
- 1: { id: 1, name: "one", has_things: true, allowed: [true, true] },
247
- });
248
- list.addListObject({ id: 2, name: "two", has_things: true, allowed: [true, false] });
249
- await doAwaitNot({
250
- obj: filter.state,
251
- prop: "running",
252
- timeout: 100,
253
- });
254
- expect(filter.state.objects).toEqual({
255
- 1: { id: 1, name: "one", has_things: true, allowed: [true, true] },
256
- });
257
- list.state.objects[1].allowed[0] = false;
258
- list.state.objects[2].allowed[1] = true;
259
- await doAwaitNot({
260
- obj: filter.state,
261
- prop: "running",
262
- timeout: 100,
263
- });
264
- expect(filter.state.objects).toEqual({
265
- 2: { id: 2, name: "two", has_things: true, allowed: [true, true] },
266
- });
267
- });
268
- it("parentInstance.relatedObjects is updated", async () => {
269
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
270
- const relatedList = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
271
- const related = useListRelated({
272
- parentState: list.state,
273
- relatedObjectsRules: {
274
- relatedRuleName: {
275
- objects: relatedList.state.objects,
276
- pkKey: "related_id",
277
- },
278
- },
279
- });
280
- const allowedFilter = ref();
281
- allowedFilter.value = (object, relatedObject) =>
282
- relatedObject.relatedRuleName.allowed && relatedObject.relatedRuleName.has_things && object.has_things;
283
- const filter = useListFilter({
284
- parentState: related.state,
285
- allowedFilter,
286
- });
287
- await doAwaitNot({
288
- obj: filter.state,
289
- prop: "running",
290
- timeout: 100,
291
- });
292
- expect(filter.state.objects).toEqual({});
293
- relatedList.addListObject({ id: 2, name: "two", has_things: true, allowed: true });
294
- list.addListObject({ id: 1, name: "one", has_things: true, related_id: 2 });
295
- await doAwaitNot({
296
- obj: filter.state,
297
- prop: "running",
298
- timeout: 100,
299
- });
300
- expect(filter.state.objects).toEqual({
301
- 1: { id: 1, name: "one", has_things: true, related_id: 2 },
302
- });
303
- relatedList.addListObject({ id: 4, name: "four", has_things: true, allowed: false });
304
- list.addListObject({ id: 3, name: "three", has_things: true, related_id: 4 });
305
- await doAwaitNot({
306
- obj: filter.state,
307
- prop: "running",
308
- timeout: 100,
309
- });
310
- expect(filter.state.objects).toEqual({
311
- 1: { id: 1, name: "one", has_things: true, related_id: 2 },
312
- });
313
- relatedList.state.objects[2].allowed = false;
314
- relatedList.state.objects[4].allowed = true;
315
- await doAwaitNot({
316
- obj: filter.state,
317
- prop: "running",
318
- timeout: 100,
319
- });
320
- expect(filter.state.objects).toEqual({
321
- 3: { id: 3, name: "three", has_things: true, related_id: 4 },
322
- });
323
- });
324
- it("parentInstance.calculatedObjects is updated", async () => {
325
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
326
- const calculated = useListCalculated({
327
- parentState: list.state,
328
- calculatedObjectsRules: reactive({
329
- calculatedRuleName: (object) => object.things_count + object.other_things_count,
330
- }),
331
- });
332
- const allowedFilter = ref();
333
- allowedFilter.value = (object, relatedObject, calculatedObject) => calculatedObject.calculatedRuleName > 5;
334
- const filter = useListFilter({
335
- parentState: calculated.state,
336
- allowedFilter,
337
- });
338
- await doAwaitNot({
339
- obj: filter.state,
340
- prop: "running",
341
- });
342
- expect(filter.state.objects).toEqual({});
343
- list.addListObject({ id: 1, name: "one", has_things: true, things_count: 2, other_things_count: 3 });
344
- await doAwaitNot({
345
- obj: filter.state,
346
- prop: "running",
347
- });
348
- expect(filter.state.objects).toEqual({});
349
- list.addListObject({ id: 2, name: "two", has_things: true, things_count: 2, other_things_count: 4 });
350
- await doAwaitNot({
351
- obj: filter.state,
352
- prop: "running",
353
- });
354
- expect(filter.state.objects).toEqual({
355
- 2: { id: 2, name: "two", has_things: true, things_count: 2, other_things_count: 4 },
356
- });
357
- list.state.objects[1].things_count = 4;
358
- list.state.objects[2].other_things_count = 0;
359
- await doAwaitNot({
360
- obj: filter.state,
361
- prop: "running",
362
- });
363
- expect(filter.state.objects).toEqual({
364
- 1: { id: 1, name: "one", has_things: true, things_count: 4, other_things_count: 3 },
365
- });
366
- });
367
- });
368
- it("you can use nested useListFilters", async () => {
369
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
370
-
371
- function filter1AllowedFilter(object) {
372
- return object.has_things && object.has_stuff;
373
- }
374
-
375
- function filter2AllowedFilter(object) {
376
- return object.has_things && object.has_other_stuff;
377
- }
378
-
379
- const filter1 = useListFilter({
380
- parentState: list.state,
381
- allowedFilter: filter1AllowedFilter,
382
- });
383
- const filter2 = useListFilter({
384
- parentState: filter1.state,
385
- allowedFilter: filter2AllowedFilter,
386
- });
387
- await doAwaitNot({
388
- obj: filter2.state,
389
- prop: "running",
390
- });
391
- expect(filter1.state.objects).toEqual({});
392
- expect(filter1.state.order).toEqual([]);
393
- expect(filter2.state.objects).toEqual({});
394
- expect(filter2.state.order).toEqual([]);
395
- list.addListObject({ id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true });
396
- await doAwaitNot({
397
- obj: filter2.state,
398
- prop: "running",
399
- });
400
- expect(filter1.state.objects).toEqual({
401
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
402
- });
403
- expect(filter1.state.order).toEqual(["1"]);
404
- expect(filter2.state.objects).toEqual({
405
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
406
- });
407
- expect(filter2.state.order).toEqual(["1"]);
408
- list.addListObject({ id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: false });
409
- await doAwaitNot({
410
- obj: filter2.state,
411
- prop: "running",
412
- });
413
- expect(filter1.state.objects).toEqual({
414
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
415
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: false },
416
- });
417
- expect(filter1.state.order).toEqual(["1", "2"]);
418
- expect(filter2.state.objects).toEqual({
419
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
420
- });
421
- expect(filter2.state.order).toEqual(["1"]);
422
- list.addListObject({ id: 3, name: "three", has_things: true, has_stuff: false, has_other_stuff: true });
423
- await doAwaitNot({
424
- obj: filter2.state,
425
- prop: "running",
426
- });
427
- expect(filter1.state.objects).toEqual({
428
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
429
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: false },
430
- });
431
- expect(filter1.state.order).toEqual(["1", "2"]);
432
- expect(filter2.state.objects).toEqual({
433
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
434
- });
435
- expect(filter2.state.order).toEqual(["1"]);
436
- list.addListObject({ id: 4, name: "four", has_things: true, has_stuff: false, has_other_stuff: false });
437
- await doAwaitNot({
438
- obj: filter2.state,
439
- prop: "running",
440
- });
441
- expect(filter1.state.objects).toEqual({
442
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
443
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: false },
444
- });
445
- expect(filter1.state.order).toEqual(["1", "2"]);
446
- expect(filter2.state.objects).toEqual({
447
- 1: { id: 1, name: "one", has_things: true, has_stuff: true, has_other_stuff: true },
448
- });
449
- expect(filter2.state.order).toEqual(["1"]);
450
- list.state.objects[1].has_stuff = false;
451
- list.state.objects[2].has_other_stuff = true;
452
- await doAwaitNot({
453
- obj: filter2.state,
454
- prop: "running",
455
- });
456
- expect(filter1.state.objects).toEqual({
457
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: true },
458
- });
459
- expect(filter1.state.order).toEqual(["2"]);
460
- expect(filter2.state.objects).toEqual({
461
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: true },
462
- });
463
- expect(filter2.state.order).toEqual(["2"]);
464
- list.addListObject({ id: 5, name: "five", has_things: true, has_stuff: false, has_other_stuff: true });
465
- list.addListObject({ id: 6, name: "six", has_things: true, has_stuff: true, has_other_stuff: false });
466
- list.addListObject({ id: 7, name: "seven", has_things: false, has_stuff: true, has_other_stuff: true });
467
- list.addListObject({ id: 8, name: "eight", has_things: true, has_stuff: true, has_other_stuff: true });
468
- await doAwaitNot({
469
- obj: filter2.state,
470
- prop: "running",
471
- });
472
- expect(filter1.state.objects).toEqual({
473
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: true },
474
- 6: { id: 6, name: "six", has_things: true, has_stuff: true, has_other_stuff: false },
475
- 8: { id: 8, name: "eight", has_things: true, has_stuff: true, has_other_stuff: true },
476
- });
477
- expect(filter1.state.order).toEqual(["2", "6", "8"]);
478
- expect(filter2.state.objects).toEqual({
479
- 2: { id: 2, name: "two", has_things: true, has_stuff: true, has_other_stuff: true },
480
- 8: { id: 8, name: "eight", has_things: true, has_stuff: true, has_other_stuff: true },
481
- });
482
- expect(filter2.state.order).toEqual(["2", "8"]);
483
- });
484
- });