@yuneta/gobj-ui 7.29.7 → 7.29.8

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.
package/README.md CHANGED
@@ -1278,7 +1278,7 @@ it used to call `tabulator.setFilter` straight from the DOM handler, where the
1278
1278
  A hook cell shows how many children the row has (`[5675]`). A click on it
1279
1279
  opens the **child topic's table, filtered** to the rows whose fkey names this
1280
1280
  row (since `7.23.162`). Above the table, a chip says which filter is on,
1281
- "filtered by models model_a", and its ✕ brings the whole topic back.
1281
+ "filtered by sites north", and its ✕ brings the whole topic back.
1282
1282
 
1283
1283
  The child table already pages, searches, opens a record and exports. Until
1284
1284
  `7.23.162` the click opened a popup that listed every child id instead:
@@ -65592,7 +65592,12 @@ function fold_split_group_key(group_key) {
65592
65592
  };
65593
65593
  }
65594
65594
  /************************************************************
65595
- * Every parent a record names, decoded, in column order.
65595
+ * Every parent a record names, decoded, in column order, and
65596
+ * in every element of a multivalued fkey. A fkey column
65597
+ * answers to one hook of one topic (the treedb refuses a
65598
+ * second), so a record that can hang from two topics has a
65599
+ * column for each; it is a hook that can hold the children
65600
+ * of several topics.
65596
65601
  *
65597
65602
  * Only the parents that will be DRAWN: a topic missing from
65598
65603
  * `descs` (a system topic such as `__assets__`, never fetched)
@@ -65587,7 +65587,12 @@ function fold_split_group_key(group_key) {
65587
65587
  };
65588
65588
  }
65589
65589
  /************************************************************
65590
- * Every parent a record names, decoded, in column order.
65590
+ * Every parent a record names, decoded, in column order, and
65591
+ * in every element of a multivalued fkey. A fkey column
65592
+ * answers to one hook of one topic (the treedb refuses a
65593
+ * second), so a record that can hang from two topics has a
65594
+ * column for each; it is a hook that can hold the children
65595
+ * of several topics.
65591
65596
  *
65592
65597
  * Only the parents that will be DRAWN: a topic missing from
65593
65598
  * `descs` (a system topic such as `__assets__`, never fetched)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.29.7",
3
+ "version": "7.29.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
@@ -78,7 +78,12 @@ export function fold_split_group_key(group_key)
78
78
  }
79
79
 
80
80
  /************************************************************
81
- * Every parent a record names, decoded, in column order.
81
+ * Every parent a record names, decoded, in column order, and
82
+ * in every element of a multivalued fkey. A fkey column
83
+ * answers to one hook of one topic (the treedb refuses a
84
+ * second), so a record that can hang from two topics has a
85
+ * column for each; it is a hook that can hold the children
86
+ * of several topics.
82
87
  *
83
88
  * Only the parents that will be DRAWN: a topic missing from
84
89
  * `descs` (a system topic such as `__assets__`, never fetched)
@@ -8,6 +8,12 @@
8
8
  * owns it), devices hanging from a site AND an owner, notes
9
9
  * hanging from a site or a device, and a topic with hooks and no
10
10
  * fkeys (extended) whose children must be roots.
11
+ *
12
+ * A note has two fkey columns, one for each topic it can hang from:
13
+ * a fkey column answers to ONE hook of ONE topic (the treedb refuses
14
+ * a second, "Only can be one fkey"). What CAN name several topics is
15
+ * a hook: one hook holding children of two topics has a case of its
16
+ * own below.
11
17
  ***********************************************************************/
12
18
  import { describe, test, expect } from "vitest";
