mirror of https://github.com/buster-so/buster.git
create listing updates
This commit is contained in:
parent
d98c5f6e37
commit
f01c6d7dc5
|
@ -26,6 +26,7 @@ import {
|
||||||
unshareCollection,
|
unshareCollection,
|
||||||
updateCollectionShare
|
updateCollectionShare
|
||||||
} from './requests';
|
} from './requests';
|
||||||
|
import type { ShareAssetType } from '@buster/server-shared/share';
|
||||||
|
|
||||||
export const useGetCollectionsList = (
|
export const useGetCollectionsList = (
|
||||||
filters: Omit<Parameters<typeof collectionsGetList>[0], 'page_token' | 'page_size'>,
|
filters: Omit<Parameters<typeof collectionsGetList>[0], 'page_token' | 'page_size'>,
|
||||||
|
@ -309,7 +310,7 @@ export const useAddAndRemoveAssetsFromCollection = () => {
|
||||||
async (variables: {
|
async (variables: {
|
||||||
collectionId: string;
|
collectionId: string;
|
||||||
assets: {
|
assets: {
|
||||||
type: 'metric' | 'dashboard';
|
type: Exclude<ShareAssetType, 'collection' | 'chat'>;
|
||||||
id: string;
|
id: string;
|
||||||
}[];
|
}[];
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -330,7 +331,7 @@ export const useAddAndRemoveAssetsFromCollection = () => {
|
||||||
currentCollection.assets
|
currentCollection.assets
|
||||||
?.filter((a) => !variables.assets.some((b) => b.id === a.id))
|
?.filter((a) => !variables.assets.some((b) => b.id === a.id))
|
||||||
.map((a) => ({
|
.map((a) => ({
|
||||||
type: a.asset_type as 'metric' | 'dashboard',
|
type: a.asset_type as Exclude<ShareAssetType, 'collection' | 'chat'>,
|
||||||
id: a.id
|
id: a.id
|
||||||
})) || [];
|
})) || [];
|
||||||
const addedAssets = variables.assets.filter(
|
const addedAssets = variables.assets.filter(
|
||||||
|
|
|
@ -107,7 +107,7 @@ export const addAssetToCollection = async ({
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
assets: {
|
assets: {
|
||||||
type: 'metric' | 'dashboard' | 'chat';
|
type: Exclude<ShareAssetType, 'collection' | 'chat'>;
|
||||||
id: string;
|
id: string;
|
||||||
}[];
|
}[];
|
||||||
}) => {
|
}) => {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { formatDate } from '@/lib';
|
||||||
import { ASSET_ICONS } from '../config/assetIcons';
|
import { ASSET_ICONS } from '../config/assetIcons';
|
||||||
import type { BusterSearchResult } from '@/api/asset_interfaces/search';
|
import type { BusterSearchResult } from '@/api/asset_interfaces/search';
|
||||||
import type { BusterListRowItem } from '@/components/ui/list/BusterList';
|
import type { BusterListRowItem } from '@/components/ui/list/BusterList';
|
||||||
|
import type { ShareAssetType } from '@buster/server-shared/share';
|
||||||
|
|
||||||
export const AddToCollectionModal: React.FC<{
|
export const AddToCollectionModal: React.FC<{
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
@ -77,15 +78,19 @@ export const AddToCollectionModal: React.FC<{
|
||||||
}, [searchResults]);
|
}, [searchResults]);
|
||||||
|
|
||||||
const handleAddAndRemoveMetrics = useMemoizedFn(async () => {
|
const handleAddAndRemoveMetrics = useMemoizedFn(async () => {
|
||||||
const keyedAssets = rows.reduce<Record<string, { type: 'metric' | 'dashboard'; id: string }>>(
|
const keyedAssets = rows.reduce<
|
||||||
(acc, asset) => {
|
Record<string, { type: Exclude<ShareAssetType, 'collection' | 'chat'>; id: string }>
|
||||||
acc[asset.id] = { type: asset.data?.type as 'metric' | 'dashboard', id: asset.id };
|
>((acc, asset) => {
|
||||||
return acc;
|
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<ShareAssetType, 'collection' | 'chat'>;
|
||||||
|
id: string;
|
||||||
|
}>((asset) => ({
|
||||||
id: asset,
|
id: asset,
|
||||||
type: keyedAssets[asset].type
|
type: keyedAssets[asset].type
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -60,17 +60,7 @@ describe('useGetChatParams', () => {
|
||||||
expect(result.current.chatId).toBe('chat-123');
|
expect(result.current.chatId).toBe('chat-123');
|
||||||
expect(result.current.messageId).toBe('msg-456');
|
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', () => {
|
it('handles metric version number from query parameter', () => {
|
||||||
mockUseParams.mockReturnValue({
|
mockUseParams.mockReturnValue({
|
||||||
metricId: 'metric-123'
|
metricId: 'metric-123'
|
||||||
|
@ -83,17 +73,7 @@ describe('useGetChatParams', () => {
|
||||||
|
|
||||||
expect(result.current.metricVersionNumber).toBe(43);
|
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', () => {
|
it('handles dashboard version number from query parameter', () => {
|
||||||
mockUseParams.mockReturnValue({
|
mockUseParams.mockReturnValue({
|
||||||
dashboardId: 'dashboard-123'
|
dashboardId: 'dashboard-123'
|
||||||
|
|
Loading…
Reference in New Issue