Skip to content

Latest commit

 

History

History
146 lines (106 loc) · 4.68 KB

File metadata and controls

146 lines (106 loc) · 4.68 KB

Fix: Empty Files Showing in Filtered View

Problem

When the "Modified" filter was active, some files marked as "unchanged" were still appearing in the file list with chevrons, even though they had no modified functions to display.

Example from Screenshot:

  • tx_isp_missing_funcs.c - marked "unchanged", showing with chevron
  • gc2053.c - marked "unchanged", showing with chevron

These files would expand to show "No function matches found for current filter" message, which is confusing and clutters the UI.

Root Cause

The code was pre-populating filteredGroups with ALL files from fileChanges, regardless of whether they had any function pairs matching the current filter:

// OLD CODE - WRONG
fileChanges.forEach(fileChange => {
  const fileKey = filePath.split('/').pop() || filePath;
  
  // This added EVERY file to filteredGroups, even if it has no matching functions
  if (!filteredGroups.has(fileKey)) {
    filteredGroups.set(fileKey, []);  // Empty array for all files
  }
  
  statusMap.set(fileKey, {...});
});

// Then later, function pairs were added
filtered.forEach(pair => {
  filteredGroups.get(fileKey)!.push(pair);
});

This meant:

  1. All files got added to filteredGroups with empty arrays
  2. Only files with matching functions got pairs added
  3. Files with no matching functions remained in filteredGroups with empty arrays
  4. The empty filtering at the end tried to remove them, but there was a logic issue

Solution

Changed the logic to only add files to filteredGroups if they actually have function pairs after filtering:

// NEW CODE - CORRECT
// Build statusMap for all files (for reference/metadata)
fileChanges.forEach(fileChange => {
  const fileKey = filePath.split('/').pop() || filePath;
  statusMap.set(fileKey, {
    ...fileChange,
    functionCount: actualCount
  });
});

// Only add files to filteredGroups if they have function pairs
filtered.forEach(pair => {
  const fileKey = fileName.split('/').pop() || fileName;
  
  // This creates the entry ONLY when there's a pair to add
  if (!filteredGroups.has(fileKey)) {
    filteredGroups.set(fileKey, []);
  }
  
  filteredGroups.get(fileKey)!.push(pair);
});

Changes Made

File: nextjs-frontend/src/components/diff/BeyondCompareFunctionDiff.tsx

  1. Removed pre-population of filteredGroups (lines 573-579 in old code)

    • No longer adds all files upfront
    • Files are only added when they have function pairs
  2. Kept statusMap population (lines 571-583 in new code)

    • Still builds metadata for all files
    • Used for displaying file badges and counts
    • But doesn't affect which files are shown
  3. Removed redundant empty filtering (lines 619-625 in old code)

    • No longer needed since we only add files with pairs
    • Simplified the code

Result

Before:

  • ❌ Files with no matching functions appeared in the list
  • ❌ Clicking chevron showed "No function matches found" message
  • ❌ Cluttered UI with irrelevant files

After:

  • ✅ Only files with matching functions appear in the list
  • ✅ Every file shown has at least one function to display
  • ✅ Clean, focused UI

Testing

To verify the fix:

  1. Set filter to "Modified"

    • Should only show files that have modified functions
    • Files with only unchanged functions should not appear
  2. Set filter to "All"

    • Should show all files with any functions
    • Files with no functions at all should still not appear
  3. Set filter to "Unchanged"

    • Should only show files with unchanged functions
    • Files with only modified functions should not appear
  4. Expand any file

    • Should always show function list (never "No function matches found")
    • Every visible file has content to display

Edge Cases Handled

  1. File marked "unchanged" but has modified functions

    • File status badge shows "unchanged" (file-level metadata)
    • File appears in list when "Modified" filter is active
    • Shows the modified functions inside
  2. File marked "modified" but all functions are unchanged

    • File does NOT appear when "Modified" filter is active
    • File appears when "Unchanged" or "All" filter is active
  3. File with no functions at all

    • Never appears in any filter view
    • Doesn't clutter the UI

Benefits

  • Cleaner UI - No empty files shown
  • Less confusion - Every file has content when expanded
  • Better performance - Fewer DOM elements to render
  • Simpler code - Removed redundant empty filtering logic

Related Files

  • nextjs-frontend/src/components/diff/BeyondCompareFunctionDiff.tsx - Main fix
  • UI_CLEANUP_AND_DEFAULTS.md - Overall UI improvements documentation
  • SESSION_SUMMARY_FINAL.md - Complete session summary