-
Notifications
You must be signed in to change notification settings - Fork 17
[Feature] Update Consensus Toggle, Major Settings Redesign & Robust Caching System #98
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
base: dev
Are you sure you want to change the base?
Conversation
package.json
Outdated
@@ -50,6 +50,7 @@ | |||
"@langchain/mistralai": "^0.2.0", | |||
"@langchain/ollama": "^0.2.0", | |||
"@langchain/openai": "^0.4.4", | |||
"docfiller": "file:", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont why this one comes up again and again ,even after I remove it , it comes back up next second 😭
This is fine🙆♂️ Will review in sometime :) |
There was a problem hiding this 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 introduces comprehensive enhancements to DocFiller spanning UI improvements, caching system optimizations, and feature updates. The changes modernize the settings interface with a card-based layout, implement a robust response caching system with automatic cleanup, and convert the consensus checkbox to a modern toggle.
- Major Settings Page Redesign: Complete overhaul with card-based sections, modern toggle switches, and improved dark mode support
- Robust Response Caching System: Type-safe caching with automatic cleanup, validation, and error handling
- UI/UX Improvements: Modern toggle buttons, collapsible advanced options, and enhanced dark theme styling
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
File | Description |
---|---|
src/utils/storage/responseCache.ts | New comprehensive response caching system with type-safe operations and cleanup |
src/utils/storage/metricsManager.ts | Enhanced metrics reset with proper error handling |
src/utils/storage/getProperties.ts | Added new cache-related property getters |
src/utils/defaultProperties.ts | Added default cache settings and updated dark theme default |
src/options/options.ts | Major refactor for toggle-based UI and cache controls |
src/options/optionApiHandler.ts | Updated consensus API handling for new toggle system |
src/options/metrics.ts | Replaced alerts with toast notifications and added modal support |
src/docFillerCore/index.ts | Integrated response caching into form filling workflow |
src/background/index.ts | Added scheduled cache cleanup with Chrome alarms API |
public/src/options/options.css | Extensive CSS updates for new card-based layout and dark mode |
public/src/options/index.html | Restructured HTML for new section-based design |
public/manifest.ts | Added alarms permission for cache cleanup |
* @param type The type of question | ||
* @returns Normalized question text as a key | ||
*/ | ||
function generateQuestionKey(question: string, type: QType | string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding input validation to ensure question and type are not empty or null before processing. This would prevent potential issues with cache key generation.
function generateQuestionKey(question: string, type: QType | string): string { | |
function generateQuestionKey(question: string, type: QType | string): string { | |
// Validate inputs | |
if ( | |
typeof question !== 'string' || | |
question.trim() === '' || | |
typeof type !== 'string' || | |
type.trim() === '' | |
) { | |
throw new Error('Invalid question or type provided to generateQuestionKey'); | |
} |
Copilot uses AI. Check for mistakes.
const result = await new Promise<{ [key: string]: any }>( | ||
(resolve, reject) => { | ||
chrome.storage.sync.get(['docFillerResponseCache'], (items) => { | ||
if (chrome.runtime.lastError) { | ||
reject(new Error(chrome.runtime.lastError.message)); | ||
} else { | ||
resolve(items); | ||
} | ||
}); | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The Promise wrapper around chrome.storage.sync.get could be extracted into a utility function since this pattern is used multiple times throughout the codebase.
const result = await new Promise<{ [key: string]: any }>( | |
(resolve, reject) => { | |
chrome.storage.sync.get(['docFillerResponseCache'], (items) => { | |
if (chrome.runtime.lastError) { | |
reject(new Error(chrome.runtime.lastError.message)); | |
} else { | |
resolve(items); | |
} | |
}); | |
}, | |
); | |
const result = await getFromChromeStorage(['docFillerResponseCache']); |
Copilot uses AI. Check for mistakes.
} else if (questionType === QType.LINEAR_SCALE_OR_STAR) { | ||
try { | ||
// Try to parse as number first (common for ratings) | ||
if (!Number.isNaN(Number(cachedResponseText))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using Number.isFinite() instead of !Number.isNaN(Number()) for more robust numeric validation, as it also excludes Infinity values.
if (!Number.isNaN(Number(cachedResponseText))) { | |
if (Number.isFinite(Number(cachedResponseText))) { |
Copilot uses AI. Check for mistakes.
chrome.storage.sync.get('enableResponseCaching', (result) => { | ||
const enabled = | ||
//biome-ignore lint/complexity/useLiteralKeys: Property name contains hyphens | ||
result['enableResponseCaching'] ?? | ||
DEFAULT_PROPERTIES.enableResponseCaching; | ||
cachingToggle.classList.toggle('active', enabled); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The cache toggle initialization could be extracted into a separate function to improve code organization and reusability.
chrome.storage.sync.get('enableResponseCaching', (result) => { | |
const enabled = | |
//biome-ignore lint/complexity/useLiteralKeys: Property name contains hyphens | |
result['enableResponseCaching'] ?? | |
DEFAULT_PROPERTIES.enableResponseCaching; | |
cachingToggle.classList.toggle('active', enabled); | |
}); | |
initializeCacheToggle(cachingToggle); |
Copilot uses AI. Check for mistakes.
const newToggleButton = enableConsensusToggleButton.cloneNode(true); | ||
if (enableConsensusToggleButton.parentNode) { | ||
enableConsensusToggleButton.parentNode.replaceChild( | ||
newToggleButton, | ||
enableConsensusToggleButton, | ||
); | ||
} | ||
|
||
// Add the event listener to the new button | ||
newToggleButton.addEventListener('click', () => { | ||
const isCurrentlyActive = ( | ||
newToggleButton as HTMLElement | ||
).classList.contains('active'); | ||
(newToggleButton as HTMLElement).classList.toggle('active'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach of cloning DOM nodes to remove event listeners is unusual and could be error-prone. Consider using removeEventListener() with the specific handler function instead.
const newToggleButton = enableConsensusToggleButton.cloneNode(true); | |
if (enableConsensusToggleButton.parentNode) { | |
enableConsensusToggleButton.parentNode.replaceChild( | |
newToggleButton, | |
enableConsensusToggleButton, | |
); | |
} | |
// Add the event listener to the new button | |
newToggleButton.addEventListener('click', () => { | |
const isCurrentlyActive = ( | |
newToggleButton as HTMLElement | |
).classList.contains('active'); | |
(newToggleButton as HTMLElement).classList.toggle('active'); | |
// Define the handler function so it can be removed and added | |
const consensusToggleHandler = () => { | |
const isCurrentlyActive = ( | |
enableConsensusToggleButton as HTMLElement | |
).classList.contains('active'); | |
(enableConsensusToggleButton as HTMLElement).classList.toggle('active'); |
Copilot uses AI. Check for mistakes.
@@ -135,6 +144,54 @@ async function runDocFillerEngine() { | |||
} | |||
|
|||
metricsManager.incrementToBeFilledQuestions(); | |||
const enableResponseCaching = await getEnableResponseCaching(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enableResponseCaching value is fetched inside the loop for each question. Consider fetching it once before the loop to improve performance.
const enableResponseCaching = await getEnableResponseCaching(); | |
// const enableResponseCaching = await getEnableResponseCaching(); // Moved outside loop |
Copilot uses AI. Check for mistakes.
// Set up an alarm to clear old responses periodically (every 6 hours) | ||
chrome.alarms.create('clearOldResponsesAlarm', { | ||
periodInMinutes: 360, // 6 hours |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider making the alarm period configurable through settings rather than hardcoding 360 minutes.
// Set up an alarm to clear old responses periodically (every 6 hours) | |
chrome.alarms.create('clearOldResponsesAlarm', { | |
periodInMinutes: 360, // 6 hours | |
// Set up an alarm to clear old responses periodically (configurable period) | |
const alarmPeriod = await getAlarmPeriodInMinutes(); | |
chrome.alarms.create('clearOldResponsesAlarm', { | |
periodInMinutes: alarmPeriod, |
Copilot uses AI. Check for mistakes.
- Add intelligent response caching for various question types - Support multiple question type formats (MCQ, date/time, dropdown, etc.) - Implement type-safe cache retrieval with fallbacks - Add cache clearing functionality with user feedback - Display toast notifications when cache operations complete - Optimize storage format based on response structure - Implement error handling throughout caching operations
- Reorganized settings page layout into clear, card-based sections - Implemented modern toggle switches with visual indicators - Added collapsible "Advanced Options" section for lesser-used settings - Overhauled dark mode with classList-based toggle and full component support - Enhanced modals with better styling and confirmation flows - Replaced alerts with toast notifications for better UX - Improved event handling and listener cleanup - Refined spacing, alignment, and section headings for visual hierarchy - Added responsive layout improvements and smooth animations - Expanded CSS variables for better theming and dark mode support
…sponse caching Fixed response cache to properly handle dropdowns and text_url fields Converted consensus menu from checkbox to modern toggle button Added automatic cleanup of old cache entries using Chrome alarms API Improved UI with better dark theme styling for buttons Enhanced caching logic with better validation and error handling
@Him7n There were few changes here and there, it is merged in dev branch now. Commit ref: d81de1b This commit only includes the UI changes, but not the response caching. Change of response caching is in https://github.com/rootCircle/docFiller/tree/ui-redesign-cache-split, you can check that and update, it is still not merged yet! :P |
This PR introduces several enhancements spanning user interface improvements, caching system optimizations, and overall feature updates. The key changes include:
Detailed Changes
1. Consensus Toggle & Caching Enhancements (Commit: 89f479a)
2. Major Settings Page Redesign (Commit: f680520)
3. Robust Response Caching System (Commit: de116f6)
Testing & Verification
Additional Notes