@yuneta/gobj-ui 7.31.8 → 7.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2689,8 +2689,9 @@ like this:
2689
2689
 
2690
2690
  and its card draws the row `version (2)`. An empty `tkey` marks no field.
2691
2691
 
2692
- The topic cards (`C_YUI_TREEDB_TOPICS`) and its topic-info panel say the same
2693
- keys. A card of a topic with `pkey2s` has a `pkey2s` line under its version and
2692
+ The topic cards (`C_YUI_TREEDB_TOPICS`) are in alphabetical order, and so
2693
+ are its tabs (7.32.0+). The system topics (`__*__`) come first. The topic
2694
+ cards and the topic-info panel say the same keys. A card of a topic with `pkey2s` has a `pkey2s` line under its version and
2694
2695
  column count. The info panel always has a `tkey` row, which says *append time*
2695
2696
  when the topic has none, a `pkey2s` row when the topic has secondary keys, and
2696
2697
  `system` by the flag names (`sf_string_key`), not by the number. In its column
@@ -59004,6 +59004,17 @@ function topic_is_shown(topic_name) {
59004
59004
  return topic_name.substring(0, 2) !== "__" || topic_name === "__icons__";
59005
59005
  }
59006
59006
  /************************************************************
59007
+ * The topics in ALPHABETICAL order, for the cards, the tabs
59008
+ * and the site map: the backend's order is not the same from
59009
+ * one load to the next, and a reader finds a topic by its
59010
+ * place. The system topics (__*__) sort first.
59011
+ ************************************************************/
59012
+ function sorted_topic_names(descs) {
59013
+ return Object.keys(descs).sort((a, b) => {
59014
+ return a.localeCompare(b);
59015
+ });
59016
+ }
59017
+ /************************************************************
59007
59018
  * The nodes of __icons__ are the user icons of the app: each
59008
59019
  * load and each write of them goes to the icon registry
59009
59020
  * (lib_icons.js), and the shell tells the views that decided
@@ -59039,7 +59050,8 @@ function process_treedb_descs$1(gobj) {
59039
59050
  let system = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "system");
59040
59051
  let treedb_name = (0, _yuneta_gobj_js.gobj_read_str_attr)(gobj, "treedb_name");
59041
59052
  let readonly = (0, _yuneta_gobj_js.gobj_read_bool_attr)(gobj, "readonly");
59042
- for (const [key, desc] of Object.entries(descs)) {
59053
+ for (const key of sorted_topic_names(descs)) {
59054
+ let desc = descs[key];
59043
59055
  if (!system && !topic_is_shown(key)) continue;
59044
59056
  let kw_topic_form = {
59045
59057
  subscriber: gobj,
@@ -59100,7 +59112,7 @@ function register_sub_routes$1(gobj) {
59100
59112
  icon: "yi-compass-drafting",
59101
59113
  gclass: "C_YUI_TREEDB_SCHEMA"
59102
59114
  });
59103
- if ((0, _yuneta_gobj_js.is_object)(descs)) for (let topic of Object.keys(descs)) {
59115
+ if ((0, _yuneta_gobj_js.is_object)(descs)) for (let topic of sorted_topic_names(descs)) {
59104
59116
  if (!system && !topic_is_shown(topic)) continue;
59105
59117
  nodes.push({
59106
59118
  route: base + "/" + topic,
@@ -58999,6 +58999,17 @@ function topic_is_shown(topic_name) {
58999
58999
  return topic_name.substring(0, 2) !== "__" || topic_name === "__icons__";
59000
59000
  }
59001
59001
  /************************************************************
59002
+ * The topics in ALPHABETICAL order, for the cards, the tabs
59003
+ * and the site map: the backend's order is not the same from
59004
+ * one load to the next, and a reader finds a topic by its
59005
+ * place. The system topics (__*__) sort first.
59006
+ ************************************************************/
59007
+ function sorted_topic_names(descs) {
59008
+ return Object.keys(descs).sort((a, b) => {
59009
+ return a.localeCompare(b);
59010
+ });
59011
+ }
59012
+ /************************************************************
59002
59013
  * The nodes of __icons__ are the user icons of the app: each
59003
59014
  * load and each write of them goes to the icon registry
59004
59015
  * (lib_icons.js), and the shell tells the views that decided
@@ -59034,7 +59045,8 @@ function process_treedb_descs$1(gobj) {
59034
59045
  let system = gobj_read_bool_attr(gobj, "system");
59035
59046
  let treedb_name = gobj_read_str_attr(gobj, "treedb_name");
59036
59047
  let readonly = gobj_read_bool_attr(gobj, "readonly");
59037
- for (const [key, desc] of Object.entries(descs)) {
59048
+ for (const key of sorted_topic_names(descs)) {
59049
+ let desc = descs[key];
59038
59050
  if (!system && !topic_is_shown(key)) continue;
59039
59051
  let kw_topic_form = {
59040
59052
  subscriber: gobj,
@@ -59095,7 +59107,7 @@ function register_sub_routes$1(gobj) {
59095
59107
  icon: "yi-compass-drafting",
59096
59108
  gclass: "C_YUI_TREEDB_SCHEMA"
59097
59109
  });
59098
- if (is_object(descs)) for (let topic of Object.keys(descs)) {
59110
+ if (is_object(descs)) for (let topic of sorted_topic_names(descs)) {
59099
59111
  if (!system && !topic_is_shown(topic)) continue;
59100
59112
  nodes.push({
59101
59113
  route: base + "/" + topic,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.31.8",
3
+ "version": "7.32.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
@@ -1269,6 +1269,19 @@ function topic_is_shown(topic_name)
1269
1269
  return topic_name.substring(0, 2) !== "__" || topic_name === ICONS_TOPIC;
1270
1270
  }
1271
1271
 
1272
+ /************************************************************
1273
+ * The topics in ALPHABETICAL order, for the cards, the tabs
1274
+ * and the site map: the backend's order is not the same from
1275
+ * one load to the next, and a reader finds a topic by its
1276
+ * place. The system topics (__*__) sort first.
1277
+ ************************************************************/
1278
+ function sorted_topic_names(descs)
1279
+ {
1280
+ return Object.keys(descs).sort((a, b) => {
1281
+ return a.localeCompare(b);
1282
+ });
1283
+ }
1284
+
1272
1285
  /************************************************************
1273
1286
  * The nodes of __icons__ are the user icons of the app: each
1274
1287
  * load and each write of them goes to the icon registry
@@ -1322,7 +1335,8 @@ function process_treedb_descs(gobj)
1322
1335
  let system = gobj_read_bool_attr(gobj, "system");
1323
1336
  let treedb_name = gobj_read_str_attr(gobj, "treedb_name");
1324
1337
  let readonly = gobj_read_bool_attr(gobj, "readonly");
1325
- for(const [key, desc] of Object.entries(descs)) {
1338
+ for(const key of sorted_topic_names(descs)) {
1339
+ let desc = descs[key];
1326
1340
  if(!system && !topic_is_shown(key)) {
1327
1341
  continue;
1328
1342
  }
@@ -1454,7 +1468,7 @@ function register_sub_routes(gobj)
1454
1468
  icon: "yi-compass-drafting", gclass: "C_YUI_TREEDB_SCHEMA"});
1455
1469
  }
1456
1470
  if(is_object(descs)) {
1457
- for(let topic of Object.keys(descs)) {
1471
+ for(let topic of sorted_topic_names(descs)) {
1458
1472
  if(!system && !topic_is_shown(topic)) {
1459
1473
  continue;
1460
1474
  }
@@ -34,7 +34,7 @@ const {
34
34
  SDATA, SDATA_END, data_type_t, event_flag_t,
35
35
  gclass_create,
36
36
  gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
37
- gobj_start, gobj_send_event,
37
+ gobj_start, gobj_send_event, gobj_write_attr,
38
38
  gobj_change_state, gobj_current_state,
39
39
  set_log_callback,
40
40
  } = gobj_js;
@@ -113,10 +113,16 @@ beforeAll(() => {
113
113
  ["EV_LOAD_NODES", ac_form_load, null],
114
114
  ["EV_LOAD_NODE_UPDATED", ac_form_update, null]
115
115
  ]]],
116
- {},
116
+ {
117
+ /* What the view mounts as the topic's tab. */
118
+ mt_create: (gobj) => {
119
+ gobj_write_attr(gobj, "$container", document.createElement("div"));
120
+ }
121
+ },
117
122
  0,
