Fix detection of custom roles
This commit is contained in:
parent
cbd84ae249
commit
d50e1cf31a
|
@ -6,3 +6,4 @@ export const NodeWidth = GridResolution * 12
|
||||||
export const NodeHSpacing = GridResolution * 6
|
export const NodeHSpacing = GridResolution * 6
|
||||||
export const NodeVSpacing = GridResolution * 2
|
export const NodeVSpacing = GridResolution * 2
|
||||||
export const MinHeight = GridResolution * 10
|
export const MinHeight = GridResolution * 10
|
||||||
|
export const EmptyStateID = "empty"
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
NodeHSpacing,
|
NodeHSpacing,
|
||||||
NodeVSpacing,
|
NodeVSpacing,
|
||||||
MinHeight,
|
MinHeight,
|
||||||
|
EmptyStateID,
|
||||||
} from "./constants"
|
} from "./constants"
|
||||||
import { getNodesBounds, Position } from "@xyflow/svelte"
|
import { getNodesBounds, Position } from "@xyflow/svelte"
|
||||||
import { Roles } from "constants/backend"
|
import { Roles } from "constants/backend"
|
||||||
|
@ -50,7 +51,7 @@ export const getAdminPosition = bounds => ({
|
||||||
|
|
||||||
// Filters out invalid nodes and edges
|
// Filters out invalid nodes and edges
|
||||||
const preProcessLayout = ({ nodes, 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]
|
const targetlessIds = [Roles.POWER]
|
||||||
return {
|
return {
|
||||||
nodes: nodes.filter(node => {
|
nodes: nodes.filter(node => {
|
||||||
|
@ -139,7 +140,7 @@ const postProcessLayout = ({ nodes, edges }) => {
|
||||||
// Add empty state node if required
|
// Add empty state node if required
|
||||||
if (!nodes.some(node => node.data.interactive)) {
|
if (!nodes.some(node => node.data.interactive)) {
|
||||||
nodes.push({
|
nodes.push({
|
||||||
id: "empty",
|
id: EmptyStateID,
|
||||||
type: "empty",
|
type: "empty",
|
||||||
position: {
|
position: {
|
||||||
x: bounds.x + bounds.width / 2 - NodeWidth / 2,
|
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
|
// Converts a role doc into a node structure
|
||||||
export const roleToNode = role => {
|
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
|
const interactive = custom || role._id === Roles.POWER
|
||||||
return {
|
return {
|
||||||
id: role._id,
|
id: role._id,
|
||||||
|
|
Loading…
Reference in New Issue