Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(settings): accurate View navigation after restore in recently deleted#4546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 31 additions & 23 deletions
54 ...sim/app/workspace/[workspaceId]/settings/components/recently-deleted/recently-deleted.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| 'use client' | ||
| import { useMemo, useState } from 'react' | ||
| import { toError } from '@sim/utils/errors' | ||
| import { formatDate } from '@sim/utils/formatting' | ||
| import { Folder, Search } from 'lucide-react' | ||
| import { useParams, useRouter } from 'next/navigation' | ||
| @@ -21,6 +22,10 @@ import { useKnowledgeBasesQuery, useRestoreKnowledgeBase } from '@/hooks/queries | ||
| import { useRestoreTable, useTablesList } from '@/hooks/queries/tables' | ||
| import { useRestoreWorkflow, useWorkflows } from '@/hooks/queries/workflows' | ||
| import { useRestoreWorkspaceFile, useWorkspaceFiles } from '@/hooks/queries/workspace-files' | ||
| import { useFolderStore } from '@/stores/folders/store' | ||
| import type { WorkflowFolder } from '@/stores/folders/types' | ||
| type ResourceType = 'all' | 'workflow' | 'table' | 'knowledge' | 'file' | 'folder' | ||
| function getResourceHref( | ||
| workspaceId: string, | ||
| @@ -36,14 +41,12 @@ function getResourceHref( | ||
| case 'knowledge': | ||
| return `${base}/knowledge/${id}` | ||
| case 'file': | ||
| return `${base}/files` | ||
| return `${base}/files/${id}` | ||
| case 'folder': | ||
| return `${base}/w` | ||
| } | ||
| } | ||
| type ResourceType = 'all' | 'workflow' | 'table' | 'knowledge' | 'file' | 'folder' | ||
| type SortColumn = 'deleted' | 'name' | 'type' | ||
| interface SortConfig { | ||
| @@ -59,7 +62,7 @@ const SORT_OPTIONS: { column: SortColumn; direction: 'asc' | 'desc'; label: stri | ||
| { column: 'type', direction: 'asc', label: 'Type (A–Z)' }, | ||
| ] | ||
| const ICON_CLASS = 'h-[14px] w-[14px]' | ||
| const ICON_CLASS = 'size-[14px]' | ||
| const RESOURCE_TYPE_TO_MOTHERSHIP: Partial< | ||
| Record<Exclude<ResourceType, 'all'>, MothershipResourceType> | ||
| @@ -119,13 +122,9 @@ function ResourceIcon({ resource }: { resource: DeletedResource }) { | ||
| const mothershipType = RESOURCE_TYPE_TO_MOTHERSHIP[resource.type] | ||
| if (!mothershipType) return null | ||
| const config = RESOURCE_REGISTRY[mothershipType] | ||
| return ( | ||
| <> | ||
| {config.renderTabIcon( | ||
| { type: mothershipType, id: resource.id, title: resource.name }, | ||
| ICON_CLASS | ||
| )} | ||
| </> | ||
| return config.renderTabIcon( | ||
| { type: mothershipType, id: resource.id, title: resource.name }, | ||
| ICON_CLASS | ||
| ) | ||
| } | ||
| @@ -141,6 +140,7 @@ export function RecentlyDeleted() { | ||
| const workflowsQuery = useWorkflows(workspaceId, { scope: 'archived' }) | ||
| const foldersQuery = useFolders(workspaceId, { scope: 'archived' }) | ||
| const activeFoldersQuery = useFolders(workspaceId) | ||
| const tablesQuery = useTablesList(workspaceId, 'archived') | ||
| const knowledgeQuery = useKnowledgeBasesQuery(workspaceId, { scope: 'archived' }) | ||
| const filesQuery = useWorkspaceFiles(workspaceId, 'archived') | ||
| @@ -220,7 +220,6 @@ export function RecentlyDeleted() { | ||
| }) | ||
| } | ||
| // Merge back restored items that are no longer in the query data | ||
| const itemIds = new Set(items.map((i) => i.id)) | ||
| for (const [id, resource] of restoredItems) { | ||
| if (!itemIds.has(id)) { | ||
| @@ -267,6 +266,23 @@ export function RecentlyDeleted() { | ||
| const showNoResults = searchTerm.trim() && filtered.length === 0 && resources.length > 0 | ||
| const selectedSort = activeSort ?? DEFAULT_SORT | ||
| function handleView(resource: DeletedResource) { | ||
| if (resource.type === 'folder') { | ||
| const setExpanded = useFolderStore.getState().setExpanded | ||
| const byId = new Map<string, WorkflowFolder>() | ||
| for (const folder of foldersQuery.data ?? []) byId.set(folder.id, folder) | ||
| for (const folder of activeFoldersQuery.data ?? []) byId.set(folder.id, folder) | ||
| let current: WorkflowFolder | undefined = byId.get(resource.id) | ||
| const seen = new Set<string>() | ||
| while (current && !seen.has(current.id)) { | ||
| seen.add(current.id) | ||
| setExpanded(current.id, true) | ||
| current = current.parentId ? byId.get(current.parentId) : undefined | ||
| } | ||
| } | ||
| router.push(getResourceHref(resource.workspaceId, resource.type, resource.id)) | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| function handleRestore(resource: DeletedResource) { | ||
| setRestoringIds((prev) => new Set(prev).add(resource.id)) | ||
| @@ -363,7 +379,7 @@ export function RecentlyDeleted() { | ||
| {error ? ( | ||
| <div className='flex h-full flex-col items-center justify-center gap-2'> | ||
| <p className='text-[var(--text-error)] text-xs leading-tight'> | ||
| {error instanceof Error ? error.message : 'Failed to load deleted items'} | ||
| {toError(error).message || 'Failed to load deleted items'} | ||
| </p> | ||
| </div> | ||
| ) : isLoading ? ( | ||
| @@ -387,7 +403,7 @@ export function RecentlyDeleted() { | ||
| return ( | ||
| <div | ||
| key={resource.id} | ||
| className='flex items-center gap-3 rounded-md p-2 hover-hover:bg-[var(--bg-hover)]' | ||
| className='flex items-center gap-3 rounded-md px-2 py-2 hover-hover:bg-[var(--bg-hover)]' | ||
| > | ||
| <ResourceIcon resource={resource} /> | ||
| @@ -405,15 +421,7 @@ export function RecentlyDeleted() { | ||
| {isRestored ? ( | ||
| <div className='flex shrink-0 items-center gap-2'> | ||
| <span className='text-[var(--text-tertiary)] text-small'>Restored</span> | ||
| <Button | ||
| variant='primary' | ||
| size='sm' | ||
| onClick={() => | ||
| router.push( | ||
| getResourceHref(resource.workspaceId, resource.type, resource.id) | ||
| ) | ||
| } | ||
| > | ||
| <Button variant='primary' size='sm' onClick={() => handleView(resource)}> | ||
| View | ||
| </Button> | ||
| </div> | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.