@@ -2,11 +2,12 @@ import React, { useEffect } from 'react';
2
2
import Box from '@mui/material/Box' ;
3
3
import CustomTextField from './CustomTextField' ;
4
4
import { DropdownV2 } from '../../../elements/dropdownV2' ;
5
- import { RadioButtonItemProps } from '../../../forms' ;
6
5
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined' ;
7
6
import IconButton from '@mui/material/IconButton' ;
8
- import { useMediaQuery } from '@mui/material' ;
7
+ import { ThemeProvider , Tooltip } from '@mui/material' ;
9
8
import { MetadataType } from './MetadataKeyValueList' ;
9
+ import { ErroredTooltip , TooltipVariant } from '../../../elements/tooltipV2/ErroredTooltip' ;
10
+ import theme from '../../../../theme' ;
10
11
11
12
export interface MetadataKeyValuePairProps {
12
13
index : number ;
@@ -75,108 +76,124 @@ export function MetadataKeyValuePair({
75
76
] ;
76
77
77
78
return (
78
- < Box
79
- sx = { {
80
- display : 'flex' ,
81
- flexDirection : 'row' ,
82
- width : '100%' ,
83
- height : '100%' ,
84
- backgroundColor : '#F8FAFC' ,
85
- borderBottom : '1px solid #E2E8F0' ,
86
- alignItems : 'center' ,
87
- flexWrap : isNewlyCreated ? 'wrap' : 'nowrap' ,
88
- } }
89
- >
79
+ < ThemeProvider theme = { theme } >
90
80
< Box
91
81
sx = { {
92
82
display : 'flex' ,
93
- flexShrink : 1 ,
94
- flexGrow : 1 ,
95
- maxWidth : '100%' ,
96
- minWidth : '35%' ,
97
- } }
98
- >
99
- { /*key name should not be editable unless its newly created*/ }
100
- < CustomTextField
101
- readOnly = { ! isNewlyCreated }
102
- value = { keyName }
103
- onInputSave = { ( newVal ) => {
104
- if ( saveKeyNameLocally ) {
105
- saveKeyNameLocally ( index , newVal ) ;
106
- }
107
- } }
108
- helperText = { description }
109
- placeholder = { isNewlyCreated || ! value ? 'Enter field name' : 'Typing...' }
110
- shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
111
- autoFocus = { autoFocusKey }
112
- />
113
- </ Box >
114
- < Box
115
- sx = { {
116
- display : 'flex' ,
117
- flexGrow : 1 ,
118
- maxWidth : '100%' ,
119
- gap : '8px' ,
120
- flexShrink : 1 ,
121
- minWidth : '65%' ,
83
+ flexDirection : 'row' ,
84
+ width : '100%' ,
122
85
height : '100%' ,
86
+ backgroundColor : '#F8FAFC' ,
87
+ borderBottom : '1px solid #E2E8F0' ,
88
+ alignItems : 'center' ,
89
+ flexWrap : isNewlyCreated ? 'wrap' : 'nowrap' ,
123
90
} }
124
91
>
125
- { isNewlyCreated && (
126
- < div style = { { width : '100%' , maxWidth : '130px' } } >
127
- < DropdownV2
128
- onChange = { ( event , value ) => {
129
- if ( saveValueTypeLocally ) {
130
- saveValueTypeLocally ( index , value ?. id ) ;
131
- }
132
- } }
133
- options = { valueTypes }
134
- isReadOnly = { true }
135
- label = { 'Value type' }
136
- errored = { false }
137
- maxWidth = { '130px' }
138
- height = { '100%' }
139
- isSquareCorners = { true }
140
- withoutBorder = { true }
141
- backgroundColorFocus = { 'white' }
142
- disableClearable
143
- shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
144
- />
145
- </ div >
146
- ) }
147
- < CustomTextField
148
- readOnly = { ! isEditable }
149
- value = { value }
150
- onInputSave = { ( newVal ) => {
151
- if ( ! ! validateValueByType && ! ! valueType ) {
152
- setIsErrored ( ! validateValueByType ( valueType , newVal as string ) ) ;
153
- }
154
- if ( saveValueLocally ) {
155
- saveValueLocally ( index , newVal ) ;
156
- }
92
+ < Box
93
+ sx = { {
94
+ display : 'flex' ,
95
+ flexShrink : 1 ,
96
+ flexGrow : 1 ,
97
+ maxWidth : '100%' ,
98
+ minWidth : '35%' ,
157
99
} }
158
- onInputChange = { ( newVal ) => {
159
- if ( ! ! validateValueByType && ! ! valueType ) {
160
- setIsErrored ( ! validateValueByType ( valueType , newVal as string ) ) ;
161
- }
100
+ >
101
+ { /*key name should not be editable unless its newly created*/ }
102
+ < Tooltip title = { keyName } disableInteractive = { true } arrow = { true } placement = { 'top' } >
103
+ < div style = { { width : '100%' } } >
104
+ < CustomTextField
105
+ readOnly = { ! isNewlyCreated }
106
+ value = { keyName }
107
+ onInputSave = { ( newVal ) => {
108
+ if ( saveKeyNameLocally ) {
109
+ saveKeyNameLocally ( index , newVal ) ;
110
+ }
111
+ } }
112
+ helperText = { description }
113
+ placeholder = { isNewlyCreated || ! value ? 'Enter field name' : 'Typing...' }
114
+ shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
115
+ autoFocus = { autoFocusKey }
116
+ />
117
+ </ div >
118
+ </ Tooltip >
119
+ </ Box >
120
+ < Box
121
+ sx = { {
122
+ display : 'flex' ,
123
+ flexGrow : 1 ,
124
+ maxWidth : '100%' ,
125
+ gap : '8px' ,
126
+ flexShrink : 1 ,
127
+ minWidth : '65%' ,
128
+ height : '100%' ,
162
129
} }
163
- placeholder = { isNewlyCreated || ! value ? 'Add value' : 'Typing...' }
164
- shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
165
- isErrored = { isErrored } //TODO: add validation
166
- />
167
- { isEditable && isRemovable && (
168
- < IconButton
169
- style = { { marginRight : '8px' , height : '100%' , padding : '6px' } }
170
- onClick = { ( ) => {
171
- if ( deleteFieldPermanently ) {
172
- deleteFieldPermanently ( index ) ;
173
- }
174
- } }
130
+ >
131
+ { isNewlyCreated && (
132
+ < div style = { { width : '100%' , maxWidth : '130px' } } >
133
+ < DropdownV2
134
+ onChange = { ( event , value ) => {
135
+ if ( saveValueTypeLocally ) {
136
+ saveValueTypeLocally ( index , value ?. id ) ;
137
+ }
138
+ } }
139
+ options = { valueTypes }
140
+ isReadOnly = { true }
141
+ label = { 'Value type' }
142
+ errored = { false }
143
+ maxWidth = { '130px' }
144
+ height = { '100%' }
145
+ isSquareCorners = { true }
146
+ withoutBorder = { true }
147
+ backgroundColorFocus = { 'white' }
148
+ disableClearable
149
+ shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
150
+ />
151
+ </ div >
152
+ ) }
153
+ < ErroredTooltip
154
+ title = { isErrored ? 'Value is not valid' : '' }
155
+ placement = { 'top' }
156
+ disableInteractive = { true }
157
+ open = { isErrored }
158
+ tooltipVariant = { TooltipVariant . Error }
175
159
>
176
- < DeleteOutlinedIcon style = { { color : 'rgba(148, 163, 184, 1)' } } fontSize = { 'medium' } />
177
- </ IconButton >
178
- ) }
160
+ < div style = { { width : '100%' } } >
161
+ < CustomTextField
162
+ readOnly = { ! isEditable }
163
+ value = { value }
164
+ onInputSave = { ( newVal ) => {
165
+ if ( ! ! validateValueByType && ! ! valueType ) {
166
+ setIsErrored ( ! validateValueByType ( valueType , newVal as string ) ) ;
167
+ }
168
+ if ( saveValueLocally ) {
169
+ saveValueLocally ( index , newVal ) ;
170
+ }
171
+ } }
172
+ onInputChange = { ( newVal ) => {
173
+ if ( ! ! validateValueByType && ! ! valueType ) {
174
+ setIsErrored ( ! validateValueByType ( valueType , newVal as string ) ) ;
175
+ }
176
+ } }
177
+ placeholder = { isNewlyCreated || ! value ? 'Add value' : 'Typing...' }
178
+ shouldHighlightIfEmpty = { shouldHighlightEmptyFields }
179
+ isErrored = { isErrored } //TODO: add validation
180
+ />
181
+ </ div >
182
+ </ ErroredTooltip >
183
+ { isEditable && isRemovable && (
184
+ < IconButton
185
+ style = { { marginRight : '8px' , height : '100%' , padding : '6px' } }
186
+ onClick = { ( ) => {
187
+ if ( deleteFieldPermanently ) {
188
+ deleteFieldPermanently ( index ) ;
189
+ }
190
+ } }
191
+ >
192
+ < DeleteOutlinedIcon style = { { color : 'rgba(148, 163, 184, 1)' } } fontSize = { 'medium' } />
193
+ </ IconButton >
194
+ ) }
195
+ </ Box >
179
196
</ Box >
180
- </ Box >
197
+ </ ThemeProvider >
181
198
) ;
182
199
}
0 commit comments