Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Feb 4, 2025
1 parent bd86bf7 commit 732bc98
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
12 changes: 10 additions & 2 deletions searchlib/components/LandingPage/TilesLandingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import buildStateFacets from '@eeacms/search/lib/search/state/facets';
import { customOrder } from '@eeacms/search/lib/utils';
import { useLandingPageData, useLandingPageRequest } from './state';
import { Icon, Term } from '@eeacms/search/components';
import { withLanguage } from '@eeacms/search/lib/hocs';

const getFacetConfig = (sections, name) => {
return sections?.find((facet) => facet.facetField === name);
Expand Down Expand Up @@ -143,6 +144,9 @@ const LandingPage = (props) => {
}
};

const { language } = props;
const options = { language };

const panes = sections.map((section, index) => {
const tabIndex = index + 1;

Expand Down Expand Up @@ -187,7 +191,11 @@ const LandingPage = (props) => {
appConfig.facets
.filter((f) => f.field !== activeSection && f.default)
.forEach((facet) => {
facet.default.values.forEach((value) =>
const fdefault =
typeof facet.default === 'function'
? facet.default(options)
: facet.default;
fdefault.values.forEach((value) =>
setFilter(
facet.field,
value,
Expand Down Expand Up @@ -276,4 +284,4 @@ const LandingPage = (props) => {
);
};

export default LandingPage;
export default withLanguage(LandingPage);
13 changes: 9 additions & 4 deletions searchlib/components/SearchApp/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ export function resetSearch(resetState) {
driver._updateSearchResults(state);
}

export function clearFilters(except = []) {
export function clearFilters(except = [], options) {
// TODO: tibi add options
const { setFilter } = this.driver;

this.driver.clearFilters(except);
this.appConfig.facets
.filter((f) => !!f.default)
.forEach((facet) => {
facet.default.values.forEach((value) =>
setFilter(facet.field, value, facet.default.type || 'any'),
);
const fdefault =
typeof facet.default === 'function'
? facet.default(options)
: facet.default;
fdefault.values.forEach((value) => {
setFilter(facet.field, value, fdefault.type || 'any');
});
});
}

Expand Down
28 changes: 13 additions & 15 deletions searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export default function useSearchApp(props) {
[appConfig, paramOnSearch, setIsLoading],
);

const onAutocomplete = React.useMemo(() => paramOnAutocomplete(appConfig), [
appConfig,
paramOnAutocomplete,
]);
const onAutocomplete = React.useMemo(
() => paramOnAutocomplete(appConfig),
[appConfig, paramOnAutocomplete],
);

const locationSearchTerm = React.useMemo(
() =>
Expand All @@ -89,6 +89,12 @@ export default function useSearchApp(props) {
[],
);

// we don't want to track the URL if our search app is configured as
// a simple separate app (for ex. search input or landing page that
// trampolines to another instance)
const trackUrlState =
mode === 'edit' ? false : appConfig.url ? false : appConfig.trackUrlState;

const elasticConfig = React.useMemo(
() => ({
...appConfig,
Expand All @@ -103,27 +109,19 @@ export default function useSearchApp(props) {
: {}),
...(initialState || {}),
},
// we don't want to track the URL if our search app is configured as
// a simple separate app (for ex. search input or landing page that
// trampolines to another instance)
trackUrlState:
mode === 'edit'
? false
: appConfig.url
? false
: appConfig.trackUrlState,
trackUrlState,
}),
[
appConfig,
onAutocomplete,
onSearch,
locationSearchTerm,
initialState,
mode,
trackUrlState,
],
);

console.log('elasticConfig', elasticConfig);
// console.log('elasticConfig', elasticConfig);

const { facetOptions } = React.useState(useFacetsWithAllOptions(appConfig));

Expand Down
18 changes: 10 additions & 8 deletions searchlib/lib/search/query/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function buildRequestFilter(filters, config, options = {}) {

// TODO: includeDefaultValues is not actually used anywhere. Instead, it's applied from
// getDefaultFilters in SearchApp
// TODO: tibi implement facet.default as function
const configuredFilters = [
...Object.entries(_configuredFacets).map(([fieldName, facetConfig]) => {
let fc = facetConfig.buildFilter(
Expand Down Expand Up @@ -68,7 +69,7 @@ export function buildRequestFilter(filters, config, options = {}) {
.map((fname) => getTermFilter(_fieldToFilterValueMap[fname]));

const res = [...configuredFilters, ...requestFilters];
console.log('res', { requestFilters, _configuredFacets });
// console.log('res', { requestFilters, _configuredFacets });

return res;
}
Expand Down Expand Up @@ -134,7 +135,8 @@ export function getRangeFilter(filter) {
};
}

const splitter_re = /(?<now>now)\s?(?<op>[\+|\-])\s?(?<count>\d+)(?<quantifier>\w)/;
const splitter_re =
/(?<now>now)\s?(?<op>[\+|\-])\s?(?<count>\d+)(?<quantifier>\w)/;

const DAY = 86400000; // 1000 * 60 * 60 * 24

Expand All @@ -150,12 +152,12 @@ export function getDateRangeFilter(filter, filterConfig) {
quantifier === 'd'
? (x) => x * 1
: quantifier === 'w'
? (x) => x * 7
: quantifier === 'm'
? (x) => x * 30
: quantifier === 'y'
? (x) => x * 365
: (x) => x * 1;
? (x) => x * 7
: quantifier === 'm'
? (x) => x * 30
: quantifier === 'y'
? (x) => x * 365
: (x) => x * 1;

const toDate = (name) => {
if (!name) return {};
Expand Down
2 changes: 1 addition & 1 deletion src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function SearchBlockView(props) {
return reg;
}, [appName, stableData, schema, mode]);

console.log('registry', registry, appName);
// console.log('registry', registry, appName);

useWhyDidYouUpdate('SearchBlockView', {
registry,
Expand Down

0 comments on commit 732bc98

Please sign in to comment.