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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,7 +66,7 @@ This example demonstrates:
```typescript
// Example of required response routes enum
export enum ChatsResponses {
'/chats/list:getChatsList' = '/chats/list:getChatsList',
'/chats/list:getThreadsList' = '/chats/list:getThreadsList',
'/chats/unsubscribe:unsubscribe' = '/chats/unsubscribe:unsubscribe',
'/chats/get:getChat' = '/chats/get:getChat',
'/chats/post:initializeChat' = '/chats/post:initializeChat',
@ -79,7 +79,7 @@ export enum ChatsResponses {
*/
export type ChatList_getChatsList = {
/** 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: (chats: ChatListItem[]) => void;
/** Optional error handler for when the request fails */