-
Notifications
You must be signed in to change notification settings - Fork 431
fix: improve pagination and scroll to the file row that is currently processing the ingestion #1884
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
Open
Wallgau
wants to merge
14
commits into
main
Choose a base branch
from
pagination-improvement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cfb6afb
improve pagination and scroll to the file row that is currently proce…
a1b7856
improve pagination and scroll to the file row that is currently proce…
05609ab
adressed coderabbit comment1
d01d60c
Merge branch 'main' into pagination-improvement
Wallgau 9af6032
fix connector ingest error
3c53962
Build backendIdentityKeys from raw searchData instead of merged backe…
abd286e
Refactor ingest-focus logic into useKnowledgeIngestFocus hook.
4517407
Preserve stored mode when no explicit mode is passed
3fa4963
Wire connector type through task polling so processing rows show the
4806b76
Resolve task-context and knowledge-table-state conflicts by keeping
29c523f
style: ruff autofix (auto)
autofix-ci[bot] 8c98ff7
Merge remote-tracking branch 'origin/main' into pagination-improvement
edwinjosechittilappilly f3ff8ee
fix: don't mask connector_type with "local" in sync paths
edwinjosechittilappilly 652a902
Merge branch 'main' into pagination-improvement
edwinjosechittilappilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| "use client"; | ||
|
|
||
| import type { AgGridReact } from "ag-grid-react"; | ||
| import { type RefObject, useCallback, useEffect, useMemo, useRef } from "react"; | ||
| import type { File } from "@/app/api/queries/useGetSearchQuery"; | ||
| import type { TaskFile } from "@/contexts/task-context"; | ||
| import { | ||
| buildGridRowsSelectionKey, | ||
| collectNewIngestFocusIdentities, | ||
| collectProcessingFocusIdentities, | ||
| consumePersistedKnowledgeIngestFocus, | ||
| focusPendingIngestRows, | ||
| type IngestFocusMode, | ||
| inferIngestFocusMode, | ||
| ingestFocusModeFromReplace, | ||
| KNOWLEDGE_INGEST_FOCUS_EVENT, | ||
| } from "@/lib/knowledge-grid-pagination"; | ||
|
|
||
| export function useKnowledgeIngestFocus( | ||
| gridRef: RefObject<AgGridReact<File> | null>, | ||
| gridRows: File[], | ||
| taskFiles: TaskFile[], | ||
| ) { | ||
| const paginationSnapshotRef = useRef({ | ||
| initialized: false, | ||
| taskFiles: [] as TaskFile[], | ||
| gridRows: [] as File[], | ||
| }); | ||
|
|
||
| const pendingFocusRef = useRef({ | ||
| identities: new Set<string>(), | ||
| modes: new Map<string, IngestFocusMode>(), | ||
| }); | ||
|
|
||
| const tryFocusPendingIngestRows = useCallback( | ||
| (rows: File[]) => { | ||
| const run = () => { | ||
| const api = gridRef.current?.api; | ||
| if (!api) { | ||
| return; | ||
| } | ||
| const pending = pendingFocusRef.current; | ||
| const resolved = focusPendingIngestRows( | ||
| api, | ||
| pending.identities, | ||
| rows, | ||
| pending.modes, | ||
| ); | ||
| for (const identity of resolved) { | ||
| pending.identities.delete(identity); | ||
| pending.modes.delete(identity); | ||
| } | ||
| }; | ||
| requestAnimationFrame(() => requestAnimationFrame(run)); | ||
| }, | ||
| [gridRef], | ||
| ); | ||
|
|
||
| const queueIngestFocusIdentities = useCallback( | ||
| (identities: string[], mode?: IngestFocusMode, rows: File[] = gridRows) => { | ||
| if (identities.length === 0) { | ||
| return; | ||
| } | ||
| const pending = pendingFocusRef.current; | ||
| for (const identity of identities) { | ||
| pending.identities.add(identity); | ||
| pending.modes.set( | ||
| identity, | ||
| mode ?? | ||
| pending.modes.get(identity) ?? | ||
| inferIngestFocusMode(identity, rows), | ||
| ); | ||
| } | ||
| tryFocusPendingIngestRows(rows); | ||
| }, | ||
| [gridRows, tryFocusPendingIngestRows], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const stored = consumePersistedKnowledgeIngestFocus(); | ||
| for (const target of stored) { | ||
| queueIngestFocusIdentities( | ||
| [target.filename], | ||
| ingestFocusModeFromReplace(target.replace), | ||
| ); | ||
| } | ||
| }, [queueIngestFocusIdentities]); | ||
|
|
||
| useEffect(() => { | ||
| const handler = (event: Event) => { | ||
| const detail = ( | ||
| event as CustomEvent<{ filename: string; replace: boolean }> | ||
| ).detail; | ||
| if (!detail?.filename) { | ||
| return; | ||
| } | ||
| queueIngestFocusIdentities( | ||
| [detail.filename], | ||
| ingestFocusModeFromReplace(detail.replace), | ||
| ); | ||
| }; | ||
| window.addEventListener(KNOWLEDGE_INGEST_FOCUS_EVENT, handler); | ||
| return () => | ||
| window.removeEventListener(KNOWLEDGE_INGEST_FOCUS_EVENT, handler); | ||
| }, [queueIngestFocusIdentities]); | ||
|
|
||
| useEffect(() => { | ||
| const snapshot = paginationSnapshotRef.current; | ||
| if (!snapshot.initialized) { | ||
| snapshot.taskFiles = taskFiles; | ||
| snapshot.gridRows = gridRows; | ||
| snapshot.initialized = true; | ||
| return; | ||
| } | ||
|
|
||
| const fromTasks = collectNewIngestFocusIdentities( | ||
| snapshot.taskFiles, | ||
| taskFiles, | ||
| ); | ||
| const fromGrid = collectProcessingFocusIdentities( | ||
| snapshot.gridRows, | ||
| gridRows, | ||
| ); | ||
| snapshot.taskFiles = taskFiles; | ||
| snapshot.gridRows = gridRows; | ||
|
|
||
| queueIngestFocusIdentities([...new Set([...fromTasks, ...fromGrid])]); | ||
| }, [taskFiles, gridRows, queueIngestFocusIdentities]); | ||
|
|
||
| const gridRowsSelectionKey = useMemo( | ||
| () => buildGridRowsSelectionKey(gridRows), | ||
| [gridRows], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| tryFocusPendingIngestRows(gridRows); | ||
| }, [gridRows, gridRowsSelectionKey, tryFocusPendingIngestRows]); | ||
|
|
||
| const onKnowledgeGridReady = useCallback(() => { | ||
| tryFocusPendingIngestRows(gridRows); | ||
| }, [gridRows, tryFocusPendingIngestRows]); | ||
|
|
||
| const onKnowledgeRowDataUpdated = useCallback(() => { | ||
| tryFocusPendingIngestRows(gridRows); | ||
| }, [gridRows, tryFocusPendingIngestRows]); | ||
|
|
||
| return { | ||
| gridRowsSelectionKey, | ||
| onKnowledgeGridReady, | ||
| onKnowledgeRowDataUpdated, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.