Update RBAC editor to use a grid and make all dimensions consistent with grid

This commit is contained in:
Andrew Kingston 2024-09-12 16:51:36 +01:00
parent 87206b1c43
commit dded09ca97
No known key found for this signature in database
4 changed files with 26 additions and 19 deletions

View File

@ -8,7 +8,7 @@
import { rolesToNodes, autoLayout } from "./layout" import { rolesToNodes, autoLayout } from "./layout"
import { onMount, setContext } from "svelte" import { onMount, setContext } from "svelte"
import Controls from "./Controls.svelte" import Controls from "./Controls.svelte"
import { MaxAutoZoom } from "./constants" import { GridResolution, MaxAutoZoom } from "./constants"
const nodes = writable([]) const nodes = writable([])
const edges = writable([]) const edges = writable([])
@ -34,7 +34,7 @@
fitView fitView
{nodes} {nodes}
{edges} {edges}
snapGrid={[25, 25]} snapGrid={[GridResolution, GridResolution]}
nodeTypes={{ role: RoleNode }} nodeTypes={{ role: RoleNode }}
edgeTypes={{ role: RoleEdge }} edgeTypes={{ role: RoleEdge }}
proOptions={{ hideAttribution: true }} proOptions={{ hideAttribution: true }}
@ -76,7 +76,6 @@
.flow :global(.svelte-flow) { .flow :global(.svelte-flow) {
/* Panel */ /* Panel */
--xy-background-color: var(--background-color); --xy-background-color: var(--background-color);
--xy-background-pattern-color-props: transparent;
/* Controls */ /* Controls */
--xy-controls-button-background-color: var(--node-background); --xy-controls-button-background-color: var(--node-background);

View File

@ -156,28 +156,30 @@
width: var(--width); width: var(--width);
height: var(--height); height: var(--height);
display: flex; display: flex;
flex-direction: column; flex-direction: row;
box-sizing: border-box;
} }
.node.selected { .node.selected {
background: var(--spectrum-global-color-blue-100); background: var(--spectrum-global-color-blue-100);
} }
.color { .color {
border-top-left-radius: 4px; border-top-left-radius: 4px;
border-top-right-radius: 4px; border-bottom-left-radius: 4px;
height: 8px; height: 100%;
width: 100%; width: 10px;
flex: 0 0 10px;
background: var(--color); background: var(--color);
} }
.content { .content {
flex: 1 1 auto; flex: 1 1 auto;
padding: 0 14px 0 14px; padding: 0 12px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: stretch; align-items: stretch;
gap: 2px; gap: 2px;
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
border-bottom-left-radius: 4px; border-top-right-radius: 4px;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
} }
.node.selected .content { .node.selected .content {
@ -199,8 +201,7 @@
.title :global(.spectrum-Icon) { .title :global(.spectrum-Icon) {
color: var(--spectrum-global-color-gray-600); color: var(--spectrum-global-color-gray-600);
} }
.name, .name {
.description {
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
@ -208,6 +209,12 @@
.description { .description {
color: var(--spectrum-global-color-gray-600); color: var(--spectrum-global-color-gray-600);
font-size: 12px; font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 1;
line-clamp: 1;
-webkit-box-orient: vertical;
} }
.node:hover .buttons { .node:hover .buttons {
display: flex; display: flex;

View File

@ -1,4 +1,5 @@
export const NodeWidth = 220
export const NodeHeight = 66
export const ZoomDuration = 300 export const ZoomDuration = 300
export const MaxAutoZoom = 1.2 export const MaxAutoZoom = 1.2
export const GridResolution = 20
export const NodeHeight = GridResolution * 3
export const NodeWidth = GridResolution * 12

View File

@ -1,5 +1,5 @@
import dagre from "@dagrejs/dagre" import dagre from "@dagrejs/dagre"
import { NodeWidth, NodeHeight } from "./constants" import { NodeWidth, NodeHeight, GridResolution } from "./constants"
import { Position } from "@xyflow/svelte" import { Position } from "@xyflow/svelte"
import { roles } from "stores/builder" import { roles } from "stores/builder"
import { Roles } from "constants/backend" import { Roles } from "constants/backend"
@ -78,8 +78,8 @@ const dagreLayout = ({ nodes, edges }) => {
dagreGraph.setDefaultEdgeLabel(() => ({})) dagreGraph.setDefaultEdgeLabel(() => ({}))
dagreGraph.setGraph({ dagreGraph.setGraph({
rankdir: "LR", rankdir: "LR",
ranksep: 200, ranksep: GridResolution * 6,
nodesep: 50, nodesep: GridResolution * 2,
}) })
nodes.forEach(node => { nodes.forEach(node => {
dagreGraph.setNode(node.id, { width: NodeWidth, height: NodeHeight }) dagreGraph.setNode(node.id, { width: NodeWidth, height: NodeHeight })
@ -89,12 +89,12 @@ const dagreLayout = ({ nodes, edges }) => {
}) })
dagre.layout(dagreGraph) dagre.layout(dagreGraph)
nodes.forEach(node => { nodes.forEach(node => {
const nodeWithPosition = dagreGraph.node(node.id) const pos = dagreGraph.node(node.id)
node.targetPosition = Position.Left node.targetPosition = Position.Left
node.sourcePosition = Position.Right node.sourcePosition = Position.Right
node.position = { node.position = {
x: nodeWithPosition.x - NodeWidth / 2, x: Math.round((pos.x - NodeWidth / 2) / GridResolution) * GridResolution,
y: nodeWithPosition.y - NodeHeight / 2, y: Math.round((pos.y - NodeHeight / 2) / GridResolution) * GridResolution,
} }
}) })
return { nodes, edges } return { nodes, edges }