Fix detection of custom roles

This commit is contained in:
Andrew Kingston 2024-10-17 13:42:23 +01:00
parent cbd84ae249
commit d50e1cf31a
No known key found for this signature in database
2 changed files with 11 additions and 3 deletions

View File

@ -6,3 +6,4 @@ export const NodeWidth = GridResolution * 12
export const NodeHSpacing = GridResolution * 6
export const NodeVSpacing = GridResolution * 2
export const MinHeight = GridResolution * 10
export const EmptyStateID = "empty"

View File

@ -6,6 +6,7 @@ import {
NodeHSpacing,
NodeVSpacing,
MinHeight,
EmptyStateID,
} from "./constants"
import { getNodesBounds, Position } from "@xyflow/svelte"
import { Roles } from "constants/backend"
@ -50,7 +51,7 @@ export const getAdminPosition = bounds => ({
// Filters out invalid nodes and edges
const preProcessLayout = ({ nodes, edges }) => {
const ignoredIds = [Roles.PUBLIC, Roles.BASIC, Roles.ADMIN, "empty"]
const ignoredIds = [Roles.PUBLIC, Roles.BASIC, Roles.ADMIN, EmptyStateID]
const targetlessIds = [Roles.POWER]
return {
nodes: nodes.filter(node => {
@ -139,7 +140,7 @@ const postProcessLayout = ({ nodes, edges }) => {
// Add empty state node if required
if (!nodes.some(node => node.data.interactive)) {
nodes.push({
id: "empty",
id: EmptyStateID,
type: "empty",
position: {
x: bounds.x + bounds.width / 2 - NodeWidth / 2,
@ -167,7 +168,13 @@ export const autoLayout = ({ nodes, edges }) => {
// Converts a role doc into a node structure
export const roleToNode = role => {
const custom = !role._id.match(/[A-Z]+/)
const custom = ![
Roles.PUBLIC,
Roles.BASIC,
Roles.POWER,
Roles.ADMIN,
Roles.BUILDER,
].includes(role._id)
const interactive = custom || role._id === Roles.POWER
return {
id: role._id,