-
Notifications
You must be signed in to change notification settings - Fork 15
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
Catalog from wanda #960
Merged
Merged
Catalog from wanda #960
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2744afc
Duplicate current catalog view in a new route
arbulu89 7f08f4b
Implement new catalog container
arbulu89 896fe47
Add tests to the catalog container
arbulu89 0d2e52f
Include process as global variable
arbulu89 0e62677
Show error message if the checks catalog is empty
arbulu89 470b64c
Extract check item to individual component
arbulu89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
assets/js/components/ChecksCatalog/CatalogContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React from 'react'; | ||
|
||
import { Disclosure, Transition } from '@headlessui/react'; | ||
|
||
import ReactMarkdown from 'react-markdown'; | ||
import remarkGfm from 'remark-gfm'; | ||
|
||
import NotificationBox from '@components/NotificationBox'; | ||
import LoadingBox from '@components/LoadingBox'; | ||
|
||
import { groupBy } from '@lib/lists'; | ||
|
||
import { EOS_ERROR } from 'eos-icons-react'; | ||
|
||
const CatalogContainer = ({ | ||
getCatalog = () => {}, | ||
catalogData = [], | ||
catalogError = null, | ||
loading = false, | ||
}) => { | ||
if (loading) { | ||
return <LoadingBox text="Loading checks catalog..." />; | ||
} | ||
|
||
if (catalogError) { | ||
return ( | ||
<NotificationBox | ||
icon={<EOS_ERROR className="m-auto" color="red" size="xl" />} | ||
text={catalogError} | ||
buttonText="Try again" | ||
buttonOnClick={getCatalog} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
{Object.entries(groupBy(catalogData.items, 'group')).map( | ||
([group, checks], idx) => ( | ||
<div | ||
key={idx} | ||
className="check-group bg-white shadow overflow-hidden sm:rounded-md mb-8" | ||
> | ||
<div className="bg-white px-4 py-5 border-b border-gray-200 sm:px-6"> | ||
<h3 className="text-lg leading-6 font-medium text-gray-900"> | ||
{group} | ||
</h3> | ||
</div> | ||
<ul role="list" className="divide-y divide-gray-200"> | ||
{checks.map((check) => ( | ||
<li key={check.id}> | ||
<Disclosure> | ||
<Disclosure.Button | ||
as="div" | ||
className="flex justify-between w-full cursor-pointer hover:bg-gray-100" | ||
> | ||
<div className="check-row px-4 py-4 sm:px-6"> | ||
<div className="flex items-center"> | ||
<p className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"> | ||
{check.id} | ||
</p> | ||
{check.premium > 0 && ( | ||
<p className="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800"> | ||
Premium | ||
</p> | ||
)} | ||
</div> | ||
<div className="mt-2 sm:flex sm:justify-between"> | ||
<div className="sm:flex"> | ||
<ReactMarkdown | ||
className="markdown text-sm" | ||
remarkPlugins={[remarkGfm]} | ||
> | ||
{check.description} | ||
</ReactMarkdown> | ||
</div> | ||
</div> | ||
</div> | ||
</Disclosure.Button> | ||
<Transition | ||
enter="transition duration-100 ease-out" | ||
enterFrom="transform opacity-0" | ||
enterTo="transform opacity-100" | ||
leave="transition duration-100 ease-out" | ||
leaveFrom="transform opacity-100" | ||
leaveTo="transform opacity-0" | ||
> | ||
<Disclosure.Panel className="check-panel border-none"> | ||
<div className="px-8 py-4 sm:px-8"> | ||
<div className="px-4 py-4 sm:px-4 bg-slate-100 rounded"> | ||
<ReactMarkdown | ||
className="markdown" | ||
remarkPlugins={[remarkGfm]} | ||
> | ||
{check.remediation} | ||
</ReactMarkdown> | ||
</div> | ||
</div> | ||
</Disclosure.Panel> | ||
</Transition> | ||
</Disclosure> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CatalogContainer; |
84 changes: 84 additions & 0 deletions
84
assets/js/components/ChecksCatalog/CatalogContainer.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
|
||
import { screen, within } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { faker } from '@faker-js/faker'; | ||
import { renderWithRouter } from '@lib/test-utils'; | ||
import { catalogCheckFactory } from '@lib/test-utils/factories'; | ||
|
||
import CatalogContainer from './CatalogContainer'; | ||
|
||
describe('ChecksCatalog CatalogContainer component', () => { | ||
it('should render the notification box', () => { | ||
renderWithRouter(<CatalogContainer catalogError />); | ||
|
||
expect(screen.getByRole('button')).toHaveTextContent('Try again'); | ||
}); | ||
|
||
it('should render the loading box', () => { | ||
renderWithRouter(<CatalogContainer loading={true} />); | ||
|
||
expect(screen.getByText('Loading checks catalog...')).toBeVisible(); | ||
}); | ||
|
||
it('should render the checks catalog', () => { | ||
const groupName1 = faker.animal.cat(); | ||
const groupName2 = faker.animal.cat(); | ||
const group1 = catalogCheckFactory.buildList(5, { group: groupName1 }); | ||
const group2 = catalogCheckFactory.buildList(5, { group: groupName2 }); | ||
const catalog = { items: group1.concat(group2) }; | ||
|
||
renderWithRouter( | ||
<CatalogContainer | ||
loading={false} | ||
catalogError={null} | ||
catalogData={catalog} | ||
/> | ||
); | ||
|
||
const groups = screen.getAllByRole('list'); | ||
expect(groups.length).toBe(2); | ||
|
||
for (let group of groups) { | ||
let { getAllByRole } = within(group); | ||
let checks = getAllByRole('listitem'); | ||
expect(checks.length).toBe(5); | ||
} | ||
}); | ||
|
||
it('should show check remediation when the row is clicked', () => { | ||
const groupName = faker.animal.cat(); | ||
const catalogChecks = catalogCheckFactory.buildList(2, { | ||
group: groupName, | ||
}); | ||
const checkRemediation1 = catalogChecks[0].remediation; | ||
const checkRemediation2 = catalogChecks[1].remediation; | ||
const catalog = { items: catalogChecks }; | ||
|
||
renderWithRouter( | ||
<CatalogContainer | ||
loading={false} | ||
catalogError={null} | ||
catalogData={catalog} | ||
/> | ||
); | ||
|
||
const groups = screen.getAllByRole('list'); | ||
const { getAllByRole } = within(groups[0]); | ||
let checks = getAllByRole('listitem'); | ||
const check1 = checks[0].querySelector('div'); | ||
const check2 = checks[1].querySelector('div'); | ||
|
||
expect(screen.queryByText(checkRemediation1)).not.toBeInTheDocument(); | ||
userEvent.click(check1); | ||
expect(screen.getByText(checkRemediation1)).toBeVisible(); | ||
userEvent.click(check1); | ||
expect(screen.queryByText(checkRemediation1)).not.toBeInTheDocument(); | ||
|
||
expect(screen.queryByText(checkRemediation2)).not.toBeInTheDocument(); | ||
userEvent.click(check2); | ||
expect(screen.getByText(checkRemediation2)).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import axios from 'axios'; | ||
|
||
import CatalogContainer from './CatalogContainer'; | ||
|
||
const wandaURL = process.env.WANDA_URL; | ||
|
||
export const ChecksCatalogNew = () => { | ||
const [catalogError, setError] = useState(null); | ||
const [loading, setLoaded] = useState(true); | ||
const [catalogData, setCatalog] = useState([]); | ||
|
||
useEffect(() => { | ||
getCatalog(); | ||
}, []); | ||
|
||
const getCatalog = () => { | ||
setLoaded(true); | ||
axios | ||
.get(`${wandaURL}/api/checks/catalog`) | ||
.then((catalog) => { | ||
setLoaded(false); | ||
setCatalog(catalog.data); | ||
}) | ||
.catch(function (error) { | ||
setLoaded(false); | ||
setError(error.message); | ||
}); | ||
}; | ||
arbulu89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<CatalogContainer | ||
getCatalog={getCatalog} | ||
arbulu89 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
catalogData={catalogData} | ||
catalogError={catalogError} | ||
loading={loading} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import ChecksCatalog from './ChecksCatalog'; | ||
|
||
export { ChecksCatalogNew } from './ChecksCatalogNew'; | ||
|
||
export default ChecksCatalog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,11 @@ export const healthSummaryFactory = Factory.define(() => ({ | |
casing: 'upper', | ||
}), | ||
})); | ||
|
||
export const catalogCheckFactory = Factory.define(() => ({ | ||
id: faker.datatype.uuid(), | ||
name: faker.animal.cat(), | ||
group: faker.animal.cat(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meow |
||
description: faker.lorem.paragraph(), | ||
remediation: faker.lorem.paragraph(), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import DatabasesOverview from '@components/DatabasesOverview'; | |
import SapSystemDetails from './components/SapSystemDetails/SapSystemDetails'; | ||
import DatabaseDetails from './components/DatabaseDetails'; | ||
import ChecksCatalog from '@components/ChecksCatalog'; | ||
import { ChecksCatalogNew } from '@components/ChecksCatalog'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry ❤️ last thing 😄 could you group these imports? You can do that just by doing |
||
import NotFound from '@components/NotFound'; | ||
import SomethingWentWrong from '@components/SomethingWentWrong'; | ||
import Settings from '@components/Settings'; | ||
|
@@ -49,6 +50,7 @@ const App = () => { | |
<Route path="sap_systems" element={<SapSystemsOverview />} /> | ||
<Route path="databases" element={<DatabasesOverview />} /> | ||
<Route path="catalog" element={<ChecksCatalog />} /> | ||
<Route path="catalog_new" element={<ChecksCatalogNew />} /> | ||
<Route path="settings" element={<Settings />} /> | ||
<Route path="about" element={<AboutPage />} /> | ||
<Route | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we wanna extract all this markup in some more granular components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to create our own markdown component with those defaults?
In this case
text-sm
would be an additional style.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do the next? Let me merge this as it is about this topic, and I will create other PR with a new markdown component and use it all around the code. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the markdown, I mean the whole HTML body of this component 😅
In a similar way to https://github.com/trento-project/web/blob/main/assets/js/components/ChecksResults/ChecksResults.jsx, we can make this code more readable just having a wrapper component for the
div
s and theul
and another component for theli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway if you wanna do that in a subsequent PR, feel free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dottorblaster CheckItem extracted to an individual component. Going further looks like an overkill to me