5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { Chip , FormControl , Grid , IconButton , Tooltip } from '@mui/material' ;
8
+ import { Box , Chip , FormControl , FormHelperText , Grid , IconButton , Tooltip } from '@mui/material' ;
9
9
import { Folder as FolderIcon } from '@mui/icons-material' ;
10
10
import { useCallback , useMemo , useState } from 'react' ;
11
11
import { FieldValues , useController , useFieldArray } from 'react-hook-form' ;
12
- import { useIntl } from 'react-intl' ;
12
+ import { FormattedMessage , useIntl } from 'react-intl' ;
13
13
import { UUID } from 'crypto' ;
14
14
import { RawReadOnlyInput } from './RawReadOnlyInput' ;
15
- import { FieldLabel } from './utils/FieldLabel' ;
16
- import { useCustomFormContext } from './provider/useCustomFormContext' ;
17
- import { isFieldRequired } from './utils/functions' ;
18
- import { ErrorInput } from './errorManagement/ErrorInput' ;
19
- import { useSnackMessage } from '../../../hooks/useSnackMessage' ;
15
+ import { FieldLabel , isFieldRequired } from './utils' ;
16
+ import { useCustomFormContext } from './provider' ;
17
+ import { ErrorInput , MidFormError } from './errorManagement' ;
18
+ import { useSnackMessage } from '../../../hooks' ;
20
19
import { TreeViewFinderNodeProps } from '../../treeViewFinder' ;
21
- import { mergeSx , type MuiStyles } from '../../../utils/styles' ;
20
+ import { type MuiStyles } from '../../../utils/styles' ;
22
21
import { OverflowableText } from '../../overflowableText' ;
23
- import { MidFormError } from './errorManagement/MidFormError' ;
24
- import { DirectoryItemSelector } from '../../directoryItemSelector/DirectoryItemSelector' ;
22
+ import { DirectoryItemSelector } from '../../directoryItemSelector' ;
25
23
import { fetchDirectoryElementPath } from '../../../services' ;
26
- import { ElementAttributes } from '../../../utils' ;
24
+ import { ElementAttributes , mergeSx } from '../../../utils' ;
27
25
import { NAME } from './constants' ;
26
+ import { getFilterEquipmentTypeLabel } from '../../filter/expert/expertFilterUtils' ;
28
27
29
28
const styles = {
30
29
formDirectoryElements1 : {
@@ -67,6 +66,7 @@ export interface DirectoryItemsInputProps {
67
66
disable ?: boolean ;
68
67
allowMultiSelect ?: boolean ;
69
68
labelRequiredFromContext ?: boolean ;
69
+ equipmentColorsMap ?: Map < string , string > ;
70
70
}
71
71
72
72
export function DirectoryItemsInput ( {
@@ -82,6 +82,7 @@ export function DirectoryItemsInput({
82
82
disable = false ,
83
83
allowMultiSelect = true ,
84
84
labelRequiredFromContext = true ,
85
+ equipmentColorsMap,
85
86
} : Readonly < DirectoryItemsInputProps > ) {
86
87
const { snackError } = useSnackMessage ( ) ;
87
88
const intl = useIntl ( ) ;
@@ -94,7 +95,7 @@ export function DirectoryItemsInput({
94
95
fields : elements ,
95
96
append,
96
97
remove,
97
- } = useFieldArray ( {
98
+ } = useFieldArray < { [ key : string ] : TreeViewFinderNodeProps [ ] } > ( {
98
99
name,
99
100
} ) ;
100
101
@@ -189,18 +190,44 @@ export function DirectoryItemsInput({
189
190
{ elements ?. length > 0 && (
190
191
< FormControl sx = { styles . formDirectoryElements2 } >
191
192
{ elements . map ( ( item , index ) => (
192
- < Chip
193
+ < Box
193
194
key = { item . id }
194
- size = "small"
195
- onDelete = { ( ) => removeElements ( index ) }
196
- onClick = { ( ) => handleChipClick ( index ) }
197
- label = {
198
- < OverflowableText
199
- text = { < RawReadOnlyInput name = { `${ name } .${ index } .${ NAME } ` } /> }
200
- sx = { { width : '100%' } }
201
- />
202
- }
203
- />
195
+ sx = { { display : 'flex' , alignItems : 'center' , flexDirection : 'column' , gap : 1 } }
196
+ >
197
+ < Chip
198
+ size = "small"
199
+ sx = { {
200
+ backgroundColor :
201
+ item ?. specificMetadata ?. equipmentType &&
202
+ equipmentColorsMap ?. get ( item ?. specificMetadata ?. equipmentType ) ,
203
+ } }
204
+ onDelete = { ( ) => removeElements ( index ) }
205
+ onClick = { ( ) => handleChipClick ( index ) }
206
+ label = {
207
+ < OverflowableText
208
+ text = {
209
+ getValues ( `${ name } .${ index } .${ NAME } ` ) ? (
210
+ < RawReadOnlyInput name = { `${ name } .${ index } .${ NAME } ` } />
211
+ ) : (
212
+ intl . formatMessage ( { id : 'elementNotFound' } )
213
+ )
214
+ }
215
+ sx = { { width : '100%' } }
216
+ />
217
+ }
218
+ />
219
+ { equipmentColorsMap && (
220
+ < FormHelperText >
221
+ { item ?. specificMetadata ?. equipmentType ? (
222
+ < FormattedMessage
223
+ id = { getFilterEquipmentTypeLabel ( item . specificMetadata . equipmentType ) }
224
+ />
225
+ ) : (
226
+ ''
227
+ ) }
228
+ </ FormHelperText >
229
+ ) }
230
+ </ Box >
204
231
) ) }
205
232
</ FormControl >
206
233
) }
0 commit comments