Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group special-components by type #280

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions src/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const editDepOfComp = (depName, component, actionObject) => {
const reorderDep = (dependencies, fromIndex, toIndex) => {
return dependencies.map((d) => {
if (d.disabled) return d

if (d.name === depName) d.position = toIndex
else if (d.position > fromIndex && d.position <= toIndex) d.position -= 1
else if (d.position < fromIndex && d.position >= toIndex) d.position += 1
Expand Down Expand Up @@ -270,6 +270,14 @@ const SpecialComponents = () => {
}

const mergedSpecialComponents = getMergedSpecialComponents(specialComponentsFeature)
const specialComponentsByType = mergedSpecialComponents.reduce((group, element) => {
return {
...group,
[element.type]: group[element.type]
? [...group[element.type], element]
: [element],
}
}, {})

const handleDragEnd = (result) => {
if (!result.destination || result.reason === 'CANCEL' || result.destination.index === result.source.index) return
Expand All @@ -295,21 +303,33 @@ const SpecialComponents = () => {
specialComponentsFeature.triggerRerender()
}

const specialComponentTypes = [... new Set(mergedSpecialComponents.map(c => c.type))]
const specialComponentTypes = Object.keys(specialComponentsByType)

return <>
<DragDropContext onDragEnd={handleDragEnd}>
<Grid container spacing={2}>
<Stack
direction='column'
spacing={2}
>
{
mergedSpecialComponents.map((component) => {
return <SpecialComponent
key={`${component.id}-${component.isAddedByUser}`}
component={component}
specialComponentsFeature={specialComponentsFeature}
/>
})
Object.entries(specialComponentsByType).map(([type, components]) => {
return <Box key={type}>
<Typography>{type}</Typography>
<Grid container spacing={2}>
{
components.map((component) => {
return <SpecialComponent
key={`${component.id}-${component.isAddedByUser}`}
component={component}
specialComponentsFeature={specialComponentsFeature}
/>
})
}
</Grid>
</Box>
} )
}
</Grid>
</Stack>
</DragDropContext>
<Fab
style={{backgroundColor: theme.dependentComponentOverview.color, color: theme.bomButton.color, position: 'fixed', bottom: '1.5rem', right: '1.5rem'}}
Expand Down Expand Up @@ -390,7 +410,7 @@ const SpecialComponentDialog = ({
<DialogTitle>Add Component to Overview</DialogTitle>
<DialogContent>
<DialogContentText>
To add a component, please enter its component name and the preferred
To add a component, please enter its component name and the preferred
displayed name. Also, specify the type which is used to group multiple
components as well as the repository context.
</DialogContentText>
Expand Down Expand Up @@ -878,7 +898,7 @@ const ComponentHeader = ({
}
{
isError ? <Typography variant='caption'>Error fetching Component</Typography> : (isEditMode ? <form>
<input type='text' onClick={(e) => e.preventDefault()} onChange={handleChangeDisplayName} defaultValue={component.displayName} maxLength={30}/>
<input type='text' onClick={(e) => e.preventDefault()} onChange={handleChangeDisplayName} defaultValue={component.displayName} maxLength={30}/>
</form> : <Typography style={{ fontSize: 'medium', fontWeight: 'bold' }}>
{component.displayName}
</Typography>)
Expand Down