Skip to content

Commit f5c1f30

Browse files
committed
Additional solr updates
- update kitconcept.solr to 2.0.0-a2, 2.0.0-alpha.2 - search result style changes - hide builtin search input - keep search term after being submitted - make search result page full width - highlight searchbox on hover and focus - update lockfile, devmode volto-solr - necessary updates on solrSearchAutosuggest - wire the search widget in the header - make search keep current state (ie. sorting by, etc.)
1 parent 62d6ef7 commit f5c1f30

8 files changed

Lines changed: 1141 additions & 985 deletions

File tree

backend/news/191.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for an autocomplete livesearch widget @reebalazs

backend/pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies = [
3535
"pas.plugins.authomatic==2.0.0",
3636
"pas.plugins.keycloakgroups==1.0.0b1",
3737
"pas.plugins.oidc==2.0.0",
38-
"kitconcept.solr==2.0.0a1",
38+
"kitconcept.solr==2.0.0a2"
3939
]
4040

4141
[dependency-groups]
@@ -61,6 +61,9 @@ container = [
6161
"zeo==6.0.0",
6262
]
6363

64+
[tool.hatch.metadata]
65+
allow-direct-references = true
66+
6467
[project.urls]
6568
Homepage = "https://github.com/kitconcept/kitconcept.intranet"
6669
PyPI = "https://pypi.python.org/pypi/kitconcept.intranet"
@@ -288,7 +291,7 @@ constraint-dependencies = [
288291
"jsonschema==4.24.0",
289292
"keyring==25.6.0",
290293
"kitconcept.core==1.0.0a22",
291-
"kitconcept.solr==2.0.0a1",
294+
"kitconcept.solr==2.0.0a2",
292295
"kitconcept.voltolighttheme==7.0.0a27",
293296
"legacy-cgi==2.6.2",
294297
"lockfile==0.12.2",

backend/uv.lock

Lines changed: 974 additions & 974 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/mrs.developer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@
128128
"url": "git@github.com:kitconcept/kitconcept.solr.git",
129129
"https": "https://github.com/kitconcept/kitconcept.solr.git",
130130
"path": "frontend",
131-
"branch": "monorepo"
131+
"branch": "2.0.0-alpha.2"
132132
}
133133
}

frontend/packages/volto-intranet/src/customizations/@kitconcept/volto-light-theme/components/SearchWidget/IntranetSearchWidget.jsx

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { connect } from 'react-redux';
1414
import Icon from '@plone/volto/components/theme/Icon/Icon';
1515
import zoomSVG from '@plone/volto/icons/zoom.svg';
1616

