1- import { Autocomplete , Notice , Typography } from '@linode/ui' ;
1+ import { Autocomplete , Notice , TextField , Typography } from '@linode/ui' ;
22import { useTheme } from '@mui/material' ;
33import React from 'react' ;
44
55import { FormLabel } from 'src/components/FormLabel' ;
66import { Link } from 'src/components/Link' ;
77import { useAccountEntities } from 'src/queries/entities/entities' ;
88
9+ import { type DrawerModes , getFormattedEntityType } from '../utilities' ;
910import {
1011 getCreateLinkForEntityType ,
11- getFormattedEntityType ,
12- placeholderMap ,
13- transformedAccountEntities ,
14- } from '../utilities ' ;
12+ getEntitiesByType ,
13+ getPlaceholder ,
14+ mapEntitiesToOptions ,
15+ } from './utils ' ;
1516
16- import type { DrawerModes , EntitiesOption } from '../utilities ' ;
17+ import type { EntitiesOption } from '../types ' ;
1718import type {
18- AccountEntity ,
1919 EntityType ,
2020 EntityTypePermissions ,
2121 IamAccessType ,
@@ -46,16 +46,18 @@ export const Entities = ({
4646 return [ ] ;
4747 }
4848 const typeEntities = getEntitiesByType ( type , entities . data ) ;
49- return typeEntities ? transformedEntities ( typeEntities ) : [ ] ;
49+ return typeEntities ? mapEntitiesToOptions ( typeEntities ) : [ ] ;
5050 } , [ entities , access , type ] ) ;
5151
5252 if ( access === 'account_access' ) {
5353 return (
5454 < >
5555 < FormLabel >
5656 < Typography
57- marginBottom = { 0.5 }
58- sx = { { marginTop : theme . tokens . spacing . S12 } }
57+ sx = { {
58+ marginTop : theme . tokens . spacing . S12 ,
59+ marginBottom : theme . tokens . spacing . S4 ,
60+ } }
5961 variant = "inherit"
6062 >
6163 Entities
@@ -73,7 +75,7 @@ export const Entities = ({
7375 return (
7476 < >
7577 < Autocomplete
76- errorText = { errorText }
78+ disabled = { ! memoizedEntities . length }
7779 getOptionLabel = { ( option ) => option . label }
7880 isOptionEqualToValue = { ( option , value ) => option . value === value . value }
7981 label = "Entities"
@@ -88,7 +90,20 @@ export const Entities = ({
8890 value . length ,
8991 memoizedEntities . length
9092 ) }
91- readOnly = { getReadonlyState ( mode , memoizedEntities . length ) }
93+ readOnly = { mode === 'change-role' }
94+ renderInput = { ( params ) => (
95+ < TextField
96+ { ...params }
97+ error = { ! ! errorText }
98+ errorText = { errorText }
99+ label = "Entities"
100+ placeholder = { getPlaceholder (
101+ type ,
102+ value . length ,
103+ memoizedEntities . length
104+ ) }
105+ />
106+ ) }
92107 sx = { { marginTop : theme . tokens . spacing . S12 } }
93108 value = { value || [ ] }
94109 />
@@ -105,38 +120,3 @@ export const Entities = ({
105120 </ >
106121 ) ;
107122} ;
108-
109- const getPlaceholder = (
110- type : EntityType | EntityTypePermissions ,
111- currentValueLength : number ,
112- possibleEntitiesLength : number
113- ) : string =>
114- currentValueLength > 0
115- ? ' '
116- : possibleEntitiesLength === 0
117- ? 'None'
118- : placeholderMap [ type ] || 'Select' ;
119-
120- const getReadonlyState = (
121- mode : DrawerModes | undefined ,
122- possibleEntitiesLength : number
123- ) : boolean => mode === 'change-role' || possibleEntitiesLength === 0 ;
124-
125- const transformedEntities = (
126- entities : { id : number ; label : string } [ ]
127- ) : EntitiesOption [ ] => {
128- return entities . map ( ( entity ) => ( {
129- label : entity . label ,
130- value : entity . id ,
131- } ) ) ;
132- } ;
133-
134- const getEntitiesByType = (
135- roleEntityType : EntityType | EntityTypePermissions ,
136- entities : AccountEntity [ ]
137- ) : Pick < AccountEntity , 'id' | 'label' > [ ] | undefined => {
138- const entitiesMap = transformedAccountEntities ( entities ) ;
139-
140- // Find the first matching entity by type
141- return entitiesMap . get ( roleEntityType as EntityType ) ;
142- } ;
0 commit comments