You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add total data count display to knowledge base pages
Update UI layout with improved styling and padding
Track data count across search and pagination operations
Decrement count when knowledge items are deleted
Diagram Walkthrough
flowchart LR
A["Knowledge Base Pages"] --> B["Add totalDataCount Variable"]
B --> C["Display Count in UI"]
C --> D["Update Count on Operations"]
D --> E["Search Results"]
D --> F["Pagination"]
D --> G["Delete Operations"]
The UI shows a hard-coded "Total data" label and forces "en-US" number formatting. Consider using the app’s i18n system for the label and the current locale for number formatting to avoid inconsistent UX.
totalDataCount is decremented only when truthy and is not clamped. Use a numeric check and clamp to zero to avoid skipping updates at 0 and prevent negatives.
When searching, totalDataCount is set to items.length, while pagination uses res.count. Verify this reflects intended total vs. page count and prefer a server-provided total if available for consistency.
The suggestion proposes to refactor the totalDataCount logic to rely solely on the server as the single source of truth. Currently, the count is derived from different sources: client-side items.length on search, server-side res.count on pagination, and a local decrement on deletion. This inconsistency leads to incorrect counts, especially for multi-page search results, and can cause the UI to drift from the actual backend state. The fix involves ensuring all operations that affect the total count (search, delete) fetch the updated total from the backend, ensuring data consistency.
// In svelte components
let totalDataCount;
// On search
searchVectorKnowledge(...).then(res => {
items=res|| [];
totalDataCount=items.length; // Incorrect: only shows count for the current page
});
// On pagination
loadMore().then(res => {
...totalDataCount=res.count; // Correctly gets total count from server
});
// On delete
deleteVectorKnowledge(id).then(() => {
if (totalDataCount) {
totalDataCount-=1; // Unreliable: local decrement can drift from backend state
}
});
After:
// In svelte components
let totalDataCount;
// On search (assuming API is updated to return total count)
searchVectorKnowledge(...).then(res => {
items=res.data|| [];
totalDataCount=res.count; // Correct: always use total count from the server
});
// On pagination
loadMore().then(res => {
...totalDataCount=res.count; // Stays consistent
});
// On delete (refetch or get new count from API response)
deleteVectorKnowledge(id).then(res => {
// Option 1: Refetch data/count// Option 2: API returns new counttotalDataCount=res.new_count;
});
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies a critical design flaw where totalDataCount is inconsistently updated from client-side calculations (items.length) and local decrements, leading to an incorrect count being displayed, which undermines the core purpose of the PR.
High
Possible issue
Safely decrement the counter
Guard the decrement to operate only on numbers and clamp at zero to avoid negative counts. This prevents accidental NaN or negative values when totalDataCount is 0, null, or undefined.
Why: The suggestion improves robustness by using a strict type check and Math.max to prevent the count from going below zero, but the original code already handles this correctly for expected values.
Low
Clamp and type-check decrement
Ensure the count is decremented only when it's a number and never goes below zero. This avoids negative values and type coercion issues during consecutive deletions.
Why: The suggestion improves robustness by using a strict type check and Math.max to prevent the count from going below zero, but the original code already handles this correctly for expected values.
Low
More
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
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.
PR Type
Enhancement
Description
Add total data count display to knowledge base pages
Update UI layout with improved styling and padding
Track data count across search and pagination operations
Decrement count when knowledge items are deleted
Diagram Walkthrough
File Walkthrough
+page.svelte
Add data count tracking to documents pagesrc/routes/page/knowledge-base/documents/+page.svelte
totalDataCountvariable to track total number of knowledge itemsformatting
+page.svelte
Add data count display to Q&A pagesrc/routes/page/knowledge-base/question-answer/+page.svelte
totalDataCountvariable for tracking knowledge items_knowledgebase.scss
Add CSS styles for data count displaysrc/lib/scss/custom/pages/_knowledgebase.scss
.knowledge-countelement with padding.action-container-paddingclass for consistent spacing