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

refactor(ui): update machine header to support tag forms #3661

Merged
merged 2 commits into from
Mar 8, 2022

Conversation

huwshimi
Copy link
Contributor

@huwshimi huwshimi commented Mar 7, 2022

Done

  • Separate the main machine/pool/tag view and header so that it can support tag header forms.

QA

MAAS deployment

To run this branch you will need access to one of the following MAAS deployments:

Running the branch

You can run this branch by:

QA steps

  • Go to the machine view and check that you can open header forms.
  • Click on the pools tab and check that clicking on the add pool button opens the form.
  • Click on the tags tab and check that clicking on the add tag button opens the placeholder form in the header.

Fixes

Fixes: canonical-web-and-design/app-tribe#741.

@@ -0,0 +1,245 @@
import { mount } from "enzyme";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file hasn't changed, just renamed from ui/src/app/pools/views/Pools.test.tsx

@@ -0,0 +1,207 @@
import { useEffect, useState } from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file hasn't been modified, just renamed from "ui/src/app/pools/views/Pools.tsx"

@petermakowski
Copy link
Contributor

QA notes

Now the subheader (number of machines) disappears if you go to a different tab. This breaks the view hierarchy which is confusing (switching to a different tab should ideally only modify content that's within that tab). This is also not consistent with how we handle this pattern in other views (e.g. KVM).

This PR

Kapture 2022-03-07 at 14 55 16

Before

Kapture 2022-03-07 at 14 54 48

KVM

Kapture 2022-03-07 at 15 03 32

@@ -0,0 +1,72 @@
import { mount } from "enzyme";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the testing library please 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably have a rule that if you're touching a file you shouldn't have to update to RTL otherwise a lot of PRs are going to get very large.

</MemoryRouter>
</Provider>
);
expect(screen.getByText("Add tag form")).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(screen.getByText("Add tag form")).toBeInTheDocument();
expect(screen.getByRole("form", { name: "Add tag" })).toBeInTheDocument();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the appropriate role. This can easily get missed when you open another PR with the full form implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK, that text isn't going to stay...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a todo here.

Comment on lines +20 to +23
<>
Add tag form{" "}
<Button onClick={() => setHeaderContent(null)}>Close</Button>
</>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<>
Add tag form{" "}
<Button onClick={() => setHeaderContent(null)}>Close</Button>
</>
<form aria-label="Add tag">
<Button onClick={() => setHeaderContent(null)}>Close</Button>
</form>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

setHeaderContent={jest.fn()}
/>
);
expect(screen.getByText("Add tag form")).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the form role instead of simple text matching please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a placeholder until the form is implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a todo here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Comment on lines +13 to +26
export const TagsHeader = ({
headerContent,
setHeaderContent,
}: Props): JSX.Element => {
return (
<MachinesHeader
buttons={[
<Button
appearance="positive"
onClick={() => setHeaderContent({ view: TagHeaderViews.AddTag })}
>
Create new tag
</Button>,
]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relates to my other comment about view hierarchy.

I think that instead of importing a parent element into a child it would make more sense to keep MachineHeader above and in a single place (views/Machines), like it was before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem we have is that other than the title and the tabs we treat the machines/tags/pools as isolated parts of the site (there's no shared state etc.) so we're having to work around that by watching for URL changes and resetting things like the filter states.

As we're now adding forms for the tags we're now conflating things further. The aim of this PR is separating the concerns of each view (machines/tags/pools) so that they no longer have a single header and form state so each section can implement things like forms in isolation.

@huwshimi
Copy link
Contributor Author

huwshimi commented Mar 7, 2022

QA notes

Now the subheader (number of machines) disappears if you go to a different tab. This breaks the view hierarchy which is confusing (switching to a different tab should ideally only modify content that's within that tab). This is also not consistent with how we handle this pattern in other views (e.g. KVM).

Oh yeah that's to match the design:

Screen Shot 2022-03-08 at 9 27 43 am

huwshimi added 2 commits March 8, 2022 09:32
Separate the main machine/pool/tag view and header so that it can support tag header forms.

Fixes: canonical/app-tribe#741.
@huwshimi huwshimi merged commit 6a28de7 into canonical:master Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants