mirror of https://github.com/Budibase/budibase.git
10 changed files with 104 additions and 17 deletions
@ -0,0 +1,43 @@ |
|||||
|
<!-- Module scoped cache of saved role options --> |
||||
|
<script context="module"> |
||||
|
import builderApi from "builderStore/api" |
||||
|
|
||||
|
let cachedRoles |
||||
|
|
||||
|
async function getRoles(force = false) { |
||||
|
if (cachedRoles && !force) { |
||||
|
return await cachedRoles |
||||
|
} |
||||
|
cachedRoles = new Promise(resolve => { |
||||
|
console.log("HIT API") |
||||
|
builderApi |
||||
|
.get("/api/roles") |
||||
|
.then(response => response.json()) |
||||
|
.then(resolve) |
||||
|
}) |
||||
|
return await cachedRoles |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<script> |
||||
|
export let roleId |
||||
|
|
||||
|
let roleName |
||||
|
$: getRole() |
||||
|
|
||||
|
async function getRole() { |
||||
|
// Try to find a matching role |
||||
|
let roles = await getRoles() |
||||
|
let role = roles.find(role => role._id === roleId) |
||||
|
|
||||
|
// If we didn't find a matching role, try updating the cached results |
||||
|
if (!role) { |
||||
|
let roles = await getRoles(true) |
||||
|
let role = roles.find(role => role._id === roleId) |
||||
|
} |
||||
|
role = roles.find(role => role._id === roleId) |
||||
|
roleName = role?.name ?? "Unknown role" |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div>{roleName}</div> |
||||
@ -1,11 +1,12 @@ |
|||||
<script> |
<script> |
||||
import { goto } from "@sveltech/routify" |
|
||||
import { store } from "builderStore" |
import { store } from "builderStore" |
||||
import PathTree from "./PathTree.svelte" |
import PathTree from "./PathTree.svelte" |
||||
|
|
||||
|
$: paths = Object.keys($store.routes || {}).sort() |
||||
</script> |
</script> |
||||
|
|
||||
<div class="root"> |
<div class="root"> |
||||
{#each Object.keys($store.routes || {}) as path} |
{#each paths as path} |
||||
<PathTree {path} route={$store.routes[path]} /> |
<PathTree {path} route={$store.routes[path]} /> |
||||
{/each} |
{/each} |
||||
</div> |
</div> |
||||
|
|||||
Loading…
Reference in new issue