-
Notifications
You must be signed in to change notification settings - Fork 1
Bugfix/workspace navigation v2 | Refactor metadata flow and simplify workspace logic #598
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
Changes from 17 commits
79a58ef
da775f9
235fe8e
a2f3b80
133cb74
2c5d35f
1598bb3
379cc6b
0a34914
47b7139
264fe8c
559553a
4aee8b7
29b9479
7778cb6
8c81d60
fb84c4a
b8c8043
eabbf5c
ccd6b28
af0f6fe
7fe730e
b9e701c
0dbfa66
7e17ada
518347f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,7 @@ import { | |||||||||
| getThreads, | ||||||||||
| } from '@/services/hasura' | ||||||||||
| import type { GetBrowseThreadsParams } from '@/services/hasura/hasura.service.type' | ||||||||||
| import type { ThreadOrganizationMetadata } from '@/types/thread.types' | ||||||||||
| import { debounce, uniqBy } from 'lodash' | ||||||||||
| import type { Thread, User } from 'mb-genql' | ||||||||||
| import type { Session } from 'next-auth' | ||||||||||
|
|
@@ -123,7 +124,7 @@ export default function UserThreadPanel({ | |||||||||
| totalThreads: number | ||||||||||
| }>({ | ||||||||||
| threads: [], | ||||||||||
| count: 0, | ||||||||||
| count: initialCount, | ||||||||||
| totalThreads: 0, | ||||||||||
| }) | ||||||||||
| const { totalThreads } = state | ||||||||||
|
|
@@ -183,17 +184,36 @@ export default function UserThreadPanel({ | |||||||||
| } | ||||||||||
|
|
||||||||||
| const threads = | ||||||||||
| state.threads.length > initialThreads.length || isAdminMode || searchTerm | ||||||||||
| ? state.threads | ||||||||||
| : initialThreads | ||||||||||
| const count = | ||||||||||
| state.count > initialCount || isAdminMode || searchTerm | ||||||||||
| ? state.count | ||||||||||
| : initialCount | ||||||||||
| const hasWorkspaceContext = | ||||||||||
| Boolean(activeOrganization) && | ||||||||||
| Boolean(activeWorkspaceDepartment?.[0]) && | ||||||||||
| Boolean(activeProject) | ||||||||||
| useMemo( | ||||||||||
| () => | ||||||||||
| (state.threads.length > initialThreads.length || | ||||||||||
| isAdminMode || | ||||||||||
| searchTerm | ||||||||||
| ? state.threads | ||||||||||
| : initialThreads | ||||||||||
| ).filter((thread) => { | ||||||||||
| const threadOrgData = thread.metadata | ||||||||||
| .organizationData as ThreadOrganizationMetadata | ||||||||||
| return ( | ||||||||||
| threadOrgData.organization === activeOrganization && | ||||||||||
| (threadOrgData.department === activeWorkspaceDepartment?.[0] || | ||||||||||
| (activeProject && threadOrgData.project === activeProject)) | ||||||||||
| ) | ||||||||||
| }), | ||||||||||
| [ | ||||||||||
| state.threads, | ||||||||||
| initialThreads, | ||||||||||
| isAdminMode, | ||||||||||
| searchTerm, | ||||||||||
| activeOrganization, | ||||||||||
| activeWorkspaceDepartment, | ||||||||||
| activeProject, | ||||||||||
| ], | ||||||||||
| ) ?? [] | ||||||||||
| const count = state.count | ||||||||||
| // state.count !== 0 || state.count > initialCount || isAdminMode || searchTerm | ||||||||||
| // ? state.count | ||||||||||
| // : initialCount | ||||||||||
|
|
||||||||||
| // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation> | ||||||||||
| const loadMore = useCallback(async () => { | ||||||||||
|
|
@@ -234,13 +254,11 @@ export default function UserThreadPanel({ | |||||||||
| departmentId: activeDepartment, | ||||||||||
| chatbotName, | ||||||||||
| keyword: searchTerm, | ||||||||||
| ...(hasWorkspaceContext && { | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization as string, | ||||||||||
| department: activeWorkspaceDepartment?.[0] as string, | ||||||||||
| project: activeProject as string, | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization || undefined, | ||||||||||
| department: activeWorkspaceDepartment?.[0], | ||||||||||
| project: activeProject || undefined, | ||||||||||
| }, | ||||||||||
| }) | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -374,19 +392,23 @@ export default function UserThreadPanel({ | |||||||||
| const currentFetchId = Date.now() // Generate a unique identifier for the current fetch | ||||||||||
| fetchIdRef.current = currentFetchId | ||||||||||
|
|
||||||||||
| const { threads: newThreads, count } = await getThreads({ | ||||||||||
| const getThreadsParams = { | ||||||||||
| jwt: session?.user?.hasuraJwt as string, | ||||||||||
| userId: session?.user.id, | ||||||||||
| limit: PAGE_SIZE, | ||||||||||
| departmentId: categoryResponse?.categoryId || activeDepartment, | ||||||||||
| chatbotName: chatbotName || activeChatbot?.name, | ||||||||||
| ...(hasWorkspaceContext && { | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization as string, | ||||||||||
| department: activeWorkspaceDepartment?.[0] as string, | ||||||||||
| project: activeProject as string, | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization || undefined, | ||||||||||
| department: activeWorkspaceDepartment?.[0], | ||||||||||
| project: activeProject || undefined, | ||||||||||
| }, | ||||||||||
| } | ||||||||||
| const { threads: newThreads, count } = await getThreads(getThreadsParams) | ||||||||||
|
|
||||||||||
| console.log('newThreads + getThreadsParams', { | ||||||||||
| newThreads, | ||||||||||
| getThreadsParams, | ||||||||||
| }) | ||||||||||
|
Comment on lines
+377
to
380
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Remove debug console.log before merging. Debug logging should be removed for production code. - console.log('newThreads + getThreadsParams', {
- newThreads,
- getThreadsParams,
- })📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| // Check if the fetchId matches the current fetchId stored in the ref | ||||||||||
|
|
@@ -451,13 +473,11 @@ export default function UserThreadPanel({ | |||||||||
| departmentId: activeDepartment, | ||||||||||
| chatbotName, | ||||||||||
| keyword: term, | ||||||||||
| ...(hasWorkspaceContext && { | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization as string, | ||||||||||
| department: activeWorkspaceDepartment?.[0] as string, | ||||||||||
| project: activeProject as string, | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| organizationData: { | ||||||||||
| organization: activeOrganization || undefined, | ||||||||||
| department: activeWorkspaceDepartment?.[0], | ||||||||||
| project: activeProject || undefined, | ||||||||||
| }, | ||||||||||
| }) | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential runtime error: Missing null checks on
thread.metadata.organizationData.The filter at lines 195-201 directly accesses
thread.metadata.organizationDatawithout null checks. If a thread has no metadata or noorganizationData, this will throw a TypeError.Apply null-safe access:
.filter((thread) => { - const threadOrgData = thread.metadata - .organizationData as ThreadOrganizationMetadata + const threadOrgData = thread.metadata + ?.organizationData as ThreadOrganizationMetadata | undefined + if (!threadOrgData) return false return ( threadOrgData.organization === activeOrganization && (threadOrgData.department === activeWorkspaceDepartment?.[0] || (activeProject && threadOrgData.project === activeProject)) ) }),🤖 Prompt for AI Agents