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,
|
queryFn: listShortcuts,
|
||||||
select: props?.select,
|
select: props?.select,
|
||||||
...props,
|
...props,
|
||||||
|
initialData: { shortcuts: [] },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
inviteUser,
|
inviteUser,
|
||||||
updateOrganizationUser,
|
updateOrganizationUser,
|
||||||
} from './requests';
|
} from './requests';
|
||||||
|
import { useGetUserBasicInfo } from './useGetUserInfo';
|
||||||
|
|
||||||
export const useGetMyUserInfo = <TData = UserResponse>(
|
export const useGetMyUserInfo = <TData = UserResponse>(
|
||||||
props?: Omit<UseQueryOptions<UserResponse | null, RustApiError, TData>, 'queryKey' | 'queryFn'>
|
props?: Omit<UseQueryOptions<UserResponse | null, RustApiError, TData>, 'queryKey' | 'queryFn'>
|
||||||
|
@ -120,11 +121,22 @@ export const useCreateUserOrganization = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetSuggestedPrompts = (params: Parameters<typeof getSuggestedPrompts>[0]) => {
|
export const useGetSuggestedPrompts = () => {
|
||||||
const queryFn = () => getSuggestedPrompts(params);
|
const user = useGetUserBasicInfo();
|
||||||
|
const queryFn = () => getSuggestedPrompts({ userId: user?.id ?? '' });
|
||||||
return useQuery({
|
return useQuery({
|
||||||
...userQueryKeys.userGetSuggestedPrompts(params.userId),
|
...userQueryKeys.userGetSuggestedPrompts(user?.id ?? ''),
|
||||||
queryFn,
|
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,
|
MentionInputSuggestionsRef,
|
||||||
} from '@/components/ui/inputs/MentionInputSuggestions';
|
} from '@/components/ui/inputs/MentionInputSuggestions';
|
||||||
import { MentionInputSuggestions } 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 { ASSET_ICONS } from '../../icons/assetIcons';
|
||||||
import { NewShortcutModal } from '../../modals/NewShortcutModal';
|
import { NewShortcutModal } from '../../modals/NewShortcutModal';
|
||||||
import { BusterChatInputButtons, type BusterChatInputMode } from './BusterChatInputButtons';
|
import { BusterChatInputButtons, type BusterChatInputMode } from './BusterChatInputButtons';
|
||||||
|
|
||||||
export type BusterChatInput = {
|
export type BusterChatInputProps = {
|
||||||
defaultValue: string;
|
defaultValue: string;
|
||||||
onSubmit: (d: {
|
onSubmit: (d: {
|
||||||
transformedValue: string;
|
transformedValue: string;
|
||||||
|
@ -36,10 +36,20 @@ export type BusterChatInput = {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
shortcuts: ListShortcutsResponse['shortcuts'];
|
shortcuts: ListShortcutsResponse['shortcuts'];
|
||||||
suggestedPrompts: GetSuggestedPromptsResponse['suggestedPrompts'];
|
suggestedPrompts: GetSuggestedPromptsResponse['suggestedPrompts'];
|
||||||
|
autoSubmit?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BusterChatInputBase: React.FC<BusterChatInput> = React.memo(
|
export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
|
||||||
({ defaultValue, onSubmit, onStop, submitting, disabled, shortcuts, suggestedPrompts }) => {
|
({
|
||||||
|
defaultValue,
|
||||||
|
onSubmit,
|
||||||
|
onStop,
|
||||||
|
autoSubmit,
|
||||||
|
submitting,
|
||||||
|
disabled,
|
||||||
|
shortcuts,
|
||||||
|
suggestedPrompts,
|
||||||
|
}) => {
|
||||||
const mentionInputSuggestionsRef = useRef<MentionInputSuggestionsRef>(null);
|
const mentionInputSuggestionsRef = useRef<MentionInputSuggestionsRef>(null);
|
||||||
const uniqueSuggestions = useUniqueSuggestions(suggestedPrompts);
|
const uniqueSuggestions = useUniqueSuggestions(suggestedPrompts);
|
||||||
const [openCreateShortcutModal, setOpenCreateShortcutModal] = useState(false);
|
const [openCreateShortcutModal, setOpenCreateShortcutModal] = useState(false);
|
||||||
|
@ -95,6 +105,16 @@ export const BusterChatInputBase: React.FC<BusterChatInput> = React.memo(
|
||||||
onSubmit({ ...value, mode });
|
onSubmit({ ...value, mode });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useMount(() => {
|
||||||
|
if (autoSubmit && defaultValue) {
|
||||||
|
onSubmitPreflight({
|
||||||
|
transformedValue: defaultValue,
|
||||||
|
arrayValue: [],
|
||||||
|
editorText: defaultValue,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<MentionInputSuggestions
|
<MentionInputSuggestions
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './BusterChatInput';
|
|
@ -203,7 +203,7 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
<SuggestionsSeperator />
|
<SuggestionsSeperator />
|
||||||
<MentionInputSuggestionsList
|
<MentionInputSuggestionsList
|
||||||
show={showSuggestionList}
|
show={showSuggestionList}
|
||||||
className={cn(suggestionsContainerClassName)}
|
className={cn('pt-1.5 overflow-y-auto max-h-[35vh]', suggestionsContainerClassName)}
|
||||||
>
|
>
|
||||||
<MentionInputSuggestionsItemsSelector
|
<MentionInputSuggestionsItemsSelector
|
||||||
suggestionItems={suggestionItems}
|
suggestionItems={suggestionItems}
|
||||||
|
@ -273,7 +273,7 @@ export const useMentionInputSuggestionsOnChangeValue = () => {
|
||||||
const SuggestionsSeperator = () => {
|
const SuggestionsSeperator = () => {
|
||||||
const hasResults = useCommandState((x) => x.filtered.count) > 0;
|
const hasResults = useCommandState((x) => x.filtered.count) > 0;
|
||||||
if (!hasResults) return null;
|
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 => {
|
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(
|
||||||
return startChat({
|
async ({ prompt, mode }: { prompt: string; mode: 'auto' | 'research' | 'deep-research' }) => {
|
||||||
prompt,
|
return startChat({
|
||||||
});
|
prompt,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const onStartChatFromFile = useMemoizedFn(
|
const onStartChatFromFile = useMemoizedFn(
|
||||||
async ({
|
async ({
|
||||||
|
|
|
@ -2,10 +2,9 @@ import { ClientOnly } from '@tanstack/react-router';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo';
|
import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo';
|
||||||
|
import { BusterChatInput } from '@/components/features/input/BusterChatInput';
|
||||||
import { Title } from '@/components/ui/typography';
|
import { Title } from '@/components/ui/typography';
|
||||||
import { cn } from '@/lib/classMerge';
|
import { cn } from '@/lib/classMerge';
|
||||||
import { isServer } from '@/lib/window';
|
|
||||||
import { NewChatInput } from './NewChatInput';
|
|
||||||
import { NewChatWarning } from './NewChatWarning';
|
import { NewChatWarning } from './NewChatWarning';
|
||||||
import { useNewChatWarning } from './useNewChatWarning';
|
import { useNewChatWarning } from './useNewChatWarning';
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ export const HomePageController: React.FC<{
|
||||||
</Title>
|
</Title>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NewChatInput initialValue={initialValue} autoSubmit={autoSubmit} />
|
<BusterChatInput initialValue={initialValue} autoSubmit={autoSubmit} />
|
||||||
</div>
|
</div>
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in New Issue