Skip to content
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
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 May 15, 2024
7475323
Add styles for custom search modal
vivekjain23 May 15, 2024
3e05305
Add list of filters for custom search based on facet tags
vivekjain23 May 15, 2024
058ce2f
Add context for search
vivekjain23 May 15, 2024
eb4a6cd
Refactor styles for custom search filter dropdown
vivekjain23 May 17, 2024
b4141e8
Refactor custom search modal
vivekjain23 May 17, 2024
6507c3b
Remove unwanted swizzle component
vivekjain23 May 17, 2024
9e87bb4
Add custom search filter page
vivekjain23 May 17, 2024
5e2c99e
Update list of filters for custom search based on facet tags
vivekjain23 May 17, 2024
4f2aa50
Refactor context for search modal and page
vivekjain23 May 17, 2024
85422c1
lint fix
vivekjain23 May 17, 2024
12110e0
Fix custom dropdown filter name
vivekjain23 May 23, 2024
8e853e2
Refractor custom dropdown filter
vivekjain23 May 23, 2024
607b2df
Update styles for custom dropdown filter
vivekjain23 May 23, 2024
b52cbd5
Add filter constants for custom dropdown filter
vivekjain23 May 23, 2024
5cc1abf
Fix footer alignment in search page
vivekjain23 Jun 6, 2024
ccf24d2
Fix linting errors
vivekjain23 Jun 7, 2024
5829d3b
Fix formatting
vivekjain23 Jun 7, 2024
550bf08
Fix styling
vivekjain23 Jun 12, 2024
c0e589e
Fix filter alignment
vivekjain23 Jun 14, 2024
68aeef9
Merge branch 'main' into feature/search-filters
Dr-Electron Jul 2, 2024
6c24de4
Fix filter build issue
vivekjain23 Jul 4, 2024
9ab4943
Add swizzle version and info
vivekjain23 Jul 5, 2024
31482b1
Add swizzle version and info
vivekjain23 Jul 5, 2024
d3510b6
Update filter select logic
vivekjain23 Jul 22, 2024
fbdf425
Remove unwanted console logs
vivekjain23 Jul 22, 2024
1ddf1d7
Remove search filter from search modal
vivekjain23 Jul 30, 2024
492f1c6
Remove unneeded swizzles
Dr-Electron Aug 5, 2024
a6f1379
Revert footer changes
Dr-Electron Aug 5, 2024
fa062f3
Remove unused dep
Dr-Electron Aug 5, 2024
ff8d16d
Revert change
Dr-Electron Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/theme/Root.js
Copy link
Collaborator

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 🤔

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>
);
}
177 changes: 177 additions & 0 deletions src/theme/SearchPage/FilterDropdown.js
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

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>
);
},
);
Loading
Loading