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

chore: Adjusted detail page titles for better ux consistency [WD-11696] #803

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
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
134 changes: 66 additions & 68 deletions src/components/RenameHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const RenameHeader: FC<Props> = ({
}) => {
const canRename = renameDisabledReason === undefined;
const enableRename = () => {
window.dispatchEvent(new Event("resize"));
if (!canRename || !formik) {
return;
}
Expand All @@ -48,76 +49,73 @@ const RenameHeader: FC<Props> = ({
return (
<div className="p-panel__header rename-header">
<h1 className="u-off-screen">{name}</h1>
{isLoaded ? (
<div className={classnames("p-panel__title", titleClassName)}>
<nav
key="breadcrumbs"
className="p-breadcrumbs p-breadcrumbs--large"
aria-label="Breadcrumbs"
>
<ol className="p-breadcrumbs__items">
{parentItems.map((item, key) => (
<li className="p-breadcrumbs__item" key={key}>
{item}
</li>
))}
{formik?.values.isRenaming ? (
<li className="p-breadcrumbs__item rename">
<Input
autoFocus
id="name"
name="name"
className="name-input"
onBlur={formik.handleBlur}
onChange={formik.handleChange}
value={formik.values.name}
error={formik.touched.name ? formik.errors.name : null}
onKeyUp={(e) =>
e.key === "Enter" && void formik.submitForm()
<div className={classnames("p-panel__title", titleClassName)}>
<nav
key="breadcrumbs"
className="p-breadcrumbs p-breadcrumbs--large"
aria-label="Breadcrumbs"
>
<ol className="p-breadcrumbs__items">
{parentItems.map((item, key) => (
<li
className="p-heading--4 u-no-margin--bottom continuous-breadcrumb"
key={key}
>
{item}
</li>
))}
{formik?.values.isRenaming ? (
<li className="p-breadcrumbs__item rename">
<Input
autoFocus
id="name"
name="name"
className="name-input"
Kxiru marked this conversation as resolved.
Show resolved Hide resolved
onBlur={formik.handleBlur}
onChange={formik.handleChange}
value={formik.values.name}
error={formik.touched.name ? formik.errors.name : null}
onKeyUp={(e) => e.key === "Enter" && void formik.submitForm()}
type="text"
/>
<div>
<Button
appearance="base"
className="cancel"
Kxiru marked this conversation as resolved.
Show resolved Hide resolved
onClick={() =>
void formik.setFieldValue("isRenaming", false)
}
type="text"
/>
<div>
<Button
appearance="base"
className="cancel"
onClick={() =>
void formik.setFieldValue("isRenaming", false)
}
>
Cancel
</Button>
<ActionButton
appearance="positive"
loading={formik.isSubmitting}
disabled={!formik.isValid || name === formik.values.name}
onClick={() => void formik.submitForm()}
>
Save
</ActionButton>
</div>
</li>
) : (
<li
className="p-breadcrumbs__item name u-truncate"
onClick={enableRename}
title={`Rename ${name}`}
>
<Tooltip
message={!canRename && renameDisabledReason}
position="btm-left"
>
{name}
</Tooltip>
</li>
)}
</ol>
</nav>
{!formik?.values.isRenaming && centerControls}
</div>
) : (
<h4 className="p-panel__title">{name}</h4>
)}
Cancel
</Button>
<ActionButton
appearance="positive"
loading={formik.isSubmitting}
Kxiru marked this conversation as resolved.
Show resolved Hide resolved
disabled={!formik.isValid || name === formik.values.name}
onClick={() => void formik.submitForm()}
>
Save
</ActionButton>
</div>
</li>
) : (
<li
className="p-heading--4 u-no-margin--bottom name continuous-breadcrumb"
onClick={enableRename}
title={`Rename ${name}`}
>
<Tooltip
message={!canRename && renameDisabledReason}
position="btm-left"
>
{name}
</Tooltip>
</li>
)}
</ol>
</nav>
{!formik?.values.isRenaming && centerControls}
</div>
{isLoaded && !formik?.values.isRenaming && (
<div className="p-panel__controls">{controls}</div>
)}
Expand Down
1 change: 1 addition & 0 deletions src/pages/instances/InstanceDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const InstanceDetail: FC = () => {
name={name}
instance={instance}
project={project}
isLoading={isLoading}
/>
}
contentClassName="detail-page"
Expand Down
68 changes: 40 additions & 28 deletions src/pages/instances/InstanceDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ interface Props {
name: string;
instance?: LxdInstance;
project: string;
isLoading: boolean;
}

const InstanceDetailHeader: FC<Props> = ({ name, instance, project }) => {
const InstanceDetailHeader: FC<Props> = ({
name,
instance,
project,
isLoading,
}) => {
const eventQueue = useEventQueue();
const navigate = useNavigate();
const toastNotify = useToastNotification();
Expand Down Expand Up @@ -87,33 +93,39 @@ const InstanceDetailHeader: FC<Props> = ({ name, instance, project }) => {
});

return (
<RenameHeader
name={name}
titleClassName="instance-detail-title"
parentItems={[
<Link to={`/ui/project/${project}/instances`} key={1}>
Instances
</Link>,
]}
renameDisabledReason={
instance?.status !== "Stopped"
? "Stop the instance to rename"
: undefined
}
centerControls={
instance ? (
<div>
<i className="status u-text--muted">{instance.status}</i>
<InstanceStateActions key="state" instance={instance} />
</div>
) : null
}
controls={
instance ? <DeleteInstanceBtn key="delete" instance={instance} /> : null
}
isLoaded={Boolean(instance)}
formik={formik}
/>
!isLoading && (
<RenameHeader
name={name}
titleClassName="instance-detail-title"
parentItems={[
<Link to={`/ui/project/${project}/instances`} key={1}>
Instances
</Link>,
]}
renameDisabledReason={
!instance
? "Invalid Instance: Cannot be renamed"
: instance?.status !== "Stopped"
? "Stop the instance to rename"
: undefined
}
centerControls={
instance ? (
<div>
<i className="status u-text--muted">{instance.status}</i>
<InstanceStateActions key="state" instance={instance} />
</div>
) : null
}
controls={
instance ? (
<DeleteInstanceBtn key="delete" instance={instance} />
) : null
}
isLoaded={Boolean(instance)}
formik={formik}
/>
)
);
};

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 @@ -24,7 +24,7 @@
$colors--light-theme--background-hover,
$colors--light-theme--background-hover
)
no-repeat 1rem;
no-repeat;
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/sass/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ body {

.p-breadcrumbs__items {
margin-bottom: 0;

.continuous-breadcrumb {
display: inline;
}
}

.p-breadcrumbs__item {
Expand All @@ -213,6 +217,19 @@ body {
padding-top: 0;
}

.continuous-breadcrumb::after {
content: "/";
padding: 0 5px; // Adjust spacing as needed
}

.continuous-breadcrumb:last-child::after {
content: ""; // Remove the slash from the last item
}

.p-breadcrumbs__item::before {
content: none;
}

.p-breadcrumbs__item:first-of-type {
margin-right: $sph--x-small;
}
Expand Down
Loading