Add uiMetdata prefix to roles everywhere

This commit is contained in:
Andrew Kingston 2024-09-13 14:03:21 +01:00
parent 0404050897
commit 2849a7a4ff
No known key found for this signature in database
13 changed files with 49 additions and 46 deletions

View File

@ -29,7 +29,7 @@
$: roleMismatch = checkRoleMismatch(permissions) $: roleMismatch = checkRoleMismatch(permissions)
$: selectedRole = roleMismatch ? null : permissions?.[0]?.value $: selectedRole = roleMismatch ? null : permissions?.[0]?.value
$: readableRole = selectedRole $: readableRole = selectedRole
? $roles.find(x => x._id === selectedRole)?.displayName ? $roles.find(x => x._id === selectedRole)?.uiMetadata.displayName
: null : null
$: buttonLabel = readableRole ? `Access: ${readableRole}` : "Access" $: buttonLabel = readableRole ? `Access: ${readableRole}` : "Access"
$: highlight = roleMismatch || selectedRole === Roles.PUBLIC $: highlight = roleMismatch || selectedRole === Roles.PUBLIC
@ -39,8 +39,8 @@
.filter(x => !builtins.includes(x._id)) .filter(x => !builtins.includes(x._id))
.slice() .slice()
.toSorted((a, b) => { .toSorted((a, b) => {
const aName = a.displayName || a.name const aName = a.uiMetadata.displayName || a.name
const bName = b.displayName || b.name const bName = b.uiMetadata.displayName || b.name
return aName < bName ? -1 : 1 return aName < bName ? -1 : 1
}) })
@ -159,23 +159,23 @@
<List> <List>
{#each builtInRoles as role} {#each builtInRoles as role}
<ListItem <ListItem
title={role.displayName} title={role.uiMetadata.displayName}
subtitle={role.description} subtitle={role.uiMetadata.description}
hoverable hoverable
selected={selectedRole === role._id} selected={selectedRole === role._id}
icon="StatusLight" icon="StatusLight"
iconColor={role.color} iconColor={role.uiMetadata.color}
on:click={() => changePermission(role._id)} on:click={() => changePermission(role._id)}
/> />
{/each} {/each}
{#each customRoles as role} {#each customRoles as role}
<ListItem <ListItem
title={role.displayName} title={role.uiMetadata.displayName}
subtitle={role.description} subtitle={role.uiMetadata.description}
hoverable hoverable
selected={selectedRole === role._id} selected={selectedRole === role._id}
icon="StatusLight" icon="StatusLight"
iconColor={role.color} iconColor={role.uiMetadata.color}
on:click={() => changePermission(role._id)} on:click={() => changePermission(role._id)}
/> />
{/each} {/each}

View File

@ -125,7 +125,7 @@
label="Role" label="Role"
bind:value={row.roleId} bind:value={row.roleId}
options={$roles} options={$roles}
getOptionLabel={role => role.displayName} getOptionLabel={role => role.uiMetadata.displayName}
getOptionValue={role => role._id} getOptionValue={role => role._id}
disabled={!creating} disabled={!creating}
/> />

View File

@ -14,11 +14,13 @@
const addRole = async () => { const addRole = async () => {
const role = { const role = {
name: Helpers.uuid(), name: Helpers.uuid(),
displayName: getSequentialName($nodes, "New role ", { uiMetadata: {
getName: x => x.data.displayName, displayName: getSequentialName($roles, "New role ", {
}), getName: x => x.uiMetadata.displayName,
color: "var(--spectrum-global-color-gray-700)", }),
description: "Custom role", color: "var(--spectrum-global-color-gray-700)",
description: "Custom role",
},
permissionId: "write", permissionId: "write",
inherits: Roles.BASIC, inherits: Roles.BASIC,
} }

View File

@ -38,7 +38,7 @@
$: targetRole = $roles.find(x => x._id === target) $: targetRole = $roles.find(x => x._id === target)
$: tooltip = $: tooltip =
sourceRole && targetRole sourceRole && targetRole
? `Stop ${targetRole.displayName} from inheriting ${sourceRole.displayName}` ? `Stop ${targetRole.uiMetadata.displayName} from inheriting ${sourceRole.uiMetadata.displayName}`
: null : null
const getEdgeClasses = (hovered, labelHovered) => { const getEdgeClasses = (hovered, labelHovered) => {

View File

@ -36,7 +36,7 @@
if (!name?.length) { if (!name?.length) {
return "Please enter a name" return "Please enter a name"
} }
if (roles.some(x => x.displayName === name && x._id !== id)) { if (roles.some(x => x.uiMetadata.displayName === name && x._id !== id)) {
return "That name is already used by another role" return "That name is already used by another role"
} }
return null return null
@ -171,6 +171,7 @@
background: var(--color); background: var(--color);
} }
.content { .content {
width: 0;
flex: 1 1 auto; flex: 1 1 auto;
padding: 0 12px; padding: 0 12px;
display: flex; display: flex;
@ -201,7 +202,8 @@
.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;
@ -209,12 +211,6 @@
.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

@ -14,9 +14,7 @@ export const roleToNode = role => ({
type: "role", type: "role",
position: { x: 0, y: 0 }, position: { x: 0, y: 0 },
data: { data: {
displayName: role.displayName, ...role.uiMetadata,
description: role.description,
color: role.color,
custom: !role._id.match(/[A-Z]+/), custom: !role._id.match(/[A-Z]+/),
}, },
}) })
@ -26,9 +24,11 @@ export const nodeToRole = node => {
const role = get(roles).find(x => x._id === node.id) const role = get(roles).find(x => x._id === node.id)
return { return {
...role, ...role,
displayName: node.data.displayName, uiMetadata: {
color: node.data.color, displayName: node.data.displayName,
description: node.data.description, color: node.data.color,
description: node.data.description,
},
} }
} }

View File

@ -49,8 +49,8 @@
let options = roles let options = roles
.filter(role => allowedRoles.includes(role._id)) .filter(role => allowedRoles.includes(role._id))
.map(role => ({ .map(role => ({
color: role.color, color: role.uiMetadata.color,
name: enrichLabel(role.displayName), name: enrichLabel(role.uiMetadata.displayName),
_id: role._id, _id: role._id,
})) }))
if (allowedRoles.includes(Constants.Roles.CREATOR)) { if (allowedRoles.includes(Constants.Roles.CREATOR)) {
@ -65,8 +65,8 @@
// Allow all core roles // Allow all core roles
let options = roles.map(role => ({ let options = roles.map(role => ({
color: role.color, color: role.uiMetadata.color,
name: enrichLabel(role.displayName), name: enrichLabel(role.uiMetadata.displayName),
_id: role._id, _id: role._id,
})) }))

View File

@ -11,9 +11,9 @@
bind:value bind:value
on:change on:change
options={$roles} options={$roles}
getOptionLabel={role => role.displayName} getOptionLabel={role => role.uiMetadata.displayName}
getOptionValue={role => role._id} getOptionValue={role => role._id}
getOptionColour={role => role.color} getOptionColour={role => role.uiMetadata.color}
{placeholder} {placeholder}
{error} {error}
/> />

View File

@ -725,10 +725,10 @@ const getRoleBindings = () => {
return { return {
type: "context", type: "context",
runtimeBinding: `'${role._id}'`, runtimeBinding: `'${role._id}'`,
readableBinding: `Role.${role.displayName}`, readableBinding: `Role.${role.uiMetadata.displayName}`,
category: "Role", category: "Role",
icon: "UserGroup", icon: "UserGroup",
display: { type: "string", name: role.displayName }, display: { type: "string", name: role.uiMetadata.displayName },
} }
}) })
} }

