mirror of https://github.com/buster-so/buster.git
Added query params
This commit is contained in:
parent
ec63a347c6
commit
52641d7b3d
|
@ -24,6 +24,7 @@ export const useListShortcuts = <TData = ListShortcutsResponse>(
|
|||
queryFn: listShortcuts,
|
||||
select: props?.select,
|
||||
...props,
|
||||
initialData: { shortcuts: [] },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import {
|
|||
inviteUser,
|
||||
updateOrganizationUser,
|
||||
} from './requests';
|
||||
import { useGetUserBasicInfo } from './useGetUserInfo';
|
||||
|
||||
export const useGetMyUserInfo = <TData = UserResponse>(
|
||||
props?: Omit<UseQueryOptions<UserResponse | null, RustApiError, TData>, 'queryKey' | 'queryFn'>
|
||||
|
@ -120,11 +121,22 @@ export const useCreateUserOrganization = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const useGetSuggestedPrompts = (params: Parameters<typeof getSuggestedPrompts>[0]) => {
|
||||
const queryFn = () => getSuggestedPrompts(params);
|
||||
export const useGetSuggestedPrompts = () => {
|
||||
const user = useGetUserBasicInfo();
|
||||
const queryFn = () => getSuggestedPrompts({ userId: user?.id ?? '' });
|
||||
return useQuery({
|
||||
...userQueryKeys.userGetSuggestedPrompts(params.userId),
|
||||
...userQueryKeys.userGetSuggestedPrompts(user?.id ?? ''),
|
||||
queryFn,
|
||||
enabled: !!user?.id,
|
||||
initialData: {
|
||||
suggestedPrompts: {
|
||||
report: [],
|
||||
dashboard: [],
|
||||
visualization: [],
|
||||
help: [],
|
||||
},
|
||||
updatedAt: '',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import type React from 'react';
|
||||
import { useListShortcuts } from '@/api/buster_rest/shortcuts/queryRequests';
|
||||
import { useGetSuggestedPrompts } from '@/api/buster_rest/users';
|
||||
import { useChat } from '@/context/Chats/useChat';
|
||||
import { useGetChatId } from '@/context/Chats/useGetChatId';
|
||||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
import { BusterChatInputBase, type BusterChatInputProps } from './BusterChatInputBase';
|
||||
|
||||
export const BusterChatInput: React.FC<{
|
||||
initialValue?: string;
|
||||
autoSubmit?: boolean;
|
||||
}> = ({ initialValue = '', autoSubmit }) => {
|
||||
const { data: suggestions, isFetched: isFetchedSuggestions } = useGetSuggestedPrompts();
|
||||
const { data: shortcuts, isFetched: isFetchedShortcuts } = useListShortcuts();
|
||||
const { onStartNewChat, onStopChat, isSubmittingChat } = useChat();
|
||||
const chatId = useGetChatId();
|
||||
|
||||
const disabled = !isFetchedSuggestions || !isFetchedShortcuts || isSubmittingChat;
|
||||
|
||||
const onStop = useMemoizedFn(() => {
|
||||
if (chatId) {
|
||||
onStopChat({ chatId });
|
||||
}
|
||||
});
|
||||
|
||||
const onSubmit: BusterChatInputProps['onSubmit'] = useMemoizedFn((d) => {
|
||||
onStartNewChat({ prompt: d.transformedValue, mode: d.mode });
|
||||
});
|
||||
|
||||
return (
|
||||
<BusterChatInputBase
|
||||
defaultValue={initialValue}
|
||||
suggestedPrompts={suggestions?.suggestedPrompts}
|
||||
shortcuts={shortcuts?.shortcuts}
|
||||
onStop={onStop}
|
||||
disabled={disabled}
|
||||
submitting={isSubmittingChat}
|
||||
onSubmit={onSubmit}
|
||||
autoSubmit={autoSubmit}
|
||||
/>
|
||||
);
|
||||
};
|
|
@ -18,12 +18,12 @@ import type {
|
|||
MentionInputSuggestionsRef,
|
||||
} from '@/components/ui/inputs/MentionInputSuggestions';
|
||||
import { MentionInputSuggestions } from '@/components/ui/inputs/MentionInputSuggestions';
|
||||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
import { useMount } from '@/hooks/useMount';
|
||||
import { ASSET_ICONS } from '../../icons/assetIcons';
|
||||
import { NewShortcutModal } from '../../modals/NewShortcutModal';
|
||||
import { BusterChatInputButtons, type BusterChatInputMode } from './BusterChatInputButtons';
|
||||
|
||||
export type BusterChatInput = {
|
||||
export type BusterChatInputProps = {
|
||||
defaultValue: string;
|
||||
onSubmit: (d: {
|
||||
transformedValue: string;
|
||||
|
@ -36,10 +36,20 @@ export type BusterChatInput = {
|
|||
disabled: boolean;
|
||||
shortcuts: ListShortcutsResponse['shortcuts'];
|
||||
suggestedPrompts: GetSuggestedPromptsResponse['suggestedPrompts'];
|
||||
autoSubmit?: boolean;
|
||||
};
|
||||
|
||||
export const BusterChatInputBase: React.FC<BusterChatInput> = React.memo(
|
||||
({ defaultValue, onSubmit, onStop, submitting, disabled, shortcuts, suggestedPrompts }) => {
|
||||
export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
|
||||
({
|
||||
defaultValue,
|
||||
onSubmit,
|
||||
onStop,
|
||||
autoSubmit,
|
||||
submitting,
|
||||
disabled,
|
||||
shortcuts,
|
||||
suggestedPrompts,
|
||||
}) => {
|
||||
const mentionInputSuggestionsRef = useRef<MentionInputSuggestionsRef>(null);
|
||||
const uniqueSuggestions = useUniqueSuggestions(suggestedPrompts);
|
||||
const [openCreateShortcutModal, setOpenCreateShortcutModal] = useState(false);
|
||||
|
@ -95,6 +105,16 @@ export const BusterChatInputBase: React.FC<BusterChatInput> = React.memo(
|
|||
onSubmit({ ...value, mode });
|
||||
};
|
||||
|
||||
useMount(() => {
|
||||
if (autoSubmit && defaultValue) {
|
||||
onSubmitPreflight({
|
||||
transformedValue: defaultValue,
|
||||
arrayValue: [],
|
||||
editorText: defaultValue,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<MentionInputSuggestions
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from './BusterChatInput';
|
|
@ -203,7 +203,7 @@ export const MentionInputSuggestions = forwardRef<
|
|||
<SuggestionsSeperator />
|
||||
<MentionInputSuggestionsList
|
||||
show={showSuggestionList}
|
||||
className={cn(suggestionsContainerClassName)}
|
||||
className={cn('pt-1.5 overflow-y-auto max-h-[35vh]', suggestionsContainerClassName)}
|
||||
>
|
||||
<MentionInputSuggestionsItemsSelector
|
||||
suggestionItems={suggestionItems}
|
||||
|
@ -273,7 +273,7 @@ export const useMentionInputSuggestionsOnChangeValue = () => {
|
|||
const SuggestionsSeperator = () => {
|
||||
const hasResults = useCommandState((x) => x.filtered.count) > 0;
|
||||
if (!hasResults) return null;
|
||||
return <div className="border-b mb-1.5" />;
|
||||
return <div className="border-b" />;
|
||||
};
|
||||
|
||||
const customFilter = (value: string, search: string, keywords?: string[]): number => {
|
||||
|
|
|
@ -49,11 +49,13 @@ export const useChat = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const onStartNewChat = useMemoizedFn(async ({ prompt }: { prompt: string }) => {
|
||||
const onStartNewChat = useMemoizedFn(
|
||||
async ({ prompt, mode }: { prompt: string; mode: 'auto' | 'research' | 'deep-research' }) => {
|
||||
return startChat({
|
||||
prompt,
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
const onStartChatFromFile = useMemoizedFn(
|
||||
async ({
|
||||
|
|
|
@ -2,10 +2,9 @@ import { ClientOnly } from '@tanstack/react-router';
|
|||
import type React from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo';
|
||||
import { BusterChatInput } from '@/components/features/input/BusterChatInput';
|
||||
import { Title } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/classMerge';
|
||||
import { isServer } from '@/lib/window';
|
||||
import { NewChatInput } from './NewChatInput';
|
||||
import { NewChatWarning } from './NewChatWarning';
|
||||
import { useNewChatWarning } from './useNewChatWarning';
|
||||
|
||||
|
@ -42,7 +41,7 @@ export const HomePageController: React.FC<{
|
|||
</Title>
|
||||
</div>
|
||||
|
||||
<NewChatInput initialValue={initialValue} autoSubmit={autoSubmit} />
|
||||
<BusterChatInput initialValue={initialValue} autoSubmit={autoSubmit} />
|
||||
</div>
|
||||
</ClientOnly>
|
||||
)}
|
||||
|
|
Loading…
Reference in New Issue