Skip to content

Commit

Permalink
Improve filters for mobile devices (#609)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
cynthia-sg authored May 28, 2024
1 parent 1edea27 commit 8910dee
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"dependencies": {
"classnames": "^2.5.1",
"clo-ui": "https://github.com/cncf/clo-ui.git#v0.2.5",
"clo-ui": "https://github.com/cncf/clo-ui.git#v0.3.0",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"react": "^18.3.1",
Expand Down
34 changes: 24 additions & 10 deletions web/src/layout/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ const Card = (props: Props) => {
});
};

const searchByProject = (project: string, foundation: string) => {
navigate({
pathname: '/search',
search: prepareQueryString({
pageNumber: 1,
filters: { [FilterKind.Project]: [project], [FilterKind.Foundation]: [foundation], ...getExtraFilter() },
}),
});
};

const searchByFilter = (filter: FilterKind, value: string) => {
navigate({
pathname: '/search',
Expand Down Expand Up @@ -128,12 +138,15 @@ const Card = (props: Props) => {
effective_theme={effective}
/>
</div>
<div className="truncateWrapper w-100">
<div className="d-flex flex-row justify-content-between align-items-end text-truncate">
<span className={`text-truncate fw-bold mb-0 ${styles.title}`}>
<div className="d-flex flex-row justify-content-between align-items-end text-truncate">
<button
className="btn btn-sm btn-link border-0 p-0 mw-100 align-baseline"
onClick={() => searchByProject(props.issue.project.name, props.issue.project.foundation)}
>
<div className={`text-truncate fw-bold mb-0 ${styles.title}`}>
{props.issue.project.display_name || props.issue.project.name}
</span>
</div>
</div>
</button>
</div>
</div>

Expand Down Expand Up @@ -199,7 +212,7 @@ const Card = (props: Props) => {
<div className="truncateWrapper">
<button
className="btn btn-sm btn-link border-0 p-0 mw-100 align-baseline"
onClick={() => searchByFilter(FilterKind.Project, props.issue.project.name)}
onClick={() => searchByProject(props.issue.project.name, props.issue.project.foundation)}
>
<div className="d-flex flex-row justify-content-between align-items-end text-truncate">
<span
Expand Down Expand Up @@ -308,20 +321,21 @@ const Card = (props: Props) => {
<GenericBadge
content={props.issue.repository.languages[0]}
className={`fw-normal text-secondary text-uppercase ms-2 bg-purple ${styles.badge}`}
onClick={() => searchByFilter(FilterKind.Language, props.issue.repository.languages[0])}
/>
</div>
)}

<div
className={`d-none d-sm-flex flex-row flex-wrap overflow-hidden justify-content-end ${styles.topicsWrapper}`}
>
{availableTopics.slice(0, 4).map((lg: string) => {
{availableTopics.slice(0, 4).map((topic: string) => {
return (
<GenericBadge
content={lg}
content={topic}
className={`text-secondary lighterText ${styles.badge} ms-2`}
key={lg}
onClick={() => searchByText(lg)}
key={topic}
onClick={() => searchByText(topic)}
/>
);
})}
Expand Down
8 changes: 8 additions & 0 deletions web/src/layout/search/Filters.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.dropdownFilter {
max-height: 200px;
}

.searchBar {
margin: 0.75rem 0.3rem !important;
width: calc(100% - 0.6rem);
}
9 changes: 7 additions & 2 deletions web/src/layout/search/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IoMdCloseCircleOutline } from 'react-icons/io';

import { AppContext } from '../../context/AppContextProvider';
import { FilterKind } from '../../types';
import styles from './Filters.module.css';

interface Props {
visibleTitle: boolean;
Expand Down Expand Up @@ -55,10 +56,10 @@ const Filters = (props: Props) => {
{props.filters.map((section: FilterSection) => {
const activeFilters = section.key ? props.activeFilters[section.key] : getActiveFiltersForOther();
const key = (section.key || section.title) as FilterKind;
const withSearchBar = [FilterKind.Language, FilterKind.Project].includes(key);

// Does not render project and language filters or disabled sections on mobile version
// Does not render disabled sections on mobile version
if (
[FilterKind.Language, FilterKind.Project].includes(key) ||
props.disabledSections.includes(key) ||
section.options.length === 0 ||
(isEmbed && key === FilterKind.Foundation)
Expand All @@ -72,6 +73,10 @@ const Filters = (props: Props) => {
activeFilters={activeFilters}
section={section}
onChange={props.onChange}
withSearchBar={withSearchBar}
contentClassName={withSearchBar ? `border overflow-auto p-3 ${styles.dropdownFilter}` : ''}
searchBarClassName={withSearchBar ? styles.searchBar : ''}
sortedBySelected={withSearchBar}
visibleTitle
/>
</React.Fragment>
Expand Down
4 changes: 4 additions & 0 deletions web/src/layout/search/FiltersInLine.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
font-size: 0.8rem;
}

.searchBar {
width: 94% !important;
}

@media only screen and (min-width: 1200px) {
.dropdownWrapper {
width: 119px;
Expand Down
2 changes: 2 additions & 0 deletions web/src/layout/search/FiltersInLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ const Filters = (props: FiltersProps) => {
contentClassName={`overflow-auto ${styles.options}`}
section={props.section}
withSearchBar={props.withSearchBar}
searchBarClassName={props.withSearchBar ? styles.searchBar : ''}
onChange={onChangeFilter}
visibleTitle={false}
disabled={props.disabled}
sortedBySelected={props.withSearchBar}
/>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3420,9 +3420,9 @@ cliui@^7.0.2:
strip-ansi "^6.0.0"
wrap-ansi "^7.0.0"

"clo-ui@https://github.com/cncf/clo-ui.git#v0.2.5":
version "0.2.5"
resolved "https://github.com/cncf/clo-ui.git#4fa10666174e9192accbbb5e1a3b23ffa21fadd7"
"clo-ui@https://github.com/cncf/clo-ui.git#v0.3.0":
version "0.3.0"
resolved "https://github.com/cncf/clo-ui.git#cb97af364d55d2c2433f3851246ddc36bd1f181d"
dependencies:
bootstrap "^5.3.3"
classnames "^2.5.1"
Expand Down

0 comments on commit 8910dee

Please sign in to comment.