-
Notifications
You must be signed in to change notification settings - Fork 3
Initial steps to re-enable Roam Discourse Context Overlay #95
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis pull request introduces improvements and refactoring across several components and utilities. The changes adjust UI elements such as semantic header elements and menu visibility while streamlining state management with new callbacks. In addition, asynchronous handling is added to overlay data fetching, and deprecated overlay configuration and observer removal functions are eliminated. Utility functions are improved for better readability and modularity, with updated exports and a shift toward the consistent use of Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application Init
participant Settings as OnloadArgs Settings
participant Observer as PageRef Observer Manager
participant Handler as OverlayPageRefHandler
App->>Settings: Check "discourse-context-overlay" setting
Settings-->>App: Return setting status
alt Setting Enabled
App->>Observer: addPageRefObserver(Handler)
Observer->>Handler: Initialized via getOverlayHandler with onloadArgs
end
sequenceDiagram
participant UI as DiscourseContextOverlay UI
participant Callback as Async getOverlayInfo Callback
participant API as roamAlphaAPI
UI->>Callback: Trigger overlay info retrieval
Callback->>API: Await data fetch for references
API-->>Callback: Return fetched refs
Callback-->>UI: Deliver overlay info including refs
Possibly related PRs
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (5)
apps/roam/src/utils/findDiscourseNode.ts (1)
6-17: Improved function structure for better readabilityThe function has been refactored from an arrow function to a block function with explicit control flow, which improves readability while maintaining the same functionality.
The early return pattern for the cached value is a good practice that makes the code's intent clearer and potentially more efficient by avoiding unnecessary computation.
apps/roam/src/components/results-view/ResultsView.tsx (1)
466-466: Simplified header renderingThe conditional rendering of the header has been simplified by directly rendering it if present, removing unnecessary conditional logic.
apps/roam/src/components/QueryDrawer.tsx (1)
97-99: Improved semantic structure with header elementReplaced a div with an
<h4>element for the error message, improving the semantic structure of the document and potentially enhancing accessibility.apps/roam/src/components/settings/HomePersonalSettings.tsx (1)
1-1: Unnecessary import that isn't being used.The
useMemohook is imported but not used anywhere in this component.-import React, { useMemo, useState } from "react"; +import React, { useState } from "react";apps/roam/src/utils/pageRefObserverHandlers.ts (1)
67-67: Consider documenting the purpose of this aliasWhile adding this alias is fine, it would be helpful to include a brief comment explaining why this alias exists - whether it's for backward compatibility or to provide a more general name for this handler.
+// Alias for previewPageRefHandler to provide a more generic reference export const previewHandler = previewPageRefHandler;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
apps/roam/src/components/DiscourseContext.tsx(4 hunks)apps/roam/src/components/DiscourseContextOverlay.tsx(6 hunks)apps/roam/src/components/QueryDrawer.tsx(3 hunks)apps/roam/src/components/results-view/ResultsView.tsx(6 hunks)apps/roam/src/components/settings/GeneralSettings.tsx(2 hunks)apps/roam/src/components/settings/HomePersonalSettings.tsx(3 hunks)apps/roam/src/components/settings/Settings.tsx(1 hunks)apps/roam/src/utils/configPageTabs.ts(0 hunks)apps/roam/src/utils/discourseConfigRef.ts(1 hunks)apps/roam/src/utils/findDiscourseNode.ts(1 hunks)apps/roam/src/utils/getDiscourseNodes.ts(2 hunks)apps/roam/src/utils/initializeObserversAndListeners.ts(2 hunks)apps/roam/src/utils/pageRefObserverHandlers.ts(3 hunks)apps/roam/src/utils/parseQuery.ts(1 hunks)
💤 Files with no reviewable changes (1)
- apps/roam/src/utils/configPageTabs.ts
🔇 Additional comments (33)
apps/roam/src/components/settings/Settings.tsx (1)
96-96: Good refactoring to use onloadArgs instead of extensionAPIThis change improves component flexibility by passing the complete
onloadArgsobject rather than justextensionAPI. This aligns with how other components in the codebase are structured and provides more context to theHomePersonalSettingscomponent.apps/roam/src/utils/parseQuery.ts (1)
7-7: Good modularization by exporting roamNodeToConditionMaking this function available for import in other modules improves code reusability. This is particularly relevant for the overlay feature being re-enabled, as the function likely needs to be accessed from other parts of the codebase.
apps/roam/src/utils/discourseConfigRef.ts (1)
56-57: Removal of overlay property as part of refactoringThe removal of the
overlayproperty from thegetFormattedConfigTreefunction return object is consistent with the PR objective of re-enabling the Roam Discourse Context Overlay. This indicates that the overlay configuration is being handled differently in the new implementation.apps/roam/src/components/settings/GeneralSettings.tsx (2)
5-6: Good addition of observer handlersImporting these specific handlers from the pageRefObserverHandlers module improves code organization and separation of concerns.
33-35: Improved preview panel with observer pattern implementationAdding the
onChangehandler that usesonPageRefObserverChangewithpreviewPageRefHandlercreates a more structured approach to handle setting changes. This is a good pattern that enhances maintainability and is aligned with the PR objective of re-enabling the overlay feature.apps/roam/src/utils/initializeObserversAndListeners.ts (2)
24-24: New import added for overlayPageRefHandlerThe import for
overlayPageRefHandlerhas been added, which will be used for handling overlay page references.
108-110: Re-enabling the Discourse Context Overlay featureThis code block enables the Discourse Context Overlay feature by adding the
overlayPageRefHandlerwhen the corresponding setting is enabled in the extension API. This aligns with the PR objective of re-enabling this functionality.The implementation correctly passes the
onloadArgsto the handler, allowing it to access necessary extension context when processing page references.apps/roam/src/components/results-view/ResultsView.tsx (5)
229-229: Added new property for menu visibility controlA new optional property
hideMenuhas been added to theResultsViewComponenttype, which will provide more control over menu visibility.
271-271: Default value set for hideMenu propertyThe
hideMenuproperty has been initialized with a default value offalse, ensuring backward compatibility with existing implementations.
320-321: Improved menu visibility state managementThe state management for menu visibility has been enhanced:
- Changed from
showMenuIconsto a more descriptiverevealMenuIcons- Created a computed
hideMenuIconsthat combines multiple conditionsThis approach provides more granular control over when the menu should be visible.
416-417: Updated mouse event handlersThe mouse event handlers have been updated to use the new
revealMenuIconsstate variable, maintaining the hover behavior for menu visibility.
469-469: Applied visibility control to menuThe
hideMenuIconscomputed property is now used to conditionally hide the menu, properly implementing the visibility logic.apps/roam/src/components/QueryDrawer.tsx (2)
90-91: Connected drawer state to menu visibilityAdded the
hideMenuprop to theResultsViewcomponent, binding it to theminimizedstate. This ensures the menu is hidden when the drawer is minimized, creating a cleaner UI.
101-191: Consistent header structureThe non-error case now also uses an
<h4>element instead of a fragment, creating consistent heading structures throughout the component and improving document semantics.apps/roam/src/components/settings/HomePersonalSettings.tsx (3)
11-13: Updated API pattern is more consistent.Good refactoring to use
onloadArgsinstead of directly passingextensionAPI. This creates consistency with other components and follows the pattern used elsewhere in the codebase.
24-24: Good initialization of the overlay handler.Properly initializing the overlay handler with the onloadArgs parameter.
45-68: Well-implemented feature toggle for the context overlay.The checkbox implementation is clean and follows the pattern used for other settings in this component. You've correctly:
- Set the default state from the existing setting
- Updated the setting when the checkbox is toggled
- Called
onPageRefObserverChangewith the overlayHandler to activate/deactivate the featureapps/roam/src/components/DiscourseContextOverlay.tsx (3)
50-60: Good conversion to async/await pattern.Converting the callback to an async function properly handles the asynchronous query to the Roam API. This is a better approach than using callbacks for asynchronous operations.
176-196: UI improvements with better layout and iconography.The button layout has been improved with:
- Proper icon display using flexbox
- Better spacing with gap utilities
- More semantic structure with separate elements for the score and references count
This makes the UI more intuitive and visually appealing.
213-228: Consistent UI pattern between main component and wrapper.Good job maintaining consistency in the UI pattern between the main component and its wrapper. This ensures a consistent user experience regardless of the component's state.
apps/roam/src/components/DiscourseContext.tsx (5)
276-288: Improved semantic HTML structure.Replacing a fragment with a proper heading element (
h4) improves the semantic structure of the document. The additional classes for styling also enhance the visual presentation of the header.
327-338: Good extraction of logic into a reusable function.Extracting the state update logic into the
addLabelsfunction improves code maintainability by:
- Reducing code duplication
- Centralizing the logic for updating the state
- Making the code more readable
344-346: Simplified callback implementation.Using the new
addLabelsfunction here simplifies the code and makes the intention clearer.
352-355: Proper state handling with forEach.Using
forEachwith theaddLabelsfunction is a cleaner way to process multiple results than the previous implementation. The dependencies array is also correctly updated to include the new function.
412-412: Improved UI alignment for empty state.Centering the "No discourse relations found" message improves the visual balance of the UI when no data is available.
apps/roam/src/utils/getDiscourseNodes.ts (3)
5-7: Updated imports to match refactored code.Good job updating the imports to use the specific
roamNodeToConditionfunction instead of the wholeparseQuerymodule. This follows the principle of importing only what you need.
67-79: Good extraction of logic into a dedicated function.Creating a separate
getSpecificationfunction improves code organization by:
- Encapsulating related logic in a single function
- Making the code more readable and maintainable
- Allowing for better testing in isolation
The implementation is clean and properly typed.
89-90: Simplified code with the new helper function.Using the new
getSpecificationfunction here makes the code more concise and readable.apps/roam/src/utils/pageRefObserverHandlers.ts (5)
13-19: Good implementation of handler caching mechanismThis is a well-implemented memoization pattern that provides a stable reference to the overlay handler. Using a closure to bind
onloadArgsto the handler function ensures consistent behavior across invocations.For even better type safety, consider adding an explicit type to
cachedHandler:-let cachedHandler: ((s: HTMLSpanElement) => void) | undefined; +let cachedHandler: ((s: HTMLSpanElement) => void) | undefined;
20-23: Parameter naming improvementRenaming
argstoonloadArgsimproves code clarity by making the parameter name more descriptive and consistent with its usage throughout the codebase.
38-38: Consistent parameter passingThis change correctly updates the parameter being passed to match the renamed function parameter.
1-100:❓ Verification inconclusive
Verify the impact of removed observer functions
The AI summary mentions that
removePageRefObserverandclearPageRefObserversfunctions have been removed. This change could potentially lead to memory leaks if observers aren't properly cleaned up elsewhere.
🏁 Script executed:
#!/bin/bash # Search for references to the removed functions to ensure they're not being called elsewhere echo "Searching for removePageRefObserver usage:" rg "removePageRefObserver" --type ts echo "Searching for clearPageRefObservers usage:" rg "clearPageRefObservers" --type ts # Look for any alternative cleanup mechanisms that might have replaced these functions echo "Searching for potential alternative cleanup functions:" rg "observer.*clean|clean.*observer|disconnect.*observer|observer.*disconnect" --type tsLength of output: 473
Manual Verification Required: Confirm Observer Cleanup Strategy
After analyzing the code and running searches for references to the removed functions (
removePageRefObserverandclearPageRefObservers), we found no evidence that they were called anywhere in the codebase. The cleanup mechanism now uses the internaldisablePageRefObserverfunction, which disconnects the MutationObserver when the set of registered handlers becomes empty (as seen in theonPageRefObserverChangefunction).
- No usage of the removed functions was detected.
- The alternative cleanup via
disablePageRefObserverappears to be in place and is invoked in the proper context.- Action: Please manually verify in your testing environment that the observer cleanup effectively prevents memory leaks, especially in long-running scenarios.
95-97:✅ Verification successful
Verify observer enabling logic
According to the AI summary, this function was simplified by removing a conditional check that would enable the observer when the size of
pageRefObserverswas one. This could lead to unexpected behavior if observers aren't properly initialized or cleaned up.
🏁 Script executed:
#!/bin/bash # Search for references to addPageRefObserver and enablePageRefObserver to understand how they're used echo "Searching for addPageRefObserver usage:" rg "addPageRefObserver" --type ts -A 5 -B 5 echo "Searching for enablePageRefObserver usage:" rg "enablePageRefObserver" --type ts -A 5 -B 5 echo "Checking if there are any initializers that would call enablePageRefObserver:" rg "enablePageRefObserver\(\)" --type ts -A 5 -B 5Length of output: 9194
Observer Enabling Logic Verified
After reviewing the usage in the codebase, I found that the change in
addPageRefObserver—removing the internal conditional that enabled the observer—is intentional and safe. The observer is enabled elsewhere:
- In the
onPageRefObserverChangehandler, which checks ifpageRefObservers.sizeis zero before callingenablePageRefObserver().- In the initializer within
apps/roam/src/utils/initializeObserversAndListeners.ts, which explicitly callsif (!!getPageRefObserversSize()) enablePageRefObserver();These patterns ensure the observer is properly initialized and cleaned up, so the simplified function now solely adds the handler without duplicating the enabling logic.
Summary by CodeRabbit
New Features
Refactor/Style
Chores