diff --git a/package-lock.json b/package-lock.json index 2d45f69..d5b5e71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23231,6 +23231,10 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", "integrity": "sha512-5teOsQWABXHHBFP9y3skS5P3d/WfWXpv3FUpy+LorMrNYaT9pI4oLMQX7jzQ2KklNpGpWHzdCXTDT2Y3XGlZBw==", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "micromatch": "^3.1.4", "normalize-path": "^2.1.1" @@ -23240,6 +23244,10 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "remove-trailing-separator": "^1.0.1" } @@ -23318,7 +23326,12 @@ "async-each": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", +<<<<<<< Updated upstream "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==" +======= + "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==", + "optional": true +>>>>>>> Stashed changes }, "async-limiter": { "version": "1.0.1", @@ -23409,7 +23422,12 @@ "binary-extensions": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz", +<<<<<<< Updated upstream "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==" +======= + "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==", + "optional": true +>>>>>>> Stashed changes }, "bluebird": { "version": "3.7.1", @@ -23629,6 +23647,10 @@ "version": "2.1.8", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", "integrity": "sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg==", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "anymatch": "^2.0.0", "async-each": "^1.0.1", @@ -24847,6 +24869,10 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "is-glob": "^3.1.0", "path-dirname": "^1.0.0" @@ -24856,6 +24882,10 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "is-extglob": "^2.1.0" } @@ -25038,6 +25068,10 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz", "integrity": "sha1-dfFmQrSA8YenEcgUFh/TpKdlWJg=", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "binary-extensions": "^1.0.0" } @@ -25090,12 +25124,21 @@ "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", +<<<<<<< Updated upstream "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" +======= + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "optional": true +>>>>>>> Stashed changes }, "is-glob": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "is-extglob": "^2.1.1" } @@ -25363,7 +25406,11 @@ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { +<<<<<<< Updated upstream "minimist": "0.0.8" +======= + "minimist": "^1.2.5" +>>>>>>> Stashed changes }, "dependencies": { "minimist": { @@ -25465,7 +25512,12 @@ "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", +<<<<<<< Updated upstream "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" +======= + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "optional": true +>>>>>>> Stashed changes }, "object-assign": { "version": "4.1.1", @@ -25609,7 +25661,12 @@ "path-dirname": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", +<<<<<<< Updated upstream "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=" +======= + "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=", + "optional": true +>>>>>>> Stashed changes }, "path-exists": { "version": "3.0.0", @@ -25793,6 +25850,10 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", "integrity": "sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ==", +<<<<<<< Updated upstream +======= + "optional": true, +>>>>>>> Stashed changes "requires": { "graceful-fs": "^4.1.11", "micromatch": "^3.1.10", @@ -25811,7 +25872,12 @@ "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", +<<<<<<< Updated upstream "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=" +======= + "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=", + "optional": true +>>>>>>> Stashed changes }, "repeat-element": { "version": "1.1.3", @@ -26386,7 +26452,12 @@ "upath": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/upath/-/upath-1.2.0.tgz", +<<<<<<< Updated upstream "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==" +======= + "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==", + "optional": true +>>>>>>> Stashed changes }, "uri-js": { "version": "4.2.2", diff --git a/src/components/theme/View/TabsChildView.jsx b/src/components/theme/View/TabsChildView.jsx index 10bce7a..6ec3fbc 100644 --- a/src/components/theme/View/TabsChildView.jsx +++ b/src/components/theme/View/TabsChildView.jsx @@ -101,7 +101,15 @@ const DefaultView = props => { { +const toSearchOptions = (searchableText, subject, queryOptions) => { return { + fullobjects: true, ...(searchableText && { SearchableText: searchableText }), ...(subject && { Subject: subject, }), - ...(path && { - path: path, - }), + ...(queryOptions && queryOptions), }; }; +const getQueryOptions = (query, schema = false) => { + const options = {}; + isObject(query) && + Object.entries(query).forEach(([key, value]) => { + if (key.includes(':query')) + options[key.split(':')[0]] = !schema + ? value + : { value: isArray(value) ? value : [value] }; + }); + return options; +}; + +const getText = block => { + let text = ''; + if (block.text && typeof block.text === 'string') text = block.text; + if (block.text && block.text.blocks && isArray(block.text.blocks)) { + block.text.blocks.forEach(block => { + text += getText(block); + }); + } + return text; +}; + +const matchedText = (text, searchableText) => { + let matchedText = text; + if (text.length > 256) { + const pos = text.toLowerCase().indexOf(searchableText.toLowerCase()); + const rightPart = text.substring(pos, text.length); + const leftPart = text.substring(0, pos - 1); + matchedText = `[...${leftPart.slice(-128)} ${rightPart.substring( + 0, + 128, + )}...]`; + } + return matchedText; +}; + +const smallText = text => { + if (text.length > 256) return `[...${text.substring(0, 256)}...]`; + return text; +}; + +const paragraph = (text, searchableText) => ( +

+ +

+); + +const getSummary = (item, searchableText) => { + let summary = { + fullSummary: [], + matchedParagraph: [], + firstParagraph: [], + }; + item.blocks && + Object.entries(item.blocks).forEach(([key, block], index) => { + const text = getText(block); + summary.fullSummary.push(paragraph(text, searchableText)); + if (text && text.length > 0 && summary.firstParagraph.length === 0) { + summary.firstParagraph.push(paragraph(smallText(text), searchableText)); + } + if ( + text.toLowerCase().includes(searchableText.toLowerCase()) && + summary.matchedParagraph.length === 0 + ) { + summary.matchedParagraph.push( + paragraph(matchedText(text, searchableText), searchableText), + ); + } + }); + return summary; +}; + /** * Search class. * @class SearchComponent @@ -76,7 +155,7 @@ class Search extends Component { constructor(props) { super(props); - this.state = { currentPage: 1 }; + this.state = { currentPage: 1, expendedItemIndex: -1 }; } /** @@ -88,7 +167,7 @@ class Search extends Component { this.doSearch( this.props.searchableText, this.props.subject, - this.props.path, + getQueryOptions(this.props.query), ); } @@ -106,7 +185,7 @@ class Search extends Component { this.doSearch( nextProps.searchableText, nextProps.subject, - this.props.path, + getQueryOptions(this.props.query), ); } }; @@ -120,21 +199,31 @@ class Search extends Component { * @returns {undefined} */ - doSearch = (searchableText, subject, path) => { + doSearch = (searchableText, subject, queryOptions) => { this.setState({ currentPage: 1 }); this.props.searchContent( '', - toSearchOptions(searchableText, subject, path), + toSearchOptions(searchableText, subject, queryOptions), ); }; + makeQuery(key) { + let query = ''; + const propsQuery = this.props.data?.[key]?.value; + isObject(propsQuery) && + Object.entries(propsQuery).forEach(([itemKey, item]) => { + if (isArray(item)) query += `&${itemKey}:${key}=${item.join(',')}&`; + }); + return query; + } + handleQueryPaginationChange = (e, { activePage }) => { window.scrollTo(0, 0); - this.setState({ currentPage: activePage }, () => { + this.setState({ currentPage: activePage, expendedItemIndex: -1 }, () => { const options = toSearchOptions( qs.parse(this.props.location.search).SearchableText, qs.parse(this.props.location.search).Subject, - qs.parse(this.props.location.search).path, + getQueryOptions(this.props.query), ); this.props.searchContent('', { @@ -156,7 +245,7 @@ class Search extends Component {
-

+

{this.props.title ? ( `${this.props.title}` ) : ( @@ -167,20 +256,28 @@ class Search extends Component { )}

-
- -
+ -
+
{this.props.searchableText ? ( - Results for{' '} - + Results for:{' '} + {this.props.searchableText} - + ) : ( '' @@ -193,33 +290,61 @@ class Search extends Component {
- {this.props.items.map(item => ( -
-

{item.title}

-
- {item['@type'] ? {item['@type']} : ''} - {item['effective'] ? ( - - {moment(item['effective']).format('DD.MM.YYYY')} - - ) : ( - '' - )} -
- {item.description && ( -
- {item.description} + {this.props.items.map((item, index) => ( +
+ +

{item.title}

+ +
+
+ {this.state.expendedItemIndex === index + ? item.summary.fullSummary.length > 0 + ? item.summary.fullSummary.map((paragraph, index) => ( + + {paragraph} + + )) + : item.description + : item.summary.matchedParagraph.length > 0 + ? item.summary.matchedParagraph[0] + : item.summary.firstParagraph.length > 0 + ? item.summary.firstParagraph[0] + : item.description}
- )} -
- - - +
@@ -283,10 +408,19 @@ export const __test__ = connect( export default compose( connect( (state, props) => ({ - items: state.search.items, searchableText: qs.parse(props.location.search).SearchableText, + items: state.search.items.map(item => { + return { + ...item, + '@id': item['@id'].replace(settings.apiPath, ''), + summary: getSummary( + item, + qs.parse(props.location.search).SearchableText, + ), + }; + }), subject: qs.parse(props.location.search).Subject, - path: qs.parse(props.location.search).path, + query: qs.parse(props.location.search), title: qs.parse(props.location.search).title, pathname: props.location.pathname, }), @@ -302,7 +436,7 @@ export default compose( toSearchOptions( qs.parse(location.search).SearchableText, qs.parse(location.search).Subject, - qs.parse(location.search).path, + getQueryOptions(qs.parse(location.search)), ), ), ), diff --git a/theme/site/globals/site.overrides b/theme/site/globals/site.overrides index ec0f404..e8dc363 100644 --- a/theme/site/globals/site.overrides +++ b/theme/site/globals/site.overrides @@ -904,7 +904,7 @@ space-around { transform: translateY(-50%); } - .clear.icon { + .clearIcon { left: unset; right: 1rem; cursor: pointer; @@ -989,18 +989,6 @@ button.solid, margin: 0 !important; } -.ui.segment.form { - .react-select__control, - .ui.input > input, - .inline.field .wrapper { - border: 0; - border-bottom: 0; - border-top: 0; - border-left: 0; - border-right: 0; - } -} - body.has-sidebar { .ui.modal { width: calc(100% - 400px) !important;