Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Feb 10, 2023
1 parent 76ae965 commit b955e23
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 0 additions & 1 deletion searchlib/components/SearchApp/useSearchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions searchlib/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function applyConfigurationSchema(config) {
config.disjunctiveFacets.push(facet.field);
}
});

return config;
}

Expand Down
23 changes: 22 additions & 1 deletion src/SearchBlock/templates/SearchResultsView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ SearchResultsView.schemaEnhancer = ({ schema, formData }) => {
'defaultResultView',
'alwaysSearchOnInitialLoad',
'showFilters',
'availableFacets',
'defaultFacets',
'defaultFilters',
'defaultSort',
],
Expand All @@ -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',
Expand All @@ -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 = {
Expand Down
19 changes: 19 additions & 0 deletions src/SearchBlock/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit b955e23

Please sign in to comment.