From b955e23d0974dc6f241b415768258b1947e17cd2 Mon Sep 17 00:00:00 2001 From: Tiberiu Ichim Date: Fri, 10 Feb 2023 14:10:13 +0200 Subject: [PATCH] WIP --- .../components/SearchApp/useSearchApp.js | 1 - searchlib/lib/utils.js | 1 + .../templates/SearchResultsView.jsx | 23 ++++++++++++++++++- src/SearchBlock/utils.js | 19 +++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/searchlib/components/SearchApp/useSearchApp.js b/searchlib/components/SearchApp/useSearchApp.js index b8b9cc26c..10f6b82a6 100644 --- a/searchlib/components/SearchApp/useSearchApp.js +++ b/searchlib/components/SearchApp/useSearchApp.js @@ -50,7 +50,6 @@ export default function useSearchApp(props) { // useWhyDidYouUpdate('sss', props); const appConfig = React.useMemo(() => { - // console.log('redo appConfig'); return { ...applyConfigurationSchema(rebind(registry.searchui[appName])), appName, diff --git a/searchlib/lib/utils.js b/searchlib/lib/utils.js index 608150d71..2049bcd74 100644 --- a/searchlib/lib/utils.js +++ b/searchlib/lib/utils.js @@ -63,6 +63,7 @@ export function applyConfigurationSchema(config) { config.disjunctiveFacets.push(facet.field); } }); + return config; } diff --git a/src/SearchBlock/templates/SearchResultsView.jsx b/src/SearchBlock/templates/SearchResultsView.jsx index dd487412a..03e52c7bd 100644 --- a/src/SearchBlock/templates/SearchResultsView.jsx +++ b/src/SearchBlock/templates/SearchResultsView.jsx @@ -78,6 +78,8 @@ SearchResultsView.schemaEnhancer = ({ schema, formData }) => { 'defaultResultView', 'alwaysSearchOnInitialLoad', 'showFilters', + 'availableFacets', + 'defaultFacets', 'defaultFilters', 'defaultSort', ], @@ -99,11 +101,21 @@ SearchResultsView.schemaEnhancer = ({ schema, formData }) => { configPath: 'showFilters', }, defaultFilters: { - title: 'Default filters', + title: 'Pre-applied filters', widget: 'object_list', schema: FilterSchema({ formData }), schemaExtender: (schema) => schema, }, + availableFacets: { + title: 'Available Facets', + widget: 'array', + choices: [], + }, + defaultFacets: { + title: 'Default Facets', + widget: 'array', + choices: [], + }, defaultSort: { title: 'Default sort', widget: 'sort_widget', @@ -113,6 +125,15 @@ SearchResultsView.schemaEnhancer = ({ schema, formData }) => { if (appConfig) { const { resultViews } = appConfig; + // console.log(appConfig); + + const availableFacets = appConfig.facets?.map(({ field, label }) => [ + field, + label, + ]); + + schema.properties.availableFacets.choices = availableFacets; + schema.properties.defaultFacets.choices = availableFacets; // fill in defaultResultView choices schema.properties.defaultResultView = { diff --git a/src/SearchBlock/utils.js b/src/SearchBlock/utils.js index 1bd06b014..3dd70ad05 100644 --- a/src/SearchBlock/utils.js +++ b/src/SearchBlock/utils.js @@ -45,6 +45,25 @@ const _applyBlockSettings = (config, appName, data, schema) => { view.isDefault = view.id === data.defaultResultView; }); } + + // console.log(settings, data); + const availableFacets = [ + ...(data.availableFacets || []), + ...(data.defaultFacets || []), + ]; + + if (data.availableFacets) { + settings.facets.forEach((f) => { + f.showInFacetsList = availableFacets.indexOf(f.field) > -1 ? true : false; + }); + } + + if (data.defaultFacets) { + settings.facets.forEach((f) => { + f.alwaysVisible = data.defaultFacets.indexOf(f.field) > -1 ? true : false; + }); + } + return config; };