mirror of https://github.com/buster-so/buster.git
update collection endpoints
This commit is contained in:
parent
dfede461bc
commit
4cd6db213d
|
@ -15,15 +15,19 @@ export const collectionsGetList = async (params: GetCollectionListParams) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const collectionsGetCollection = async (params: GetCollectionParams) => {
|
export const collectionsGetCollection = async (params: GetCollectionParams) => {
|
||||||
return await mainApi.get<BusterCollection>('/collections', { params }).then((res) => res.data);
|
return await mainApi
|
||||||
|
.get<BusterCollection>(`/collections/${params.id}`, { params })
|
||||||
|
.then((res) => res.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const collectionsCreateCollection = async (params: CreateCollectionParams) => {
|
export const collectionsCreateCollection = async (params: CreateCollectionParams) => {
|
||||||
return await mainApi.post<BusterCollection>('/collections', { params }).then((res) => res.data);
|
return await mainApi.post<BusterCollection>('/collections', params).then((res) => res.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const collectionsUpdateCollection = async (params: UpdateCollectionParams) => {
|
export const collectionsUpdateCollection = async (params: UpdateCollectionParams) => {
|
||||||
return await mainApi.put<BusterCollection>('/collections', { params }).then((res) => res.data);
|
return await mainApi
|
||||||
|
.put<BusterCollection>(`/collections/${params.id}`, params)
|
||||||
|
.then((res) => res.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const collectionsDeleteCollection = async (params: DeleteCollectionParams) => {
|
export const collectionsDeleteCollection = async (params: DeleteCollectionParams) => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const SaveToCollectionsDropdown: React.FC<{
|
||||||
onSaveToCollection: (collectionId: string[]) => Promise<void>;
|
onSaveToCollection: (collectionId: string[]) => Promise<void>;
|
||||||
onRemoveFromCollection: (collectionId: string) => Promise<void>;
|
onRemoveFromCollection: (collectionId: string) => Promise<void>;
|
||||||
}> = React.memo(({ children, onRemoveFromCollection, onSaveToCollection, selectedCollections }) => {
|
}> = React.memo(({ children, onRemoveFromCollection, onSaveToCollection, selectedCollections }) => {
|
||||||
const { data: collectionsList } = useGetCollectionsList({});
|
const { data: collectionsList, isPending: isCreatingCollection } = useGetCollectionsList({});
|
||||||
const onChangePage = useAppLayoutContextSelector((s) => s.onChangePage);
|
const onChangePage = useAppLayoutContextSelector((s) => s.onChangePage);
|
||||||
const [openCollectionModal, setOpenCollectionModal] = React.useState(false);
|
const [openCollectionModal, setOpenCollectionModal] = React.useState(false);
|
||||||
const [showDropdown, setShowDropdown] = React.useState(false);
|
const [showDropdown, setShowDropdown] = React.useState(false);
|
||||||
|
@ -34,14 +34,7 @@ export const SaveToCollectionsDropdown: React.FC<{
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
return collectionsItems;
|
||||||
return [
|
|
||||||
...collectionsItems,
|
|
||||||
{
|
|
||||||
value: 'new',
|
|
||||||
label: 'New collection'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}, [collectionsList, selectedCollections]);
|
}, [collectionsList, selectedCollections]);
|
||||||
|
|
||||||
const onClickItem = useMemoizedFn((collection: BusterCollectionListItem) => {
|
const onClickItem = useMemoizedFn((collection: BusterCollectionListItem) => {
|
||||||
|
@ -69,34 +62,38 @@ export const SaveToCollectionsDropdown: React.FC<{
|
||||||
|
|
||||||
const onOpenChange = useMemoizedFn((open: boolean) => {
|
const onOpenChange = useMemoizedFn((open: boolean) => {
|
||||||
setShowDropdown(open);
|
setShowDropdown(open);
|
||||||
console.log('open', open);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const onClick = useMemoizedFn(() => {
|
const onOpenNewCollectionModal = useMemoizedFn(() => {
|
||||||
setOpenCollectionModal(true);
|
setOpenCollectionModal(true);
|
||||||
setShowDropdown(false);
|
setShowDropdown(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
const memoizedButton = useMemo(() => {
|
const memoizedButton = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<Button variant="ghost" block className="justify-start!" prefix={<Plus />} onClick={onClick}>
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
block
|
||||||
|
loading={isCreatingCollection}
|
||||||
|
className="justify-start!"
|
||||||
|
prefix={<Plus />}
|
||||||
|
onClick={onOpenNewCollectionModal}>
|
||||||
New collection
|
New collection
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}, [onClick]);
|
}, [onOpenNewCollectionModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
side="bottom"
|
side="bottom"
|
||||||
align="start"
|
align="center"
|
||||||
menuHeader={'Save to a collection'}
|
menuHeader={items.length > 0 ? 'Save to a collection' : undefined}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
footerContent={memoizedButton}
|
footerContent={memoizedButton}
|
||||||
|
emptyStateText="No collections found"
|
||||||
items={items}>
|
items={items}>
|
||||||
<div>
|
<AppTooltip title={showDropdown ? '' : 'Save to collection'}>{children} </AppTooltip>
|
||||||
<AppTooltip title={showDropdown ? '' : 'Save to collection'}>{children} </AppTooltip>
|
|
||||||
</div>
|
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|
||||||
<NewCollectionModal
|
<NewCollectionModal
|
||||||
|
|
|
@ -84,7 +84,7 @@ export const SaveToDashboardDropdown: React.FC<{
|
||||||
<Dropdown
|
<Dropdown
|
||||||
side="bottom"
|
side="bottom"
|
||||||
align="start"
|
align="start"
|
||||||
menuHeader={'Save to a dashboard'}
|
menuHeader={items.length > 0 ? 'Save to a dashboard' : undefined}
|
||||||
open={showDropdown}
|
open={showDropdown}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
footerContent={memoizedButton}
|
footerContent={memoizedButton}
|
||||||
|
|
|
@ -159,7 +159,9 @@ export const DropdownBase = <T,>({
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
dir={dir}
|
dir={dir}
|
||||||
modal={modal}>
|
modal={modal}>
|
||||||
<DropdownMenuTrigger asChild>{children}</DropdownMenuTrigger>
|
<DropdownMenuTrigger asChild>
|
||||||
|
<span className="dropdown-trigger">{children}</span>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent
|
<DropdownMenuContent
|
||||||
className={cn('max-w-72 min-w-44', className)}
|
className={cn('max-w-72 min-w-44', className)}
|
||||||
align={align}
|
align={align}
|
||||||
|
|
Loading…
Reference in New Issue