Skip to content

Commit

Permalink
feat: make width consistent for settings pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-Topher committed Dec 11, 2023
1 parent 0f19253 commit 51da80e
Show file tree
Hide file tree
Showing 78 changed files with 729 additions and 695 deletions.
109 changes: 109 additions & 0 deletions cypress/e2e/with-users/settings/headings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { generateMAASURL } from "../../utils";

const settingsPages = [
{
path: "/settings/configuration/general",
label: "General",
},
{
path: "/settings/configuration/commissioning",
label: "Commissioning",
},
{
path: "/settings/configuration/deploy",
label: "Deploy",
},
{
path: "/settings/configuration/kernel-parameters",
label: "Kernel parameters",
},
{
path: "/settings/security/security-protocols",
label: "Security protocols",
},
{
path: "/settings/security/secret-storage",
label: "Secret storage",
},
{
path: "/settings/security/session-timeout",
label: "Session timeout",
},
{
path: "/settings/security/ipmi-settings",
label: "IPMI settings",
},
{
path: "/settings/users",
label: "Users",
},
{
path: "/settings/images/ubuntu",
label: "Ubuntu",
},
{
path: "/settings/images/windows",
label: "Windows",
},
{
path: "/settings/images/vmware",
label: "VMware",
},
{
path: "/settings/license-keys",
label: "License keys",
},
{
path: "/settings/storage",
label: "Storage",
},
{
path: "/settings/network/proxy",
label: "Proxy",
},
{
path: "/settings/network/dns",
label: "DNS",
},
{
path: "/settings/network/ntp",
label: "NTP",
},
{
path: "/settings/network/syslog",
label: "Syslog",
},
{
path: "/settings/network/network-discovery",
label: "Network discovery",
},
{
path: "/settings/scripts/commissioning",
label: "Commissioning scripts",
},
{
path: "/settings/scripts/testing",
label: "Testing scripts",
},
{
path: "/settings/dhcp",
label: "DHCP snippets",
},
{
path: "/settings/repositories",
label: "Package repos",
},
];

