-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track site insight event when opening scalar client (#2658)
- Loading branch information
Showing
12 changed files
with
138 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@gitbook/react-openapi': minor | ||
--- | ||
|
||
Add an optional client context to get a callback called when the Scalar client is opened for a block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'gitbook': minor | ||
--- | ||
|
||
Track an event into site insights when visitor is opening the Scalar API client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useEventCallback } from 'usehooks-ts'; | ||
|
||
interface OpenAPIOperationPointer { | ||
path: string; | ||
method: string; | ||
} | ||
|
||
interface OpenAPIOperationContextValue { | ||
onOpenClient: (pointer: OpenAPIOperationPointer) => void; | ||
} | ||
|
||
const OpenAPIOperationContext = React.createContext<OpenAPIOperationContextValue>({ | ||
onOpenClient: () => {}, | ||
}); | ||
|
||
/** | ||
* Provider for the OpenAPIOperationContext. | ||
*/ | ||
export function OpenAPIOperationContextProvider( | ||
props: React.PropsWithChildren<Partial<OpenAPIOperationContextValue>>, | ||
) { | ||
const { children } = props; | ||
|
||
const onOpenClient = useEventCallback((pointer: OpenAPIOperationPointer) => { | ||
props.onOpenClient?.(pointer); | ||
}); | ||
|
||
const value = React.useMemo(() => ({ onOpenClient }), [onOpenClient]); | ||
|
||
return ( | ||
<OpenAPIOperationContext.Provider value={value}> | ||
{children} | ||
</OpenAPIOperationContext.Provider> | ||
); | ||
} | ||
|
||
/** | ||
* Hook to access the OpenAPIOperationContext. | ||
*/ | ||
export function useOpenAPIOperationContext() { | ||
return React.useContext(OpenAPIOperationContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './fetchOpenAPIOperation'; | ||
export * from './OpenAPIOperation'; | ||
export type { OpenAPIFetcher } from './types'; | ||
export * from './OpenAPIOperationContext'; |