Skip to content

Commit 0bea845

Browse files
authored
feat(settings): Move settings from the modal into a tab panel. (#186)
1 parent 96e6436 commit 0bea845

File tree

10 files changed

+172
-224
lines changed

10 files changed

+172
-224
lines changed

src/components/CentralContainer/Sidebar/SidebarTabs/CustomTabPanel.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.sidebar-tab-panel {
2-
padding: 0.75rem;
2+
min-width: 0 !important;
3+
padding: 0.75rem !important;
4+
padding-right: 0.5rem !important;
35
}
46

57
.sidebar-tab-panel-container {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.theme-switch-toggle-button-group {
2+
flex-wrap: wrap;
3+
}

src/components/modals/SettingsModal/ThemeSwitchFormField.tsx renamed to src/components/CentralContainer/Sidebar/SidebarTabs/SettingsTabPanel/ThemeSwitchFormField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import DarkModeIcon from "@mui/icons-material/DarkMode";
1212
import LightModeIcon from "@mui/icons-material/LightMode";
1313
import SettingsBrightnessIcon from "@mui/icons-material/SettingsBrightness";
1414

15-
import {THEME_NAME} from "../../../typings/config";
15+
import {THEME_NAME} from "../../../../../typings/config";
16+
17+
import "./ThemeSwitchFormField.css";
1618

1719

1820
/**
@@ -29,6 +31,7 @@ const ThemeSwitchFormField = () => {
2931
Theme
3032
</FormLabel>
3133
<ToggleButtonGroup
34+
className={"theme-switch-toggle-button-group"}
3235
size={"sm"}
3336
value={mode as string}
3437
onChange={(__, newValue) => {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.settings-tab-container {
2+
overflow: hidden;
3+
display: flex;
4+
flex-direction: column;
5+
gap: 0.75rem;
6+
7+
height: 100%;
8+
}
9+
10+
.settings-form-fields-container {
11+
overflow-y: auto;
12+
display: flex;
13+
flex-direction: column;
14+
flex-grow: 1;
15+
gap: 0.75rem;
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
import React, {
2-
forwardRef,
32
useCallback,
43
useContext,
54
} from "react";
65

76
import {
7+
Box,
88
Button,
9-
DialogActions,
10-
DialogContent,
11-
DialogTitle,
9+
Divider,
1210
FormControl,
1311
FormHelperText,
1412
FormLabel,
1513
Input,
1614
Link,
17-
ModalDialog,
1815
} from "@mui/joy";
1916

20-
import {NotificationContext} from "../../../contexts/NotificationContextProvider";
21-
import {StateContext} from "../../../contexts/StateContextProvider";
22-
import {Nullable} from "../../../typings/common";
17+
import {NotificationContext} from "../../../../../contexts/NotificationContextProvider";
18+
import {StateContext} from "../../../../../contexts/StateContextProvider";
19+
import {Nullable} from "../../../../../typings/common";
2320
import {
2421
CONFIG_KEY,
2522
LOCAL_STORAGE_KEY,
26-
} from "../../../typings/config";
27-
import {LOG_LEVEL} from "../../../typings/logs";
28-
import {DO_NOT_TIMEOUT_VALUE} from "../../../typings/notifications";
29-
import {ACTION_NAME} from "../../../utils/actions";
23+
} from "../../../../../typings/config";
24+
import {LOG_LEVEL} from "../../../../../typings/logs";
25+
import {DO_NOT_TIMEOUT_VALUE} from "../../../../../typings/notifications";
26+
import {
27+
TAB_DISPLAY_NAMES,
28+
TAB_NAME,
29+
} from "../../../../../typings/tab";
30+
import {ACTION_NAME} from "../../../../../utils/actions";
3031
import {
3132
getConfig,
3233
setConfig,
33-
} from "../../../utils/config";
34+
} from "../../../../../utils/config";
35+
import CustomTabPanel from "../CustomTabPanel";
3436
import ThemeSwitchFormField from "./ThemeSwitchFormField";
3537

38+
import "./index.css";
39+
3640

3741
/**
3842
* Gets form fields information for user input of configuration values.
@@ -58,29 +62,29 @@ const getConfigFormFields = () => [
5862
</span>
5963
),
6064
initialValue: getConfig(CONFIG_KEY.DECODER_OPTIONS).formatString,
65+
key: LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING,
6166
label: "Decoder: Format string",
62-
name: LOCAL_STORAGE_KEY.DECODER_OPTIONS_FORMAT_STRING,
6367
type: "text",
6468
},
6569
{
6670
helperText: "[JSON] Key to extract the log level from.",
6771
initialValue: getConfig(CONFIG_KEY.DECODER_OPTIONS).logLevelKey,
72+
key: LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY,
6873
label: "Decoder: Log level key",
69-
name: LOCAL_STORAGE_KEY.DECODER_OPTIONS_LOG_LEVEL_KEY,
7074
type: "text",
7175
},
7276
{
7377
helperText: "[JSON] Key to extract the log timestamp from.",
7478
initialValue: getConfig(CONFIG_KEY.DECODER_OPTIONS).timestampKey,
79+
key: LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY,
7580
label: "Decoder: Timestamp key",
76-
name: LOCAL_STORAGE_KEY.DECODER_OPTIONS_TIMESTAMP_KEY,
7781
type: "text",
7882
},
7983
{
8084
helperText: "Number of log messages to display per page.",
8185
initialValue: getConfig(CONFIG_KEY.PAGE_SIZE),
86+
key: LOCAL_STORAGE_KEY.PAGE_SIZE,
8287
label: "View: Page size",
83-
name: LOCAL_STORAGE_KEY.PAGE_SIZE,
8488
type: "number",
8589
},
8690
];
@@ -97,13 +101,13 @@ const handleConfigFormReset = (ev: React.FormEvent) => {
97101
};
98102

99103
/**
100-
* Renders a settings dialog for configurations.
104+
* Displays a setting tab panel for configurations.
101105
*
102106
* @return
103107
*/
104-
const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
108+
const SettingsTabPanel = () => {
105109
const {postPopUp} = useContext(NotificationContext);
106-
const {loadPageByAction, setIsSettingsModalOpen} = useContext(StateContext);
110+
const {loadPageByAction} = useContext(StateContext);
107111

108112
const handleConfigFormSubmit = useCallback((ev: React.FormEvent) => {
109113
ev.preventDefault();
@@ -134,67 +138,56 @@ const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
134138
});
135139
} else {
136140
loadPageByAction({code: ACTION_NAME.RELOAD, args: null});
137-
setIsSettingsModalOpen(false);
138141
}
139142
}, [
140143
loadPageByAction,
141144
postPopUp,
142-
setIsSettingsModalOpen,
143145
]);
144146

