Skip to content

Fix/tooltip dashboard#45

Merged
maxi07 merged 10 commits intomainfrom
fix/tooltip-dashboard
Jul 27, 2025
Merged

Fix/tooltip dashboard#45
maxi07 merged 10 commits intomainfrom
fix/tooltip-dashboard

Conversation

@maxi07
Copy link
Owner

@maxi07 maxi07 commented Jul 27, 2025

Fixes an issue, where badges would not render properly.

@maxi07 maxi07 requested a review from Copilot July 27, 2025 14:56

This comment was marked as outdated.

@maxi07 maxi07 requested a review from Copilot July 27, 2025 17:34

This comment was marked as outdated.

maxi07 and others added 2 commits July 27, 2025 19:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@maxi07 maxi07 requested a review from Copilot July 27, 2025 17:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors badge rendering in the dashboard by moving badge generation from client-side JavaScript to server-side Python, ensuring consistent badge colors and proper ordering across all scenarios.

  • Introduces a unified badge_generator.py module that generates badges server-side with deterministic color assignment
  • Refactors both dashboard initial load and live update processes to use server-generated badge data
  • Fixes upload service to properly handle multiple OneDrive destinations and web URLs in correct order

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
web_service/src/static/js/dashboard.js Replaces client-side badge generation logic with server-generated badge rendering
web_service/src/routes/dashboard.py Integrates badge generator for initial dashboard load and maintains SMB target ordering
web_service/src/main.py Updates real-time updates to use unified badge generation
web_service/src/badge_generator.py New unified badge generator with deterministic color assignment and alphabetical sorting
upload_service/main.py Collects web URLs in correct order after uploads complete
tests/test_badge_generator.py Comprehensive test suite for badge generation functionality
scansynclib/scansynclib/onedrive_api.py Updates upload functions to store web URLs in OneDriveDestination objects
scansynclib/scansynclib/ProcessItem.py Adds web_url field to OneDriveDestination class
metadata_service/main.py Processes SMB destinations individually to maintain correct ordering
docker-compose.test.yml Adds web_service volume mapping for test environment

"url": web_urls[i] if i < len(web_urls) else None,
"title": remote_paths[i] if i < len(remote_paths) else 'Open in OneDrive',
"is_main": False
}) # Sort all badges alphabetically by text
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before the comment. The line should have proper spacing between the closing brace and the comment.

Suggested change
}) # Sort all badges alphabetically by text
}) # Sort all badges alphabetically by text

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +67
# Use deterministic hash for consistent colors across application restarts
text_hash = _deterministic_hash(local_filepath or 'N/A') % len(SMB_TAG_COLORS)
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions 'deterministic hash for consistent colors' but the actual implementation uses text_hash based on filename, not the target ID. This could be misleading since the color is determined by the filename content, not the SMB target ID as suggested by the function name getBadgeColor(id) in the JavaScript.

Suggested change
# Use deterministic hash for consistent colors across application restarts
text_hash = _deterministic_hash(local_filepath or 'N/A') % len(SMB_TAG_COLORS)
# Use deterministic hash based on SMB target ID for consistent colors across application restarts
text_hash = _deterministic_hash(str(target_id) or 'N/A') % len(SMB_TAG_COLORS)

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +63
web_urls.append("") # Empty placeholder to maintain order

# Update the database with all web URLs in the correct order
if web_urls:
update_scanneddata_database(item, {'web_url': ",".join(web_urls)})
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding empty strings as placeholders could lead to unexpected behavior when these URLs are processed later. Consider using None or filtering out missing URLs with proper index tracking instead.

Suggested change
web_urls.append("") # Empty placeholder to maintain order
# Update the database with all web URLs in the correct order
if web_urls:
update_scanneddata_database(item, {'web_url': ",".join(web_urls)})
web_urls.append(None) # Use None as a placeholder to maintain order
# Update the database with all web URLs in the correct order
if web_urls:
update_scanneddata_database(item, {'web_url': ",".join(filter(None, web_urls))})

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +16
// Global function to get consistent badge colors based on SMB target ID
function getBadgeColor(id) {
if (typeof id !== 'number' || !Number.isFinite(id)) {
return '#6c757d';
}
const idx = id - 1;
if (Array.isArray(smb_tag_colors) && smb_tag_colors.length > 0 && idx >= 0) {
return smb_tag_colors[idx % smb_tag_colors.length];
}
return '#6c757d';
}
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global getBadgeColor function is defined but appears to be unused since badge colors are now generated server-side. This function should be removed to avoid confusion and reduce dead code.

Suggested change
// Global function to get consistent badge colors based on SMB target ID
function getBadgeColor(id) {
if (typeof id !== 'number' || !Number.isFinite(id)) {
return '#6c757d';
}
const idx = id - 1;
if (Array.isArray(smb_tag_colors) && smb_tag_colors.length > 0 && idx >= 0) {
return smb_tag_colors[idx % smb_tag_colors.length];
}
return '#6c757d';
}
// Removed unused `getBadgeColor` function as badge colors are now generated server-side.

Copilot uses AI. Check for mistakes.
@maxi07 maxi07 merged commit fc0eaad into main Jul 27, 2025
4 checks passed
@maxi07 maxi07 deleted the fix/tooltip-dashboard branch July 27, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments