1
1
import React , { useEffect , useState } from 'react'
2
- import {
3
- RadioGroupItem ,
4
- VisibleModal ,
5
- RadioGroup ,
6
- CustomInput ,
7
- InfoColourBar ,
8
- } from '@devtron-labs/devtron-fe-common-lib'
2
+ import { RadioGroupItem , VisibleModal , RadioGroup , InfoColourBar } from '@devtron-labs/devtron-fe-common-lib'
9
3
import Select from 'react-select'
10
4
import { SingleDatePicker } from 'react-dates'
11
5
import 'react-dates/initialize'
@@ -52,11 +46,12 @@ export const InputForSelectedOption = ({
52
46
filterTypeRadio,
53
47
} : InputSelectionProps ) : JSX . Element => {
54
48
const [ untilTimeOptions , setUntilTimeOptions ] =
55
- useState < { label : string ; value : string ; isdisabled ?: boolean } [ ] > ( ALLOW_UNTIL_TIME_OPTIONS )
49
+ useState < { label : string ; value : string ; isDisabled ?: boolean } [ ] > ( ALLOW_UNTIL_TIME_OPTIONS )
56
50
const [ focused , setFocused ] = useState ( false )
57
51
const handleFocusChange = ( { focused : isFocused } ) => {
58
52
setFocused ( isFocused )
59
53
}
54
+ const minValue = filterTypeRadio === CUSTOM_LOGS_FILTER . DURATION ? 0 : - 1
60
55
61
56
const setUntilTimeOptionsWithExcluded = ( ) => {
62
57
const nearestOption = getNearestTimeOptionBeforeNow ( )
@@ -101,8 +96,8 @@ export const InputForSelectedOption = ({
101
96
let errorString
102
97
if ( e . target . value === '' ) {
103
98
errorString = 'This field is required'
104
- } else if ( Number . isNaN ( Number ( e . target . value ) ) ) {
105
- errorString = 'Please enter a valid number '
99
+ } else if ( e . target . value === '0' ) {
100
+ errorString = 'Value cannot be 0 '
106
101
} else if ( customLogFilterOptions [ filterTypeRadio ] . error ) {
107
102
errorString = ''
108
103
}
@@ -114,11 +109,13 @@ export const InputForSelectedOption = ({
114
109
115
110
const handleInputChange = ( e ) => {
116
111
checkInputError ( e )
117
- setCustomLogFilterOptions ( {
118
- ...customLogFilterOptions ,
119
- [ filterTypeRadio ] : { ...customLogFilterOptions [ filterTypeRadio ] , value : e . target . value } ,
120
- } )
112
+ const val = Number ( e . target . value ) < minValue ? minValue . toString ( ) : e . target . value
113
+ setCustomLogFilterOptions ( ( prevState ) => ( {
114
+ ...prevState ,
115
+ [ filterTypeRadio ] : { ...prevState [ filterTypeRadio ] , value : val } ,
116
+ } ) )
121
117
}
118
+
122
119
const changeTimeUnits = ( selected ) => {
123
120
setCustomLogFilterOptions ( {
124
121
...customLogFilterOptions ,
@@ -128,25 +125,31 @@ export const InputForSelectedOption = ({
128
125
129
126
const offset = moment ( new Date ( ) ) . format ( 'Z' )
130
127
const timeZone = `${ Intl ?. DateTimeFormat ( ) ?. resolvedOptions ( ) ?. timeZone ?? '' } (GMT ${ offset } )`
131
-
132
128
switch ( filterTypeRadio ) {
133
129
case CUSTOM_LOGS_FILTER . DURATION :
134
130
case CUSTOM_LOGS_FILTER . LINES :
135
131
return (
136
- < div className = "flexbox-col" >
137
- < div className = "dc__required-field mb-6 fs-13 fcn-7 " >
132
+ < div className = "flexbox-col cn-7 " >
133
+ < div className = "dc__required-field mb-6 fs-13" >
138
134
{ filterTypeRadio === CUSTOM_LOGS_FILTER . DURATION ? 'View logs for last' : 'Set number of lines' }
139
135
</ div >
140
136
< div className = "flex dc__align-start" >
141
- < div className = "w-180" >
142
- < CustomInput
143
- error = { customLogFilterOptions [ filterTypeRadio ] . error }
144
- name = "duration-lines"
145
- handleOnBlur = { checkInputError }
137
+ < div className = "flexbox-col dc__gap-8" >
138
+ < input
139
+ type = "number"
140
+ autoComplete = "off"
141
+ min = { minValue }
142
+ className = "input-focus-none"
146
143
value = { customLogFilterOptions [ filterTypeRadio ] . value }
147
- rootClassName = "input-focus-none"
148
144
onChange = { handleInputChange }
145
+ onBlur = { checkInputError }
149
146
/>
147
+ { customLogFilterOptions [ filterTypeRadio ] . error && (
148
+ < div className = "fs-11 cr-5 flex flex-justify-start" >
149
+ < Warn className = "form__icon form__icon--error mr-4" />
150
+ { customLogFilterOptions [ filterTypeRadio ] . error }
151
+ </ div >
152
+ ) }
150
153
</ div >
151
154
< div className = "flex-grow-1" >
152
155
{ filterTypeRadio === CUSTOM_LOGS_FILTER . DURATION ? (
@@ -168,11 +171,11 @@ export const InputForSelectedOption = ({
168
171
} }
169
172
components = { {
170
173
IndicatorSeparator : null ,
171
- Option : ( props ) => < Option { ...props } showTippy style = { { direction : 'rtl' } } /> ,
174
+ Option : ( props ) => < Option { ...props } style = { { direction : 'rtl' } } /> ,
172
175
} }
173
176
/>
174
177
) : (
175
- < div className = "dc__border h-38 dc__right-radius-4 flex fs-13 flex-justify-start pl-8" >
178
+ < div className = "dc__border h-38 dc__right-radius-4 flex fs-13 flex-justify-start pl-8 cn-9 " >
176
179
Lines
177
180
</ div >
178
181
) }
@@ -183,7 +186,7 @@ export const InputForSelectedOption = ({
183
186
case 'all' :
184
187
return (
185
188
< div className = "flexbox-col" >
186
- < div className = "fs-13 fw-4 fcn -9 mb-16" > All available logs will be shown.</ div >
189
+ < div className = "fs-13 fw-4 cn -9 mb-16" > All available logs will be shown.</ div >
187
190
< InfoColourBar
188
191
classname = "warn"
189
192
Icon = { Warn }
@@ -194,8 +197,8 @@ export const InputForSelectedOption = ({
194
197
)
195
198
case 'since' :
196
199
return (
197
- < div className = "flexbox-col" >
198
- < div className = "dc__required-field mb-6 fs-13 fcn-7 " > View logs since</ div >
200
+ < div className = "flexbox-col cn-7 " >
201
+ < div className = "dc__required-field mb-6 fs-13" > View logs since</ div >
199
202
< div className = "flexbox-col" >
200
203
< div className = "flex" >
201
204
< SingleDatePicker
@@ -212,7 +215,7 @@ export const InputForSelectedOption = ({
212
215
hideKeyboardShortcutsPanel
213
216
withFullScreenPortal = { false }
214
217
orientation = "horizontal"
215
- customInputIcon = { < CalendarIcon className = "icon-dim-20 " /> }
218
+ customInputIcon = { < CalendarIcon className = "icon-dim-16 " /> }
216
219
isOutsideRange = { ( day ) => moment ( ) . startOf ( 'day' ) . isBefore ( day , 'day' ) }
217
220
/>
218
221
< div className = "flex-grow-1" >
@@ -227,30 +230,32 @@ export const InputForSelectedOption = ({
227
230
IndicatorSeparator : null ,
228
231
ClearIndicator : null ,
229
232
DropdownIndicator,
233
+ Option : ( props ) => < Option { ...props } /> ,
230
234
} }
231
235
styles = { {
236
+ ...multiSelectStyles ,
232
237
control : ( base ) => ( {
233
238
...base ,
234
- display : 'flex' ,
235
- flexDirection : 'row-reverse' ,
236
239
border : '1px solid var(--N200)' ,
240
+ backgroundColor : 'var(--N50)' ,
237
241
borderRadius : '4px' ,
242
+ display : 'flex' ,
243
+ flexDirection : 'row-reverse' ,
238
244
boxShadow : 'none' ,
239
245
cursor : 'pointer' ,
240
- backgroundColor : 'var(--N50)' ,
241
246
} ) ,
242
247
valueContainer : ( base ) => ( {
243
248
...base ,
244
249
padding : '0px 4px' ,
245
250
} ) ,
246
251
} }
247
- isOptionDisabled = { ( option ) => option . isdisabled }
252
+ isOptionDisabled = { ( option ) => option . isDisabled }
248
253
/>
249
254
</ div >
250
255
</ div >
251
256
< div className = "flex mt-4 flex-justify-start" >
252
257
< Info className = "icon-dim-16" />
253
- < div className = "ml-4 fs-11 fw-4 fcn -7" > Browser time zone: { timeZone } </ div >
258
+ < div className = "ml-4 fs-11 fw-4 cn -7" > Browser time zone: { timeZone } </ div >
254
259
</ div >
255
260
</ div >
256
261
</ div >
@@ -295,7 +300,6 @@ const CustomLogsModal = ({
295
300
setSelectedCustomLogFilter,
296
301
setLogsShownOption,
297
302
setNewFilteredLogs,
298
- onLogsCleared,
299
303
setShowCustomOptionsMoadal,
300
304
} : CustomLogsModalProps ) : JSX . Element => {
301
305
const [ customLogFilterOptions , setCustomLogFilterOptions ] = useState < CustomLogFilterOptionsType > (
@@ -310,7 +314,6 @@ const CustomLogsModal = ({
310
314
311
315
const handleSubmitSelectedFilter = ( ) => {
312
316
setShowCustomOptionsMoadal ( false )
313
- onLogsCleared ( )
314
317
setNewFilteredLogs ( true )
315
318
setSelectedCustomLogFilter ( {
316
319
option : filterTypeRadio ,
@@ -326,11 +329,11 @@ const CustomLogsModal = ({
326
329
return (
327
330
< VisibleModal className = "" >
328
331
< div className = "custom-logs-modal w-500 br-4" >
329
- < div className = "flex dc__border-bottom-n1 pt-12 pb-12 pl-20 pr-20" >
332
+ < div className = "flex pt-12 pb-12 pl-20 pr-20" >
330
333
< div className = "fs-16 fw-6" > View Logs</ div >
331
334
< Close className = "icon-dim-24 ml-auto cursor" onClick = { handleClose } />
332
335
</ div >
333
- < div className = "flex dc__border-bottom-n1" >
336
+ < div className = "flex h-200 dc__align-start dc__border-bottom-n1 dc__border-top-n1 h-200 " >
334
337
< RadioGroup
335
338
value = { filterTypeRadio }
336
339
name = "custom-logs"
@@ -339,7 +342,7 @@ const CustomLogsModal = ({
339
342
>
340
343
{ CUSTOM_LOGS_OPTIONS . map ( ( { label, value } ) => (
341
344
< RadioGroupItem value = { value } >
342
- < span > { label } </ span >
345
+ < span className = "custom-selection-radio" > { label } </ span >
343
346
</ RadioGroupItem >
344
347
) ) }
345
348
</ RadioGroup >
@@ -352,7 +355,7 @@ const CustomLogsModal = ({
352
355
</ div >
353
356
</ div >
354
357
< div className = "flex flex-justify-end pt-16 pb-16 pl-20 pr-20" >
355
- < button type = "button" className = "cta cancel h-36 flex mr-16 " onClick = { handleClose } >
358
+ < button type = "button" className = "cta cancel h-36 flex mr-12 " onClick = { handleClose } >
356
359
Cancel
357
360
</ button >
358
361
< button
0 commit comments