View File

@ -7,12 +7,13 @@
let showTooltip = false let showTooltip = false
$: color = role.color || "var(--spectrum-global-color-static-magenta-400)"
$: role = $roles.find(role => role._id === roleId) $: role = $roles.find(role => role._id === roleId)
$: color =
role?.uiMetadata.color || "var(--spectrum-global-color-static-magenta-400)"
$: tooltip = $: tooltip =
roleId === Roles.PUBLIC roleId === Roles.PUBLIC
? "Open to the public" ? "Open to the public"
: `Requires ${role?.displayName} access` : `Requires ${role?.uiMetadata.displayName || "Unknown role"} access`
</script> </script>
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->

View File

@ -11,7 +11,7 @@
const getRoleLabel = roleId => { const getRoleLabel = roleId => {
return roleId === Constants.Roles.CREATOR return roleId === Constants.Roles.CREATOR
? capitalise(Constants.Roles.CREATOR.toLowerCase()) ? capitalise(Constants.Roles.CREATOR.toLowerCase())
: role?.displayName || role?.name || "Custom role" : role?.uiMetadata.displayName || role?.name || "Custom role"
} }
</script> </script>

View File

@ -9,9 +9,12 @@ export function createRolesStore() {
...role, ...role,
// Ensure we have new metadata for all roles // Ensure we have new metadata for all roles
displayName: role.displayName || role.name, uiMetadata: {
color: role.color || "var(--spectrum-global-color-magenta-400)", displayName: role.uiMetadata?.displayName || role.name,
description: role.description || "Custom role", color:
role.uiMetadata?.color || "var(--spectrum-global-color-magenta-400)",
description: role.uiMetadata?.description || "Custom role",
},
})) }))
}) })

View File

@ -12,11 +12,12 @@
<StatusLight <StatusLight
square square
size="L" size="L"
color={role?.color || "var(--spectrum-global-color-magenta-400)"} color={role?.uiMetadata?.color ||
"var(--spectrum-global-color-static-magenta-400)"}
/> />
</div> </div>
<div class="value"> <div class="value">
{role?.displayName || role?.name || value} {role?.uiMetadata?.displayName || role?.name || "Unknown role"}
</div> </div>
</div> </div>