Skip to content

Commit

Permalink
merge with facet_updates branch
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Dec 15, 2023
2 parents db223bf + 528f293 commit 1c36558
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 23 deletions.
36 changes: 19 additions & 17 deletions searchlib/components/Facets/DropdownFacetsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,25 @@ const DropdownFacetsList = ({ defaultWrapper }) => {
wrapper="DropdownFacetWrapper"
/>
))}
<div className="dropdown-facet">
<Button
className="sui-button basic"
onClick={() => setShowSidebar(true)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
setShowSidebar(true);
}
if (e.key === 'Escape') {
setShowSidebar(false);
}
}}
// disabled={isLiveSearch}
>
<span className="facet-title">+ More filters</span>
</Button>
</div>
{sidebarFacets.length > 0 && (
<div className="dropdown-facet">
<Button
className="sui-button basic"
onClick={() => setShowSidebar(true)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
setShowSidebar(true);
}
if (e.key === 'Escape') {
setShowSidebar(false);
}
}}
// disabled={isLiveSearch}
>
<span className="facet-title">+ More filters</span>
</Button>
</div>
)}
{/*
{filterNames.length > 0 && (
<Button
Expand Down
12 changes: 8 additions & 4 deletions searchlib/components/Facets/Wrappers/AccordionFacetWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { connect } from 'react-redux';
import { Accordion, Icon } from 'semantic-ui-react';
import { useAtom } from 'jotai';
import { openFacetsAtom } from '../state';
Expand All @@ -8,9 +9,9 @@ import Facet from '../Facet';
import { Dimmer } from 'semantic-ui-react';

const AccordionFacetWrapper = (props) => {
const { collapsable = true, field, label, isLoading } = props;
const { collapsable = true, field, label, token, isLoading } = props;
const searchContext = useSearchContext();
const { filters } = searchContext;
const { facets, filters } = searchContext;

const hasFilter = !!filters.find((filter) => field === filter.field);
const [openFacets] = useAtom(openFacetsAtom);
Expand Down Expand Up @@ -43,7 +44,8 @@ const AccordionFacetWrapper = (props) => {

let isOpened = openFacets[field]?.opened || false;
const [counter, setCounter] = React.useState(0);

if (facets[field] === undefined) return null;
if (facet?.authOnly && token === undefined) return null;
return collapsable ? (
<Accordion>
<Accordion.Title
Expand Down Expand Up @@ -100,4 +102,6 @@ const AccordionFacetWrapper = (props) => {
);
};

export default AccordionFacetWrapper;
export default connect((state) => ({
token: state.userSession?.token,
}))(AccordionFacetWrapper);
10 changes: 8 additions & 2 deletions searchlib/components/Facets/Wrappers/DropdownFacetWrapper.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { connect } from 'react-redux';
import {
useAppConfig,
useProxiedSearchContext,
Expand Down Expand Up @@ -31,13 +32,14 @@ const DropdownFacetWrapper = (props) => {
sortedOptions,
filterType,
isLoading,
token,
} = props;
const rawSearchContext = useSearchContext();
const {
searchContext: facetSearchContext,
applySearch,
} = useProxiedSearchContext(rawSearchContext);
const { filters } = facetSearchContext;
const { facets, filters } = facetSearchContext;

const { appConfig } = useAppConfig();
const facet = appConfig.facets?.find((f) => f.field === field);
Expand Down Expand Up @@ -65,6 +67,8 @@ const DropdownFacetWrapper = (props) => {

const { width } = useWindowDimensions();
const isSmallScreen = width < SMALL_SCREEN_SIZE;
if (facets[field] === undefined) return null;
if (facet?.authOnly && token === undefined) return null;

return (
<>
Expand Down Expand Up @@ -199,4 +203,6 @@ const DropdownFacetWrapper = (props) => {
);
};

export default DropdownFacetWrapper;
export default connect((state) => ({
token: state.userSession?.token,
}))(DropdownFacetWrapper);
1 change: 1 addition & 0 deletions src/SearchBlock/SearchBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function SearchBlockView(props) {
const schemaFields = [
'availableFacets',
'defaultFacets',
'authOnlyFacets',
'defaultFilters',
'showClusters',
'defaultSort',
Expand Down
9 changes: 9 additions & 0 deletions src/SearchBlock/templates/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const searchResultsSchemaEnhancer = ({ schema, formData }) => {
'landingPageURL',
'availableFacets',
'defaultFacets',
'authOnlyFacets',
'defaultFilters',
'defaultSort',
],
Expand Down Expand Up @@ -112,6 +113,11 @@ export const searchResultsSchemaEnhancer = ({ schema, formData }) => {
widget: 'array',
choices: [],
},
authOnlyFacets: {
title: 'Facets for authenticated users',
widget: 'array',
choices: [],
},
defaultSort: {
title: 'Default sort',
// widget: 'sort_widget',
Expand All @@ -138,6 +144,9 @@ export const searchResultsSchemaEnhancer = ({ schema, formData }) => {
schema.properties.defaultFacets.choices = availableFacets;
schema.properties.defaultFacets.items = { choices: availableFacets };

schema.properties.authOnlyFacets.choices = availableFacets;
schema.properties.authOnlyFacets.items = { choices: availableFacets };

// fill in defaultResultView choices
schema.properties.defaultResultView = {
...schema.properties.defaultResultView,
Expand Down
6 changes: 6 additions & 0 deletions src/SearchBlock/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const _applyBlockSettings = (config, appName, data, schema) => {
});
}

if (data.authOnlyFacets) {
settings.facets.forEach((f) => {
f.authOnly = data.authOnlyFacets.indexOf(f.field) > -1 ? true : false;
});
}

if (data.defaultFilters) {
const filters = data.defaultFilters
.map((f) => ({
Expand Down

0 comments on commit 1c36558

Please sign in to comment.