Skip to content

Commit

Permalink
Simplify mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanu1 committed Nov 4, 2021
1 parent 90fafc7 commit 044a6e2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
6 changes: 4 additions & 2 deletions sample-app/src/components/DecoratedAppliedFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { AppliedQueryFilter } from "@yext/answers-core";
import { useAnswersState } from '@yext/answers-headless-react';
import { GroupedFilters } from '../models/groupedFilters';
import { getGroupedAppliedFilters } from '../utils/appliedfilterutils';
import { StaticFiltersLabelConfig } from "./StaticFilters";

export interface DecoratedAppliedFiltersConfig {
showFieldNames?: boolean,
hiddenFields?: Array<string>,
labelText?: string,
delimiter?: string,
staticFiltersGroupLabels?: Record<string, StaticFiltersLabelConfig>,
/**
* A mapping of static filter fieldIds to their displayed group labels.
*/
staticFiltersGroupLabels?: Record<string, string>,
appliedQueryFilters?: AppliedQueryFilter[]
}

Expand Down
4 changes: 0 additions & 4 deletions sample-app/src/components/StaticFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import React, { Fragment } from 'react';
import { Filter, CombinedFilter, FilterCombinator, Matcher } from '@yext/answers-core';
import { AnswersHeadlessContext } from '@yext/answers-headless-react';

export interface StaticFiltersLabelConfig {
label: string
}

interface CheckBoxProps {
fieldId: string,
value: string,
Expand Down
4 changes: 1 addition & 3 deletions sample-app/src/pages/VerticalSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ const facetConfigs = {
}

const staticFiltersGroupLabels = {
c_employeeCountry: {
label: 'Employee Country'
}
c_employeeCountry: 'Employee Country'
}

export default function VerticalSearchPage(props: {
Expand Down
3 changes: 1 addition & 2 deletions sample-app/src/utils/appliedfilterutils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
getDisplayableAppliedFacets,
getDisplayableNlpFilters
} from "./displayablefilterutils";
import { StaticFiltersLabelConfig } from "../components/StaticFilters";

/**
* Returns a new list of nlp filters with duplicates of other filters and
Expand Down Expand Up @@ -65,7 +64,7 @@ export function getGroupedAppliedFilters(
appliedFiltersState: FiltersState,
nlpFilters: AppliedQueryFilter[],
hiddenFields: string[],
staticFiltersGroupLabels: Record<string, StaticFiltersLabelConfig>
staticFiltersGroupLabels: Record<string, string>
): Array<GroupedFilters> {
const displayableStaticFilters = getDisplayableStaticFilters(flattenFilters(appliedFiltersState?.static), staticFiltersGroupLabels);
const displayableFacets = getDisplayableAppliedFacets(appliedFiltersState?.facets);
Expand Down
5 changes: 2 additions & 3 deletions sample-app/src/utils/displayablefilterutils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AppliedQueryFilter, Filter, DisplayableFacet } from '@yext/answers-core';
import { StaticFiltersLabelConfig } from '../components/StaticFilters';
import { DisplayableFilter } from '../models/displayableFilter';
import { getFilterDisplayValue } from './filterutils';

Expand Down Expand Up @@ -32,14 +31,14 @@ export function getDisplayableAppliedFacets(facets: DisplayableFacet[] | undefin
*/
export function getDisplayableStaticFilters(
filters: Filter[],
groupLabels: Record<string, StaticFiltersLabelConfig>
groupLabels: Record<string, string>
): DisplayableFilter[] {
let appliedStaticFilters: DisplayableFilter[] = [];
filters?.forEach(filter => {
appliedStaticFilters.push({
filterType: 'STATIC_FILTER',
filter: filter,
groupLabel: groupLabels?.[filter.fieldId]?.label || filter.fieldId,
groupLabel: groupLabels?.[filter.fieldId] || filter.fieldId,
label: getFilterDisplayValue(filter),
});
});
Expand Down

0 comments on commit 044a6e2

Please sign in to comment.