Skip to content

Commit

Permalink
fix(detailed pages): Make delete btns more visible on detail pages
Browse files Browse the repository at this point in the history
update breakpoint, btn look and text and new hook
  • Loading branch information
aaryanporwal authored and edlerd committed May 31, 2023
1 parent 27a1f06 commit 4b69109
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
13 changes: 13 additions & 0 deletions src/context/useDeleteIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import useEventListener from "@use-it/event-listener";
import { useState } from "react";
import { isWidthBelow } from "util/helpers";

export const useDeleteIcon = (): boolean => {
const [isSmallScreen, setIsSmallScreen] = useState(isWidthBelow(620));
const handleResize = () => {
const newSmall = isWidthBelow(620);
newSmall !== isSmallScreen && setIsSmallScreen(newSmall);
};
useEventListener("resize", handleResize);
return isSmallScreen;
};
11 changes: 7 additions & 4 deletions src/pages/instances/actions/DeleteInstanceBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { useNavigate } from "react-router-dom";
import { useNotify } from "context/notify";
import ItemName from "components/ItemName";
import { deletableStatuses } from "util/instanceDelete";
import { useDeleteIcon } from "context/useDeleteIcon";

interface Props {
instance: LxdInstance;
}

const DeleteInstanceBtn: FC<Props> = ({ instance }) => {
const isDeleteIcon = useDeleteIcon();
const notify = useNotify();
const [isLoading, setLoading] = useState(false);
const navigate = useNavigate();
Expand Down Expand Up @@ -42,11 +44,11 @@ const DeleteInstanceBtn: FC<Props> = ({ instance }) => {
return (
<ConfirmationButton
onHoverText="Delete instance"
toggleAppearance="base"
className="delete-instance-btn"
toggleAppearance={isDeleteIcon ? "base" : "default"}
className="u-no-margin--bottom"
isLoading={isLoading}
icon="delete"
title="Confirm delete"
toggleCaption={isDeleteIcon ? undefined : "Delete instance"}
confirmMessage={
<>
Are you sure you want to delete instance{" "}
Expand All @@ -57,7 +59,8 @@ const DeleteInstanceBtn: FC<Props> = ({ instance }) => {
confirmButtonLabel="Delete"
onConfirm={handleDelete}
isDisabled={isDisabled}
isDense
isDense={false}
icon={isDeleteIcon ? "delete" : undefined}
/>
);
};
Expand Down
11 changes: 7 additions & 4 deletions src/pages/profiles/actions/DeleteProfileBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom";
import { LxdProfile } from "types/profile";
import { useNotify } from "context/notify";
import ItemName from "components/ItemName";
import { useDeleteIcon } from "context/useDeleteIcon";

interface Props {
profile: LxdProfile;
Expand All @@ -17,6 +18,7 @@ const DeleteProfileBtn: FC<Props> = ({
project,
featuresProfiles,
}) => {
const isDeleteIcon = useDeleteIcon();
const notify = useNotify();
const [isLoading, setLoading] = useState(false);
const navigate = useNavigate();
Expand All @@ -38,11 +40,11 @@ const DeleteProfileBtn: FC<Props> = ({
return (
<ConfirmationButton
onHoverText="Delete profile"
toggleAppearance="base"
className="delete-profile-btn"
toggleAppearance={isDeleteIcon ? "base" : "default"}
className="u-no-margin--bottom"
isLoading={isLoading}
icon="delete"
title="Confirm delete"
toggleCaption={isDeleteIcon ? undefined : "Delete profile"}
confirmMessage={
<>
Are you sure you want to delete profile{" "}
Expand All @@ -53,7 +55,8 @@ const DeleteProfileBtn: FC<Props> = ({
confirmButtonLabel="Delete"
onConfirm={handleDelete}
isDisabled={profile.name === "default" || !featuresProfiles}
isDense
isDense={false}
icon={isDeleteIcon ? "delete" : undefined}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/pages/storage/StorageDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const StorageDetailHeader: FC<Props> = ({ name, storagePool, project }) => {
key="delete"
storage={storagePool}
project={project}
shouldExpand={true}
/>
}
isLoaded={true}
Expand Down
18 changes: 14 additions & 4 deletions src/pages/storage/actions/DeleteStorageBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import { queryKeys } from "util/queryKeys";
import { useNotify } from "context/notify";
import ItemName from "components/ItemName";
import { useNavigate } from "react-router-dom";
import { useDeleteIcon } from "context/useDeleteIcon";

interface Props {
storage: LxdStoragePool;
project: string;
shouldExpand?: boolean;
}

const DeleteStorageBtn: FC<Props> = ({ storage, project }) => {
const DeleteStorageBtn: FC<Props> = ({
storage,
project,
shouldExpand = false,
}) => {
const isSmallScreen = useDeleteIcon();
const navigate = useNavigate();
const notify = useNotify();
const [isLoading, setLoading] = useState(false);
Expand All @@ -40,11 +47,13 @@ const DeleteStorageBtn: FC<Props> = ({ storage, project }) => {

return (
<ConfirmationButton
toggleAppearance="base"
toggleAppearance={!isSmallScreen && shouldExpand ? "default" : "base"}
className="u-no-margin--bottom"
isLoading={isLoading}
icon="delete"
title="Confirm delete"
toggleCaption={
!isSmallScreen && shouldExpand ? "Delete storage" : undefined
}
confirmMessage={
<>
Are you sure you want to delete storage{" "}
Expand All @@ -54,7 +63,8 @@ const DeleteStorageBtn: FC<Props> = ({ storage, project }) => {
}
confirmButtonLabel="Delete"
onConfirm={handleDelete}
isDense={true}
isDense={!shouldExpand}
icon={!isSmallScreen && shouldExpand ? undefined : "delete"}
/>
);
};
Expand Down
6 changes: 0 additions & 6 deletions src/sass/_instance_detail_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
}
}

.delete-instance-btn {
margin: 0;
padding-left: $sph--x-large;
padding-right: $sph--x-large;
}

.p-panel__content {
margin-top: -$spv--medium;
padding-bottom: 0;
Expand Down
6 changes: 0 additions & 6 deletions src/sass/_profile_detail_page.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
.profile-detail-page {
.delete-profile-btn {
margin: 0;
padding-left: $sph--x-large;
padding-right: $sph--x-large;
}

.p-panel__content {
margin-top: -$spv--medium;
padding-bottom: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/sass/_rename_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
flex-direction: column;
max-width: none;

@include large {
@include extra-large {
align-items: center;
flex-direction: row;
}
Expand Down

0 comments on commit 4b69109

Please sign in to comment.