Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apiserver/plane/app/views/workspace/favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def get(self, request, slug):
def post(self, request, slug):
try:
workspace = Workspace.objects.get(slug=slug)

user_favorites = UserFavorite.objects.filter(
workspace=workspace,
user_id=request.user.id,
entity_type=request.data.get("entity_type"),
entity_identifier=request.data.get("entity_identifier")
)
# If the favorite exists return
if request.data.get("entity_identifier") and user_favorites.exists():
user_favorite = user_favorites.first()
serializer = UserFavoriteSerializer(user_favorite)
return Response(serializer.data, status=status.HTTP_200_OK)

serializer = UserFavoriteSerializer(data=request.data)
if serializer.is_valid():
serializer.save(
Expand Down
4 changes: 3 additions & 1 deletion web/core/store/favorite.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ export class FavoriteStore implements IFavoriteStore {
* @returns Promise<IFavorite>
*/
addFavorite = async (workspaceSlug: string, data: Partial<IFavorite>) => {
const id = uuidv4();
data = { ...data, parent: null, is_folder: data.entity_type === "folder" };

if (data.entity_identifier && this.entityMap[data.entity_identifier]) return this.entityMap[data.entity_identifier];
try {
// optimistic addition
const id = uuidv4();
runInAction(() => {
set(this.favoriteMap, [id], data);
data.entity_identifier && set(this.entityMap, [data.entity_identifier], data);
Expand Down Expand Up @@ -271,6 +272,7 @@ export class FavoriteStore implements IFavoriteStore {
* @returns Promise<void>
*/
deleteFavorite = async (workspaceSlug: string, favoriteId: string) => {
if (!this.favoriteMap[favoriteId]) return;
const parent = this.favoriteMap[favoriteId].parent;
const children = this.groupedFavorites[favoriteId].children;
const entity_identifier = this.favoriteMap[favoriteId].entity_identifier;
Expand Down