145147
return (
146-
<form
147-
ref={ref}
148-
tabIndex={-1}
149-
onReset={handleConfigFormReset}
150-
onSubmit={handleConfigFormSubmit}
148+
<CustomTabPanel
149+
tabName={TAB_NAME.SETTINGS}
150+
title={TAB_DISPLAY_NAMES[TAB_NAME.SETTINGS]}
151151
>
152-
<ModalDialog
153-
minWidth={"md"}
154-
size={"lg"}
152+
<form
153+
className={"settings-tab-container"}
154+
tabIndex={-1}
155+
onReset={handleConfigFormReset}
156+
onSubmit={handleConfigFormSubmit}
155157
>
156-
<DialogTitle className={"settings-dialog-title"}>
157-
Settings
158-
</DialogTitle>
159-
<DialogContent>
158+
<Box className={"settings-form-fields-container"}>
160159
<ThemeSwitchFormField/>
161160
{getConfigFormFields().map((field, index) => (
162-
<FormControl
163-
className={"config-form-control"}
164-
key={index}
165-
>
161+
<FormControl key={index}>
166162
<FormLabel>
167163
{field.label}
168164
</FormLabel>
169165
<Input
170166
defaultValue={field.initialValue}
171-
name={field.name}
167+
name={field.key}
172168
type={field.type}/>
173169
<FormHelperText>
174170
{field.helperText}
175171
</FormHelperText>
176172
</FormControl>
177173
))}
178-
</DialogContent>
179-
<DialogActions>
180-
<Button
181-
color={"primary"}
182-
type={"submit"}
183-
>
184-
Apply
185-
</Button>
186-
<Button
187-
color={"neutral"}
188-
type={"reset"}
189-
>
190-
Reset Default
191-
</Button>
192-
</DialogActions>
193-
</ModalDialog>
194-
</form>
174+
</Box>
175+
<Divider/>
176+
<Button
177+
color={"primary"}
178+
type={"submit"}
179+
>
180+
Apply
181+
</Button>
182+
<Button
183+
color={"neutral"}
184+
type={"reset"}
185+
>
186+
Reset Default
187+
</Button>
188+
</form>
189+
</CustomTabPanel>
195190
);
196-
});
197-
198-
SettingsDialog.displayName = "SettingsDialog";
191+
};
199192

200-
export default SettingsDialog;
193+
export default SettingsTabPanel;

0 commit comments

Comments
 (0)