Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): show moved items in destination folder without hard refresh (#4464)

Evan Hutnik46afcba41842
diff --git a/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx b/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx
index ef95435e22..296b3f1ee5 100644
--- a/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx
+++ b/js/app/packages/app/component/bulk-edit-entity/BulkMoveToProjectView.tsx
@@ -213,24 +213,21 @@ export const BulkMoveToProjectView = (props: {
const rootItems: Project[] = [];
// Build project tree structure
- // First pass: create item map and identify root items
+ // First pass: create item map
for (const project of allProjects) {
itemMap[project.id] = { ...project, children: [] };
- if (!project.parentId) {
- rootItems.push(project);
- } else {
- // This will be processed in second pass
- const parentId = project.parentId;
- if (!itemMap[parentId]) {
- itemMap[parentId] = { ...project, children: [] };
- }
- }
}
- // Second pass: build parent-child relationships
+ // Second pass: attach children; projects with a missing or self-referencing parent become roots
for (const project of allProjects) {
- if (project.parentId && itemMap[project.parentId]) {
+ if (
+ project.parentId &&
+ project.parentId !== project.id &&
+ itemMap[project.parentId]
+ ) {
itemMap[project.parentId].children!.push(project);
+ } else {
+ rootItems.push(project);
}
}
@@ -240,8 +237,10 @@ export const BulkMoveToProjectView = (props: {
const getProjectPath = (projectId: string): string => {
const tree = projectTree();
const path: string[] = [];
+ const visited = new Set<string>();
let currentId: string | undefined = projectId;
- while (currentId) {
+ while (currentId && !visited.has(currentId)) {
+ visited.add(currentId);
const project: Project & { children?: Project[] } =
tree.itemMap[currentId];
if (project) {
diff --git a/js/app/packages/macro-entity/src/queries/dss.ts b/js/app/packages/macro-entity/src/queries/dss.ts
index 8d6944a3ea..60ab2e2916 100644
--- a/js/app/packages/macro-entity/src/queries/dss.ts
+++ b/js/app/packages/macro-entity/src/queries/dss.ts
@@ -12,6 +12,7 @@ import { queryClient } from '@queries/client';
import {
getSoupEntityById,
invalidateSoupEntity,
+ invalidateSoupQueriesReferencing,
optimisticUpdateSoupEntity,
removeSearchEntities,
removeSoupEntities,
@@ -91,6 +92,7 @@ export function createBulkDeleteDssItemsMutation() {
function invalidateAfterMove(
entityIds: string[],
+ destinationProjectId: string,
hasProjects: boolean,
failed?: boolean
) {
@@ -98,9 +100,12 @@ function invalidateAfterMove(
toast.failure('Failed to move item');
}
+ // Covers queries already containing the entities (including the source folder's list)
for (const id of entityIds) {
invalidateSoupEntity(id);
}
+ // Destination folder's list queries don't contain the entities yet, so match by project id in the key
+ invalidateSoupQueriesReferencing([destinationProjectId]);
queryClient.invalidateQueries({ queryKey: ['entity'] });
// If moving a project, invalidate all project queries since nested projects' breadcrumbs change too
if (hasProjects) {
@@ -143,14 +148,14 @@ export function createMoveToProjectDssEntityMutation() {
});
}
},
- onSettled: (data, error, { entity: { id, type } }, context) => {
+ onSettled: (data, error, { entity: { id, type }, project }, context) => {
const failed = data?.success === false || !!error;
if (failed) {
context?.rollback();
console.error(`Failed to move dss item ${id}`, data, error);
}
- invalidateAfterMove([id], type === 'project', failed);
+ invalidateAfterMove([id], project.id, type === 'project', failed);
},
}));
}
@@ -281,7 +286,7 @@ export function createBulkMoveToProjectDssEntityMutation() {
});
},
- onSettled: (data, error, { entities }, context) => {
+ onSettled: (data, error, { entities, project }, context) => {
const failed = data?.success === false || !!error;
if (failed) {
context?.forEach((txn) => txn.rollback());
@@ -290,6 +295,7 @@ export function createBulkMoveToProjectDssEntityMutation() {
invalidateAfterMove(
entities.map((e) => e.id),
+ project.id,
entities.some((e) => e.type === 'project'),
failed
);
diff --git a/js/app/packages/queries/soup/normalized-cache/index.ts b/js/app/packages/queries/soup/normalized-cache/index.ts
index 7f51e8ed16..649ff8f9e9 100644
--- a/js/app/packages/queries/soup/normalized-cache/index.ts
+++ b/js/app/packages/queries/soup/normalized-cache/index.ts
@@ -4,6 +4,7 @@ export {
hasSoupEntity,
invalidateAllSoup,
invalidateSoupEntity,
+ invalidateSoupQueriesReferencing,
optimisticUpdateSoupEntity,
optimisticUpdateSoupItemUpdatedAt,
optimisticUpdateSoupItemViewedAt,
diff --git a/js/app/packages/queries/soup/normalized-cache/operations.ts b/js/app/packages/queries/soup/normalized-cache/operations.ts
index 631d6f4b18..923f5f5ca9 100644
--- a/js/app/packages/queries/soup/normalized-cache/operations.ts
+++ b/js/app/packages/queries/soup/normalized-cache/operations.ts
@@ -128,6 +128,18 @@ export function invalidateSoupEntity(entityId: string): void {
}
}
+/** Mark stale soup queries whose query key references any of the given ids (e.g. project-scoped views). */
+export function invalidateSoupQueriesReferencing(ids: string[]): void {
+ if (ids.length === 0) return;
+ queryClient.invalidateQueries({
+ queryKey: ['soup'],
+ predicate: (query) => {
+ const serialized = JSON.stringify(query.queryKey);
+ return ids.some((id) => serialized.includes(id));
+ },
+ });
+}
+
/** Mark every soup list query stale. Use `invalidateSoupEntity` when the entity ID is known. */
export function invalidateAllSoup(): void {
queryClient.invalidateQueries({