Skip to content

Commit

Permalink
- Fixes inability to delete single profiles
Browse files Browse the repository at this point in the history
- Minor UI and scss changes
- Profile dropdown defaults to the first profile in the list
- Scrollbar 'follows' new additions of profiles.

Signed-off-by: Nkeiruka <[email protected]>
  • Loading branch information
Kxiru committed May 24, 2024
1 parent bcad8b1 commit 74d0169
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/components/ScrollableContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const ScrollableContainer: FC<Props> = ({

return (
<div ref={ref} className={classnames("scrollable-container", className)}>
<div className="content-details">{children}</div>
<div id="content-details" className="content-details">
{children}
</div>
</div>
);
};
Expand Down
104 changes: 59 additions & 45 deletions src/pages/profiles/ProfileSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react";
import { FC, useEffect } from "react";
import {
Button,
Icon,
Expand Down Expand Up @@ -38,6 +38,14 @@ const ProfileSelector: FC<Props> = ({
queryFn: () => fetchProfiles(project),
});

useEffect(() => {
const contentdetails = document.getElementById("content-details");

if (contentdetails) {
contentdetails.scrollTop = contentdetails.scrollHeight;
}
}, [selected]);

if (isLoading) {
return <Loader text="Loading profiles..." />;
}
Expand All @@ -53,7 +61,7 @@ const ProfileSelector: FC<Props> = ({
);

const addProfile = () => {
const nextProfile = unselected.pop()?.name;
const nextProfile = unselected[0]?.name;
if (nextProfile) {
setSelected([...selected, nextProfile]);
}
Expand Down Expand Up @@ -94,59 +102,65 @@ const ProfileSelector: FC<Props> = ({
title={title}
></Select>
</div>
{!readOnly && (index > 0 || selected.length > 1) && (
<div>
<Button
appearance="link"
className="profile-action-btn"
onClick={() => {
const newSelection = [...selected];
newSelection.splice(index, 1);
newSelection.splice(index - 1, 0, value);
setSelected(newSelection);
}}
type="button"
aria-label="move profile up"
title="move profile up"
disabled={index === 0}
>
<Icon name="chevron-up" />
</Button>
<Button
appearance="link"
className="profile-action-btn"
onClick={() => {
const newSelection = [...selected];
newSelection.splice(index, 1);
newSelection.splice(index + 1, 0, value);
setSelected(newSelection);
}}
type="button"
aria-label="move profile down"
title="move profile down"
disabled={index === selected.length - 1}
>
<Icon name="chevron-down" />
</Button>
{index > 0 && (

<div className="profile-actions">
{!readOnly && (index > 0 || selected.length > 1) && (
<div>
<Button
appearance="link"
className="profile-delete-btn"
onClick={() =>
setSelected(selected.filter((item) => item !== value))
}
className="profile-action-btn"
onClick={() => {
const newSelection = [...selected];
newSelection.splice(index, 1);
newSelection.splice(index - 1, 0, value);
setSelected(newSelection);
}}
type="button"
aria-label="move profile up"
title="move profile up"
disabled={index === 0}
>
Delete
<Icon name="chevron-up" />
</Button>
)}
</div>
)}
<Button
appearance="link"
className="profile-action-btn"
onClick={() => {
const newSelection = [...selected];
newSelection.splice(index, 1);
newSelection.splice(index + 1, 0, value);
setSelected(newSelection);
}}
type="button"
aria-label="move profile down"
title="move profile down"
disabled={index === selected.length - 1}
>
<Icon name="chevron-down" />
</Button>
</div>
)}

{!readOnly && (
<Button
appearance="link"
className="profile-remove-btn"
onClick={() =>
setSelected(selected.filter((item) => item !== value))
}
type="button"
>
Remove
</Button>
)}
</div>
</div>
))}
{!readOnly && (
<Button
id="addProfileButton"
disabled={unselected.length === 0}
className="profile-add-btn"
onClick={addProfile}
type="button"
>
Expand Down
17 changes: 13 additions & 4 deletions src/sass/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,23 @@
}
}

.profile-action-btn {
margin-right: $sph--large;
.profile-actions {
display: flex;

.profile-action-btn {
margin-right: $sph--large;
}
}

.profile-delete-btn {
.profile-remove-btn {
align-self: flex-start;
margin-left: $sph--large;
}

.profile-add-btn {
display: block;
}

.delete-device {
margin-top: $spv--x-large;
}
Expand All @@ -111,7 +120,7 @@
}
}

@media screen and (width <= 1400px) {
@media screen and (width <=1400px) {
.cpu-limit-label,
.memory-limit-label {
display: block !important;
Expand Down

0 comments on commit 74d0169

Please sign in to comment.