diff --git a/Atlas/CHANGELOG.md b/Atlas/CHANGELOG.md index 1e8805f..4c1b24b 100644 --- a/Atlas/CHANGELOG.md +++ b/Atlas/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.4.0 (2026-12-01) + +- Cypher tables now show enumeration labels. A column that returns an enumeration-bound property of a typed variable (`MATCH (p:CNCProduction) RETURN p.AlarmCode.Value AS Alarm`, with or without `.Value` and `AS`) gets the same value mappings as the Data view, so dashboards no longer need hand-made mappings for Atlas codes. Expressions, functions and untyped variables are left as returned. +- Data > Current: a record property that holds several rows (MaintainX `LiveOpenWorkOrders`: one row per open work order) now gives one table row per record row in the Columns layout, ordered by the row's sequential number, and numbered parts in the Rows layout. It used to show one work order per machine, because Atlas's plain node read returns only one row; the plugin now reads records with a typed `UNWIND`. +- Data > Current: static properties (plain values with no history, such as a person's `Specialty` or a machine's `SerialNumber`) can be picked in the selection tree, marked "fixed value", and type or nested picks of them are read. Trend still offers only properties with history. + ## 0.3.0 (2026-11-24) Breaking: the plugin ID is now `flowsoftware-timebaseatlas-datasource` (was `flowsoftware-atlas-datasource`), so both Timebase plugins read as Timebase products (the Historian's is `flowsoftware-timebasehistorian-datasource`). It installs as a new plugin: data sources and dashboards made with 0.2.0 have to be recreated or pointed at the new type, and the `allow_loading_unsigned_plugins` setting needs the new ID. diff --git a/Atlas/package-lock.json b/Atlas/package-lock.json index daa81cc..0691222 100644 --- a/Atlas/package-lock.json +++ b/Atlas/package-lock.json @@ -1,12 +1,12 @@ { "name": "timebaseatlas-datasource", - "version": "0.3.0", + "version": "0.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "timebaseatlas-datasource", - "version": "0.3.0", + "version": "0.4.0", "license": "Apache-2.0", "dependencies": { "@emotion/css": "11.10.6", diff --git a/Atlas/package.json b/Atlas/package.json index a02474b..fd31bb4 100644 --- a/Atlas/package.json +++ b/Atlas/package.json @@ -1,6 +1,6 @@ { "name": "timebaseatlas-datasource", - "version": "0.3.0", + "version": "0.4.0", "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", "dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development", diff --git a/Atlas/pkg/plugin/cypherenums.go b/Atlas/pkg/plugin/cypherenums.go new file mode 100644 index 0000000..01427d1 --- /dev/null +++ b/Atlas/pkg/plugin/cypherenums.go @@ -0,0 +1,149 @@ +package plugin + +import ( + "regexp" + "strings" + + "github.com/grafana/grafana-plugin-sdk-go/data" +) + +// Enumerations on Cypher tables. +// +// A Cypher table column is just a name ("Alarm"), so the plugin cannot see +// that it holds an enumeration-bound property. It reads that from the query +// text instead: the node patterns give each variable its type +// ("(p:CNCProduction)"), and each RETURN item that is a plain property read +// ("p.AlarmCode", "p.AlarmCode.Value", optionally "AS Alarm") names the +// property. When the property is bound to an enumeration on that type, the +// column gets the same value mappings the Values and History views attach. +// Anything else (expressions, functions, CASE, untyped variables) is left as +// it is, so a query the parser does not understand behaves as before. + +var ( + cypherNodePattern = regexp.MustCompile(`\(\s*([A-Za-z_]\w*)\s*:\s*` + "`?" + `([A-Za-z_][\w-]*)`) + cypherReturnWord = regexp.MustCompile(`(?i)\bRETURN\b`) + cypherReturn = regexp.MustCompile(`(?is)^RETURN\s+(?:DISTINCT\s+)?(.*)$`) + cypherReturnEnd = regexp.MustCompile(`(?is)\s+(?:ORDER\s+BY|SKIP|LIMIT|UNION)\b`) + cypherReturnItem = regexp.MustCompile("(?is)^([A-Za-z_]\\w*)\\.([A-Za-z_]\\w*)(?:\\.Value)?(?:\\s+AS\\s+(`[^`]+`|[A-Za-z_]\\w*))?$") +) + +// cypherColumn is one RETURN item that reads a property of a typed variable. +type cypherColumn struct { + Column string // the column name the result will carry + Variable string + Type string // local type name from the node pattern + Property string // local property name +} + +// cypherPropertyColumns lists the RETURN items of the last RETURN clause that +// are plain property reads of a variable with a type label. +func cypherPropertyColumns(cypher string) []cypherColumn { + types := map[string]string{} + for _, m := range cypherNodePattern.FindAllStringSubmatch(cypher, -1) { + if _, seen := types[m[1]]; !seen { + types[m[1]] = m[2] + } + } + if len(types) == 0 { + return nil + } + // The last RETURN is the one that shapes the result. + idx := cypherReturnWord.FindAllStringIndex(cypher, -1) + if len(idx) == 0 { + return nil + } + m := cypherReturn.FindStringSubmatch(cypher[idx[len(idx)-1][0]:]) + if m == nil { + return nil + } + clause := m[1] + if end := cypherReturnEnd.FindStringIndex(clause); end != nil { + clause = clause[:end[0]] + } + var out []cypherColumn + for _, item := range splitTopLevel(clause) { + item = strings.TrimSpace(item) + m := cypherReturnItem.FindStringSubmatch(item) + if m == nil { + continue + } + t, ok := types[m[1]] + if !ok { + continue + } + col := strings.Trim(m[3], "`") + if col == "" { + col = item + } + out = append(out, cypherColumn{Column: col, Variable: m[1], Type: t, Property: m[2]}) + } + return out +} + +// splitTopLevel splits a RETURN clause on commas that are not inside +// brackets, braces, parentheses or quotes. +func splitTopLevel(s string) []string { + var parts []string + depth, start := 0, 0 + var quote rune + for i, r := range s { + switch { + case quote != 0: + if r == quote { + quote = 0 + } + case r == '"' || r == '\'' || r == '`': + quote = r + case r == '(' || r == '[' || r == '{': + depth++ + case r == ')' || r == ']' || r == '}': + depth-- + case r == ',' && depth == 0: + parts = append(parts, s[start:i]) + start = i + 1 + } + } + return append(parts, s[start:]) +} + +// typeURIByLocal finds the entity type whose local name is name. +func (r *kindResolver) typeURIByLocal(name string) string { + if r == nil { + return "" + } + for uri := range r.types { + if localName(uri) == name { + return uri + } + } + return "" +} + +// applyCypherTableEnums puts enumeration value mappings on the columns of a +// Cypher table that return an enumeration-bound property. +func applyCypherTableEnums(frame *data.Frame, cypher string, r *kindResolver) { + if frame == nil || r == nil || len(r.enums) == 0 { + return + } + cols := cypherPropertyColumns(cypher) + if len(cols) == 0 { + return + } + byName := map[string]cypherColumn{} + for _, c := range cols { + byName[c.Column] = c + byName[strings.Join(strings.Fields(c.Column), "")] = c // Atlas may echo an unaliased item without spaces + } + for _, fl := range frame.Fields { + c, ok := byName[fl.Name] + if !ok { + c, ok = byName[strings.Join(strings.Fields(fl.Name), "")] + } + if !ok { + continue + } + if e := r.enumInfoOf(r.typeURIByLocal(c.Type), c.Property); e != nil { + setMappings(fl, e) + } + } +} diff --git a/Atlas/pkg/plugin/cypherenums_test.go b/Atlas/pkg/plugin/cypherenums_test.go new file mode 100644 index 0000000..1347751 --- /dev/null +++ b/Atlas/pkg/plugin/cypherenums_test.go @@ -0,0 +1,68 @@ +package plugin + +import ( + "testing" + + "github.com/grafana/grafana-plugin-sdk-go/data" + + "github.com/flow-software/Timebase-Grafana/Atlas/pkg/atlas" +) + +func TestCypherPropertyColumns(t *testing.T) { + q := "MATCH (m:CNCMachine)-[]->(p:CNCProduction)\n" + + "RETURN m.entityId AS Machine, p.AlarmCode.Value AS Alarm, p.Program AS `Part program`,\n" + + " p.MTBF.Value * 2 AS Double, count(p) AS n, p.State, CASE WHEN p.X = 1 THEN 'a' ELSE 'b' END AS c\n" + + "ORDER BY Machine LIMIT 5" + got := map[string]cypherColumn{} + for _, c := range cypherPropertyColumns(q) { + got[c.Column] = c + } + for col, want := range map[string]cypherColumn{ + "Machine": {Variable: "m", Type: "CNCMachine", Property: "entityId"}, + "Alarm": {Variable: "p", Type: "CNCProduction", Property: "AlarmCode"}, + "Part program": {Variable: "p", Type: "CNCProduction", Property: "Program"}, + "p.State": {Variable: "p", Type: "CNCProduction", Property: "State"}, + } { + g, ok := got[col] + if !ok || g.Variable != want.Variable || g.Type != want.Type || g.Property != want.Property { + t.Errorf("column %q: got %+v (found %v), want %+v", col, g, ok, want) + } + } + for _, skipped := range []string{"Double", "n", "c"} { + if _, ok := got[skipped]; ok { + t.Errorf("expression column %q should not be treated as a property read", skipped) + } + } + if len(cypherPropertyColumns("MATCH (n) RETURN n.State AS s")) != 0 { + t.Error("an untyped variable has no type to look the enumeration up on") + } + // Only the last RETURN shapes the result. + cols := cypherPropertyColumns("CALL { MATCH (a:Machine) RETURN a.State AS x } MATCH (b:Machine) RETURN b.Mode AS y") + if len(cols) != 1 || cols[0].Column != "y" { + t.Errorf("last RETURN: %+v", cols) + } +} + +func TestApplyCypherTableEnums(t *testing.T) { + tvq := &atlas.CompoundRange{BaseCompoundURI: tvqURI, FieldEnumOverrides: map[string]string{"Value": stateEnumURI}} + r := newKindResolver([]atlas.EntityType{ + {URI: "urn:x:Machine", Properties: []atlas.EntityProperty{{URI: "urn:x:State", CompoundRange: tvq}, {URI: "urn:x:RPM"}}}, + }, []atlas.EnumType{stateEnum()}) + frame := data.NewFrame("result", + data.NewField("Machine", nil, []*string{}), + data.NewField("Now", nil, []*float64{}), + data.NewField("m.State", nil, []*float64{}), + data.NewField("Speed", nil, []*float64{}), + ) + applyCypherTableEnums(frame, "MATCH (m:Machine) RETURN m.entityId AS Machine, m.State.Value AS Now, m.State, m.RPM.Value AS Speed", r) + for _, f := range frame.Fields { + has := f.Config != nil && len(f.Config.Mappings) > 0 + want := f.Name == "Now" || f.Name == "m.State" + if has != want { + t.Errorf("%s: mappings %v, want %v", f.Name, has, want) + } + } + // A resolver without enumerations, or a nil one, leaves the frame alone. + applyCypherTableEnums(frame, "MATCH (m:Machine) RETURN m.State AS s", nil) + applyCypherTableEnums(nil, "MATCH (m:Machine) RETURN m.State AS s", r) +} diff --git a/Atlas/pkg/plugin/datasource.go b/Atlas/pkg/plugin/datasource.go index 0a91475..9e88e01 100644 --- a/Atlas/pkg/plugin/datasource.go +++ b/Atlas/pkg/plugin/datasource.go @@ -534,6 +534,9 @@ func (d *Datasource) cypherQuery(ctx context.Context, branch, domain string, qm } } else { frames = data.Frames{cypherTable("result", res.Columns, rows)} + if format != formatSeries { + applyCypherTableEnums(frames[0], text, d.kinds(ctx, branch, domain, false)) + } if format == formatSeries { if frames, err = splitSeries(frames[0]); err != nil { return nil, err diff --git a/Atlas/pkg/plugin/datasource_test.go b/Atlas/pkg/plugin/datasource_test.go index 0394f84..f9138a4 100644 --- a/Atlas/pkg/plugin/datasource_test.go +++ b/Atlas/pkg/plugin/datasource_test.go @@ -804,7 +804,7 @@ func TestExpandPicksNestedAndType(t *testing.T) { {Instance: "CNC01", Scope: "nested", Property: "RPM"}, {Instance: "Plain", Property: "X"}, {Instance: "CNC02", Scope: "nested", NestedType: "urn:x:CNCProduction", Property: "FeedRate"}, - }) + }, false) if err != nil { t.Fatal(err) } diff --git a/Atlas/pkg/plugin/history.go b/Atlas/pkg/plugin/history.go index be8173e..edd635c 100644 --- a/Atlas/pkg/plugin/history.go +++ b/Atlas/pkg/plugin/history.go @@ -103,8 +103,9 @@ const ( // expandPicks resolves nested and type picks into plain instance picks, in // tree order, using the cached instance tree. With a property, only // instances that have it as a live value are kept, so a scope does not -// report every instance that lacks it. -func (d *Datasource) expandPicks(ctx context.Context, branch, domain string, picks []historyPick) ([]historyPick, error) { +// report every instance that lacks it. withStatic (Current selections) also +// accepts static properties, which have a value but no history. +func (d *Datasource) expandPicks(ctx context.Context, branch, domain string, picks []historyPick, withStatic bool) ([]historyPick, error) { dynamic := false for _, p := range picks { if p.Scope == pickNested || p.Scope == pickType { @@ -129,6 +130,13 @@ func (d *Datasource) expandPicks(ctx context.Context, branch, domain string, pic return true } } + if withStatic { + for _, l := range byID[id].Static { + if l.Name == prop { + return true + } + } + } return false } var out []historyPick @@ -331,7 +339,7 @@ func (d *Datasource) scopeNodes(ctx context.Context, branch, domain string, qm q // targets. A pick without a property takes every live property of the // instance. The notice names picks that give no series. func (d *Datasource) selectionTargets(ctx context.Context, branch, domain string, picks []historyPick) ([]historyTarget, map[string]string, string, error) { - picks, err := d.expandPicks(ctx, branch, domain, picks) + picks, err := d.expandPicks(ctx, branch, domain, picks, false) if err != nil { return nil, nil, "", err } diff --git a/Atlas/pkg/plugin/records.go b/Atlas/pkg/plugin/records.go new file mode 100644 index 0000000..ee3af40 --- /dev/null +++ b/Atlas/pkg/plugin/records.go @@ -0,0 +1,140 @@ +package plugin + +import ( + "context" + "sort" + "strings" +) + +// Multi-row records in Current selections. +// +// A record property can hold several rows at once: MaintainX +// LiveOpenWorkOrders on a machine is one row per open work order. Atlas's +// node read (MATCH (n) ... RETURN n) gives only one of them, and so does an +// UNWIND over an untyped (n). Live-checked on Atlas 2.0.1 (cesmii-workshop, +// 2026-12-01): MATCH (n:CNCMachine) ... UNWIND n.LiveOpenWorkOrders returns +// every current row (CNC03: #21, #27, #30, as in MaintainX), so records are +// re-read that way, one query per type and property. + +// recordLists re-reads the record properties of nodes as lists. A record +// that holds more than one row becomes []any of its rows; the returned set +// names, per instance id, the properties that did. +func (d *Datasource) recordLists(ctx context.Context, branch, domain string, nodes []map[string]any) (map[string]map[string]bool, error) { + type key struct{ typ, prop string } + groups := map[key][]string{} + for _, n := range nodes { + for k, v := range n { + if nodeMetaKeys[k] || !isRecord(v) || !labelPattern.MatchString(k) { + continue + } + kk := key{shortName(str(n["typeId"])), k} + groups[kk] = append(groups[kk], str(n["entityId"])) + } + } + if len(groups) == 0 { + return nil, nil + } + rowsOf := map[string]map[string][]any{} // id -> prop -> rows + for g, ids := range groups { + if !labelPattern.MatchString(g.typ) { + continue + } + q := "MATCH (n:`" + g.typ + "`) WHERE n.entityId IN $ids UNWIND n.`" + g.prop + "` AS r RETURN n.entityId, r" + res, err := d.client.Query(ctx, branch, domain, q, map[string]any{"ids": ids}) + if err != nil { + return nil, err + } + rows, err := decodeRows(res) + if err != nil { + return nil, err + } + for _, row := range rows { + if len(row) < 2 { + continue + } + if _, ok := asMap(row[1]); !ok { + continue + } + id := str(row[0]) + if rowsOf[id] == nil { + rowsOf[id] = map[string][]any{} + } + rowsOf[id][g.prop] = append(rowsOf[id][g.prop], row[1]) + } + } + multi := map[string]map[string]bool{} + for _, n := range nodes { + id := str(n["entityId"]) + for prop, rows := range rowsOf[id] { + if len(rows) < 2 { + continue + } + sortRecordRows(rows) + n[prop] = rows + if multi[id] == nil { + multi[id] = map[string]bool{} + } + multi[id][prop] = true + } + } + return multi, nil +} + +// recordRows gives one table row per record row: an instance whose record +// property holds several rows appears once per row, with its other values +// repeated. Two multi-row records on one instance are listed one after the +// other (not combined), each row leaving the other record empty. +func recordRows(nodes []map[string]any, multi map[string]map[string]bool) []map[string]any { + if len(multi) == 0 { + return nodes + } + var out []map[string]any + for _, n := range nodes { + props := multi[str(n["entityId"])] + if len(props) == 0 { + out = append(out, n) + continue + } + names := make([]string, 0, len(props)) + for p := range props { + names = append(names, p) + } + sort.Strings(names) + for _, p := range names { + rows, _ := n[p].([]any) + for _, r := range rows { + row := make(map[string]any, len(n)) + for k, v := range n { + if props[k] && k != p { + continue + } + row[k] = v + } + row[p] = r + out = append(out, row) + } + } + } + return out +} + +// sortRecordRows orders the rows of one record by their sequential number +// (a field ending in "SequentialId", e.g. MxSequentialId) when they have one, +// so work orders read #21, #27, #30. Rows without one keep Atlas's order. +func sortRecordRows(rows []any) { + seq := func(v any) (float64, bool) { + m, _ := asMap(v) + for k, x := range m { + if strings.HasSuffix(k, "SequentialId") { + f, ok := x.(float64) + return f, ok + } + } + return 0, false + } + sort.SliceStable(rows, func(i, j int) bool { + a, okA := seq(rows[i]) + b, okB := seq(rows[j]) + return okA && okB && a < b + }) +} diff --git a/Atlas/pkg/plugin/records_test.go b/Atlas/pkg/plugin/records_test.go new file mode 100644 index 0000000..8a76c33 --- /dev/null +++ b/Atlas/pkg/plugin/records_test.go @@ -0,0 +1,77 @@ +package plugin + +import ( + "strings" + "testing" + + "github.com/flow-software/Timebase-Grafana/Atlas/pkg/atlas" +) + +func TestStaticProperties(t *testing.T) { + node := map[string]any{ + "entityId": "person-maria", "typeId": "urn:x:Technician", "entityLabel": "Maria", + "Specialty": "Electrical", "PersonId": "1558074", "Shift": nil, "Rate": 12.5, "Active": true, + "LiveUser": map[string]any{"Timestamp": "2026-11-27T06:22:05Z", "MxUserId": 1558074.0}, + "Temp": map[string]any{"Timestamp": "2026-11-27T06:22:05Z", "Value": 21.0, "Quality": 192.0}, + "Tags": []any{"a"}, + "bad-name!": "x", + } + live := []LiveProperty{{Name: "LiveUser", Kind: "record"}, {Name: "Temp", Kind: "number"}} + got := staticProperties(node, live, nil) + var names []string + for _, p := range got { + names = append(names, p.Name+":"+p.Kind) + } + if s := strings.Join(names, " "); s != "Active:boolean PersonId:text Rate:number Specialty:text" { + t.Fatalf("static properties %q", s) + } +} + +func TestStaticPropertiesUseDeclaredKindAndEnum(t *testing.T) { + r := newKindResolver([]atlas.EntityType{{URI: "urn:x:Machine", Properties: []atlas.EntityProperty{ + {URI: "urn:x:Mode", Range: "http://www.w3.org/2001/XMLSchema#long", EnumType: stateEnumURI}, + }}}, []atlas.EnumType{stateEnum()}) + got := staticProperties(map[string]any{"entityId": "m", "typeId": "urn:x:Machine", "Mode": 2.0}, nil, r) + if len(got) != 1 || got[0].Enum == nil { + t.Fatalf("Mode should carry its enumeration: %+v", got) + } +} + +func TestRecordRowsOnePerRow(t *testing.T) { + wo := func(n float64) map[string]any { + return map[string]any{"Timestamp": "2026-11-27T08:26:20Z", "MxSequentialId": n, "MxTitle": "wo"} + } + rows := []any{wo(30), wo(21), wo(27)} + sortRecordRows(rows) + var order []float64 + for _, r := range rows { + order = append(order, r.(map[string]any)["MxSequentialId"].(float64)) + } + if order[0] != 21 || order[1] != 27 || order[2] != 30 { + t.Fatalf("rows not in sequential order: %v", order) + } + nodes := []map[string]any{ + {"entityId": "CNC03", "typeId": "urn:x:CNCMachine", "LiveAsset": map[string]any{"Timestamp": "t", "MxAssetName": "CNC03"}, + "LiveOpenWorkOrders": rows, "Other": []any{wo(1), wo(2)}}, + {"entityId": "CNC01", "typeId": "urn:x:CNCMachine", "LiveOpenWorkOrders": wo(25)}, + } + multi := map[string]map[string]bool{"CNC03": {"LiveOpenWorkOrders": true, "Other": true}} + out := recordRows(nodes, multi) + // CNC03: 3 open work orders + 2 "Other" rows, listed one after the other; CNC01 unchanged. + if len(out) != 6 { + t.Fatalf("got %d rows, want 6", len(out)) + } + first := out[0] + if _, ok := first["LiveOpenWorkOrders"].(map[string]any); !ok || first["LiveAsset"] == nil { + t.Fatalf("a row carries one work order and the instance's other values: %+v", first) + } + if _, has := first["Other"]; has { + t.Fatal("a work-order row must not also carry the other multi-row record") + } + if out[5]["entityId"] != "CNC01" { + t.Fatalf("single-row instance kept as is: %+v", out[5]) + } + if got := recordRows(nodes, nil); len(got) != 2 { + t.Fatal("no multi-row records: nodes unchanged") + } +} diff --git a/Atlas/pkg/plugin/tree.go b/Atlas/pkg/plugin/tree.go index 0f22492..41fcb9d 100644 --- a/Atlas/pkg/plugin/tree.go +++ b/Atlas/pkg/plugin/tree.go @@ -18,6 +18,51 @@ type TreeNode struct { ParentID string `json:"parentId,omitempty"` // Live (timestamp/value/quality) properties, for picking History series. Live []LiveProperty `json:"live,omitempty"` + // Static properties: plain values with no timestamp or history (a + // person's Specialty, a machine's serial number). Offered for Current + // selections only; Trend has nothing to draw for them. + Static []LiveProperty `json:"static,omitempty"` +} + +// staticProperties lists the plain values of a node (text, number, +// boolean) that are not live properties, sorted by name. Empty values are +// left out: an unset static property has nothing to show. +func staticProperties(m map[string]any, live []LiveProperty, declared *kindResolver) []LiveProperty { + isLive := make(map[string]bool, len(live)) + for _, l := range live { + isLive[l.Name] = true + } + typeID := str(m["typeId"]) + var out []LiveProperty + for k, v := range m { + if nodeMetaKeys[k] || isLive[k] || !labelPattern.MatchString(k) { + continue + } + kind := scalarKind(v) + if kind == "" { + continue + } + if dk := declared.kind(typeID, k); dk != "" && dk != "record" { + kind = dk + } + out = append(out, LiveProperty{Name: k, Kind: kind, Enum: declared.enumInfoOf(typeID, k)}) + } + sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name }) + return out +} + +// scalarKind is the kind of a plain value, or "" for anything else +// (null, compounds, lists). +func scalarKind(v any) string { + switch v.(type) { + case string: + return "text" + case float64, int, int64: + return "number" + case bool: + return "boolean" + } + return "" } // LiveProperty is a property with stored history and the kind of its value. @@ -80,6 +125,7 @@ func (d *Datasource) instanceTree(ctx context.Context, branch, domain string) ([ labels := map[string]string{} live := map[string][]LiveProperty{} + static := map[string][]LiveProperty{} declared := d.kinds(ctx, branch, domain, false) res, err := d.client.Query(ctx, branch, domain, "MATCH (n) RETURN n", nil) if err != nil { @@ -108,6 +154,7 @@ func (d *Datasource) instanceTree(ctx context.Context, branch, domain string) ([ } live[id] = append(live[id], lp) } + static[id] = staticProperties(m, live[id], declared) } } @@ -149,7 +196,7 @@ func (d *Datasource) instanceTree(ctx context.Context, branch, domain string) ([ out := make([]TreeNode, len(items)) for i, it := range items { - out[i] = TreeNode{ID: it.ElementID, Label: labels[it.ElementID], Type: shortName(it.TypeURI), ParentID: parent[it.ElementID], Live: live[it.ElementID]} + out[i] = TreeNode{ID: it.ElementID, Label: labels[it.ElementID], Type: shortName(it.TypeURI), ParentID: parent[it.ElementID], Live: live[it.ElementID], Static: static[it.ElementID]} } sort.SliceStable(out, func(i, j int) bool { return strings.ToLower(nodeName(out[i])) < strings.ToLower(nodeName(out[j])) }) return out, nil diff --git a/Atlas/pkg/plugin/values.go b/Atlas/pkg/plugin/values.go index 8244f88..f121591 100644 --- a/Atlas/pkg/plugin/values.go +++ b/Atlas/pkg/plugin/values.go @@ -314,7 +314,7 @@ func jsonText(v any) string { // property; a property pick shows only that property (a record expands into // its parts). Instances keep the order they were picked in. func (d *Datasource) selectionValues(ctx context.Context, branch, domain string, qm queryModel) (data.Frames, error) { - picks, err := d.expandPicks(ctx, branch, domain, qm.Selection) + picks, err := d.expandPicks(ctx, branch, domain, qm.Selection, true) if err != nil { return nil, err } @@ -373,11 +373,18 @@ func (d *Datasource) selectionValues(ctx context.Context, branch, domain string, nodes = append(nodes, n) } + // Records with several rows (open work orders) are read in full: one + // table row per record row in Columns, numbered parts in Rows. + multi, err := d.recordLists(ctx, branch, domain, nodes) + if err != nil { + return nil, err + } enumOf := d.kinds(ctx, branch, domain, false).enumInfoOf var frame *data.Frame if qm.Layout == layoutColumns { - frame = nodesTable("values", nodes, tableOptions{IncludeQuality: qm.IncludeQuality, IncludeTime: qm.IncludeTime}) - applyTableEnums(frame, nodes, enumOf) + rows := recordRows(nodes, multi) + frame = nodesTable("values", rows, tableOptions{IncludeQuality: qm.IncludeQuality, IncludeTime: qm.IncludeTime}) + applyTableEnums(frame, rows, enumOf) } else { frame = rowsTable("values", nodes, len(nodes) > 1, enumOf) } diff --git a/Atlas/src/components/HistoryBrowser.tsx b/Atlas/src/components/HistoryBrowser.tsx index f271fc9..a4d1d85 100644 --- a/Atlas/src/components/HistoryBrowser.tsx +++ b/Atlas/src/components/HistoryBrowser.tsx @@ -763,7 +763,9 @@ function PropertyRow({ .join(', ')}${en.members.length > 4 ? ', …' : ''}` : prop.kind === 'record' ? 'record: one column per part' - : prop.kind; + : prop.fixed + ? `${prop.kind}, fixed value` + : prop.kind; return (