Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Sep 11, 2025

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

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"]
Loading

File Walkthrough

Relevant files
Enhancement
+page.svelte
Add data count tracking to documents page                               

src/routes/page/knowledge-base/documents/+page.svelte

  • Add totalDataCount variable to track total number of knowledge items
  • Display formatted data count in UI header with localized number
    formatting
  • Update count when searching, paginating, and deleting knowledge items
  • Restructure header layout with improved styling and padding
+30/-18 
+page.svelte
Add data count display to Q&A page                                             

src/routes/page/knowledge-base/question-answer/+page.svelte

  • Add totalDataCount variable for tracking knowledge items
  • Display total data count in UI with proper formatting
  • Update count during search operations and item deletion
  • Apply consistent header layout improvements
+18/-5   
_knowledgebase.scss
Add CSS styles for data count display                                       

src/lib/scss/custom/pages/_knowledgebase.scss

  • Add styling for .knowledge-count element with padding
  • Add .action-container-padding class for consistent spacing
  • Improve layout consistency across knowledge base components
+8/-0     

@qodo-merge-pro
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

i18n/Locale

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.

<div class="mt-2 knowledge-table-header">
	{#if totalDataCount != null && totalDataCount != undefined}
		<div class="knowledge-count line-align-center text-muted font-size-11">
			{`Total data: ${Number(totalDataCount).toLocaleString("en-US")}`}
		</div>
Count Decrement Logic

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.

if (totalDataCount) {
	totalDataCount -= 1;
}
Count Consistency

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.

totalDataCount = items.length;
isFromSearch = true;

@iceljc iceljc merged commit 93b00dd into SciSharp:main Sep 11, 2025
1 of 2 checks passed
@qodo-merge-pro
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Use a single server-sourced count

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.

Examples:

src/routes/page/knowledge-base/documents/+page.svelte [214]
				totalDataCount = items.length;
src/routes/page/knowledge-base/documents/+page.svelte [455-457]
				if (totalDataCount) {
					totalDataCount -= 1;
				}

Solution Walkthrough:

Before:

// 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 count
    totalDataCount = 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.

src/routes/page/knowledge-base/documents/+page.svelte [455-457]

-if (totalDataCount) {
-	totalDataCount -= 1;
+if (typeof totalDataCount === 'number') {
+	totalDataCount = Math.max(0, totalDataCount - 1);
 }
  • Apply / Chat
Suggestion importance[1-10]: 3

__

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.

src/routes/page/knowledge-base/question-answer/+page.svelte [468-470]

-if (totalDataCount) {
-	totalDataCount -= 1;
+if (typeof totalDataCount === 'number') {
+	totalDataCount = Math.max(0, totalDataCount - 1);
 }
  • Apply / Chat
Suggestion importance[1-10]: 3

__

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant