Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d2oracle: fix set with classes setting labels #1868

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,19 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
break
}
}
} else {
// Even if not imported or different board, a label can be not writeable if it's in a class or var or glob
// In those cases, the label is not a direct object reference
found := false
for _, ref := range obj.References {
if ref.MapKey == obj.Label.MapKey {
found = true
break
}
}
if !found {
writeableLabelMK = false
}
}
var m *d2ast.Map
if objK != nil {
Expand Down
77 changes: 77 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,83 @@ b
}
}
b: {style.fill: green}
`,
},
{
name: "class-with-label",
text: `classes: {
user: {
label: ""
}
}

a.class: user
`,
key: `a.style.opacity`,
value: go2.Pointer(`0.5`),
exp: `classes: {
user: {
label: ""
}
}

a.class: user
a.style.opacity: 0.5
`,
},
{
name: "edge-class-with-label",
text: `classes: {
user: {
label: ""
}
}

a -> b: {
class: user
}
`,
key: `(a -> b)[0].style.opacity`,
value: go2.Pointer(`0.5`),
exp: `classes: {
user: {
label: ""
}
}

a -> b: {
class: user
style.opacity: 0.5
}
`,
},
{
name: "var-with-label",
text: `vars: {
user: ""
}

a: ${user}
`,
key: `a.style.opacity`,
value: go2.Pointer(`0.5`),
exp: `vars: {
user: ""
}

a: ${user} {style.opacity: 0.5}
`,
},
{
name: "glob-with-label",
text: `*.label: ""
a
`,
key: `a.style.opacity`,
value: go2.Pointer(`0.5`),
exp: `*.label: ""
a
a.style.opacity: 0.5
`,
},
{
Expand Down
Loading
Loading