-
Notifications
You must be signed in to change notification settings - Fork 283
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
Implementation of filters in custom search modal. #1560
Open
vivekjain23
wants to merge
31
commits into
main
Choose a base branch
from
feature/search-filters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
21ec770
Add custom component for search modal
vivekjain23 7475323
Add styles for custom search modal
vivekjain23 3e05305
Add list of filters for custom search based on facet tags
vivekjain23 058ce2f
Add context for search
vivekjain23 eb4a6cd
Refactor styles for custom search filter dropdown
vivekjain23 b4141e8
Refactor custom search modal
vivekjain23 6507c3b
Remove unwanted swizzle component
vivekjain23 9e87bb4
Add custom search filter page
vivekjain23 5e2c99e
Update list of filters for custom search based on facet tags
vivekjain23 4f2aa50
Refactor context for search modal and page
vivekjain23 85422c1
lint fix
vivekjain23 12110e0
Fix custom dropdown filter name
vivekjain23 8e853e2
Refractor custom dropdown filter
vivekjain23 607b2df
Update styles for custom dropdown filter
vivekjain23 b52cbd5
Add filter constants for custom dropdown filter
vivekjain23 5cc1abf
Fix footer alignment in search page
vivekjain23 ccf24d2
Fix linting errors
vivekjain23 5829d3b
Fix formatting
vivekjain23 550bf08
Fix styling
vivekjain23 c0e589e
Fix filter alignment
vivekjain23 68aeef9
Merge branch 'main' into feature/search-filters
Dr-Electron 6c24de4
Fix filter build issue
vivekjain23 9ab4943
Add swizzle version and info
vivekjain23 31482b1
Add swizzle version and info
vivekjain23 d3510b6
Update filter select logic
vivekjain23 fbdf425
Remove unwanted console logs
vivekjain23 1ddf1d7
Remove search filter from search modal
vivekjain23 492f1c6
Remove unneeded swizzles
Dr-Electron a6f1379
Revert footer changes
Dr-Electron fa062f3
Remove unused dep
Dr-Electron ff8d16d
Revert change
Dr-Electron 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* SWIZZLED VERSION: 2.4.3 | ||
* REASONS: | ||
* - Wrapped the component in context provider inorder to transfer data seamlessly between search bar and search page | ||
*/ | ||
|
||
/* eslint-disable */ | ||
import React from 'react'; | ||
import { SearchProvider } from '@site/src/utils/SearchContext'; | ||
|
||
export default function Root({ children }) { | ||
return ( | ||
<SearchProvider> | ||
<div>{children}</div> | ||
</SearchProvider> | ||
); | ||
} |
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. Can you make this tsx? Will make it easier for us to migrate to the new docs |
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,177 @@ | ||
/* eslint-disable */ | ||
import React, { forwardRef, useEffect, useState } from 'react'; | ||
import { | ||
facetNamesJson, | ||
allFacets, | ||
subFilters, | ||
subChildFilters, | ||
buildSubFilters, | ||
identitySubFilters, | ||
maintainSubFilters, | ||
} from '../../utils/searchConstant'; | ||
import clsx from 'clsx'; | ||
import styles from './styles.module.css'; | ||
import { useAnnouncementBar } from '@docusaurus/theme-common/internal'; | ||
import useIsBrowser from '@docusaurus/useIsBrowser'; | ||
|
||
export const FilterDropdown = forwardRef( | ||
({ selectedFacets, setSelectedFacets, styleProps = {} }, ref) => { | ||
const { isActive: isAnnouncementBarActive } = useAnnouncementBar(); | ||
const actualFacets = allFacets[1]; | ||
const [isScrolled, setIsScrolled] = useState(false); | ||
const isBrowser = useIsBrowser(); | ||
|
||
const handleCheckboxChange = (event) => { | ||
const { value, checked } = event.target; | ||
|
||
// If selecting an individual item when "Select All" is checked, clear all and select only the clicked item | ||
if (actualFacets.every((facet) => selectedFacets[1].includes(facet))) { | ||
setSelectedFacets([selectedFacets[0], [value]]); | ||
return; | ||
} | ||
|
||
let updatedFacetList = checked | ||
? [...selectedFacets[1], value] | ||
: selectedFacets[1].filter((facet) => facet !== value); | ||
|
||
if (!checked && updatedFacetList.length === 0) { | ||
return; | ||
} | ||
|
||
if (checked) { | ||
// If a parent filter is checked, add its child filters | ||
if (value === 'docusaurus_tag:docs-build-current') { | ||
updatedFacetList = [ | ||
...new Set([...updatedFacetList, ...buildSubFilters]), | ||
]; | ||
} else if (value === 'docusaurus_tag:docs-identity-rs-1-0-current') { | ||
updatedFacetList = [ | ||
...new Set([...updatedFacetList, ...identitySubFilters]), | ||
]; | ||
} else if (value === 'docusaurus_tag:docs-maintain-current') { | ||
updatedFacetList = [ | ||
...new Set([...updatedFacetList, ...maintainSubFilters]), | ||
]; | ||
} | ||
} else { | ||
// If a parent filter is unchecked, remove its child filters | ||
if (value === 'docusaurus_tag:docs-build-current') { | ||
updatedFacetList = updatedFacetList.filter( | ||
(facet) => !buildSubFilters.includes(facet), | ||
); | ||
} else if (value === 'docusaurus_tag:docs-identity-rs-1-0-current') { | ||
updatedFacetList = updatedFacetList.filter( | ||
(facet) => !identitySubFilters.includes(facet), | ||
); | ||
} else if (value === 'docusaurus_tag:docs-maintain-current') { | ||
updatedFacetList = updatedFacetList.filter( | ||
(facet) => !maintainSubFilters.includes(facet), | ||
); | ||
} | ||
} | ||
|
||
setSelectedFacets([selectedFacets[0], updatedFacetList]); | ||
}; | ||
|
||
const handleSelectAll = (event) => { | ||
const checked = event.target.checked; | ||
const updatedFacetList = checked ? actualFacets.slice() : []; | ||
setSelectedFacets([selectedFacets[0], updatedFacetList]); | ||
}; | ||
|
||
useEffect(() => { | ||
// Check if all subfilters are selected, if yes, select the parent filter | ||
const parentFilterStatus = { | ||
'docusaurus_tag:docs-maintain-current': maintainSubFilters.every( | ||
(facet) => selectedFacets[1].includes(facet), | ||
), | ||
'docusaurus_tag:docs-build-current': buildSubFilters.every((facet) => | ||
selectedFacets[1].includes(facet), | ||
), | ||
'docusaurus_tag:docs-identity-rs-1-0-current': identitySubFilters.every( | ||
(facet) => selectedFacets[1].includes(facet), | ||
), | ||
}; | ||
|
||
Object.keys(parentFilterStatus).forEach((parentFilter) => { | ||
if ( | ||
parentFilterStatus[parentFilter] && | ||
!selectedFacets[1].includes(parentFilter) | ||
) { | ||
setSelectedFacets((prevState) => [ | ||
prevState[0], | ||
[...prevState[1], parentFilter], | ||
]); | ||
} | ||
}); | ||
}, [selectedFacets, setSelectedFacets]); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (isBrowser && window.scrollY > 28) { | ||
setIsScrolled(true); | ||
} | ||
}; | ||
handleScroll(); | ||
}, [isBrowser && window.scrollY]); | ||
|
||
return ( | ||
<div | ||
className={clsx('dropdown dropdown--hoverable', styles.dropdown, { | ||
[styles.activeAnnouncementBar]: isAnnouncementBarActive, | ||
[styles.isScrolled]: isScrolled, | ||
})} | ||
style={styleProps} | ||
ref={ref} | ||
> | ||
<button | ||
className={clsx( | ||
'button button--primary button--outline', | ||
styles.filterButton, | ||
)} | ||
> | ||
filter | ||
</button> | ||
<ul className={clsx('dropdown__menu', styles.dropdownMenu)}> | ||
<label> | ||
<input | ||
disabled={actualFacets.every((facet) => | ||
selectedFacets[1].includes(facet), | ||
)} | ||
type='checkbox' | ||
onChange={handleSelectAll} | ||
checked={actualFacets.every((facet) => | ||
selectedFacets[1].includes(facet), | ||
)} | ||
/> | ||
Select All | ||
</label> | ||
{actualFacets.map((facet, index) => ( | ||
<li key={index} className={clsx(styles.dropdownElements)}> | ||
<label | ||
className={ | ||
subFilters.includes(facetNamesJson[facet]) | ||
? clsx(styles.subFilters) | ||
: subChildFilters.includes(facetNamesJson[facet]) | ||
? clsx(styles.subChildFilters) | ||
: '' | ||
} | ||
> | ||
<input | ||
style={{ width: '10px' }} | ||
type='checkbox' | ||
value={facet} | ||
onChange={handleCheckboxChange} | ||
checked={selectedFacets[1].includes(facet)} | ||
/> | ||
{facetNamesJson.hasOwnProperty(facet) | ||
? facetNamesJson[facet] | ||
: facet.slice(15)} | ||
</label> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}, | ||
); |
Oops, something went wrong.
Oops, something went wrong.
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 want this? I think in most cases the search filter state should revert again 🤔