mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* basic StorageBucketResponse items in table * basic bucket file explorer * policy count for each bucket * don't show root folder on explorer It's confusing in the new surrounding UI * fix height for StorageExplorer * reuse existing header * fix overrides * fix additional overrides * improve table columns * clarify copywriting and remove redundancy * organise imports * minor clean up --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { useMemo } from 'react'
|
|
|
|
import { formatPoliciesForStorage } from 'components/interfaces/Storage/Storage.utils'
|
|
import { useDatabasePoliciesQuery } from 'data/database-policies/database-policies-query'
|
|
import { Bucket } from 'data/storage/buckets-query'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
|
|
export const useStoragePolicyCounts = (buckets: Bucket[]) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: policiesData = [], isLoading } = useDatabasePoliciesQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
schema: 'storage',
|
|
})
|
|
|
|
const policyCountMap = useMemo(() => {
|
|
const storageObjectsPolicies = policiesData.filter((policy: any) => policy.table === 'objects')
|
|
const formattedPolicies = formatPoliciesForStorage(buckets, storageObjectsPolicies)
|
|
|
|
return formattedPolicies.reduce((acc: Record<string, number>, bucketGroup: any) => {
|
|
acc[bucketGroup.name] = bucketGroup.policies.length
|
|
return acc
|
|
}, {})
|
|
}, [buckets, policiesData])
|
|
|
|
const getPolicyCount = (bucketName: string) => {
|
|
return policyCountMap[bucketName] || 0
|
|
}
|
|
|
|
return {
|
|
getPolicyCount,
|
|
isLoading,
|
|
policyCountMap,
|
|
}
|
|
}
|