I have a table element with items set in an array of object that I am using to filter through.
Right now I have the filter working however I need to update the state of the profile items I am filtering through. I am showing the filtered items in a table, and selecting an item via a select dropdown.
I need to loop through profiles and find the value for BiosafetlyLevelId + update state for profiles.
How can I do this?
useEffect(() => {
setError(false)
setLoading(true)
// Get Data
$.ajax({
method: 'GET',
url: `${API_HOST}/api-bsl`
})
.done((data) => {
const profiles = JSON.parse(data)
console.log('profile', profiles)
setProfiles(
profiles.length > 0 ? profiles.sort((a, b) => a.name.localeCompare(b.name)) : []
)
const selectProfile = createSelectList(profiles, 'biosafetyLevelId', 'name')
setArrayState(selectProfile)
setLoading(false)
})
.fail(() => {
setError(true)
setLoading(false)
setProfiles(null)
})
}, [])
<div className='content column white-bg search'>
<Select
options={arrayState}
onChange={(value) => setChangeState(value)}
value={changeState}
required
inForm
parentClass='form-group-column'
label='Select Biosafety Level'
addEmpty
emptyLabel='Select Biosafety Level'
id='user_type'
error={error && profiles === ''}
/>
</div>
<table className='fixed-header lab-profile-menu-sub-row'>
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
{profiles !== null &&
profiles.length > 0 &&
profiles.map((profile) => (
<tr key={profile.uuid}>
<td>{profile.name}</td>
<td>
<Button
onClick={() => toggleBioProfileModal(profile, true)}
className='add-edit-button'
>
Edit
</Button>
</td>
</tr>
))}
</tbody>
</table>