1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

Improve messaging

This commit is contained in:
Adria Navarro 2023-09-01 17:23:47 +02:00
parent 3e3b965bb3
commit bb8aacd830
5 changed files with 37 additions and 15 deletions

View file

@ -65,11 +65,27 @@
$: requiresPlanToModify = permissions.requiresPlanToModify
let dependantResources
async function loadDependantResources() {
dependantResources = await permissionsStore.getDependantsCount(resourceId)
let dependantsInfoMessage
async function loadDependantInfo() {
const dependantsInfo = await permissionsStore.getDependantsInfo(resourceId)
const resourceByType = dependantsInfo?.resourceByType
if (resourceByType) {
const total = Object.values(resourceByType).reduce((p, c) => p + c, 0)
let resourceDisplay =
Object.keys(resourceByType).length === 1 && resourceByType.view
? "view"
: "resource"
if (total === 1) {
dependantsInfoMessage = `1 ${resourceDisplay} is inheriting this access.`
} else if (total > 1) {
dependantsInfoMessage = `${total} ${resourceDisplay}s are inheriting this access.`
}
}
}
loadDependantResources()
loadDependantInfo()
</script>
<ModalContent showCancelButton={false} confirmText="Done">
@ -101,12 +117,12 @@
{/each}
</div>
{#if dependantResources}
{#if dependantsInfoMessage}
<div class="inheriting-resources">
<Icon name="Alert" />
<Body size="S">
<i>
{dependantResources} resource/s are inheriting this access.
{dependantsInfoMessage}
</i>
</Body>
</div>

View file

@ -26,8 +26,8 @@ export function createPermissionStore() {
forResourceDetailed: async resourceId => {
return await API.getPermissionForResource(resourceId)
},
getDependantsCount: async resourceId => {
return (await API.getDependants(resourceId)).total
getDependantsInfo: async resourceId => {
return await API.getDependants(resourceId)
},
}
}

View file

@ -185,7 +185,7 @@ export async function getDependantResources(
) {
const resourceId = ctx.params.resourceId
ctx.body = {
total: await sdk.permissions.getDependantResources(resourceId),
resourceByType: await sdk.permissions.getDependantResources(resourceId),
}
}

View file

@ -137,9 +137,11 @@ export async function getResourcePerms(
return result
}
export async function getDependantResources(resourceId: string) {
export async function getDependantResources(
resourceId: string
): Promise<Record<string, number> | undefined> {
if (db.isTableId(resourceId)) {
const dependants = new Set<string>()
const dependants: Record<string, Set<string>> = {}
const table = await sdk.tables.getTable(resourceId)
const views = Object.values(table.views || {})
@ -152,13 +154,17 @@ export async function getDependantResources(resourceId: string) {
const permissions = await getResourcePerms(view.id)
for (const [level, roleInfo] of Object.entries(permissions)) {
if (roleInfo.type === PermissionSource.INHERITED) {
dependants.add(view.id)
dependants[VirtualDocumentType.VIEW] ??= new Set()
dependants[VirtualDocumentType.VIEW].add(view.id)
}
}
}
return dependants.size
return Object.entries(dependants).reduce((p, [type, resources]) => {
p[type] = resources.size
return p
}, {} as Record<string, number>)
}
return 0
return
}

View file

@ -12,5 +12,5 @@ export interface GetResourcePermsResponse {
}
export interface GetDependantResourcesResponse {
total: number
resourceByType?: Record<string, number>
}