update controller

This commit is contained in:
Nate Kelley 2025-02-18 20:17:38 -07:00
parent afae3eb0f5
commit 3dc28509d9
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
19 changed files with 52 additions and 36 deletions

View File

@ -7,7 +7,7 @@ import {
} from './eventInterfaces'; } from './eventInterfaces';
export enum ChatsResponses { export enum ChatsResponses {
'/chats/list:getChatsList' = '/chats/list:getChatsList', '/chats/list:getThreadsList' = '/chats/list:getThreadsList',
'/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe', '/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe',
'/chats/get:getChat' = '/chats/get:getChat', '/chats/get:getChat' = '/chats/get:getChat',
'/chats/post:initializeChat' = '/chats/post:initializeChat', '/chats/post:initializeChat' = '/chats/post:initializeChat',
@ -20,7 +20,7 @@ export enum ChatsResponses {
} }
export type ChatList_getChatsList = { export type ChatList_getChatsList = {
route: '/chats/list:getChatsList'; route: '/chats/list:getThreadsList';
callback: (d: BusterChatListItem[]) => void; callback: (d: BusterChatListItem[]) => void;
onError?: (d: unknown | RustApiError) => void; onError?: (d: unknown | RustApiError) => void;
}; };

View File

@ -56,7 +56,10 @@ export const useSocketQueryEmitOn = <
} as UseQueryOptions<TData, TError, TData, TQueryKey>; } as UseQueryOptions<TData, TError, TData, TQueryKey>;
}, [options.queryKey, enabledTrigger]); }, [options.queryKey, enabledTrigger]);
const queryResult = useSocketQueryOn({ responseEvent, options: emitOptions, callback }); return useSocketQueryOn({
responseEvent,
return { ...queryResult }; options: emitOptions,
callback,
isEmitOn: true
});
}; };

View File

