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