-
Notifications
You must be signed in to change notification settings - Fork 10
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
Replace search engine and improve UX #337
Changes from all commits
bf3d06d
e58cf14
e45caf5
98ba085
c9fcc62
d5c4de7
d9978ab
61b645b
3baf6de
771f884
72f4b6d
2ffa44b
6d6cd96
fdf9222
5de8b75
de2f245
a2dea4a
f530426
aeec36e
aeec0cd
1986844
c694f37
b98596d
5df2785
aeab13e
0950c24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { GherkinDocument } from '@cucumber/messages' | ||
import React from 'react' | ||
|
||
import countScenariosByStatuses from '../../countScenariosByStatuses.js' | ||
import filterByStatus from '../../filter/filterByStatus.js' | ||
import { useQueries, useSearch } from '../../hooks/index.js' | ||
import Search from '../../search/Search.js' | ||
import { useFilteredDocuments } from '../../hooks/useFilteredDocuments.js' | ||
import { useResultStatistics } from '../../hooks/useResultStatistics.js' | ||
import { ExecutionSummary } from './ExecutionSummary.js' | ||
import styles from './FilteredResults.module.scss' | ||
import { GherkinDocumentList } from './GherkinDocumentList.js' | ||
|
@@ -17,24 +15,10 @@ interface IProps { | |
} | ||
|
||
export const FilteredResults: React.FunctionComponent<IProps> = ({ className }) => { | ||
const { cucumberQuery, gherkinQuery, envelopesQuery } = useQueries() | ||
const { envelopesQuery } = useQueries() | ||
const { scenarioCountByStatus, statusesWithScenarios, totalScenarioCount } = useResultStatistics() | ||
const { query, hideStatuses, update } = useSearch() | ||
const allDocuments = gherkinQuery.getGherkinDocuments() | ||
|
||
const { scenarioCountByStatus, statusesWithScenarios, totalScenarioCount } = | ||
countScenariosByStatuses(gherkinQuery, cucumberQuery, envelopesQuery) | ||
|
||
const search = new Search(gherkinQuery) | ||
for (const gherkinDocument of allDocuments) { | ||
search.add(gherkinDocument) | ||
} | ||
|
||
const onlyShowStatuses = statusesWithScenarios.filter((s) => !hideStatuses.includes(s)) | ||
|
||
const matches = query ? search.search(query) : allDocuments | ||
const filtered = matches | ||
.map((document) => filterByStatus(document, gherkinQuery, cucumberQuery, onlyShowStatuses)) | ||
.filter((document) => document !== null) as GherkinDocument[] | ||
const filtered = useFilteredDocuments(query, hideStatuses) | ||
|
||
return ( | ||
<div className={className}> | ||
|
@@ -52,15 +36,22 @@ export const FilteredResults: React.FunctionComponent<IProps> = ({ className }) | |
/> | ||
<SearchBar | ||
query={query} | ||
onSearch={(query) => update({ query })} | ||
onSearch={(newValue) => update({ query: newValue })} | ||
statusesWithScenarios={statusesWithScenarios} | ||
hideStatuses={hideStatuses} | ||
onFilter={(hideStatuses) => update({ hideStatuses })} | ||
onFilter={(newValue) => update({ hideStatuses: newValue })} | ||
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. As above. |
||
/> | ||
</div> | ||
|
||
{filtered.length > 0 && <GherkinDocumentList gherkinDocuments={filtered} preExpand={true} />} | ||
{filtered.length < 1 && <NoMatchResult query={query} />} | ||
{filtered !== undefined && ( | ||
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.
|
||
<> | ||
{filtered.length > 0 ? ( | ||
<GherkinDocumentList gherkinDocuments={filtered} preExpand={true} /> | ||
) : ( | ||
<NoMatchResult query={query} /> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { TestStepResultStatus as Status } from '@cucumber/messages' | |
import { faFilter, faSearch } from '@fortawesome/free-solid-svg-icons' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import React, { FunctionComponent } from 'react' | ||
import { useDebouncedCallback } from 'use-debounce' | ||
|
||
import statusName from '../gherkin/statusName.js' | ||
import styles from './SearchBar.module.scss' | ||
|
@@ -22,11 +23,12 @@ export const SearchBar: FunctionComponent<IProps> = ({ | |
onSearch, | ||
onFilter, | ||
}) => { | ||
const debouncedSearchChange = useDebouncedCallback((newValue) => { | ||
onSearch(newValue) | ||
}, 500) | ||
const searchSubmitted = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault() | ||
const formData = new window.FormData(event.currentTarget) | ||
const query = formData.get('query') | ||
onSearch((query || '').toString()) | ||
debouncedSearchChange.flush() | ||
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.
|
||
} | ||
const filterChanged = (name: Status, show: boolean) => { | ||
onFilter(show ? hideStatuses.filter((s) => s !== name) : hideStatuses.concat(name)) | ||
|
@@ -42,6 +44,7 @@ export const SearchBar: FunctionComponent<IProps> = ({ | |
name="query" | ||
placeholder="Search with text or @tags" | ||
defaultValue={query} | ||
onChange={(e) => debouncedSearchChange(e.target.value)} | ||
/> | ||
<small className={styles.searchHelp}> | ||
You can search with plain text or{' '} | ||
|
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.
This was shadowing a variable higher in the scope.