1
1
import React , {
2
- forwardRef ,
3
2
useCallback ,
4
3
useContext ,
5
4
} from "react" ;
6
5
7
6
import {
7
+ Box ,
8
8
Button ,
9
- DialogActions ,
10
- DialogContent ,
11
- DialogTitle ,
9
+ Divider ,
12
10
FormControl ,
13
11
FormHelperText ,
14
12
FormLabel ,
15
13
Input ,
16
14
Link ,
17
- ModalDialog ,
18
15
} from "@mui/joy" ;
19
16
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" ;
23
20
import {
24
21
CONFIG_KEY ,
25
22
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" ;
30
31
import {
31
32
getConfig ,
32
33
setConfig ,
33
- } from "../../../utils/config" ;
34
+ } from "../../../../../utils/config" ;
35
+ import CustomTabPanel from "../CustomTabPanel" ;
34
36
import ThemeSwitchFormField from "./ThemeSwitchFormField" ;
35
37
38
+ import "./index.css" ;
39
+
36
40
37
41
/**
38
42
* Gets form fields information for user input of configuration values.
@@ -58,29 +62,29 @@ const getConfigFormFields = () => [
58
62
</ span >
59
63
) ,
60
64
initialValue : getConfig ( CONFIG_KEY . DECODER_OPTIONS ) . formatString ,
65
+ key : LOCAL_STORAGE_KEY . DECODER_OPTIONS_FORMAT_STRING ,
61
66
label : "Decoder: Format string" ,
62
- name : LOCAL_STORAGE_KEY . DECODER_OPTIONS_FORMAT_STRING ,
63
67
type : "text" ,
64
68
} ,
65
69
{
66
70
helperText : "[JSON] Key to extract the log level from." ,
67
71
initialValue : getConfig ( CONFIG_KEY . DECODER_OPTIONS ) . logLevelKey ,
72
+ key : LOCAL_STORAGE_KEY . DECODER_OPTIONS_LOG_LEVEL_KEY ,
68
73
label : "Decoder: Log level key" ,
69
- name : LOCAL_STORAGE_KEY . DECODER_OPTIONS_LOG_LEVEL_KEY ,
70
74
type : "text" ,
71
75
} ,
72
76
{
73
77
helperText : "[JSON] Key to extract the log timestamp from." ,
74
78
initialValue : getConfig ( CONFIG_KEY . DECODER_OPTIONS ) . timestampKey ,
79
+ key : LOCAL_STORAGE_KEY . DECODER_OPTIONS_TIMESTAMP_KEY ,
75
80
label : "Decoder: Timestamp key" ,
76
- name : LOCAL_STORAGE_KEY . DECODER_OPTIONS_TIMESTAMP_KEY ,
77
81
type : "text" ,
78
82
} ,
79
83
{
80
84
helperText : "Number of log messages to display per page." ,
81
85
initialValue : getConfig ( CONFIG_KEY . PAGE_SIZE ) ,
86
+ key : LOCAL_STORAGE_KEY . PAGE_SIZE ,
82
87
label : "View: Page size" ,
83
- name : LOCAL_STORAGE_KEY . PAGE_SIZE ,
84
88
type : "number" ,
85
89
} ,
86
90
] ;
@@ -97,13 +101,13 @@ const handleConfigFormReset = (ev: React.FormEvent) => {
97
101
} ;
98
102
99
103
/**
100
- * Renders a settings dialog for configurations.
104
+ * Displays a setting tab panel for configurations.
101
105
*
102
106
* @return
103
107
*/
104
- const SettingsDialog = forwardRef < HTMLFormElement > ( ( _ , ref ) => {
108
+ const SettingsTabPanel = ( ) => {
105
109
const { postPopUp} = useContext ( NotificationContext ) ;
106
- const { loadPageByAction, setIsSettingsModalOpen } = useContext ( StateContext ) ;
110
+ const { loadPageByAction} = useContext ( StateContext ) ;
107
111
108
112
const handleConfigFormSubmit = useCallback ( ( ev : React . FormEvent ) => {
109
113
ev . preventDefault ( ) ;
@@ -134,67 +138,56 @@ const SettingsDialog = forwardRef<HTMLFormElement>((_, ref) => {
134
138
} ) ;
135
139
} else {
136
140
loadPageByAction ( { code : ACTION_NAME . RELOAD , args : null } ) ;
137
- setIsSettingsModalOpen ( false ) ;
138
141
}
139
142
} , [
140
143
loadPageByAction ,
141
144
postPopUp ,
142
- setIsSettingsModalOpen ,
143
145
] ) ;
144
146
145
147
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 ] }
151
151
>
152
- < ModalDialog
153
- minWidth = { "md" }
154
- size = { "lg" }
152
+ < form
153
+ className = { "settings-tab-container" }
154
+ tabIndex = { - 1 }
155
+ onReset = { handleConfigFormReset }
156
+ onSubmit = { handleConfigFormSubmit }
155
157
>
156
- < DialogTitle className = { "settings-dialog-title" } >
157
- Settings
158
- </ DialogTitle >
159
- < DialogContent >
158
+ < Box className = { "settings-form-fields-container" } >
160
159
< ThemeSwitchFormField />
161
160
{ getConfigFormFields ( ) . map ( ( field , index ) => (
162
- < FormControl
163
- className = { "config-form-control" }
164
- key = { index }
165
- >
161
+ < FormControl key = { index } >
166
162
< FormLabel >
167
163
{ field . label }
168
164
</ FormLabel >
169
165
< Input
170
166
defaultValue = { field . initialValue }
171
- name = { field . name }
167
+ name = { field . key }
172
168
type = { field . type } />
173
169
< FormHelperText >
174
170
{ field . helperText }
175
171
</ FormHelperText >
176
172
</ FormControl >
177
173
) ) }
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 >
195
190
) ;
196
- } ) ;
197
-
198
- SettingsDialog . displayName = "SettingsDialog" ;
191
+ } ;
199
192
200
- export default SettingsDialog ;
193
+ export default SettingsTabPanel ;
0 commit comments