From f01c6d7dc595207f312dd8b081cd0f83ad6fc4ce Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 4 Aug 2025 13:39:08 -0600 Subject: [PATCH] create listing updates --- .../buster_rest/collections/queryRequests.ts | 5 +++-- .../api/buster_rest/collections/requests.ts | 2 +- .../features/modal/AddToCollectionModal.tsx | 21 ++++++++++++------- .../useGetChatParams.test.tsx | 20 ------------------ 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/apps/web/src/api/buster_rest/collections/queryRequests.ts b/apps/web/src/api/buster_rest/collections/queryRequests.ts index 50c7263ea..02c21a3e4 100644 --- a/apps/web/src/api/buster_rest/collections/queryRequests.ts +++ b/apps/web/src/api/buster_rest/collections/queryRequests.ts @@ -26,6 +26,7 @@ import { unshareCollection, updateCollectionShare } from './requests'; +import type { ShareAssetType } from '@buster/server-shared/share'; export const useGetCollectionsList = ( filters: Omit[0], 'page_token' | 'page_size'>, @@ -309,7 +310,7 @@ export const useAddAndRemoveAssetsFromCollection = () => { async (variables: { collectionId: string; assets: { - type: 'metric' | 'dashboard'; + type: Exclude; id: string; }[]; }) => { @@ -330,7 +331,7 @@ export const useAddAndRemoveAssetsFromCollection = () => { currentCollection.assets ?.filter((a) => !variables.assets.some((b) => b.id === a.id)) .map((a) => ({ - type: a.asset_type as 'metric' | 'dashboard', + type: a.asset_type as Exclude, id: a.id })) || []; const addedAssets = variables.assets.filter( diff --git a/apps/web/src/api/buster_rest/collections/requests.ts b/apps/web/src/api/buster_rest/collections/requests.ts index 83dcf65d0..285a71692 100644 --- a/apps/web/src/api/buster_rest/collections/requests.ts +++ b/apps/web/src/api/buster_rest/collections/requests.ts @@ -107,7 +107,7 @@ export const addAssetToCollection = async ({ }: { id: string; assets: { - type: 'metric' | 'dashboard' | 'chat'; + type: Exclude; id: string; }[]; }) => { diff --git a/apps/web/src/components/features/modal/AddToCollectionModal.tsx b/apps/web/src/components/features/modal/AddToCollectionModal.tsx index 8cfc98518..91fcb84d7 100644 --- a/apps/web/src/components/features/modal/AddToCollectionModal.tsx +++ b/apps/web/src/components/features/modal/AddToCollectionModal.tsx @@ -15,6 +15,7 @@ import { formatDate } from '@/lib'; import { ASSET_ICONS } from '../config/assetIcons'; import type { BusterSearchResult } from '@/api/asset_interfaces/search'; import type { BusterListRowItem } from '@/components/ui/list/BusterList'; +import type { ShareAssetType } from '@buster/server-shared/share'; export const AddToCollectionModal: React.FC<{ open: boolean; @@ -77,15 +78,19 @@ export const AddToCollectionModal: React.FC<{ }, [searchResults]); const handleAddAndRemoveMetrics = useMemoizedFn(async () => { - const keyedAssets = rows.reduce>( - (acc, asset) => { - acc[asset.id] = { type: asset.data?.type as 'metric' | 'dashboard', id: asset.id }; - return acc; - }, - {} - ); + const keyedAssets = rows.reduce< + Record; id: string }> + >((acc, asset) => { + if (asset.data?.type && asset.data?.type !== 'collection' && asset.data?.type !== 'chat') { + acc[asset.id] = { type: asset.data?.type, id: asset.id }; + } + return acc; + }, {}); - const assets = selectedAssets.map<{ type: 'metric' | 'dashboard'; id: string }>((asset) => ({ + const assets = selectedAssets.map<{ + type: Exclude; + id: string; + }>((asset) => ({ id: asset, type: keyedAssets[asset].type })); diff --git a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useGetChatParams.test.tsx b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useGetChatParams.test.tsx index 66b819235..847d83292 100644 --- a/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useGetChatParams.test.tsx +++ b/apps/web/src/layouts/ChatLayout/ChatLayoutContext/useGetChatParams.test.tsx @@ -60,17 +60,7 @@ describe('useGetChatParams', () => { expect(result.current.chatId).toBe('chat-123'); expect(result.current.messageId).toBe('msg-456'); }); - it('handles metric version number from path parameter', () => { - mockUseParams.mockReturnValue({ - metricId: 'metric-123', - versionNumber: '42' - }); - const { result } = renderHook(() => useGetChatParams()); - - expect(result.current.metricId).toBe('metric-123'); - expect(result.current.metricVersionNumber).toBe(42); - }); it('handles metric version number from query parameter', () => { mockUseParams.mockReturnValue({ metricId: 'metric-123' @@ -83,17 +73,7 @@ describe('useGetChatParams', () => { expect(result.current.metricVersionNumber).toBe(43); }); - it('handles dashboard version number from path parameter', () => { - mockUseParams.mockReturnValue({ - dashboardId: 'dashboard-123', - versionNumber: '44' - }); - const { result } = renderHook(() => useGetChatParams()); - - expect(result.current.dashboardId).toBe('dashboard-123'); - expect(result.current.dashboardVersionNumber).toBe(44); - }); it('handles dashboard version number from query parameter', () => { mockUseParams.mockReturnValue({ dashboardId: 'dashboard-123'