mirror of
https://github.com/makeplane/plane
synced 2025-08-07 19:59:33 +00:00
fix: favorite mutation on quick actions (#6741)
* fix: fav mutation on quick actions * fix: user favorite fetch * fix: exist validation --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
@@ -34,6 +34,22 @@ class WorkspaceFavoriteEndpoint(BaseAPIView):
|
||||
def post(self, request, slug):
|
||||
try:
|
||||
workspace = Workspace.objects.get(slug=slug)
|
||||
|
||||
# If the favorite exists return
|
||||
if request.data.get("entity_identifier"):
|
||||
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"),
|
||||
).first()
|
||||
|
||||
# If the favorite exists return
|
||||
if user_favorites:
|
||||
serializer = UserFavoriteSerializer(user_favorites)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
# else create a new favorite
|
||||
serializer = UserFavoriteSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save(
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user