Removed the isCommunity filter / custom filter labels functionality (only used for that before)
This commit is contained in:
@@ -48,7 +48,7 @@ const settings: ObjectMap<IAlgoliaSettings> = {
|
||||
},
|
||||
tools: {
|
||||
...sharedSettings,
|
||||
attributesForFaceting: ['type', 'tags', 'difficulty', 'isCommunity'],
|
||||
attributesForFaceting: ['type', 'tags', 'difficulty'],
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -6,7 +6,6 @@ import { colors } from 'ts/style/colors';
|
||||
export interface IFilterProps extends IFilterCheckboxProps {
|
||||
label: string;
|
||||
currentRefinement: string[];
|
||||
customLabels?: ICustomLabels;
|
||||
isDisabled?: boolean;
|
||||
value: string;
|
||||
refine: (value: string | string[]) => void;
|
||||
@@ -16,20 +15,7 @@ interface IFilterCheckboxProps {
|
||||
isRefined: boolean;
|
||||
}
|
||||
|
||||
interface ICustomLabels {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export const Filter: React.FC<IFilterProps> = ({
|
||||
currentRefinement,
|
||||
customLabels,
|
||||
isDisabled,
|
||||
isRefined,
|
||||
label,
|
||||
refine,
|
||||
}) => {
|
||||
const filterLabel = customLabels ? customLabels[label] : label;
|
||||
|
||||
export const Filter: React.FC<IFilterProps> = ({ currentRefinement, isDisabled, isRefined, label, refine }) => {
|
||||
const handleClick = () => {
|
||||
if (isRefined) {
|
||||
const refinement = [...currentRefinement].filter((item: string) => item !== label); // Remove from current refinement
|
||||
@@ -42,7 +28,7 @@ export const Filter: React.FC<IFilterProps> = ({
|
||||
return (
|
||||
<FilterWrapper isDisabled={isDisabled} onClick={handleClick}>
|
||||
<FilterCheckbox isRefined={isRefined} />
|
||||
<FilterLabel>{filterLabel}</FilterLabel>
|
||||
<FilterLabel>{label}</FilterLabel>
|
||||
</FilterWrapper>
|
||||
);
|
||||
};
|
||||
|
@@ -10,12 +10,6 @@ interface IFiltersProps {
|
||||
interface IFiltersGroupProps {
|
||||
attribute: string;
|
||||
heading: string;
|
||||
hiddenLabels?: string[];
|
||||
customLabels?: ICustomLabels;
|
||||
}
|
||||
|
||||
interface ICustomLabels {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export const Filters: React.FC<IFiltersProps> = ({ filters }) => {
|
||||
|
@@ -11,9 +11,7 @@ import { difficultyOrder } from 'ts/utils/algolia_constants';
|
||||
interface IFilterListProps {
|
||||
attribute: string;
|
||||
currentRefinement: string[];
|
||||
customLabels?: ICustomLabels;
|
||||
heading: string;
|
||||
hiddenLabels?: string[];
|
||||
isDisabled?: boolean;
|
||||
items: IFilterProps[];
|
||||
operator: string;
|
||||
@@ -21,19 +19,7 @@ interface IFilterListProps {
|
||||
transformItems: (items: IFilterProps[]) => void;
|
||||
}
|
||||
|
||||
interface ICustomLabels {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
const FiltersList: React.FC<IFilterListProps> = ({
|
||||
attribute,
|
||||
items,
|
||||
currentRefinement,
|
||||
customLabels,
|
||||
heading,
|
||||
hiddenLabels,
|
||||
refine,
|
||||
}) => {
|
||||
const FiltersList: React.FC<IFilterListProps> = ({ attribute, items, currentRefinement, heading, refine }) => {
|
||||
const [filters, setFilters] = React.useState<IFilterProps[]>([]);
|
||||
// Note (Piotr): Whenever you choose a filter (refinement), algolia removes all filters that could not match the query.
|
||||
// What we are doing instead is first grabbing the list of all possible filters on mount (or clearing all filters) and
|
||||
@@ -85,20 +71,9 @@ const FiltersList: React.FC<IFilterListProps> = ({
|
||||
<Heading asElement="h3" size={18} fontWeight="400" marginBottom="1rem">
|
||||
{heading}
|
||||
</Heading>
|
||||
{sortedFilters.map((filter: IFilterProps, index: number) => {
|
||||
if (hiddenLabels && hiddenLabels.includes(filter.label)) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Filter
|
||||
key={`filter-${index}`}
|
||||
currentRefinement={currentRefinement}
|
||||
customLabels={customLabels}
|
||||
refine={refine}
|
||||
{...filter}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{sortedFilters.map((filter: IFilterProps, index: number) => (
|
||||
<Filter key={`filter-${index}`} currentRefinement={currentRefinement} refine={refine} {...filter} />
|
||||
))}
|
||||
</FiltersGroupWrapper>
|
||||
);
|
||||
};
|
||||
|
@@ -124,10 +124,4 @@ const filters = [
|
||||
{ attribute: 'type', heading: 'Type' },
|
||||
{ attribute: 'tags', heading: 'Developer Persona' },
|
||||
{ attribute: 'difficulty', heading: 'Level' },
|
||||
{
|
||||
attribute: 'isCommunity',
|
||||
heading: 'Community maintained',
|
||||
hiddenLabels: ['false'],
|
||||
customLabels: { true: 'Only community maintained' },
|
||||
},
|
||||
];
|
||||
|
Reference in New Issue
Block a user