Skip to content

Commit

Permalink
[AAP-26562] Add an optional disabled property to the AWX and HUB cont…
Browse files Browse the repository at this point in the history
…ext, active user and config AwxActiveUserProvider, AwxCo… (#2628)
  • Loading branch information
lgalis authored Jul 3, 2024
1 parent 2781459 commit 51b1a8e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
9 changes: 8 additions & 1 deletion frontend/awx/common/useAwxActiveUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export function useAwxActiveUser() {
return useContext(AwxActiveUserContext);
}

export function AwxActiveUserProvider(props: { children: ReactNode }) {
export function AwxActiveUserProvider(props: { children: ReactNode; disabled?: boolean }) {
return props?.disabled ? (
<AwxActiveUserContext.Provider value={{}}>{props.children}</AwxActiveUserContext.Provider>
) : (
<AwxActiveUserProviderInternal>{props?.children}</AwxActiveUserProviderInternal>
);
}
export function AwxActiveUserProviderInternal(props: { children: ReactNode }) {
const response = useSWR<AwxItemsResponse<AwxUser>>(awxAPI`/me/`, requestGet, {
dedupingInterval: 0,
refreshInterval: 10 * 1000,
Expand Down
14 changes: 13 additions & 1 deletion frontend/awx/common/useAwxConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ export function useAwxConfigState() {
return useContext(AwxConfigContext);
}

export function AwxConfigProvider(props: { children?: ReactNode }) {
export function AwxConfigProvider(props: { children: ReactNode; disabled?: boolean }) {
return props?.disabled ? (
<AwxConfigContext.Provider
value={{ awxConfig: undefined, awxConfigError: undefined, refreshAwxConfig: undefined }}
>
{props.children}
</AwxConfigContext.Provider>
) : (
<AwxConfigProviderInternal>{props?.children}</AwxConfigProviderInternal>
);
}

export function AwxConfigProviderInternal(props: { children?: ReactNode }) {
const response = useSWR<Config>(awxAPI`/config/`, requestGet);
const value = useMemo(
() => ({
Expand Down
10 changes: 9 additions & 1 deletion frontend/hub/common/useHubActiveUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export function useHubActiveUser() {
return useContext(HubActiveUserContext);
}

export function HubActiveUserProvider(props: { children: ReactNode }) {
export function HubActiveUserProvider(props: { children: ReactNode; disabled?: boolean }) {
return props?.disabled ? (
<HubActiveUserContext.Provider value={{}}>{props.children}</HubActiveUserContext.Provider>
) : (
<HubActiveUserProviderInternal>{props?.children}</HubActiveUserProviderInternal>
);
}

export function HubActiveUserProviderInternal(props: { children: ReactNode }) {
const response = useSWR<HubUser>(hubAPI`/_ui/v1/me/`, requestGet, {
dedupingInterval: 0,
refreshInterval: 10 * 1000,
Expand Down
18 changes: 17 additions & 1 deletion frontend/hub/common/useHubContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@ export function useHubContext() {
return useContext(HubContext);
}

export function HubContextProvider(props: { children: ReactNode }) {
export function HubContextProvider(props: { children: ReactNode; disabled?: boolean }) {
return props?.disabled ? (
<HubContext.Provider
value={{
featureFlags: {},
settings: {},
user: undefined,
hasPermission: () => false,
}}
>
{props.children}
</HubContext.Provider>
) : (
<HubContextProviderInternal>{props?.children}</HubContextProviderInternal>
);
}
export function HubContextProviderInternal(props: { children: ReactNode }) {
const hubFeatureFlagResponse = useSWR<HubFeatureFlags>(
hubAPI`/_ui/v1/feature-flags/`,
requestGet
Expand Down

0 comments on commit 51b1a8e

Please sign in to comment.