@@ -4,6 +4,7 @@ import React from "react";
44import type { Namespace , NamespaceRole , NamespaceRoleAbility } from "@code0-tech/sagittarius-graphql-types" ;
55import { useParams } from "next/navigation" ;
66import {
7+ AuroraBackground ,
78 Button ,
89 Card ,
910 CheckboxInput ,
@@ -13,10 +14,10 @@ import {
1314 Row ,
1415 Spacing ,
1516 Text ,
17+ toast ,
1618 useForm ,
1719 useService ,
18- useStore ,
19- toast
20+ useStore
2021} from "@code0-tech/pictor" ;
2122import { RoleService } from "@edition/role/Role.service" ;
2223import { ProjectService } from "@edition/project/Project.service" ;
@@ -40,7 +41,6 @@ type PermissionObject = {
4041
4142type PermissionTemplate = {
4243 name : string
43- description : string
4444 abilities : PermissionObject
4545}
4646
@@ -68,7 +68,7 @@ const permissions: PermissionGroup[] = [
6868 permissions : [
6969 { label : "Create role" , ability : "CREATE_NAMESPACE_ROLE" } ,
7070 { label : "Update role" , ability : "UPDATE_NAMESPACE_ROLE" } ,
71- { label : "Assign project roles" , ability : "ASSIGN_ROLE_PROJECTS" } ,
71+ { label : "Limit roles to projects " , ability : "ASSIGN_ROLE_PROJECTS" } ,
7272 { label : "Assign role abilities" , ability : "ASSIGN_ROLE_ABILITIES" } ,
7373 ]
7474 } ,
@@ -124,8 +124,7 @@ const defaultPermissions = {
124124
125125const permissionTemplates : PermissionTemplate [ ] = [
126126 {
127- name : "Flow builder role template" ,
128- description : "" ,
127+ name : "Flow developer role template" ,
129128 abilities : {
130129 ...defaultPermissions ,
131130 "CREATE_FLOW" : true ,
@@ -138,7 +137,6 @@ const permissionTemplates: PermissionTemplate[] = [
138137 } ,
139138 {
140139 name : "Team manager role template" ,
141- description : "" ,
142140 abilities : {
143141 ...defaultPermissions ,
144142 "INVITE_MEMBER" : true ,
@@ -152,8 +150,7 @@ const permissionTemplates: PermissionTemplate[] = [
152150 }
153151 } ,
154152 {
155- name : "Infrastructure role template" ,
156- description : "" ,
153+ name : "Runtime manager role template" ,
157154 abilities : {
158155 ...defaultPermissions ,
159156 "CREATE_RUNTIME" : true ,
@@ -164,8 +161,7 @@ const permissionTemplates: PermissionTemplate[] = [
164161 }
165162 } ,
166163 {
167- name : "Project role template" ,
168- description : "" ,
164+ name : "Project manager role template" ,
169165 abilities : {
170166 ...defaultPermissions ,
171167 "CREATE_NAMESPACE_PROJECT" : true ,
@@ -217,7 +213,6 @@ export const RoleSettingsPage: React.FC = () => {
217213 const updatedAbilities = Object . entries ( values )
218214 . filter ( ( [ _ , enabled ] ) => enabled )
219215 . map ( ( [ ability , _ ] ) => ability as NamespaceRoleAbility )
220- console . log ( updatedAbilities )
221216 roleService . roleAssignAbilities ( {
222217 roleId : roleId ! ! ,
223218 abilities : updatedAbilities
@@ -259,29 +254,52 @@ export const RoleSettingsPage: React.FC = () => {
259254 } >
260255 < >
261256 < TabContent value = { "permission" } style = { { overflow : "hidden" } } >
262- < Text size = { "xl" } hierarchy = { "primary" } > Select from role templates</ Text >
257+ < Text size = { "xl" } hierarchy = { "primary" } style = { { fontWeight : 600 } } > Select from role
258+ templates</ Text >
263259 < Spacing spacing = { "xl" } />
264- < Row >
265- { permissionTemplates . map ( permissionTemplate => {
266- return < Col >
267- < Card >
268- < Text size = { "lg" } hierarchy = { "secondary" } >
269- { permissionTemplate . name }
270- </ Text >
271- < Spacing spacing = { "xxs" } />
272- < Text size = { "sm" } hierarchy = { "tertiary" } >
273- { permissionTemplate . description }
274- </ Text >
275- < Spacing spacing = { "xl" } />
276- < Button color = { "primary" } w = { "100%" }
277- onClick = { ( ) => setInitialValues ( permissionTemplate . abilities ) } > Select
278- template</ Button >
279- </ Card >
280- </ Col >
281- } ) }
282- </ Row >
260+ { React . useMemo ( ( ) => {
261+ return < Row >
262+ { permissionTemplates . map ( permissionTemplate => {
263+
264+ //schreibe mir hier eine variable isSelected die true ist wenn die permissionTemplate.abilities genau den gleichen inhalten entsprechen wie die aktuellen rule abilities hat
265+
266+
267+ const templateAbilities = Object . entries ( permissionTemplate . abilities )
268+ . filter ( ( [ _ , enabled ] ) => enabled )
269+ . map ( ( [ ability ] ) => ability as NamespaceRoleAbility ) ;
270+
271+ const roleAbilities = Object . entries ( initialValues )
272+ . filter ( ( [ _ , enabled ] ) => enabled )
273+ . map ( ( [ ability ] ) => ability as NamespaceRoleAbility ) ;
274+
275+ const isSelected = templateAbilities . length === roleAbilities . length
276+ && templateAbilities . every ( a => new Set ( roleAbilities ) . has ( a ) ) ;
277+
278+
279+ return < Col >
280+ < Card >
281+ < Text style = { { fontWeight : 500 } } size = { "lg" } hierarchy = { "secondary" } >
282+ { permissionTemplate . name }
283+ </ Text >
284+ < Spacing spacing = { "xs" } />
285+ < DNamespaceRolePermissions
286+ abilities = { Object . entries ( permissionTemplate . abilities )
287+ . filter ( ( [ _ , enabled ] ) => enabled )
288+ . map ( ( [ ability , _ ] ) => ability as NamespaceRoleAbility ) } />
289+ < Spacing spacing = { "xl" } />
290+ < Button disabled = { isSelected } color = { "secondary" } variant = { "filled" }
291+ w = { "100%" }
292+ onClick = { ( ) => setInitialValues ( permissionTemplate . abilities ) } > Select
293+ template</ Button >
294+ { isSelected ? < AuroraBackground /> : null }
295+ </ Card >
296+ </ Col >
297+ } ) }
298+ </ Row >
299+ } , [ initialValues , role ] ) }
283300 < Spacing spacing = { "xl" } />
284- < Text size = { "xl" } hierarchy = { "primary" } > Current applied permissions</ Text >
301+ < Text size = { "xl" } hierarchy = { "primary" } style = { { fontWeight : 600 } } > Current stored
302+ permissions</ Text >
285303 < Spacing spacing = { "xs" } />
286304 < DNamespaceRolePermissions abilities = { role ?. abilities ! ! } />
287305 < Spacing spacing = { "xl" } />
0 commit comments