Explorar o código

Merge pull request #9663 from overleaf/jel-archiving-trashed

[web] Update view when archiving trashed project

GitOrigin-RevId: c40fb036a0c6c2bd18c2245a24f41e3979efd707
Jessica Lawshe %!s(int64=3) %!d(string=hai) anos
pai
achega
db7d0beda3

+ 6 - 1
services/web/frontend/js/features/project-list/components/table/cells/action-buttons/archive-project-button.tsx

@@ -35,7 +35,12 @@ function ArchiveProjectButton({
 
   const handleArchiveProject = useCallback(async () => {
     await archiveProject(project.id)
-    updateProjectViewData({ ...project, archived: true, selected: false })
+    updateProjectViewData({
+      ...project,
+      archived: true,
+      selected: false,
+      trashed: false,
+    })
   }, [project, updateProjectViewData])
 
   if (project.archived) return null

+ 6 - 1
services/web/frontend/js/features/project-list/components/table/project-tools/buttons/archive-projects-button.tsx

@@ -28,7 +28,12 @@ function ArchiveProjectsButton() {
   const handleArchiveProjects = useCallback(async () => {
     for (const project of selectedProjects) {
       await archiveProject(project.id)
-      updateProjectViewData({ ...project, archived: true, selected: false })
+      updateProjectViewData({
+        ...project,
+        archived: true,
+        selected: false,
+        trashed: false,
+      })
     }
   }, [selectedProjects, updateProjectViewData])
 

+ 19 - 0
services/web/test/frontend/features/project-list/components/project-list-root.test.tsx

@@ -223,6 +223,25 @@ describe('<ProjectListRoot />', function () {
 
         expect(screen.queryByText('No projects')).to.be.null
       })
+
+      it('removes project from view when archiving', async function () {
+        fetchMock.post(`express:/project/:id/archive`, {
+          status: 200,
+        })
+
+        const untrashButton =
+          within(actionsToolbar).getByLabelText<HTMLInputElement>('Archive')
+        fireEvent.click(untrashButton)
+
+        const confirmButton = screen.getByText<HTMLInputElement>('Confirm')
+        fireEvent.click(confirmButton)
+        expect(confirmButton.disabled).to.be.true
+
+        await fetchMock.flush(true)
+        expect(fetchMock.done()).to.be.true
+
+        screen.getByText('No projects')
+      })
     })
   })