17+
import config from '@plone/volto/registry';
18+
1719
const messages = defineMessages({
1820
search: {
1921
id: 'Search',
@@ -29,11 +31,16 @@ const messages = defineMessages({
2931
},
3032
});
3133

34+
// Fallback Input component in case kitconcept.solr is not installed
35+
// (which provides the SolrSearchAutosuggest widget)
36+
const FallbackInput = (props) => <Input {...props} />;
37+
3238
/**
3339
* IntranetSearchWidget component class.
3440
* @class IntranetSearchWidget
3541
* @extends Component
3642
*/
43+
3744
class IntranetSearchWidget extends Component {
3845
/**
3946
* Property types.
@@ -86,18 +93,53 @@ class IntranetSearchWidget extends Component {
8693
? `&path=${encodeURIComponent(this.props.pathname)}`
8794
: '';
8895

96+
/* START CUSTOMIZATION */
8997
if (searchURL) {
9098
// If searchURL contains {searchTerm}, replace it with the encoded search text
9199
const externalUrl =
92100
searchURL.replace('{searchTerm}', encodeURIComponent(this.state.text)) +
93101
path;
94102
window.open(externalUrl, '_blank', 'noopener,noreferrer');
95103
} else {
96-
this.props.history.push(
97-
`/search?SearchableText=${encodeURIComponent(this.state.text)}${path}`,
98-
);
104+
/*
105+
* These could be imported directly:
106+
*
107+
* ```js
108+
* import {
109+
* queryStateFromParams,
110+
* queryStateToParams,
111+
* qs,
112+
* } from '@kitconcept/volto-solr/components';
113+
* ```
114+
*
115+
* However, we want to avoid to require a dependency on kitconcept.volto-solr.
116+
* So we access these utilities via the registry.
117+
*
118+
*/
119+
const voltoSolrUtils = config.views.voltoSolrUtils;
120+
if (voltoSolrUtils !== undefined) {
121+
const { queryStateFromParams, queryStateToParams, qs } = voltoSolrUtils;
122+
// Update the URL query parameters with the new search text
123+
// Keep the other query params, only update SearchableText.
124+
// This way, sorting, filters, etc. are preserved.
125+
const newQueryParams = queryStateToParams({
126+
...queryStateFromParams(qs.parse(this.props.history.location.search)),
127+
searchword: this.state.text,
128+
// Reset pagination
129+
currentPage: 1,
130+
});
131+
this.props.history.push({
132+
pathname: '/search',
133+
search: qs.stringify(newQueryParams),
134+
});
135+
} else {
136+
// Fall back without volto-solr. Only the search text is set, all other
137+
// query parameters are lost.
138+
this.props.history.push(
139+
`/search?SearchableText=${encodeURIComponent(this.state.text)}${path}`,
140+
);
141+
}
99142
}
100-
/* START CUSTOMIZATION */
101143
// reset input value
102144
// this.setState({
103145
// text: '',
@@ -112,15 +154,20 @@ class IntranetSearchWidget extends Component {
112154
* @returns {string} Markup for the component.
113155
*/
114156
render() {
157+
// Get the SolrSearchAutosuggest widget from the registry,
158+
// with a fallback in case kitconcept.solr is not installed
159+
const SolrSearchAutosuggest =
160+
config.widgets.SolrSearchAutosuggest || FallbackInput;
115161
const { intl } = this.props;
116162
const searchFieldPlaceholder =
117163
this.props.site['kitconcept.intranet.search_field_placeholder'];
118164
return (
119165
<Form action="/search" onSubmit={this.onSubmit}>
120166
<Form.Field className="searchbox">
121-
<Input
167+
<SolrSearchAutosuggest
122168
aria-label={intl.formatMessage(messages.search)}
123169
onChange={this.onChangeText}
170+
onSubmit={this.onSubmit}
124171
name="SearchableText"
125172
value={this.state.text}
126173
transparent

frontend/packages/volto-intranet/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { ConfigType } from '@plone/registry';
1+
import './theme/custom.scss';
2+
import { ConfigType } from '@plone/registry';
23
import installSettings from './config/settings';
34
import installSlots from './config/slots';
45
import installWidgets from './config/widgets';
@@ -21,8 +22,9 @@ declare module '@plone/types' {
2122
const applyConfig = (config: ConfigType) => {
2223
installSettings(config);
2324
installSlots(config);
24-
installWidgets(config);
25-
installBlocks(config);
25+
(
26+
config.settings.solrSearchOptions as { showSearchInput?: boolean }
27+
).showSearchInput = false;
2628
return config;
2729
};
2830

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Make the search page full width
2+
#page-search > .ui.container {
3+
width: 100% !important;
4+
max-width: 1440px !important;
5+
padding: 0 10px !important;
6+
margin: 0 auto !important;
7+
}
8+
9+
// Highlight searchbox on hover and focus
10+
.header-wrapper.intranet-header
11+
.header
12+
.search-wrapper
13+
.search
14+
.field.searchbox {
15+
border: 1px solid transparent !important;
16+
border-radius: 2px;
17+
&:hover,
18+
&:focus,
19+
&:focus-within {
20+
border-color: #2563b5 !important;
21+
box-shadow: 0 0 0 3px rgba(124, 128, 131, 0.3);
22+
transition:
23+
box-shadow 0.2s,
24+
border-color 0.2s;
25+
}
26+
}

frontend/pnpm-lock.yaml

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)