Skip to content

Commit 9d6c582

Browse files
committed
Edits long text in new modal
- Modify global.d.ts to export closeModal2 method - Adds unfold icon
1 parent 22afa90 commit 9d6c582

File tree

4 files changed

+134
-24
lines changed

4 files changed

+134
-24
lines changed

frontend/global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare global {
3838
const DYNATRACE_URL: string | undefined
3939
const dtrum: undefined | { identifyUser: (id: string) => void }
4040
const closeModal: () => void
41+
const closeModal2: () => void
4142
const toast: (message: string) => void
4243
const Tooltip: FC<TooltipProps>
4344
}

frontend/web/components/Icon.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type IconName =
4040
| 'moon'
4141
| 'more-vertical'
4242
| 'nav-logo'
43+
| 'unfold'
4344
| 'open-external-link'
4445
| 'options-2'
4546
| 'paste'
@@ -1367,6 +1368,20 @@ const Icon: FC<IconType> = ({ fill, fill2, height, name, width, ...rest }) => {
13671368
</svg>
13681369
)
13691370
}
1371+
case 'unfold': {
1372+
return (
1373+
<svg
1374+
viewBox='0 0 24 24'
1375+
height={height || '16'}
1376+
width={width || '16'}
1377+
fill={fill || '#000000'}
1378+
xmlns='http://www.w3.org/2000/svg'
1379+
>
1380+
<path d='M0 0h24v24H0z' fill='none' />
1381+
<path d='M12 5.83L15.17 9l1.41-1.41L12 3 7.41 7.59 8.83 9 12 5.83zm0 12.34L8.83 15l-1.41 1.41L12 21l4.59-4.59L15.17 15 12 18.17z' />
1382+
</svg>
1383+
)
1384+
}
13701385
default:
13711386
return null
13721387
}

frontend/web/components/Tooltip.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, ReactElement, ReactNode, useRef } from 'react'
1+
import React, { FC, ReactNode } from 'react'
22
import ReactTooltip, { TooltipProps as _TooltipProps } from 'react-tooltip'
33
import Utils from 'common/utils/utils'
44
import classNames from 'classnames'

frontend/web/components/modals/RuleInputValue.tsx

+117-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import React, { RefObject, useRef } from 'react'
1+
import React from 'react'
22
import Input from 'components/base/forms/Input'
3+
import Icon from 'components/Icon'
4+
import InputGroup from 'components/base/forms/InputGroup'
5+
import Button from 'components/base/forms/Button'
6+
import Utils from 'common/utils/utils'
7+
import ModalHR from './ModalHR'
38

49
type RuleInputValueProps = {
510
'data-test'?: string
@@ -10,7 +15,72 @@ type RuleInputValueProps = {
1015
disabled?: boolean
1116
readOnly?: boolean
1217
isValid?: boolean
13-
error?: string
18+
}
19+
20+
const TextAreaModal = ({
21+
disabled,
22+
isValid,
23+
onChange,
24+
placeholder,
25+
readOnly,
26+
style,
27+
value,
28+
}: RuleInputValueProps) => {
29+
const [textAreaValue, setTextAreaValue] = React.useState(value)
30+
31+
return (
32+
<div>
33+
<div className='modal-body'>
34+
<InputGroup
35+
id='rule-value-textarea'
36+
data-test='rule-value-textarea'
37+
value={textAreaValue}
38+
inputProps={{
39+
style: style,
40+
}}
41+
isValid={isValid}
42+
onChange={(e: InputEvent) => {
43+
const value = Utils.safeParseEventValue(e)
44+
setTextAreaValue(value.replace(/\n/g, ''))
45+
}}
46+
type='text'
47+
className='w-100'
48+
readOnly={readOnly}
49+
placeholder={placeholder}
50+
disabled={disabled}
51+
textarea
52+
/>
53+
</div>
54+
<ModalHR />
55+
<div className='modal-footer'>
56+
<Button
57+
className='mr-2'
58+
theme='secondary'
59+
id='rule-value-textarea-cancel'
60+
data-tests='rule-value-textarea-cancel'
61+
onClick={closeModal2}
62+
>
63+
Cancel
64+
</Button>
65+
<Button
66+
type='button'
67+
id='rule-value-textarea-save'
68+
data-tests='rule-value-textarea-save'
69+
onClick={() => {
70+
const event = new InputEvent('input', { bubbles: true })
71+
Object.defineProperty(event, 'target', {
72+
value: { value: textAreaValue },
73+
writable: false,
74+
})
75+
onChange?.(event)
76+
closeModal2()
77+
}}
78+
>
79+
Apply
80+
</Button>
81+
</div>
82+
</div>
83+
)
1484
}
1585

1686
const RuleInputValue = (props: RuleInputValueProps) => {
@@ -29,8 +99,6 @@ const RuleInputValue = (props: RuleInputValueProps) => {
2999
isOnlyWhitespace
30100
const isLongText = String(value).length >= 10
31101

32-
const ref = useRef(null)
33-
34102
const validate = () => {
35103
if (isOnlyWhitespace) {
36104
return 'This value is only whitespaces'
@@ -45,31 +113,57 @@ const RuleInputValue = (props: RuleInputValueProps) => {
45113
return 'This value ends with whitespaces'
46114
}
47115
if (isLongText) {
48-
return String(value)
116+
return 'Click to edit text in a larger area'
49117
}
50118
return ''
51119
}
52120

121+
const showIcon = hasWarning || isLongText
53122
return (
54-
<Tooltip
55-
title={
56-
<div>
57-
<Input
58-
type='text'
59-
{...props}
60-
ref={ref}
61-
inputClassName={hasWarning && 'border-warning'}
62-
/>
123+
<div className='relative'>
124+
<Input
125+
type='text'
126+
{...props}
127+
inputClassName={
128+
showIcon ? `pr-5 ${hasWarning ? 'border-warning' : ''}` : ''
129+
}
130+
/>
131+
{showIcon && (
132+
<div style={{ position: 'absolute', right: 5, top: 10 }}>
133+
<Tooltip
134+
title={
135+
<div
136+
className={`flex bg-white bg-opacity-10 rounded-2 p-1 ${
137+
hasWarning ? '' : 'cursor-pointer'
138+
}`}
139+
onClick={() => {
140+
if (hasWarning) return
141+
openModal2(
142+
'Edit Value',
143+
<TextAreaModal
144+
value={value}
145+
onChange={props.onChange}
146+
isValid={props.isValid}
147+
/>,
148+
)
149+
}}
150+
>
151+
<Icon
152+
name={hasWarning ? 'warning' : 'unfold'}
153+
fill={hasWarning ? undefined : '#fff'}
154+
width={18}
155+
height={18}
156+
/>
157+
</div>
158+
}
159+
place='top'
160+
effect='solid'
161+
>
162+
{validate()}
163+
</Tooltip>
63164
</div>
64-
}
65-
place='top'
66-
effect='solid'
67-
afterShow={() => {
68-
;(ref as RefObject<HTMLElement>).current?.focus()
69-
}}
70-
>
71-
{validate()}
72-
</Tooltip>
165+
)}
166+
</div>
73167
)
74168
}
75169

0 commit comments

Comments
 (0)