@ -23,7 +23,8 @@ export const useSocketQueryOn = <
>({ >({
responseEvent, responseEvent,
options, options,
callback callback,
isEmitOn
}: { }: {
responseEvent: TRoute; responseEvent: TRoute;
options?: UseQueryOptions<TData, TError, TData, TQueryKey> | null; options?: UseQueryOptions<TData, TError, TData, TQueryKey> | null;
@ -33,6 +34,7 @@ export const useSocketQueryOn = <
newData: InferBusterSocketResponseData<TRoute> newData: InferBusterSocketResponseData<TRoute>
) => TData | undefined | void) ) => TData | undefined | void)
| null; | null;
isEmitOn?: boolean;
}): UseSocketQueryOnResult<TData, TError> => { }): UseSocketQueryOnResult<TData, TError> => {
const busterSocket = useBusterWebSocket(); const busterSocket = useBusterWebSocket();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -63,7 +65,7 @@ export const useSocketQueryOn = <
useMount(() => { useMount(() => {
const hasCallbacks = busterSocket.getCurrentListeners(responseEvent).length > 0; const hasCallbacks = busterSocket.getCurrentListeners(responseEvent).length > 0;
if (!hasCallbacks) busterSocket.on(socketConfig); if (!hasCallbacks || isEmitOn) busterSocket.on(socketConfig);
}); });
useUnmount(() => { useUnmount(() => {

View File

@ -13,6 +13,6 @@ export const termsGetTerm = (termId: string) =>
}); });
export const termsQueryKeys = { export const termsQueryKeys = {
'/terms/list:getTermsList': termsGetList, termsGetList,
'/terms/get:getTerm': termsGetTerm termsGetTerm
}; };

View File

@ -14,7 +14,6 @@ export const MetricController: React.FC<{
}> = React.memo(({ metricId }) => { }> = React.memo(({ metricId }) => {
const { metric, isFetchedMetricData } = useMetricIndividual({ metricId }); const { metric, isFetchedMetricData } = useMetricIndividual({ metricId });
const selectedFileView = useChatLayoutContextSelector((x) => x.selectedFileView) || 'chart'; const selectedFileView = useChatLayoutContextSelector((x) => x.selectedFileView) || 'chart';
const isFetchedConfig = metric.fetched; const isFetchedConfig = metric.fetched;
const showLoader = !isFetchedConfig || !isFetchedMetricData; const showLoader = !isFetchedConfig || !isFetchedMetricData;

View File

@ -1,6 +1,6 @@
import { SelectedFile } from '@appLayouts/ChatLayout'; import { SelectedFile } from '@appLayouts/ChatLayout';
import { useBusterDashboardContextSelector } from '@/context/Dashboards'; import { useBusterDashboardContextSelector } from '@/context/Dashboards';
import { useMetricIndividual } from '@/context/Metrics'; import { useBusterMetricsIndividualContextSelector, useMetricIndividual } from '@/context/Metrics';
import { useEffect, useMemo } from 'react'; import { useEffect, useMemo } from 'react';
import { FileType } from '@/api/asset_interfaces'; import { FileType } from '@/api/asset_interfaces';
import { import {
@ -16,9 +16,14 @@ export const useFileFallback = ({
defaultSelectedFile?: SelectedFile; defaultSelectedFile?: SelectedFile;
}) => { }) => {
const fileId = defaultSelectedFile?.id || ''; const fileId = defaultSelectedFile?.id || '';
const onUpdateChatMessage = useBusterChatContextSelector((x) => x.onUpdateChatMessage); const onUpdateChatMessage = useBusterChatContextSelector((x) => x.onUpdateChatMessage);
const { metricTitle, metricVersionNumber } = useMetricParams(fileId); const { metricTitle, metricVersionNumber } = useMetricParams(
const { dashboardTitle, dashboardVersionNumber } = useDashboardParams(fileId); defaultSelectedFile?.type === 'metric' ? fileId : ''
);
const { dashboardTitle, dashboardVersionNumber } = useDashboardParams(
defaultSelectedFile?.type === 'dashboard' ? fileId : ''
);
const fileType: FileType = useMemo(() => { const fileType: FileType = useMemo(() => {
if (defaultSelectedFile?.type === 'metric') { if (defaultSelectedFile?.type === 'metric') {
@ -133,17 +138,18 @@ const fallbackToFileChatMessage = ({
}; };
}; };
const useMetricParams = (fileId: string) => { const useMetricParams = (metricId: string) => {
const { metric } = useMetricIndividual({ metricId: fileId }); const getMetricMemoized = useBusterMetricsIndividualContextSelector((x) => x.getMetricMemoized);
const metric = getMetricMemoized({ metricId });
const metricTitle = metric?.title; const metricTitle = metric?.title;
const metricVersionNumber = metric?.version_number; const metricVersionNumber = metric?.version_number;
return { metricTitle, metricVersionNumber }; return { metricTitle, metricVersionNumber };
}; };
const useDashboardParams = (fileId: string) => { const useDashboardParams = (dashboardId: string) => {
const getDashboardMemoized = useBusterDashboardContextSelector((x) => x.getDashboardMemoized); const getDashboardMemoized = useBusterDashboardContextSelector((x) => x.getDashboardMemoized);
const dashboard = getDashboardMemoized(fileId); const dashboard = getDashboardMemoized(dashboardId);
const dashboardTitle = dashboard?.dashboard?.name; const dashboardTitle = dashboard?.dashboard?.name;
const dashboardVersionNumber = dashboard?.dashboard?.version_number; const dashboardVersionNumber = dashboard?.dashboard?.version_number;

View File

@ -30,13 +30,13 @@ export const ChatItemsContainer: React.FC<{
const logsRecord = useCreateListByDate({ data: chats }); const logsRecord = useCreateListByDate({ data: chats });
const chatsByDate: BusterListRow[] = useMemo(() => { const chatsByDate: BusterListRow[] = useMemo(() => {
return Object.entries(logsRecord).flatMap(([key, metrics]) => { return Object.entries(logsRecord).flatMap(([key, chats]) => {
const records = metrics.map((metric) => ({ const records = chats.map((chat) => ({
id: metric.id, id: chat.id,
data: metric, data: chat,
link: createBusterRoute({ link: createBusterRoute({
route: BusterRoutes.APP_METRIC_ID, route: BusterRoutes.APP_CHAT_ID,
metricId: metric.id chatId: chat.id
}) })
})); }));
const hasRecords = records.length > 0; const hasRecords = records.length > 0;
@ -63,7 +63,7 @@ export const ChatItemsContainer: React.FC<{
dataIndex: 'title', dataIndex: 'title',
title: 'Title', title: 'Title',
render: (title, record) => ( render: (title, record) => (
<TitleCell title={title} status={record?.status} metricId={record?.id} /> <TitleCell title={title} status={record?.status} chatId={record?.id} />
) )
}, },
{ {
@ -105,8 +105,6 @@ export const ChatItemsContainer: React.FC<{
[] []
); );
console.log(chatsByDate, loading);
return ( return (
<div <div
ref={tableContainerRef} ref={tableContainerRef}
@ -153,8 +151,8 @@ const ChatsEmptyState: React.FC<{
); );
}; };
const TitleCell = React.memo<{ title: string; status: VerificationStatus; metricId: string }>( const TitleCell = React.memo<{ title: string; status: VerificationStatus; chatId: string }>(
({ title, status, metricId }) => { ({ title, status, chatId }) => {
const onFavoriteDivClick = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => { const onFavoriteDivClick = useMemoizedFn((e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation(); e.stopPropagation();
}); });
@ -167,7 +165,7 @@ const TitleCell = React.memo<{ title: string; status: VerificationStatus; metric
<Text ellipsis={true}>{title}</Text> <Text ellipsis={true}>{title}</Text>
<div className="flex items-center" onClick={onFavoriteDivClick}> <div className="flex items-center" onClick={onFavoriteDivClick}>
<FavoriteStar <FavoriteStar
id={metricId} id={chatId}
type={ShareAssetType.METRIC} type={ShareAssetType.METRIC}
iconStyle="tertiary" iconStyle="tertiary"
title={title} title={title}

View File

@ -16,7 +16,7 @@ export const useBusterChatListByFilter = (
route: '/chats/list', route: '/chats/list',
payload: filters payload: filters
}, },
responseEvent: '/chats/list:getChatsList', responseEvent: '/chats/list:getThreadsList',
options: queryKeys['chatsGetList'](filters) options: queryKeys['chatsGetList'](filters)
}); });

View File

@ -7,11 +7,14 @@ import {
createContext createContext
} from '@fluentui/react-context-selector'; } from '@fluentui/react-context-selector';
import { queryKeys } from '@/api/query_keys'; import { queryKeys } from '@/api/query_keys';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
type CollectionListFilters = Omit<CollectionsListEmit['payload'], 'page' | 'page_size'>; type CollectionListFilters = Omit<CollectionsListEmit['payload'], 'page' | 'page_size'>;
export const useCollectionLists = () => { export const useCollectionLists = () => {
const [collectionListFilters, setCollectionListFilters] = useState<CollectionListFilters>({}); const [collectionListFilters, setCollectionListFilters] = useState<CollectionListFilters>({});
const currentSegment = useAppLayoutContextSelector((x) => x.currentSegment);
const enabled = currentSegment === 'collections';
const payload = useMemo(() => { const payload = useMemo(() => {
return { page: 0, page_size: 1000, ...collectionListFilters }; return { page: 0, page_size: 1000, ...collectionListFilters };
@ -27,7 +30,8 @@ export const useCollectionLists = () => {
payload payload
}, },
responseEvent: '/collections/list:listCollections', responseEvent: '/collections/list:listCollections',
options: queryKeys.collectionsGetList(payload) options: queryKeys.collectionsGetList(payload),
enabledTrigger: enabled
}); });
return { return {

View File

@ -27,7 +27,7 @@ export const useBusterTermsCreate = () => {
const { mutate: deleteTermMutation } = useSocketQueryMutation({ const { mutate: deleteTermMutation } = useSocketQueryMutation({
emitEvent: '/terms/delete', emitEvent: '/terms/delete',
responseEvent: '/terms/delete:DeleteTerm', responseEvent: '/terms/delete:DeleteTerm',
options: queryKeys['/terms/list:getTermsList'], options: queryKeys.termsGetList,
preCallback: (currentData, variables) => { preCallback: (currentData, variables) => {
return (currentData || []).filter((term) => !variables.ids.includes(term.id)); return (currentData || []).filter((term) => !variables.ids.includes(term.id));
} }

View File

@ -9,7 +9,7 @@ export const useBusterTermsIndividual = ({ termId }: { termId: string }) => {
} = useSocketQueryEmitOn({ } = useSocketQueryEmitOn({
emitEvent: { route: '/terms/get', payload: { id: termId } }, emitEvent: { route: '/terms/get', payload: { id: termId } },
responseEvent: '/terms/get:GetTerm', responseEvent: '/terms/get:GetTerm',
options: queryKeys['/terms/get:getTerm'](termId), options: queryKeys.termsGetTerm(termId),
enabledTrigger: termId enabledTrigger: termId
}); });

View File

@ -6,8 +6,11 @@ import {
useContextSelector, useContextSelector,
ContextSelector ContextSelector
} from '@fluentui/react-context-selector'; } from '@fluentui/react-context-selector';
import { useAppLayoutContextSelector } from '../BusterAppLayout';
export const useBusterTermsList = () => { export const useBusterTermsList = () => {
const currentSegment = useAppLayoutContextSelector((x) => x.currentSegment);
const enabled = currentSegment === 'terms';
const { const {
data: termsList, data: termsList,
refetch: refetchTermsList, refetch: refetchTermsList,
@ -15,7 +18,8 @@ export const useBusterTermsList = () => {
} = useSocketQueryEmitOn({ } = useSocketQueryEmitOn({
emitEvent: { route: '/terms/list', payload: { page: 0, page_size: 3000 } }, emitEvent: { route: '/terms/list', payload: { page: 0, page_size: 3000 } },
responseEvent: '/terms/list:ListTerms', responseEvent: '/terms/list:ListTerms',
options: queryKeys['/terms/list:getTermsList'] options: queryKeys.termsGetList,
enabledTrigger: enabled
}); });
return { return {

View File

@ -66,7 +66,7 @@ This example demonstrates:
```typescript ```typescript
// Example of required response routes enum // Example of required response routes enum
export enum ChatsResponses { export enum ChatsResponses {
'/chats/list:getChatsList' = '/chats/list:getChatsList', '/chats/list:getThreadsList' = '/chats/list:getThreadsList',
'/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe', '/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe',
'/chats/get:getChat' = '/chats/get:getChat', '/chats/get:getChat' = '/chats/get:getChat',
'/chats/post:initializeChat' = '/chats/post:initializeChat', '/chats/post:initializeChat' = '/chats/post:initializeChat',
@ -79,7 +79,7 @@ export enum ChatsResponses {
*/ */
export type ChatList_getChatsList = { export type ChatList_getChatsList = {
/** The route identifier for getting the chats list */ /** The route identifier for getting the chats list */
route: '/chats/list:getChatsList'; route: '/chats/list:getThreadsList';
/** Callback function that receives the chat list data */ /** Callback function that receives the chat list data */
callback: (chats: ChatListItem[]) => void; callback: (chats: ChatListItem[]) => void;
/** Optional error handler for when the request fails */ /** Optional error handler for when the request fails */