Quick fix for using the roles option within the builder - this was broken in JS which was a bit of a pain - this works properly now and allows more compat between HBS and JS.
This commit is contained in:
parent
c72141dc56
commit
32e4493a96
3 changed files with 13 additions and 1 deletions
|
@ -728,7 +728,7 @@ const getRoleBindings = () => {
|
||||||
return (get(rolesStore) || []).map(role => {
|
return (get(rolesStore) || []).map(role => {
|
||||||
return {
|
return {
|
||||||
type: "context",
|
type: "context",
|
||||||
runtimeBinding: `trim "${role._id}"`,
|
runtimeBinding: `'${role._id}'`,
|
||||||
readableBinding: `Role.${role.name}`,
|
readableBinding: `Role.${role.name}`,
|
||||||
category: "Role",
|
category: "Role",
|
||||||
icon: "UserGroup",
|
icon: "UserGroup",
|
||||||
|
|
|
@ -33,7 +33,12 @@ const removeSquareBrackets = (value: string) => {
|
||||||
// Our context getter function provided to JS code as $.
|
// Our context getter function provided to JS code as $.
|
||||||
// Extracts a value from context.
|
// Extracts a value from context.
|
||||||
const getContextValue = (path: string, context: any) => {
|
const getContextValue = (path: string, context: any) => {
|
||||||
|
const literalStringRegex = /^(["'`]).*\1$/
|
||||||
let data = context
|
let data = context
|
||||||
|
// check if it's a literal string - just return path if its quoted
|
||||||
|
if (literalStringRegex.test(path)) {
|
||||||
|
return path.substring(1, path.length - 1)
|
||||||
|
}
|
||||||
path.split(".").forEach(key => {
|
path.split(".").forEach(key => {
|
||||||
if (data == null || typeof data !== "object") {
|
if (data == null || typeof data !== "object") {
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -149,4 +149,11 @@ describe("Javascript", () => {
|
||||||
expect(output).toMatch(UUID_REGEX)
|
expect(output).toMatch(UUID_REGEX)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("JS literal strings", () => {
|
||||||
|
it("should be able to handle a literal string that is quoted (like role IDs)", () => {
|
||||||
|
const output = processJS(`return $("'Custom'")`)
|
||||||
|
expect(output).toBe("Custom")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue