-
Notifications
You must be signed in to change notification settings - Fork 14
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
new-log-viewer: Persist active tab across sessions. #93
Conversation
WalkthroughThe changes involve significant updates to the Changes
Sequence Diagram(s)sequenceDiagram
participant Sidebar as Sidebar Component
participant Config as Config Management
participant LocalStorage as Local Storage
Sidebar->>Config: getConfig(INITIAL_TAB_NAME)
Config-->>Sidebar: return initialTabName
Sidebar->>Sidebar: useEffect to set panel width
Sidebar->>LocalStorage: setConfig(INITIAL_TAB_NAME, value)
LocalStorage-->>Sidebar: confirm storage
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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 (
|
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: 2
🧹 Outside diff range and nitpick comments (3)
new-log-viewer/src/typings/config.ts (1)
31-31
: LGTM: ConfigMap updated correctly, consider adding a commentThe
INITIAL_TAB_NAME
entry has been correctly added to theConfigMap
type with the proper typing. This ensures type-safe usage of the new configuration option.Consider adding a brief comment above this line to explain the purpose of the
INITIAL_TAB_NAME
configuration, for improved code documentation. For example:// Stores the name of the initially active tab [CONFIG_KEY.INITIAL_TAB_NAME]: TAB_NAME,new-log-viewer/src/utils/config.ts (2)
25-25
: LGTM! Consider using a type assertion for improved type safety.The addition of
INITIAL_TAB_NAME
toCONFIG_DEFAULT
is consistent with the PR objectives. It's a good practice to set a default value for the initial tab.For improved type safety, consider using a type assertion:
[CONFIG_KEY.INITIAL_TAB_NAME]: TAB_NAME.FILE_INFO as const,This ensures that the type of
INITIAL_TAB_NAME
is specificallyTAB_NAME.FILE_INFO
rather than the more generalTAB_NAME
type.
93-95
: LGTM! Consider adding error handling for localStorage operations.The implementation correctly stores the
INITIAL_TAB_NAME
value in localStorage, consistent with how other configuration values are handled.Consider adding error handling for the localStorage operation:
case CONFIG_KEY.INITIAL_TAB_NAME: try { window.localStorage.setItem(CONFIG_KEY.INITIAL_TAB_NAME, value.toString()); } catch (error) { console.error(`Failed to set ${CONFIG_KEY.INITIAL_TAB_NAME} in localStorage:`, error); } break;This will catch and log any errors that might occur during the localStorage operation, such as when storage is full or disabled.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- new-log-viewer/src/components/CentralContainer/Sidebar/index.tsx (4 hunks)
- new-log-viewer/src/typings/config.ts (3 hunks)
- new-log-viewer/src/utils/config.ts (4 hunks)
🧰 Additional context used
🔇 Additional comments (8)
new-log-viewer/src/typings/config.ts (3)
2-2
: LGTM: New import added correctlyThe import of
TAB_NAME
from "./tab" is correctly added and necessary for the newINITIAL_TAB_NAME
configuration.
13-13
: LGTM: Enum additions are correct and consistentThe
INITIAL_TAB_NAME
entries have been correctly added to bothCONFIG_KEY
andLOCAL_STORAGE_KEY
enums. The naming and structure are consistent with existing entries.Also applies to: 23-23
Line range hint
1-31
: Summary: Changes align well with PR objectivesThe modifications to this file successfully implement the necessary type definitions and configurations to support the new
INITIAL_TAB_NAME
feature. These changes align well with the PR objective of persisting the active tab across sessions.The additions are well-integrated into the existing code structure, maintaining consistency in naming conventions and type safety. This implementation provides a solid foundation for the feature's functionality in other parts of the application.
new-log-viewer/src/utils/config.ts (1)
Line range hint
1-168
: Overall assessment: Changes meet PR objectives with minor improvements needed.The implementation successfully adds support for persisting the initial tab name across sessions, meeting the PR objectives. The changes are well-integrated into the existing code structure and follow established patterns.
Key points:
- The addition of
INITIAL_TAB_NAME
toCONFIG_DEFAULT
is appropriate.- The
setConfig
andgetConfig
functions have been correctly updated to handle the new configuration key.- Minor improvements can be made for type safety and error handling.
- An inconsistency in the localStorage key usage needs to be addressed.
Once the suggested changes are implemented, particularly fixing the localStorage key inconsistency, the code will be ready for merge.
new-log-viewer/src/components/CentralContainer/Sidebar/index.tsx (4)
3-4
: Imports are correctly added.The addition of
useEffect
anduseMemo
to the imports is appropriate for the hooks used in this component.
9-14
: Configuration imports are necessary and well-placed.Importing
CONFIG_KEY
,getConfig
, andsetConfig
is essential for managing the configuration state within the component.
63-71
: Persisting active tab state is correctly implemented.The logic within
handleActiveTabNameChange
effectively updates the active tab, adjusts the panel width, and persists the active tab name to the configuration. This ensures a consistent user experience across sessions.
103-113
: Initialization effect accurately manages panel display.The
useEffect
hook appropriately sets the panel width based on theinitialTabName
. This ensures the sidebar panel is correctly displayed or hidden upon initial load, aligning with the user's last active tab preference.
case CONFIG_KEY.INITIAL_TAB_NAME: | ||
value = window.localStorage.getItem(LOCAL_STORAGE_KEY.INITIAL_TAB_NAME); | ||
break; |
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.
LGTM! Fix inconsistency in localStorage key usage.
The implementation correctly retrieves the INITIAL_TAB_NAME
value from localStorage. However, there's an inconsistency in the key used to access the value.
In the setConfig
function, CONFIG_KEY.INITIAL_TAB_NAME
is used as the localStorage key, but here LOCAL_STORAGE_KEY.INITIAL_TAB_NAME
is used. To fix this inconsistency, replace line 133 with:
value = window.localStorage.getItem(CONFIG_KEY.INITIAL_TAB_NAME);
This ensures that the same key is used for both setting and getting the INITIAL_TAB_NAME
value.
const initialTabName = useMemo(() => getConfig(CONFIG_KEY.INITIAL_TAB_NAME), []); | ||
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(initialTabName); |
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.
Handle potential undefined initialTabName
.
When retrieving initialTabName
from the configuration, there's a possibility it might be undefined
or not set. To ensure robustness, consider providing a default value:
- const initialTabName = useMemo(() => getConfig(CONFIG_KEY.INITIAL_TAB_NAME), []);
+ const initialTabName = useMemo(() => getConfig(CONFIG_KEY.INITIAL_TAB_NAME) || TAB_NAME.DEFAULT_TAB, []);
Replace TAB_NAME.DEFAULT_TAB
with an appropriate default tab name to prevent any unintended behaviour.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const initialTabName = useMemo(() => getConfig(CONFIG_KEY.INITIAL_TAB_NAME), []); | |
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(initialTabName); | |
const initialTabName = useMemo(() => getConfig(CONFIG_KEY.INITIAL_TAB_NAME) || TAB_NAME.DEFAULT_TAB, []); | |
const [activeTabName, setActiveTabName] = useState<TAB_NAME>(initialTabName); |
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.
Code looks pretty good to me. I had one comment, otherwise i am happy.
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.
Maybe add an empty case into testConfig()? I know it wont do anything but at least its shows we considered it. See suggestion
case CONFIG_KEY.INITIAL_TAB_NAME:
break;
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.
LGTM
References
new-log-viewer series: #45 #46 #48 #51 #52 #53 #54 #55 #56 #59 #60 #61 #62 #63 #66 #67 #68 #69 #70 #71 #72 #73 #74 #76 #77 #78 #79 #80 #81 #82 #83 #84 #89 #91
Description
Validation performed
Summary by CodeRabbit
New Features
Bug Fixes
Documentation