From eb088b8d0ca82dc3e5b54029ac300f442338a64d Mon Sep 17 00:00:00 2001 From: Rishi Raj Date: Thu, 13 Aug 2026 15:25:07 +0530 Subject: [PATCH] feat(useAccessibleOrgs): accept triggerGetKeys as parameter for multi-app support Signed-off-by: Rishi Raj --- src/custom/useAccessibleOrgs.ts | 50 +++++++++++++++++++++++++-------- src/index.tsx | 3 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/custom/useAccessibleOrgs.ts b/src/custom/useAccessibleOrgs.ts index d749b934c..60bcbf701 100644 --- a/src/custom/useAccessibleOrgs.ts +++ b/src/custom/useAccessibleOrgs.ts @@ -1,4 +1,3 @@ -import { useLazyGetUserKeysQuery } from '@meshery/schemas/cloudApi'; import { Key } from '@meshery/schemas/permissions'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { getPermissionKeys, isPermissionKeySet, PermissionKeySpec } from './PermissionProvider'; @@ -37,11 +36,21 @@ const orgHasPermission = ( const hasDefiniteId = (org: T): org is T & { id: string } => Boolean(org.id); +/** + * The shape of the trigger function returned by RTK Query's + * `useLazyGetUserKeysQuery`. Both `cloudApi` and `mesheryApi` export one + * with the same signature — callers pass whichever is appropriate. + */ +export type TriggerGetKeys = ( + arg: { orgId: string } +) => { unwrap: () => Promise<{ keys?: Array<{ id: string; function: string }> }> }; + /** * Configuration for `useAccessibleOrgs`. * - * The hook does NOT read orgs or the current org from any global store — both - * are supplied by the host application so the hook stays framework-agnostic. + * The hook does NOT read orgs, the current org, or the keys endpoint from any + * global store — all are supplied by the host application so the hook stays + * framework-agnostic. * * Generic over `T` so the element type of `allOrgs` flows through to * `accessibleOrgs` — callers keep `org.name`, `org.avatar`, etc. typed. @@ -58,6 +67,16 @@ export interface UseAccessibleOrgsOptions({ allOrgs, currentOrgId, orgsLoaded, - permissionKey + permissionKey, + triggerGetKeys }: UseAccessibleOrgsOptions) => { - const [triggerGetKeys] = useLazyGetUserKeysQuery(); - // Track which orgs have been checked and their results. // Map const [checkedOrgs, setCheckedOrgs] = useState>(new Map()); diff --git a/src/index.tsx b/src/index.tsx index b982bc264..56e20a4f8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -94,7 +94,8 @@ export { export { useAccessibleOrgs, - type UseAccessibleOrgsOptions + type UseAccessibleOrgsOptions, + type TriggerGetKeys } from './custom/useAccessibleOrgs'; export { BottomSheet, type BottomSheetProps } from './custom/BottomSheet';