Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ai answer #22

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@appbaseio/enterprise-search-ui": "latest",
"@appbaseio/reactivesearch": "3.42.1",
"@appbaseio/reactivesearch": "^4.0.0",
"@emotion/core": "^10.0.35",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down
5 changes: 4 additions & 1 deletion src/components/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React from 'react';
import { css, jsx } from '@emotion/core';
import get from 'lodash.get';
import { Collapse } from 'antd';
import { componentTypes, ReactiveComponent } from '@appbaseio/reactivesearch';
import {
componentTypes,
ReactiveComponentPrivate as ReactiveComponent,
} from '@appbaseio/reactivesearch';
import createDOMPurify from 'dompurify';
import { getReactDependenciesFromPreferences, staticFacetsIds } from '../utils';
import { mediaMax } from '../utils/media';
Expand Down
20 changes: 15 additions & 5 deletions src/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import React, { Component } from 'react';
import {
ReactiveBase,
SelectedFilters,
ReactiveComponent,
ReactiveComponentPrivate as ReactiveComponent,
componentTypes,
AIAnswer,
} from '@appbaseio/reactivesearch';
import get from 'lodash.get';
import { string, bool } from 'prop-types';
Expand Down Expand Up @@ -306,8 +307,9 @@ class Search extends Component {
defaultPreferences.resultSettings.rsConfig.infiniteScroll,
)
) {
const containerCollection =
document.getElementsByClassName('ant-modal');
const containerCollection = document.getElementsByClassName(
'ant-modal',
);

if (containerCollection && containerCollection.length > 0) {
// eslint-disable-next-line
Expand Down Expand Up @@ -548,8 +550,7 @@ class Search extends Component {
url={this.url}
credentials={this.credentials}
theme={this.theme}
enableAppbase
appbaseConfig={{
reactivesearchAPIConfig={{
recordAnalytics: true,
...userIdObj,
}}
Expand Down Expand Up @@ -699,6 +700,15 @@ class Search extends Component {
</div>
) : null}

{this.resultSettings.showAIAnswer ? (
<AIAnswer
componentId="AI_ANSWER"
showIcon
react={{ and: 'search' }}
enterButton
/>
) : null}

<ResultsLayoutByCategory
preferences={this.preferences}
toggleFilters={toggleFilters}
Expand Down
32 changes: 32 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,42 @@ function transformPreferences(preferences) {
resultComponent.resultHighlight
? highlightConfig
: undefined;
resultComponent.rsConfig.dataField =
resultComponent.fields.title.dataField || 'title';
}
if (searchComponent) {
searchComponent.rsConfig.highlightConfig =
searchComponent.highlight ? highlightConfig : undefined;
searchComponent.rsConfig.dataField =
searchComponent.fields.title.dataField || 'title';

if (
searchComponent.rsConfig &&
searchComponent.rsConfig.AIUIConfig
) {
let { AIUIConfig } = searchComponent.rsConfig;
try {
AIUIConfig = {
...AIUIConfig,
renderSourceDocument:
AIUIConfig &&
AIUIConfig.sourceDocumentLabel &&
!AIUIConfig.renderSourceDocument
? // eslint-disable-next-line no-new-func
new Function(
'source',
`return ${AIUIConfig.sourceDocumentLabel}`,
)
: AIUIConfig.renderSourceDocument,
};
delete AIUIConfig.sourceDocumentLabel;
} catch {
console.error(
'Invalid string passed to renderSourceDocument function',
);
}
searchComponent.rsConfig.AIUIConfig = AIUIConfig;
}
}
},
);
Expand Down
97 changes: 63 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
jsonpointer "^5.0.0"
leven "^3.1.0"

"@appbaseio/analytics@^1.2.0-alpha.1":
version "1.2.0-alpha.1"
resolved "https://registry.yarnpkg.com/@appbaseio/analytics/-/analytics-1.2.0-alpha.1.tgz#786fce19ac03930aa8698aaf6929856c208778d6"
integrity sha512-IoRR71bah4w7LwgdokL7RVa67CX/CDmusNacupqOtFo8o81tA2w91Lq8NIpT1EVn3Cm3RD2TxzRJBs3Ls1nmGg==
dependencies:
cross-fetch "^3.0.4"

"@appbaseio/enterprise-search-ui@latest":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@appbaseio/enterprise-search-ui/-/enterprise-search-ui-1.1.1.tgz#0e62ebd2877e62beab8840bfecf7433842c56b88"
Expand All @@ -104,27 +111,30 @@
lodash "^4.17.21"
lodash-es "^4.17.21"

"@appbaseio/reactivecore@9.14.29":
version "9.14.29"
resolved "https://registry.yarnpkg.com/@appbaseio/reactivecore/-/reactivecore-9.14.29.tgz#fe75b9a9394f65fef4dbc06ff8c2fce301dab6e0"
integrity sha512-zdBALqZ91y1lZCKoVLekA7sc0x1qCPaXdJG9PiUawGZG+KojizNz9rZZoXSRoJCZ36q47rj+qcKzWKma6oHKyQ==
"@appbaseio/reactivecore@10.0.0":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@appbaseio/reactivecore/-/reactivecore-10.0.0.tgz#c1d510b33345907498347fadd3854dc20843c2e8"
integrity sha512-j22qeXlcjzp2hgJ5ProVv39tvMHbXfFmFLEqKJGuel2xRnLg+LzaNrLYDo6Bhfcf1TYOy3Rf0b8A3g+tjMGvPg==
dependencies:
cross-fetch "^3.0.4"
dayjs "^1.11.7"
prop-types "^15.6.0"
redux "^4.0.0"
redux-thunk "^2.3.0"
xdate "^0.8.2"

"@appbaseio/reactivesearch@3.42.1":
version "3.42.1"
resolved "https://registry.yarnpkg.com/@appbaseio/reactivesearch/-/reactivesearch-3.42.1.tgz#5f02dc967f5a6448b6f665eb0415e6a0f75d411e"
integrity sha512-6oR6Y/c6XRIOI/T2EbKwEBUEFO3AydjrHybaD6Ehu+ob2SIkWz0DidI41oPno0C1ltF/DEIlSi1EpSPQ6lRxvw==
"@appbaseio/reactivesearch@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@appbaseio/reactivesearch/-/reactivesearch-4.0.1.tgz#f2d8b49e570b7b8d472131bfafeb68c9894a7e00"
integrity sha512-xcc26jAi5ELfPfjYX+D+heBfrTRRpLDosbX6behyG+bbupRVFqldesEAJNHEG1P09FOwwFcpAj5q8RJnuwMhyA==
dependencies:
"@appbaseio/reactivecore" "9.14.29"
"@appbaseio/analytics" "^1.2.0-alpha.1"
"@appbaseio/reactivecore" "10.0.0"
"@appbaseio/rheostat" "^1.0.0-alpha.15"
"@emotion/core" "^10.0.28"
"@emotion/styled" "^10.0.27"
appbase-js "^5.2.0"
appbase-js "^5.3.3"
cross-env "^5.2.0"
dayjs "^1.11.7"
downshift "^1.31.2"
echarts "^5.3.3"
echarts-for-react "^3.0.2"
Expand All @@ -135,11 +145,18 @@
prop-types "^15.6.0"
react-day-picker "^7.0.5"
react-redux "^6.0.1"
rheostat "^2.1.1"
remarkable "^2.0.1"
url-search-params-polyfill "^7.0.0"
xdate "^0.8.2"
xss "^1.0.11"

"@appbaseio/rheostat@^1.0.0-alpha.15":
version "1.0.0-alpha.15"
resolved "https://registry.yarnpkg.com/@appbaseio/rheostat/-/rheostat-1.0.0-alpha.15.tgz#c4db000c7e0adf973aaf95951ab9b4e90d806b26"
integrity sha512-dFDWv8SGGLRv5yGcQ5/3zYhVRDq2iIYmmU5v6s4/R0XRj2zCwld5O9DWi8WBZiDQJWQ7/7YUWTzqEgtxbYMOJA==
dependencies:
object.assign "^4.0.4"
prop-types "^15.5.10"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.18.6", "@babel/code-frame@^7.8.3":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a"
Expand Down Expand Up @@ -2970,10 +2987,10 @@ anymatch@^3.0.3, anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"

appbase-js@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/appbase-js/-/appbase-js-5.2.0.tgz#990da7227ae89cd0a002fdfc85428a001306ac27"
integrity sha512-4B/xXivn7i6CATxcRZauDplCL3m9imOmbLH7j+cW4xwkqSN3aHDtj/OuvJDQqaMG0Awon8HUiiuwdh0+yY9DAw==
appbase-js@^5.3.3:
version "5.3.4"
resolved "https://registry.yarnpkg.com/appbase-js/-/appbase-js-5.3.4.tgz#c30add29133fcfd7cc938a710a347cb89377670e"
integrity sha512-rbjCC7jmcPh1cjnW3W7TjTugQpLOB8SrPIdnkKwrNDdsl8d0nzPTJH4/082UTnkvlMkjm4WYY2HYCRl2vpDlpw==
dependencies:
cross-fetch "^3.1.5"
querystring "^0.2.0"
Expand All @@ -2984,7 +3001,7 @@ arg@^5.0.2:
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.2.tgz#c81433cc427c92c4dcf4865142dbca6f15acd59c"
integrity sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==

argparse@^1.0.7:
argparse@^1.0.10, argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
Expand Down Expand Up @@ -3121,6 +3138,13 @@ at-least-node@^1.0.0:
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==

autolinker@^3.11.0:
version "3.16.2"
resolved "https://registry.yarnpkg.com/autolinker/-/autolinker-3.16.2.tgz#6bb4f32432fc111b65659336863e653973bfbcc9"
integrity sha512-JiYl7j2Z19F9NdTmirENSUUIIL/9MytEWtmzhfmsKPCp9E+G35Y0UNCMoM9tFigxT59qSc8Ml2dlZXOCVTYwuA==
dependencies:
tslib "^2.3.0"

autoprefixer@^10.4.13:
version "10.4.13"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.13.tgz#b5136b59930209a321e9fa3dca2e7c4d223e83a8"
Expand Down Expand Up @@ -4139,7 +4163,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==

[email protected]:
[email protected], dayjs@^1.11.7:
version "1.11.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==
Expand Down Expand Up @@ -7414,7 +7438,7 @@ object-keys@^1.1.1:
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==

object.assign@^4.1.0, object.assign@^4.1.2, object.assign@^4.1.3, object.assign@^4.1.4:
object.assign@^4.0.4, object.assign@^4.1.4:
version "4.1.4"
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.4.tgz#9673c7c7c351ab8c4d0b516f4343ebf4dfb7799f"
integrity sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==
Expand All @@ -7424,6 +7448,16 @@ object.assign@^4.1.0, object.assign@^4.1.2, object.assign@^4.1.3, object.assign@
has-symbols "^1.0.3"
object-keys "^1.1.1"

object.assign@^4.1.2, object.assign@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.3.tgz#d36b7700ddf0019abb6b1df1bb13f6445f79051f"
integrity sha512-ZFJnX3zltyjcYJL0RoCJuzb+11zWGyaDbjgxZbdV7rFEcHQuYxrZqhow67aA7xpes6LhojyFDaBKAFfogQrikA==
dependencies:
call-bind "^1.0.2"
define-properties "^1.1.4"
has-symbols "^1.0.3"
object-keys "^1.1.1"

object.entries@^1.1.5, object.entries@^1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/object.entries/-/object.entries-1.1.6.tgz#9737d0e5b8291edd340a3e3264bb8a3b00d5fa23"
Expand Down Expand Up @@ -9624,6 +9658,14 @@ relateurl@^0.2.7:
resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9"
integrity sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog==

remarkable@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/remarkable/-/remarkable-2.0.1.tgz#280ae6627384dfb13d98ee3995627ca550a12f31"
integrity sha512-YJyMcOH5lrR+kZdmB0aJJ4+93bEojRZ1HGDn9Eagu6ibg7aVZhc3OWbbShRid+Q5eAfsEqWxpe+g5W5nYNfNiA==
dependencies:
argparse "^1.0.10"
autolinker "^3.11.0"

renderkid@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/renderkid/-/renderkid-3.0.0.tgz#5fd823e4d6951d37358ecc9a58b1f06836b6268a"
Expand Down Expand Up @@ -9716,14 +9758,6 @@ reusify@^1.0.4:
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==

rheostat@^2.1.1:
version "2.2.0"
resolved "https://registry.yarnpkg.com/rheostat/-/rheostat-2.2.0.tgz#d6b388e21f9c6bf5753a8e9518a8eea3467287d2"
integrity sha512-cO6MvZ3fXtgP7NH7smWZhZczropunZJ50cdCLdlXR5Rhw0FNRaMM23Wx4NJjs5TGta3jOec39A/L0Lg8h8bPRQ==
dependencies:
object.assign "^4.1.0"
prop-types "^15.6.0"

rimraf@^3.0.0, rimraf@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
Expand Down Expand Up @@ -10589,7 +10623,7 @@ tslib@^1.8.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.0.3:
tslib@^2.0.3, tslib@^2.3.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
Expand Down Expand Up @@ -11291,11 +11325,6 @@ ws@^8.4.2:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.12.1.tgz#c51e583d79140b5e42e39be48c934131942d4a8f"
integrity sha512-1qo+M9Ba+xNhPB+YTWUlK6M17brTut5EXbcBaMRN5pH5dFrXz7lzz1ChFSUq3bOUl8yEvSenhHmYUNJxFzdJew==

xdate@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/xdate/-/xdate-0.8.2.tgz#d7b033c00485d02695baf0044f4eacda3fc961a3"
integrity sha512-sNBlLfOC8S3V0vLDEUianQOXcTsc9j4lfeKU/klHe0RjHAYn0CXsSttumTot8dzalboV8gZbH38B+WcCIBjhFQ==

xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
Expand Down