context("settings pages titles", () => {
beforeEach(() => {
cy.login();
});

settingsPages.forEach((page) => {
it(`${page.label} page`, () => {
cy.visit(generateMAASURL(page.path));
cy.findByRole("heading", { name: page.label }).should("exist");
});
});
});
5 changes: 1 addition & 4 deletions src/app/base/components/ActionForm/ActionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getLabel = (

export type ActionFormProps<V extends object, E = null> = Omit<
FormikFormProps<V, E>,
"buttonsAlign" | "saved" | "saving" | "savingLabel" | "submitLabel"
"saved" | "saving" | "savingLabel" | "submitLabel"
> & {
actionName: string;
loaded?: boolean;
Expand All @@ -53,7 +53,6 @@ export enum Labels {
const ActionForm = <V extends object, E = null>({
actionErrors,
actionName,
buttonsBordered = false,
children,
errors,
loaded = true,
Expand Down Expand Up @@ -90,8 +89,6 @@ const ActionForm = <V extends object, E = null>({

return (
<FormikForm<V, E>
buttonsAlign="right"
buttonsBordered={buttonsBordered}
onSubmit={(values?, formikHelpers?) => {
onSubmit(values, formikHelpers);
// Set selected count in component state once form is submitted, so
Expand Down
4 changes: 0 additions & 4 deletions src/app/base/components/FormikForm/FormikForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export type Props<V extends object, E = null> = ContentProps<V, E> &
const FormikForm = <V extends object, E = null>({
allowAllEmpty,
allowUnchanged,
buttonsAlign,
buttonsBordered,
buttonsClassName,
buttonsHelpClassName,
buttonsHelp,
Expand Down Expand Up @@ -55,8 +53,6 @@ const FormikForm = <V extends object, E = null>({
allowAllEmpty={allowAllEmpty}
allowUnchanged={allowUnchanged}
aria-label={ariaLabel}
buttonsAlign={buttonsAlign}
buttonsBordered={buttonsBordered}
buttonsClassName={buttonsClassName}
buttonsHelp={buttonsHelp}
buttonsHelpClassName={buttonsHelpClassName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ it("can display a tooltip for the secondary submit action", async () => {
).toBeInTheDocument();
});

it("displays a border if bordered is true", () => {
render(
<Formik initialValues={{}} onSubmit={jest.fn()}>
<FormikFormButtons buttonsBordered submitLabel="Save" />
</Formik>
);

expect(screen.getByTestId("buttons-wrapper")).toHaveClass("is-bordered");
});

it("displays inline if inline is true", () => {
render(
<Formik initialValues={{}} onSubmit={jest.fn()}>
Expand Down
57 changes: 23 additions & 34 deletions src/app/base/components/FormikFormButtons/FormikFormButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type FormikContextFunc<V, R = void> = (
) => R;

export type Props<V> = {
buttonsAlign?: "left" | "right";
buttonsBordered?: boolean;
buttonsClassName?: string;
buttonsHelp?: ReactNode;
buttonsHelpClassName?: string;
Expand Down Expand Up @@ -47,8 +45,6 @@ export enum Labels {
}

export const FormikFormButtons = <V,>({
buttonsAlign = "right",
buttonsBordered = true,
buttonsClassName,
buttonsHelp,
buttonsHelpClassName,
Expand Down Expand Up @@ -111,7 +107,6 @@ export const FormikFormButtons = <V,>({
<>
<div
className={classNames("formik-form-buttons", buttonsClassName, {
"is-bordered": buttonsBordered,
"is-inline": inline,
})}
data-testid={TestIds.ButtonsWrapper}
Expand All @@ -127,37 +122,31 @@ export const FormikFormButtons = <V,>({
{buttonsHelp}
</div>
)}
<div
className={classNames("formik-form-buttons__container", {
"u-align--right": buttonsAlign === "right",
})}
>
{onCancel && (
<Button
appearance="base"
className="formik-form-buttons__button"
data-testid={TestIds.CancelButton}
disabled={cancelDisabled}
onClick={
onCancel ? () => onCancel(values, formikContext) : undefined
}
type="button"
>
{cancelLabel}
</Button>
)}
{secondaryButton}
<ActionButton
appearance={submitAppearance}
{onCancel && (
<Button
appearance="base"
className="formik-form-buttons__button"
disabled={submitDisabled}
loading={saving}
success={saved}
type="submit"
data-testid={TestIds.CancelButton}
disabled={cancelDisabled}
onClick={
onCancel ? () => onCancel(values, formikContext) : undefined
}
type="button"
>
{submitLabel}
</ActionButton>
</div>
{cancelLabel}
</Button>
)}
{secondaryButton}
<ActionButton
appearance={submitAppearance}
className="formik-form-buttons__button"
disabled={submitDisabled}
loading={saving}
success={saved}
type="submit"
>
{submitLabel}
</ActionButton>
</div>
{saving && savingLabel && (
<p
Expand Down
60 changes: 0 additions & 60 deletions src/app/base/components/FormikFormButtons/_index.scss

This file was deleted.

47 changes: 28 additions & 19 deletions src/app/base/components/FormikFormContent/FormikFormContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReactNode, AriaAttributes } from "react";
import React, { useEffect, useRef } from "react";

import { ContentSection } from "@canonical/maas-react-components";
import { Form, Notification } from "@canonical/react-components";
import type { FormikContextType } from "formik";
import { useFormikContext } from "formik";
Expand Down Expand Up @@ -172,25 +173,33 @@ const FormikFormContent = <V extends object, E = null>({
inline={inline}
onSubmit={handleSubmit}
>
{!!nonFieldError && (
<Notification severity="negative" title="Error:">
{nonFieldError}
</Notification>
)}
{typeof children === "function"
? children({ ...formikContext })
: children}
{editable && (
<FormikFormButtons
{...buttonsProps}
cancelDisabled={cancelDisabled === false ? false : saving}
inline={inline}
saved={saved}
saving={saving}
submitDisabled={loading || saving || formDisabled || submitDisabled}
/>
)}
{footer}
<ContentSection>
<ContentSection.Content>
{!!nonFieldError && (
<Notification severity="negative" title="Error:">
{nonFieldError}
</Notification>
)}
{typeof children === "function"
? children({ ...formikContext })
: children}
</ContentSection.Content>
<ContentSection.Footer>
{editable && (
<FormikFormButtons
{...buttonsProps}
cancelDisabled={cancelDisabled === false ? false : saving}
inline={inline}
saved={saved}
saving={saving}
submitDisabled={
loading || saving || formDisabled || submitDisabled
}
/>
)}
{footer}
</ContentSection.Footer>
</ContentSection>
</Form>
);
};
Expand Down
Loading

0 comments on commit 51da80e

Please sign in to comment.