-
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
Add search to table component #2684
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
557a34c
Add search to table component
janvhs e5df506
Functional JavaScript aka. fix ESLint
janvhs 44b9b00
Implement changes proposed by Jamie
janvhs def78b8
Ripping search out of the Table
janvhs 2e41932
Move HostRelevantPatchesPage to new search API
janvhs 54109f3
Add search to UpgradablePackagesPage
janvhs e562fa3
Add inspect function
janvhs de58640
Add test fro search
janvhs fe0b2d5
Add test for filtering in pages
janvhs 689f21b
Remove dead code
janvhs cd80e1f
Add search to UpgradablePackagesPage
janvhs a8b9e6a
Keep consistent casing
janvhs d7d71a0
Fix case
janvhs e61395a
Rename Page and UpgradablePackages
janvhs fca4d40
Merge branch 'suse-manager-overviews' into search
janvhs a071650
Fix ESLint
janvhs 6c6c670
Implement changes proposed by Jamie
janvhs 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
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,4 @@ | ||
const regularizeString = (str) => str.normalize().trim().toLowerCase(); | ||
|
||
export const containsSubstring = (str = '', substring = '') => | ||
regularizeString(str).includes(regularizeString(substring)); |
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 { faker } from '@faker-js/faker'; | ||
|
||
import { containsSubstring } from '.'; | ||
|
||
describe('search', () => { | ||
it('should always match with an empty search string', () => { | ||
expect(containsSubstring('', '')).toBe(true); | ||
expect(containsSubstring(faker.word.words(10), '')).toBe(true); | ||
}); | ||
|
||
it('should match strings case in an insensitive fashion', () => { | ||
const original = faker.word.words(1); | ||
const upper = original.toUpperCase(); | ||
const lower = original.toLowerCase(); | ||
|
||
expect(containsSubstring(original, upper)).toBe(true); | ||
expect(containsSubstring(original, lower)).toBe(true); | ||
}); | ||
|
||
it('should match substrings', () => { | ||
const original = faker.word.words(1); | ||
const sub = original.substring(original.length / 2); | ||
|
||
expect(containsSubstring(original, sub)).toBe(true); | ||
}); | ||
|
||
it('should not match not included words', () => { | ||
const words = faker.word.words(2).split(' '); | ||
|
||
expect(containsSubstring(words[0], words[1])).toBe(false); | ||
expect(containsSubstring('', words[1])).toBe(false); | ||
}); | ||
|
||
it('should match unicode in different forms', () => { | ||
const name1 = '\u0041\u006d\u00e9\u006c\u0069\u0065'; | ||
const name2 = '\u0041\u006d\u0065\u0301\u006c\u0069\u0065'; | ||
|
||
expect(containsSubstring(name1, name2)).toBe(true); | ||
}); | ||
}); |
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
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
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
40 changes: 40 additions & 0 deletions
40
assets/js/pages/UpgradablePackagesPage/UpgradablePackages.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,40 @@ | ||
import React, { useState } from 'react'; | ||
import { EOS_SEARCH } from 'eos-icons-react'; | ||
|
||
import UpgradablePackagesList from '@common/UpgradablePackagesList'; | ||
import PageHeader from '@common/PageHeader'; | ||
import Input from '@common/Input'; | ||
import { containsSubstring } from '@lib/filter'; | ||
|
||
export default function UpgradablePackages({ hostName, upgradablePackages }) { | ||
const [search, setSearch] = useState(''); | ||
|
||
const displayedPackages = upgradablePackages.filter( | ||
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. nice 😎 |
||
({ name, patches }) => | ||
containsSubstring(name, search) || | ||
patches | ||
.map(({ advisory }) => containsSubstring(advisory, search)) | ||
.includes(true) | ||
); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-wrap"> | ||
<div className="flex w-2/3 h-auto overflow-ellipsis break-words"> | ||
<PageHeader> | ||
Upgradable packages: <span className="font-bold">{hostName}</span> | ||
</PageHeader> | ||
</div> | ||
<div className="flex w-1/3 justify-end"> | ||
<Input | ||
className="flex" | ||
onChange={(e) => setSearch(e.target.value)} | ||
placeholder="Search by Name or Patch" | ||
prefix={<EOS_SEARCH size="l" />} | ||
/> | ||
</div> | ||
</div> | ||
<UpgradablePackagesList upgradablePackages={displayedPackages} /> | ||
</> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
assets/js/pages/UpgradablePackagesPage/UpgradablePackages.stories.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,20 @@ | ||
import React from 'react'; | ||
|
||
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage'; | ||
import { hostFactory } from '@lib/test-utils/factories/hosts'; | ||
|
||
import UpgradablePackages from './UpgradablePackages'; | ||
|
||
export default { | ||
title: 'Layouts/UpgradablePackages', | ||
components: UpgradablePackages, | ||
argTypes: {}, | ||
render: (args) => <UpgradablePackages {...args} />, | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
hostName: hostFactory.build().hostname, | ||
upgradablePackages: upgradablePackageFactory.buildList(5), | ||
}, | ||
}; |
42 changes: 42 additions & 0 deletions
42
assets/js/pages/UpgradablePackagesPage/UpgradablePackages.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,42 @@ | ||
import React from 'react'; | ||
import { screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { renderWithRouter as render } from '@lib/test-utils'; | ||
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage'; | ||
|
||
import UpgradablePackages from './UpgradablePackages'; | ||
|
||
describe('UpgradablePackages', () => { | ||
it('shows all packages by default', () => { | ||
const packages = upgradablePackageFactory.buildList(8); | ||
|
||
const { container } = render( | ||
<UpgradablePackages upgradablePackages={packages} /> | ||
); | ||
|
||
const tableRows = container.querySelectorAll('tbody > tr'); | ||
|
||
expect(tableRows.length).toBe(8); | ||
}); | ||
|
||
it('should filter package by its name', async () => { | ||
const user = userEvent.setup(); | ||
|
||
const packages = upgradablePackageFactory.buildList(8); | ||
const searchTerm = packages[0].name; | ||
|
||
const { container } = render( | ||
<UpgradablePackages upgradablePackages={packages} /> | ||
); | ||
|
||
const searchInput = screen.getByRole('textbox'); | ||
await user.click(searchInput); | ||
await user.type(searchInput, searchTerm); | ||
|
||
const tableRows = container.querySelectorAll('tbody > tr'); | ||
|
||
expect(tableRows.length).toBe(1); | ||
}); | ||
}); |
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
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
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.
is this used anywhere?
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.
No, but I used it for debugging long call chains a lot. I thought it might be useful to have it in the test utils