118
123
  [
119
124
  SDATA(data_type_t.DTP_STRING, "topic_name", 0, "", "topic"),
125
+ SDATA(data_type_t.DTP_POINTER, "$container", 0, null, "the tab's content"),
120
126
  SDATA(data_type_t.DTP_BOOLEAN, "with_remote_paging", 0, false, "pulls its pages"),
121
127
  SDATA(data_type_t.DTP_POINTER, "tabulator", 0, null, "the table: only getRow() is read"),
122
128
  SDATA_END()
@@ -833,3 +839,50 @@ describe("a link told as EV_TREEDB_NODE_LINKED / UNLINKED", () => {
833
839
  expect(shown).toEqual([]);
834
840
  });
835
841
  });
842
+
843
+ /*
844
+ * The topics are shown in ALPHABETICAL order, whatever order the
845
+ * backend's `descs` comes in: the backend's order is not the same from
846
+ * one load to the next. The view loads its topics in the order it shows
847
+ * them, so the `nodes` requests tell that order.
848
+ */
849
+ describe("the topics in alphabetical order", () => {
850
+
851
+ function load_descs(name, system)
852
+ {
853
+ const host = gobj_create(`${name}_host`, "C_TEST_VIEW_HOST", {}, yuno);
854
+ const topics = gobj_create_service(`${name}_topics`, "C_YUI_TREEDB_TOPICS", {
855
+ treedb_name: "treedb_test",
856
+ gobj_remote_yuno: remote,
857
+ system: system
858
+ }, host);
859
+ gobj_start(topics);
860
+ commands.length = 0;
861
+ const descs = {};
862
+ for(const topic of ["users", "__snaps__", "places", "__icons__",
863
+ "controllers", "__assets__", "device_types"]) {
864
+ descs[topic] = {topic_name: topic, cols: {}};
865
+ }
866
+ gobj_send_event(topics, "EV_MT_COMMAND_ANSWER", {
867
+ result: 0, comment: "", data: descs, __md_iev__: {
868
+ command_stack: [{command: "descs", kw: {}}]
869
+ }
870
+ }, remote);
871
+ return commands.filter((c) => c.command === "nodes")
872
+ .map((c) => c.kw.topic_name);
873
+ }
874
+
875
+ test("every topic, the system ones first, when system is true", () => {
876
+ build("to0");
877
+ expect(load_descs("to1", true)).toEqual([
878
+ "__assets__", "__icons__", "__snaps__",
879
+ "controllers", "device_types", "places", "users"
880
+ ]);
881
+ });
882
+
883
+ test("the user topics and __icons__, when system is false", () => {
884
+ expect(load_descs("to2", false)).toEqual([
885
+ "__icons__", "controllers", "device_types", "places", "users"
886
+ ]);
887
+ });
888
+ });