13
19
  import {
@@ -53,6 +59,7 @@ const devices_desc = {
53
59
  {id: "id", flag: []},
54
60
  {id: "site", flag: ["fkey"], fkey: {sites: "devices"}},
55
61
  {id: "owner", flag: ["fkey"], fkey: {owners: "devices"}},
62
+ {id: "group", flag: ["fkey"], fkey: {groups: "members"}},
56
63
  {id: "photo", flag: ["fkey", "file"], fkey: {__assets__: "photos"}},
57
64
  {id: "notes", flag: ["hook"], hook: {notes: "device"}},
58
65
  ],
@@ -162,6 +169,8 @@ describe("the model", () => {
162
169
  let recs = make_records(1);
163
170
  recs.devices[0] = {id: "d0", group: "groups^g1^members"};
164
171
  let m = fold_build_model(descs, recs);
172
+ /* devices_desc has the fkey column `group`: the ref is read, and refused */
173
+ expect(m.nodes.get(K("devices", "d0")).parents).toEqual([]);
165
174
  expect(m.nodes.get(K("groups", "g1")).hooks).toEqual({});
166
175
  /* devices hang from sites (the main topic), so a device with
167
176
  * no parent is LOOSE, not a root -- see the "main topic" block */
@@ -175,6 +184,53 @@ describe("the model", () => {
175
184
  expect(m3.groups.get(fold_root_group_key("devices"))).toEqual([K("devices", "d0")]);
176
185
  });
177
186
 
187
+ test("a multivalued fkey names a parent in every element, not only the first", () => {
188
+ let recs = make_records(1);
189
+ recs.owners.push({id: "o2", parent: ""}, {id: "o3", parent: ""});
190
+ recs.devices[0].owner = ["owners^o1^devices", "owners^o2^devices", "owners^o3^devices"];
191
+ let m = fold_build_model(descs, recs);
192
+ expect(m.nodes.get(K("devices", "d0")).parents.map((p) => p.node_key))
193
+ .toEqual([K("sites", "site1"), K("owners", "o1"), K("owners", "o2"), K("owners", "o3")]);
194
+ for(let o of ["o1", "o2", "o3"]) {
195
+ expect(m.groups.get(fold_group_key(K("owners", o), "devices"))).toEqual([K("devices", "d0")]);
196
+ }
197
+ });
198
+
199
+ test("a hook can hold the children of two topics: one group, in topic order", () => {
200
+ /* sites.items holds devices AND notes; each child's own fkey
201
+ * column names that one hook */
202
+ let sites_items = {topic_name: "sites", node_treedb_type: "entity", cols: [
203
+ {id: "id", flag: []},
204
+ {id: "site", flag: ["fkey"], fkey: {sites: "sites"}},
205
+ {id: "sites", flag: ["hook"], hook: {sites: "site"}},
206
+ {id: "items", flag: ["hook"], hook: {devices: "place", notes: "place"}},
207
+ ]};
208
+ let devices_items = {topic_name: "devices", node_treedb_type: "child", cols: [
209
+ {id: "id", flag: []},
210
+ {id: "place", flag: ["fkey"], fkey: {sites: "items"}},
211
+ ]};
212
+ let notes_items = {topic_name: "notes", node_treedb_type: "child", cols: [
213
+ {id: "id", flag: []},
214
+ {id: "place", flag: ["fkey"], fkey: {sites: "items"}},
215
+ ]};
216
+ let d = {sites: sites_items, devices: devices_items, notes: notes_items};
217
+ let recs = {
218
+ sites: [{id: "site1", site: ""}],
219
+ devices: [{id: "d0", place: "sites^site1^items"}],
220
+ notes: [{id: "n1", place: "sites^site1^items"}, {id: "n2"}],
221
+ };
222
+ let m = fold_build_model(d, recs);
223
+ expect(m.main_topic).toBe("sites");
224
+ expect([...m.linked].sort()).toEqual(["devices", "notes", "sites"]);
225
+ expect(m.groups.get(fold_group_key(K("sites", "site1"), "items")))
226
+ .toEqual([K("devices", "d0"), K("notes", "n1")]);
227
+ expect(m.loose.notes).toEqual([K("notes", "n2")]);
228
+ let st = fold_new_state(24);
229
+ fold_expand_all(m, st);
230
+ expect([...fold_visible_set(m, st)].sort())
231
+ .toEqual([K("devices", "d0"), K("notes", "n1"), K("sites", "site1")]);
232
+ });
233
+
178
234
  test("a cycle with no way in gets one root, not a row of them", () => {
179
235
  let recs = {
180
236
  sites: [
@@ -224,6 +280,25 @@ describe("main topic, hidden topics, loose records", () => {
224
280
  expect(fold_main_topic({sites: sites_desc})).toBe("sites");
225
281
  });
226
282
 
283
+ test("a tie is broken by schema order: the first of the tied topics", () => {
284
+ /* without notes, sites and owners both reach devices alone */
285
+ let tied = {sites: sites_desc, owners: owners_desc, devices: devices_desc};
286
+ expect(fold_main_topic(tied)).toBe("sites");
287
+ let tied_back = {owners: owners_desc, sites: sites_desc, devices: devices_desc};
288
+ expect(fold_main_topic(tied_back)).toBe("owners");
289
+ expect(fold_build_model(tied_back, {}).main_topic).toBe("owners");
290
+ });
291
+
292
+ test("two topics marked: the first in schema order wins", () => {
293
+ let sites_marked = Object.assign({}, sites_desc, {main_topic: true});
294
+ let owners_marked = Object.assign({}, owners_desc, {main_topic: true});
295
+ /* owners first: the deduction would pick sites, the marks owners */
296
+ expect(fold_main_topic({owners: owners_marked, sites: sites_marked,
297
+ devices: devices_desc, notes: notes_desc})).toBe("owners");
298
+ expect(fold_main_topic({sites: sites_marked, owners: owners_marked,
299
+ devices: devices_desc, notes: notes_desc})).toBe("sites");
300
+ });
301
+
227
302
  test("the schema's mark wins over the deduction, among hierarchical topics", () => {
228
303
  /* two hierarchical topics; sites reaches more (devices, notes) */
229
304
  expect(fold_main_topic(descs)).toBe("sites");
@@ -295,6 +370,32 @@ describe("main topic, hidden topics, loose records", () => {
295
370
  });
296
371
 
297
372
  test("hiding a topic in the middle: what hung from it alone becomes loose", () => {
373
+ /* devices sit between sites and notes: n_dev hangs from d0
374
+ * alone, n_both from d0 AND site1 */
375
+ let recs = make_records(2);
376
+ recs.notes.push({id: "n_dev", device: "devices^d0^notes"});
377
+ recs.notes.push({id: "n_both", site: "sites^site1^notes", device: "devices^d0^notes"});
378
+ let shown = fold_build_model(descs, recs);
379
+ expect(shown.loose.notes).toEqual([]);
380
+ expect(shown.nodes.get(K("notes", "n_dev")).parents.map((p) => p.node_key))
381
+ .toEqual([K("devices", "d0")]);
382
+ let m = fold_build_model(descs, recs, {hidden_topics: ["devices"]});
383
+ expect(m.main_topic).toBe("sites");
384
+ expect(m.nodes.get(K("notes", "n_dev")).parents).toEqual([]);
385
+ expect(m.loose.notes).toEqual([K("notes", "n_dev")]);
386
+ expect(m.groups.get(fold_root_group_key("notes"))).toBeUndefined();
387
+ expect(m.nodes.get(K("notes", "n_both")).parents.map((p) => p.node_key))
388
+ .toEqual([K("sites", "site1")]);
389
+ expect(m.groups.get(fold_group_key(K("sites", "site1"), "notes")))
390
+ .toEqual([K("notes", "n1"), K("notes", "n_both")]);
391
+ let st = fold_new_state(24);
392
+ fold_expand_all(m, st);
393
+ expect(fold_visible_set(m, st).has(K("notes", "n_dev"))).toBe(false);
394
+ let m2 = fold_build_model(descs, recs, {hidden_topics: ["devices"], loose_topics: ["notes"]});
395
+ expect(m2.groups.get(fold_root_group_key("notes"))).toEqual([K("notes", "n_dev")]);
396
+ });
397
+
398
+ test("hiding a side tree, or the main topic itself", () => {
298
399
  let m = fold_build_model(descs, make_records(12), {hidden_topics: ["owners"]});
299
400
  /* d0..d9 hang from site1 AND o1: still under site1 */
300
401
  expect(m.nodes.get(K("devices", "d0")).parents.length).toBe(1);
@@ -39,12 +39,12 @@ describe("entry_shown_lines", () => {
39
39
  const $e = painted({
40
40
  result: 0,
41
41
  comment: "db_history^7301: 500 nodes",
42
- data: {sites: [1, 2, 3], buildings: [4], devices: [5, 6]},
42
+ data: {sites: [1, 2, 3], owners: [4], devices: [5, 6]},
43
43
  });
44
44
  expect(entry_shown_lines($e)).toEqual([
45
45
  " • result: 0",
46
46
  " • comment: db_history^7301: 500 nodes",
47
- " ▸ data {sites:[…],buildings:[…],devices:[…]}",
47
+ " ▸ data {sites:[…],owners:[…],devices:[…]}",
48
48
  ]);
49
49
  });
50
50