mirror of https://github.com/buster-so/buster.git
avoid duplicate version checks for the metric
This commit is contained in:
parent
7c49aaadef
commit
05a4a631c8
|
@ -93,6 +93,14 @@ export const useGetMetric = <TData = IBusterMetric>(
|
||||||
const isLatestVersion =
|
const isLatestVersion =
|
||||||
updatedMetric.version_number === last(updatedMetric.versions)?.version_number;
|
updatedMetric.version_number === last(updatedMetric.versions)?.version_number;
|
||||||
if (isLatestVersion) setOriginalMetric(updatedMetric);
|
if (isLatestVersion) setOriginalMetric(updatedMetric);
|
||||||
|
|
||||||
|
if (!versionNumber && result?.version_number) {
|
||||||
|
queryClient.setQueryData(
|
||||||
|
metricsQueryKeys.metricsGetMetric(result.id, result.version_number).queryKey,
|
||||||
|
updatedMetric
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return updatedMetric;
|
return updatedMetric;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,6 @@ export const ChatContextProvider = React.memo(({ children }: PropsWithChildren<{
|
||||||
onSetSelectedFile
|
onSetSelectedFile
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(selectedFile);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IndividualChatContext.Provider value={useChatContextValue}>
|
<IndividualChatContext.Provider value={useChatContextValue}>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useGetChatMessageMemoized, useGetChatMessage } from '@/api/buster_rest/chats';
|
import {
|
||||||
|
useGetChatMessageMemoized,
|
||||||
|
useGetChatMessage,
|
||||||
|
useGetChatMemoized
|
||||||
|
} from '@/api/buster_rest/chats';
|
||||||
import type { SelectedFile } from '../interfaces';
|
import type { SelectedFile } from '../interfaces';
|
||||||
import { MutableRefObject, useEffect, useRef } from 'react';
|
import { MutableRefObject, useEffect, useRef } from 'react';
|
||||||
import findLast from 'lodash/findLast';
|
import findLast from 'lodash/findLast';
|
||||||
|
@ -20,6 +24,8 @@ export const useAutoChangeLayout = ({
|
||||||
selectedFileId: string | undefined;
|
selectedFileId: string | undefined;
|
||||||
chatId: string | undefined;
|
chatId: string | undefined;
|
||||||
}) => {
|
}) => {
|
||||||
|
const getChatMemoized = useGetChatMemoized();
|
||||||
|
const getChatMessageMemoized = useGetChatMessageMemoized();
|
||||||
const onSetSelectedFile = useChatLayoutContextSelector((x) => x.onSetSelectedFile);
|
const onSetSelectedFile = useChatLayoutContextSelector((x) => x.onSetSelectedFile);
|
||||||
const messageId = useChatLayoutContextSelector((x) => x.messageId);
|
const messageId = useChatLayoutContextSelector((x) => x.messageId);
|
||||||
const metricId = useChatLayoutContextSelector((x) => x.metricId);
|
const metricId = useChatLayoutContextSelector((x) => x.metricId);
|
||||||
|
@ -35,7 +41,6 @@ export const useAutoChangeLayout = ({
|
||||||
lastMessageId,
|
lastMessageId,
|
||||||
(x) => x?.reasoning_message_ids?.length || 0
|
(x) => x?.reasoning_message_ids?.length || 0
|
||||||
);
|
);
|
||||||
const getChatMessageMemoized = useGetChatMessageMemoized();
|
|
||||||
const { getFileLinkMeta } = useGetFileLink();
|
const { getFileLinkMeta } = useGetFileLink();
|
||||||
|
|
||||||
const previousIsCompletedStream = usePrevious(isCompletedStream);
|
const previousIsCompletedStream = usePrevious(isCompletedStream);
|
||||||
|
@ -100,11 +105,11 @@ export const useAutoChangeLayout = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatMessage = getChatMessageMemoized(lastMessageId);
|
const chat = getChatMemoized(chatId);
|
||||||
|
|
||||||
//reasoning_message_mode
|
//reasoning_message_mode
|
||||||
if (messageId) {
|
if (messageId) {
|
||||||
const messageExists = !!chatMessage?.reasoning_message_ids.find((id) => id === messageId);
|
const messageExists = !!chat?.message_ids.some((id) => id === messageId);
|
||||||
if (messageExists) {
|
if (messageExists) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,16 +124,26 @@ export const useAutoChangeLayout = ({
|
||||||
|
|
||||||
//dashboard_mode
|
//dashboard_mode
|
||||||
if (dashboardId) {
|
if (dashboardId) {
|
||||||
|
console.log('dashboardId', dashboardId);
|
||||||
if (!dashboardVersionNumber) {
|
if (!dashboardVersionNumber) {
|
||||||
const lastMatchingDashboardInChat = chatMessage?.response_message_ids.reduce<
|
const lastMatchingDashboardInChat = chat?.message_ids.reduce<
|
||||||
BusterChatResponseMessage_file | undefined
|
BusterChatResponseMessage_file | undefined
|
||||||
>((acc, messageId) => {
|
>((acc, chatMessageId) => {
|
||||||
const message = chatMessage?.response_messages[messageId]!;
|
const chatMessage = getChatMessageMemoized(chatMessageId);
|
||||||
const isFile =
|
|
||||||
message.type === 'file' &&
|
console.log('chatMessage', chatMessage);
|
||||||
message.file_type === 'dashboard' &&
|
|
||||||
message.id === dashboardId;
|
chatMessage?.response_message_ids.forEach((responseMessageId) => {
|
||||||
if (isFile) return message;
|
const message = chatMessage?.response_messages[responseMessageId]!;
|
||||||
|
const isFile =
|
||||||
|
message.type === 'file' &&
|
||||||
|
message.file_type === 'dashboard' &&
|
||||||
|
message.id === dashboardId;
|
||||||
|
|
||||||
|
if (isFile) {
|
||||||
|
acc = message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, undefined);
|
}, undefined);
|
||||||
|
@ -151,13 +166,22 @@ export const useAutoChangeLayout = ({
|
||||||
//metric_mode
|
//metric_mode
|
||||||
if (metricId) {
|
if (metricId) {
|
||||||
if (!metricVersionNumber) {
|
if (!metricVersionNumber) {
|
||||||
const lastMatchingMetricInChat = chatMessage?.response_message_ids.reduce<
|
const lastMatchingMetricInChat = chat?.message_ids.reduce<
|
||||||
BusterChatResponseMessage_file | undefined
|
BusterChatResponseMessage_file | undefined
|
||||||
>((acc, messageId) => {
|
>((acc, chatMessageId) => {
|
||||||
const message = chatMessage?.response_messages[messageId]!;
|
const chatMessage = getChatMessageMemoized(chatMessageId);
|
||||||
const isFile =
|
|
||||||
message.type === 'file' && message.file_type === 'metric' && message.id === metricId;
|
chatMessage?.response_message_ids.forEach((responseMessageId) => {
|
||||||
if (isFile) return message;
|
const message = chatMessage?.response_messages[responseMessageId]!;
|
||||||
|
const isFile =
|
||||||
|
message.type === 'file' &&
|
||||||
|
message.file_type === 'metric' &&
|
||||||
|
message.id === metricId;
|
||||||
|
|
||||||
|
if (isFile) {
|
||||||
|
acc = message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, undefined);
|
}, undefined);
|
||||||
|
|
Loading…
Reference in New Issue