-
Notifications
You must be signed in to change notification settings - Fork 18
feat(settings): Move settings from the modal into a tab panel. #186
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
WalkthroughThe changes refactor the sidebar configuration interface by transitioning from a modal-based approach to a tab-based system. Component logic and CSS styling have been updated to integrate a new SettingsTabPanel, while state management now relies on context rather than local state. Import paths have been corrected, and new CSS classes have been introduced to support the updated layout. Additionally, the legacy SettingsModal and its associated styles have been removed. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant ST as SidebarTabs
participant SC as StateContext
participant SB as Sidebar
participant STP as SettingsTabPanel
User->>ST: Clicks on a tab (e.g., Settings)
ST->>SC: Calls setActiveTabName("Settings")
SC-->>SB: Updates activeTabName state
SB->>STP: Renders SettingsTabPanel based on activeTabName
Suggested reviewers
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
🪧 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 (
|
This PR depends on #184 |
# Conflicts: # src/components/modals/SettingsModal/SettingsDialog.tsx # src/components/modals/SettingsModal/index.css
…id overflowing the wrapping container.
@junhaoliao - is this off draft? if so, lmk and I will look |
Just fixed some overflowing issues. It's now ready for review. |
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: 3
🧹 Nitpick comments (6)
src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx (2)
39-81
: Consider adding TypeScript interface for form field configuration.The form field configuration is well-structured, but adding a TypeScript interface would improve type safety and maintainability.
+interface ConfigFormField { + helperText: string | JSX.Element; + initialValue: string | number; + key: LOCAL_STORAGE_KEY; + label: string; + type: 'text' | 'number'; +} -const CONFIG_FORM_FIELDS = [ +const CONFIG_FORM_FIELDS: ConfigFormField[] = [
137-179
: Consider grouping related form fields.The form fields could be organized into logical groups using fieldsets for better organization and accessibility.
<Box className={"settings-form-fields-container"}> <ThemeSwitchFormField/> + <fieldset> + <legend>Decoder Settings</legend> {CONFIG_FORM_FIELDS.filter(field => field.key.startsWith('decoderOptions')).map((field, index) => ( <FormControl key={index}> <FormLabel>{field.label}</FormLabel> <Input defaultValue={field.initialValue} name={field.key} type={field.type}/> <FormHelperText>{field.helperText}</FormHelperText> </FormControl> ))} + </fieldset> + <fieldset> + <legend>View Settings</legend> {CONFIG_FORM_FIELDS.filter(field => !field.key.startsWith('decoderOptions')).map((field, index) => ( <FormControl key={index}> <FormLabel>{field.label}</FormLabel> <Input defaultValue={field.initialValue} name={field.key} type={field.type}/> <FormHelperText>{field.helperText}</FormHelperText> </FormControl> ))} + </fieldset> </Box>src/components/CentralContainer/Sidebar/index.tsx (2)
50-54
: Consider debouncing the resize handler.To improve performance, consider debouncing the resize handler to prevent excessive state updates.
+import debounce from 'lodash/debounce'; const handleResizeHandleRelease = useCallback(() => { if (getPanelWidth() === tabListRef.current?.clientWidth) { changeActiveTabName(TAB_NAME.NONE); } -}, [changeActiveTabName]); +}, [changeActiveTabName]); + +const debouncedHandleResizeHandleRelease = debounce(handleResizeHandleRelease, 150);
80-97
: Consider throttling window resize handler.To improve performance during window resizing, consider throttling the handler.
+import throttle from 'lodash/throttle'; useEffect(() => { - const handleWindowResize = () => { + const handleWindowResize = throttle(() => { const availableWidth = Math.max( window.innerWidth - EDITOR_MIN_WIDTH_IN_PIXELS, PANEL_CLIP_THRESHOLD_IN_PIXELS ); if (getPanelWidth() > availableWidth) { setPanelWidth(availableWidth); } - }; + }, 100);src/contexts/StateContextProvider.tsx (2)
111-111
: Consider using a more type-safe default implementation.Instead of using a null-returning arrow function, consider throwing an error to catch uninitialized context usage:
- changeActiveTabName: () => null, + changeActiveTabName: () => { + throw new Error('StateContext not initialized'); + },
279-292
: Consider moving side effects to useEffect.The
setConfig
calls within the state setter function could lead to unnecessary re-renders. Consider moving them to a useEffect:const changeActiveTabName = useCallback((tabName: TAB_NAME) => { setActiveTabName((oldTabName) => { if (oldTabName === tabName) { - setConfig({key: CONFIG_KEY.INITIAL_TAB_NAME, value: TAB_NAME.NONE}); return TAB_NAME.NONE; } - setConfig({key: CONFIG_KEY.INITIAL_TAB_NAME, value: tabName}); return tabName; }); }, []); +useEffect(() => { + setConfig({key: CONFIG_KEY.INITIAL_TAB_NAME, value: activeTabName}); +}, [activeTabName]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
src/components/CentralContainer/Sidebar/SidebarTabs/CustomTabPanel.css
(1 hunks)src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.css
(1 hunks)src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.tsx
(2 hunks)src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.css
(1 hunks)src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx
(1 hunks)src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
(2 hunks)src/components/CentralContainer/Sidebar/index.tsx
(3 hunks)src/components/modals/SettingsModal/SettingsDialog.tsx
(0 hunks)src/components/modals/SettingsModal/index.css
(0 hunks)src/components/modals/SettingsModal/index.tsx
(0 hunks)src/contexts/StateContextProvider.tsx
(12 hunks)
💤 Files with no reviewable changes (3)
- src/components/modals/SettingsModal/index.tsx
- src/components/modals/SettingsModal/index.css
- src/components/modals/SettingsModal/SettingsDialog.tsx
✅ Files skipped from review due to trivial changes (3)
- src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.css
- src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.css
- src/components/CentralContainer/Sidebar/SidebarTabs/CustomTabPanel.css
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.tsx
src/components/CentralContainer/Sidebar/index.tsx
src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/index.tsx
src/contexts/StateContextProvider.tsx
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
🔇 Additional comments (6)
src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.tsx (3)
15-17
: LGTM! Import paths are correctly updated.The import paths have been properly adjusted to reflect the new file location in the directory structure.
25-27
: LGTM! Theme handling is well-implemented.The component correctly uses the
useColorScheme
hook from MUI Joy for theme management.
33-34
: LGTM! UI layout improvement.The addition of the
theme-switch-toggle-button-group
class improves the layout by enabling button wrapping.src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (2)
48-52
: LGTM! State management is properly migrated to context.The component correctly uses StateContext for tab management, improving state management consistency.
65-99
: LGTM! Tab panel integration is well-implemented.The tabs are properly configured with correct orientation and variant, and the SettingsTabPanel is well-integrated.
src/components/CentralContainer/Sidebar/index.tsx (1)
99-120
: LGTM! Tab state handling is well-implemented.The effect properly handles panel width updates based on the active tab state, including edge cases.
const handleConfigFormReset = (ev: React.FormEvent) => { | ||
ev.preventDefault(); | ||
window.localStorage.clear(); | ||
window.location.reload(); | ||
}; |
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.
🛠️ Refactor suggestion
Consider selective localStorage clearing.
The current implementation clears all localStorage data. Consider clearing only configuration-related keys to preserve other application data.
- window.localStorage.clear();
+ Object.values(LOCAL_STORAGE_KEY).forEach(key => {
+ window.localStorage.removeItem(key);
+ });
📝 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 handleConfigFormReset = (ev: React.FormEvent) => { | |
ev.preventDefault(); | |
window.localStorage.clear(); | |
window.location.reload(); | |
}; | |
const handleConfigFormReset = (ev: React.FormEvent) => { | |
ev.preventDefault(); | |
Object.values(LOCAL_STORAGE_KEY).forEach(key => { | |
window.localStorage.removeItem(key); | |
}); | |
window.location.reload(); | |
}; |
const handleConfigFormSubmit = useCallback( | ||
(ev: React.FormEvent) => { | ||
ev.preventDefault(); | ||
const formData = new FormData(ev.target as HTMLFormElement); | ||
const getFormDataValue = (key: string) => formData.get(key) as string; | ||
|
||
const formatString = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING); | ||
const logLevelKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY); | ||
const timestampKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY); | ||
const pageSize = getFormDataValue(LOCAL_STORAGE_KEY.PAGE_SIZE); | ||
|
||
let error: Nullable<string> = null; | ||
error ||= setConfig({ | ||
key: CONFIG_KEY.DECODER_OPTIONS, | ||
value: {formatString, logLevelKey, timestampKey}, | ||
}); | ||
error ||= setConfig({ | ||
key: CONFIG_KEY.PAGE_SIZE, | ||
value: Number(pageSize), | ||
}); | ||
|
||
if (null !== error) { | ||
postPopUp({ | ||
level: LOG_LEVEL.ERROR, | ||
message: error, | ||
timeoutMillis: DO_NOT_TIMEOUT_VALUE, | ||
title: "Unable to apply config.", | ||
}); | ||
} else { | ||
window.location.reload(); | ||
} | ||
}, | ||
[postPopUp], | ||
); |
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.
🛠️ Refactor suggestion
Add input validation before applying configuration.
Consider validating the form data before applying the configuration to prevent invalid values.
const handleConfigFormSubmit = useCallback(
(ev: React.FormEvent) => {
ev.preventDefault();
const formData = new FormData(ev.target as HTMLFormElement);
const getFormDataValue = (key: string) => formData.get(key) as string;
const formatString = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING);
const logLevelKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY);
const timestampKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY);
const pageSize = getFormDataValue(LOCAL_STORAGE_KEY.PAGE_SIZE);
+ // Validate page size
+ const pageSizeNum = Number(pageSize);
+ if (isNaN(pageSizeNum) || pageSizeNum <= 0) {
+ postPopUp({
+ level: LOG_LEVEL.ERROR,
+ message: "Page size must be a positive number",
+ timeoutMillis: DO_NOT_TIMEOUT_VALUE,
+ title: "Invalid configuration",
+ });
+ return;
+ }
📝 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 handleConfigFormSubmit = useCallback( | |
(ev: React.FormEvent) => { | |
ev.preventDefault(); | |
const formData = new FormData(ev.target as HTMLFormElement); | |
const getFormDataValue = (key: string) => formData.get(key) as string; | |
const formatString = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING); | |
const logLevelKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY); | |
const timestampKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY); | |
const pageSize = getFormDataValue(LOCAL_STORAGE_KEY.PAGE_SIZE); | |
let error: Nullable<string> = null; | |
error ||= setConfig({ | |
key: CONFIG_KEY.DECODER_OPTIONS, | |
value: {formatString, logLevelKey, timestampKey}, | |
}); | |
error ||= setConfig({ | |
key: CONFIG_KEY.PAGE_SIZE, | |
value: Number(pageSize), | |
}); | |
if (null !== error) { | |
postPopUp({ | |
level: LOG_LEVEL.ERROR, | |
message: error, | |
timeoutMillis: DO_NOT_TIMEOUT_VALUE, | |
title: "Unable to apply config.", | |
}); | |
} else { | |
window.location.reload(); | |
} | |
}, | |
[postPopUp], | |
); | |
const handleConfigFormSubmit = useCallback( | |
(ev: React.FormEvent) => { | |
ev.preventDefault(); | |
const formData = new FormData(ev.target as HTMLFormElement); | |
const getFormDataValue = (key: string) => formData.get(key) as string; | |
const formatString = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING); | |
const logLevelKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY); | |
const timestampKey = getFormDataValue(LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY); | |
const pageSize = getFormDataValue(LOCAL_STORAGE_KEY.PAGE_SIZE); | |
// Validate page size | |
const pageSizeNum = Number(pageSize); | |
if (isNaN(pageSizeNum) || pageSizeNum <= 0) { | |
postPopUp({ | |
level: LOG_LEVEL.ERROR, | |
message: "Page size must be a positive number", | |
timeoutMillis: DO_NOT_TIMEOUT_VALUE, | |
title: "Invalid configuration", | |
}); | |
return; | |
} | |
let error: Nullable<string> = null; | |
error ||= setConfig({ | |
key: CONFIG_KEY.DECODER_OPTIONS, | |
value: { formatString, logLevelKey, timestampKey }, | |
}); | |
error ||= setConfig({ | |
key: CONFIG_KEY.PAGE_SIZE, | |
value: Number(pageSize), | |
}); | |
if (null !== error) { | |
postPopUp({ | |
level: LOG_LEVEL.ERROR, | |
message: error, | |
timeoutMillis: DO_NOT_TIMEOUT_VALUE, | |
title: "Unable to apply config.", | |
}); | |
} else { | |
window.location.reload(); | |
} | |
}, | |
[postPopUp], | |
); |
const handleTabButtonClick = (tabName: TAB_NAME) => { | ||
switch (tabName) { | ||
case TAB_NAME.SETTINGS: | ||
setIsSettingsModalOpen(true); | ||
break; | ||
case TAB_NAME.DOCUMENTATION: | ||
openInNewTab(DOCUMENTATION_URL); | ||
break; | ||
default: | ||
onActiveTabNameChange(tabName); | ||
changeActiveTabName(tabName); | ||
} | ||
}; |
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.
🛠️ Refactor suggestion
Add security attributes for external links.
When opening documentation in a new tab, consider adding security-related attributes.
case TAB_NAME.DOCUMENTATION:
- openInNewTab(DOCUMENTATION_URL);
+ openInNewTab(DOCUMENTATION_URL, { rel: 'noopener noreferrer' });
break;
📝 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 handleTabButtonClick = (tabName: TAB_NAME) => { | |
switch (tabName) { | |
case TAB_NAME.SETTINGS: | |
setIsSettingsModalOpen(true); | |
break; | |
case TAB_NAME.DOCUMENTATION: | |
openInNewTab(DOCUMENTATION_URL); | |
break; | |
default: | |
onActiveTabNameChange(tabName); | |
changeActiveTabName(tabName); | |
} | |
}; | |
const handleTabButtonClick = (tabName: TAB_NAME) => { | |
switch (tabName) { | |
case TAB_NAME.DOCUMENTATION: | |
openInNewTab(DOCUMENTATION_URL, { rel: 'noopener noreferrer' }); | |
break; | |
default: | |
changeActiveTabName(tabName); | |
} | |
}; |
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.
Initial high level comment + 1 small nit
activeTabName, | ||
onActiveTabNameChange, | ||
}, | ||
const SidebarTabs = forwardRef<HTMLDivElement>(( |
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.
Should probably just fix this now? it's deprecated
https://react.dev/reference/react/forwardRef
@@ -297,7 +313,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => { | |||
children: "Settings", | |||
startDecorator: <SettingsOutlinedIcon/>, | |||
onClick: () => { | |||
setIsSettingsModalOpen(true); | |||
changeActiveTabName(TAB_NAME.SETTINGS); |
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.
can we just call setActiveTabName
here, and get rid of changeActiveTabName
? We could then not delete exisitng handleActiveTabNameChange
in src/components/CentralContainer/Sidebar/index.tsx
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 feel like the less in StateContextProvider the better
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.
We do need to save the last active tab name into localStorage and I feel it's best if we can save the name whenever a tab name change is request, to avoid duplicate code. If the function is not purely state settings, i want to avoid naming it with the set
prefix to reduce confusion for code readers.
That said, an attempt was made to remove the toggling on same tab name logic from changeActiveTabName
, which also fixes a bug in this pop up, where an active settings tab can be closed once the user click this primary action.
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.
save the last active tab name into localStorage and I feel it's best if we can save the name whenever a tab name change is request, to avoid duplicate code.
You can move the setConfig
into the useEffect in /Sidebar/index.tsx, it should work. After that, you can remove changeActiveTabName
entirely, and replace all references of it to setActiveTabName
from useState.
I dont think we are adding duplicate code, and I think slightly simpler.
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: 1
♻️ Duplicate comments (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)
59-61
:⚠️ Potential issueAdd security attributes for external links.
When opening documentation in a new tab, consider adding security-related attributes.
Apply this diff:
case TAB_NAME.DOCUMENTATION: - openInNewTab(DOCUMENTATION_URL); + openInNewTab(DOCUMENTATION_URL, { rel: 'noopener noreferrer' }); break;
🧹 Nitpick comments (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)
28-28
: Move hardcoded URL to configuration file.Consider moving the
DOCUMENTATION_URL
to a configuration file for better maintainability and centralized management of external URLs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
🧠 Learnings (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#74
File: new-log-viewer/src/components/SidebarContainer/index.tsx:107-107
Timestamp: 2024-11-10T16:46:58.543Z
Learning: The `PanelTabs` component is already wrapped with `React.forwardRef` and passes the `ref` to the appropriate child element.
🔇 Additional comments (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)
67-102
: Well-structured tab implementation with proper state management.The tab implementation effectively uses context for state management and maintains a clean separation between tab buttons and panels. The structure aligns well with the PR objective of moving settings into a tab panel.
const SidebarTabs = ({ | ||
ref, | ||
}: SidebarTabsProps) => { |
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.
Restore forwardRef wrapper.
Based on the retrieved learnings, this component should be wrapped with React.forwardRef
. The current implementation might break ref forwarding functionality.
Apply this diff to restore the forwardRef wrapper:
-const SidebarTabs = ({
- ref,
-}: SidebarTabsProps) => {
+const SidebarTabs = forwardRef<HTMLDivElement, SidebarTabsProps>(({}, ref) => {
📝 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 SidebarTabs = ({ | |
ref, | |
}: SidebarTabsProps) => { | |
-const SidebarTabs = ({ | |
- ref, | |
-}: SidebarTabsProps) => { | |
+const SidebarTabs = forwardRef<HTMLDivElement, SidebarTabsProps>(({}, ref) => { |
# Conflicts: # src/components/modals/SettingsModal/SettingsDialog.tsx
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 (1)
src/contexts/StateContextProvider.tsx (1)
97-97
: Default state for the active tab.
PullingactiveTabName
from the config is helpful for remembering the last-open tab. Consider adding a fallback ifgetConfig(CONFIG_KEY.INITIAL_TAB_NAME)
returns an invalid tab:- activeTabName: getConfig(CONFIG_KEY.INITIAL_TAB_NAME), + activeTabName: (() => { + const candidate = getConfig(CONFIG_KEY.INITIAL_TAB_NAME); + return isValidTabName(candidate) ? candidate : TAB_NAME.NONE; + })(),Also applies to: 114-114
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
(3 hunks)src/components/CentralContainer/Sidebar/index.tsx
(3 hunks)src/contexts/StateContextProvider.tsx
(11 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}
: - Preferfalse == <expression>
rather than!<expression>
.
src/contexts/StateContextProvider.tsx
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx
src/components/CentralContainer/Sidebar/index.tsx
🧠 Learnings (1)
src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#74
File: new-log-viewer/src/components/SidebarContainer/index.tsx:107-107
Timestamp: 2025-03-14T10:38:03.498Z
Learning: The `PanelTabs` component is already wrapped with `React.forwardRef` and passes the `ref` to the appropriate child element.
🔇 Additional comments (16)
src/components/CentralContainer/Sidebar/index.tsx (4)
3-3
: No issues with the updated imports.
These new imports are necessary for adopting the context-based approach.Also applies to: 8-8
49-49
: Effective usage of the context-based tab management.
AccessingactiveTabName
andsetActiveTabName
from context simplifies local state logic and keeps the component focused.Also applies to: 52-52, 56-56
101-124
: Persisting the active tab name usingsetConfig
.
Storing the active tab in the config ensures a consistent user experience when reloading. Please verify thatINITIAL_TAB_NAME
remains valid for all consumers.
129-133
: Conditional rendering of the resize handle.
Hiding the resize handle whenactiveTabName
isNONE
neatly improves usability.src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (7)
2-2
: Properly referencing a ref prop and the new SettingsTabPanel import.
Explicitly typing theref
prop asRef<HTMLDivElement>
ensures clarity. Adding theSettingsTabPanel
import aligns with the newly introduced tab.Also applies to: 22-22, 42-42
48-49
: Documentation improvements.
It is helpful to see the docstrings updated to mention theref
prop for clarity.
52-54
: RestoreforwardRef
for prop-based ref usage.
The same recommendation was made earlier, advising wrapping the component inReact.forwardRef
to properly handle the passed-in ref.
55-55
: Directly consumingactiveTabName
andsetActiveTabName
from context.
This context usage avoids repetitive prop passing and keeps the component simpler.
62-68
: Tab toggling logic.
Closing the tab upon repeated selection provides an intuitive user experience. Nicely done.
92-103
: Positioning help and settings at the bottom.
Placing these tabs at the bottom can make them more consistently visible and easier to distinguish.
104-107
: Introducing integrated tab panels.
RenderingFileInfoTabPanel
,SearchTabPanel
, andSettingsTabPanel
within these tabs unifies the UI under one tabbed interface.src/contexts/StateContextProvider.tsx (5)
33-33
: Refine import usage.
EnsuringTAB_NAME
is accurately imported preserves consistency across the application.
70-70
: Additional fields in StateContext.
DefiningactiveTabName
andsetActiveTabName
streamlines tab-based navigation and removes the need for separate modal state.Also applies to: 87-87
254-254
: State initialization ofactiveTabName
.
UsingSTATE_DEFAULT.activeTabName
unifies defaults between the static config and runtime state.
280-281
: Launch the settings tab on the format popup action.
Switching to the settings tab when a format string is missing guides users to implement custom formatting.
558-558
: Context value updated to includeactiveTabName
andsetActiveTabName
.
Exposing these props in the provider supports the tab-based approach throughout the application.Also applies to: 575-575
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.
Tested basic functionality. Lgtm
I am good with title |
Description
Checklist
breaking change.
Validation performed
Summary by CodeRabbit
New Features
Style
Refactor
Bug Fixes