Skip to content

Commit

Permalink
UploadDevicesTypeFieldsMatcherOne
Browse files Browse the repository at this point in the history
  • Loading branch information
erasta committed Nov 19, 2024
1 parent 33e56f3 commit 12609af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
4 changes: 3 additions & 1 deletion client/src/IO/UploadDevices/UploadDevicesButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const UploadDevicesButton = ({
accept=".json,.geojson,.csv,.zip"
tooltip={'Upload devices as geojson, csv, zip of csvs'}
onChange={handleChangeFile}
onClickCapture={() => setCurrTrial({ experimentName: experiment.name, trialTypeName: trialType.name, trialName: trial.name })}
onClickCapture={() => {
setCurrTrial({ experimentName: experiment.name, trialTypeName: trialType.name, trialName: trial.name })
}}
disabled={working}
>
{working
Expand Down
58 changes: 33 additions & 25 deletions client/src/IO/UploadDevices/UploadDevicesTypeFieldsMatcher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ function uniq(list) {
return list.reduce((acc, d) => acc.includes(d) ? acc : acc.concat(d), []);
}

const UploadDevicesTypeFieldsMatcherOne = ({ oneMatch, setOneMatch, attrName, attrOptions }) => {
const locationUnassigned = oneMatch === FIELD_UNASSIGNED && LOCATION_FIELDS.includes(attrName);
return (
<Grid container direction='row'>
<Grid item xs={3} alignSelf={'center'}>
<Typography>{attrName}</Typography>
</Grid>
<Grid item xs={4}>
<SelectProperty
styleFormControl={{ width: '100%' }}
label={attrName}
data={oneMatch}
setData={v => setOneMatch(v)}
options={attrOptions}
/>
</Grid>
<Grid item xs={2} alignSelf={'center'} sx={{ margin: 1, color: 'red' }}>
{!locationUnassigned ? null :
<Typography>Assign location fields</Typography>
}
</Grid>
</Grid>
)
}

export const UploadDevicesTypeFieldsMatcher = ({ devicesDetails, deviceType, attrMatch, setAttrMatch }) => {
const fieldNamesOnDetails = uniq(devicesDetails.flatMap(x => {
return Object.keys(x.attributes).filter(f => !IGNORE_FIELDS.includes(f));
Expand All @@ -28,31 +53,14 @@ export const UploadDevicesTypeFieldsMatcher = ({ devicesDetails, deviceType, att

return (
<Stack direction='column' spacing={1} sx={{ margin: 1 }}>
{attributeTypeNames.map((attrName, i) => {
const oneMatch = attrMatch[attrName] || FIELD_UNASSIGNED;
const locationUnassigned = oneMatch === FIELD_UNASSIGNED && LOCATION_FIELDS.includes(attrName);
return (
<Grid container direction='row' key={i}>
<Grid item xs={3} alignSelf={'center'}>
<Typography key={'a' + i}>{attrName}</Typography>
</Grid>
<Grid item xs={4}>
<SelectProperty
styleFormControl={{ width: '100%' }}
label={attrName}
data={attrMatch[attrName] || FIELD_UNASSIGNED}
setData={v => setAttrMatch({ ...attrMatch, [attrName]: v })}
options={attrOptions}
/>
</Grid>
<Grid item xs={2} alignSelf={'center'} sx={{ margin: 1, color: 'red' }}>
{!locationUnassigned ? null :
<Typography>Assign location fields</Typography>
}
</Grid>
</Grid>
)
})}
{attributeTypeNames.map((attrName, i) => (
<UploadDevicesTypeFieldsMatcherOne key={i}
attrName={attrName}
oneMatch={attrMatch[attrName] || FIELD_UNASSIGNED}
setOneMatch={v => setAttrMatch({ ...attrMatch, [attrName]: v })}
attrOptions={attrOptions}
/>
))}
</Stack>
)
}

0 comments on commit 12609af

Please sign in to comment.