Use role display names for picking preview roles

This commit is contained in:
Andrew Kingston 2024-10-22 15:16:07 +01:00
parent 86620b9a26
commit 3ae5ce9802
No known key found for this signature in database
1 changed files with 10 additions and 9 deletions

View File

@ -2,27 +2,28 @@
import { Heading, Select, ActionButton } from "@budibase/bbui"
import { devToolsStore, appStore, roleStore } from "../../stores"
import { getContext, onMount } from "svelte"
import { API } from "api"
const context = getContext("context")
const SELF_ROLE = "self"
let staticRoleList
let roles
$: previewOptions = buildRoleList(staticRoleList)
$: previewOptions = buildRoleList(roles)
function buildRoleList(roleIds) {
function buildRoleList(roles) {
const list = []
list.push({
label: "View as yourself",
value: SELF_ROLE,
})
if (!roleIds) {
if (!roles) {
return list
}
for (let roleId of roleIds) {
for (let role of roles) {
list.push({
label: `View as ${roleId.toLowerCase()} user`,
value: roleId,
label: `View as ${role.uiMetadata?.displayName || role.name}`,
value: role._id,
})
}
return list
@ -31,12 +32,12 @@
onMount(async () => {
// make sure correct before starting
await devToolsStore.actions.changeRole(SELF_ROLE)
staticRoleList = await roleStore.actions.fetchAccessibleRoles()
roles = await API.getRoles()
})
</script>
<div class="dev-preview-header" class:mobile={$context.device.mobile}>
<Heading size="XS">Preview</Heading>
<Heading size="XS">Previ werewr eww</Heading>
<Select
quiet
options={previewOptions}