mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-14 09:09:42 +00:00
Open search in the current space from scoped search buttons (#4666)
This commit is contained in:
@@ -13,9 +13,14 @@ const INPUT_SIZE_MAP: Record<NonNullable<ButtonProps['size']>, 'small' | 'medium
|
||||
};
|
||||
|
||||
export function InlineActionButton(
|
||||
props: { action: 'ask' | 'search'; query?: string } & { buttonProps: ButtonProps } // TODO: Type this properly: Pick<api.DocumentInlineButton, 'action' | 'query'> & { buttonProps: ButtonProps }
|
||||
props: {
|
||||
action: 'ask' | 'search';
|
||||
query?: string;
|
||||
/** Where a search runs: the whole site, or only the space the visitor is reading. */
|
||||
scope?: 'site' | 'space';
|
||||
} & { buttonProps: ButtonProps } // TODO: Type this properly: Pick<api.DocumentInlineButton, 'action' | 'query'> & { buttonProps: ButtonProps }
|
||||
) {
|
||||
const { action, query, buttonProps } = props;
|
||||
const { action, query, scope, buttonProps } = props;
|
||||
|
||||
const { assistants } = useAI();
|
||||
const chatState = useAIChatState();
|
||||
@@ -29,7 +34,7 @@ export function InlineActionButton(
|
||||
setSearchState((prev) => ({
|
||||
...prev,
|
||||
ask: null,
|
||||
scope: 'default',
|
||||
scope: scope === 'space' ? 'current' : 'default',
|
||||
query: value ?? query,
|
||||
open: true,
|
||||
}));
|
||||
|
||||
@@ -47,6 +47,11 @@ export function InlineButton(props: InlineProps<api.DocumentInlineButton>) {
|
||||
<InlineActionButton
|
||||
action={inline.data.action.action}
|
||||
query={inline.data.action.query ?? ''}
|
||||
scope={
|
||||
inline.data.action.action === 'search'
|
||||
? inline.data.action.scope
|
||||
: undefined
|
||||
}
|
||||
buttonProps={buttonProps}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user