π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-2774] fix:favorites reorder (#6179)
Vamsi Krishna7fca7fd86cef
diff --git a/web/core/components/workspace/sidebar/favorites/favorite-folder.tsx b/web/core/components/workspace/sidebar/favorites/favorite-folder.tsxindex 6fc2c1b524..8806b2d081 100644--- a/web/core/components/workspace/sidebar/favorites/favorite-folder.tsx+++ b/web/core/components/workspace/sidebar/favorites/favorite-folder.tsx@@ -27,6 +27,7 @@ import { CustomMenu, Tooltip, DropIndicator, FavoriteFolderIcon, DragHandle } frimport { cn } from "@/helpers/common.helper";// hooksimport { useAppTheme } from "@/hooks/store";+import { useFavorite } from "@/hooks/store/use-favorite";import { usePlatformOS } from "@/hooks/use-platform-os";// constantsimport { FavoriteRoot } from "./favorite-items";@@ -45,7 +46,7 @@ export const FavoriteFolder: React.FC<Props> = (props) => {const { favorite, handleRemoveFromFavorites, isLastChild, handleDrop } = props;// store hooksconst { sidebarCollapsed: isSidebarCollapsed } = useAppTheme();-+ const { getGroupedFavorites } = useFavorite();const { isMobile } = usePlatformOS();const { workspaceSlug } = useParams();// states@@ -58,6 +59,12 @@ export const FavoriteFolder: React.FC<Props> = (props) => {const actionSectionRef = useRef<HTMLDivElement | null>(null);const elementRef = useRef<HTMLDivElement | null>(null);+ useEffect(() => {+ if (favorite.children === undefined && workspaceSlug) {+ getGroupedFavorites(workspaceSlug.toString(), favorite.id);+ }+ }, [favorite.id, favorite.children, workspaceSlug, getGroupedFavorites]);+useEffect(() => {const element = elementRef.current;@@ -123,7 +130,7 @@ export const FavoriteFolder: React.FC<Props> = (props) => {}));// eslint-disable-next-line react-hooks/exhaustive-deps- }, [isDragging, favorite.id]);+ }, [isDragging, favorite.id, isLastChild, favorite.id]);useOutsideClickDetector(actionSectionRef, () => setIsMenuActive(false));diff --git a/web/core/components/workspace/sidebar/favorites/favorite-items/root.tsx b/web/core/components/workspace/sidebar/favorites/favorite-items/root.tsxindex 2ae16528ae..49931802e8 100644--- a/web/core/components/workspace/sidebar/favorites/favorite-items/root.tsx+++ b/web/core/components/workspace/sidebar/favorites/favorite-items/root.tsx@@ -131,7 +131,7 @@ export const FavoriteRoot: FC<Props> = observer((props) => {}));// eslint-disable-next-line react-hooks/exhaustive-deps- }, [elementRef?.current, isDragging]);+ }, [elementRef?.current, isDragging, isLastChild, favorite.id]);useOutsideClickDetector(actionSectionRef, () => setIsMenuActive(false));diff --git a/web/core/components/workspace/sidebar/favorites/favorites-menu.tsx b/web/core/components/workspace/sidebar/favorites/favorites-menu.tsxindex 8aea968eca..6773e3a64b 100644--- a/web/core/components/workspace/sidebar/favorites/favorites-menu.tsx+++ b/web/core/components/workspace/sidebar/favorites/favorites-menu.tsx@@ -87,33 +87,27 @@ export const SidebarFavoritesMenu = observer(() => {const sourceData = source.data as TargetData;if (!sourceData.id) return;-if (isFolder) {// handle move to a new parent folder if dropped on a folderif (parentId && parentId !== sourceData.parentId) {- handleMoveToFolder(sourceData.id, parentId);- }- //handle remove from folder if dropped outside of the folder- if (parentId && parentId !== sourceData.parentId && sourceData.isChild) {- handleRemoveFromFavoritesFolder(sourceData.id);+ handleMoveToFolder(sourceData.id, parentId); /**parent id */}-// handle reordering at root levelif (droppedFavId) {if (instruction != "make-child") {- handleReorder(sourceData.id, droppedFavId, instruction);+ handleReorder(sourceData.id, droppedFavId, instruction); /** sequence */}}} else {//handling reordering for favoritesif (droppedFavId) {- handleReorder(sourceData.id, droppedFavId, instruction);+ handleReorder(sourceData.id, droppedFavId, instruction); /** sequence */}+ }- // handle removal from folder if dropped outside a folder- if (!parentId && sourceData.isChild) {- handleRemoveFromFavoritesFolder(sourceData.id);- }+ /**remove if dropped outside and source is a child */+ if (!parentId && sourceData.isChild) {+ handleRemoveFromFavoritesFolder(sourceData.id); /**parent null */}};diff --git a/web/core/store/favorite.store.ts b/web/core/store/favorite.store.tsindex 3f4f636d34..a588f2af3b 100644--- a/web/core/store/favorite.store.ts+++ b/web/core/store/favorite.store.ts@@ -174,23 +174,14 @@ export class FavoriteStore implements IFavoriteStore {* @returns Promise<void>*/moveFavoriteToFolder = async (workspaceSlug: string, favoriteId: string, data: Partial<IFavorite>) => {- const oldParent = this.favoriteMap[favoriteId].parent;try {+ await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, data);runInAction(() => {// add parent of the favoriteset(this.favoriteMap, [favoriteId, "parent"], data.parent);});- await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, data);} catch (error) {- console.error("Failed to move favorite from favorite store");-- // revert the changes- runInAction(() => {- if (!data.parent) return;-- // revert the parent- set(this.favoriteMap, [favoriteId, "parent"], oldParent);- });+ console.error("Failed to move favorite to folder", error);throw error;}};@@ -201,7 +192,6 @@ export class FavoriteStore implements IFavoriteStore {destinationId: string,edge: string | undefined) => {- const initialSequence = this.favoriteMap[favoriteId].sequence;try {let resultSequence = 10000;if (edge) {@@ -221,35 +211,27 @@ export class FavoriteStore implements IFavoriteStore {}}}++ await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, { sequence: resultSequence });+runInAction(() => {set(this.favoriteMap, [favoriteId, "sequence"], resultSequence);});-- await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, { sequence: resultSequence });} catch (error) {console.error("Failed to move favorite folder");- runInAction(() => {- set(this.favoriteMap, [favoriteId, "sequence"], initialSequence);- throw error;- });+ throw error;}};removeFromFavoriteFolder = async (workspaceSlug: string, favoriteId: string) => {- const parent = this.favoriteMap[favoriteId].parent;try {+ await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, { parent: null });runInAction(() => {//remove parentset(this.favoriteMap, [favoriteId, "parent"], null);});- await this.favoriteService.updateFavorite(workspaceSlug, favoriteId, { parent: null });} catch (error) {console.error("Failed to move favorite");- runInAction(() => {- set(this.favoriteMap, [favoriteId, "parent"], parent);-- throw error;- });throw error;}};@@ -384,7 +366,7 @@ export class FavoriteStore implements IFavoriteStore {set(this.favoriteMap, [favorite.id], favorite);this.favoriteIds.push(favorite.id);this.favoriteIds = uniqBy(this.favoriteIds, (id) => id);- favorite.entity_identifier && set(this.entityMap, [favorite.entity_identifier], favorite);+ if (favorite.entity_identifier) set(this.entityMap, [favorite.entity_identifier], favorite);});});