Skip to content

Commit

Permalink
Recommendations v2 (openedx#1040)
Browse files Browse the repository at this point in the history
* feat: add personalized recommendations (openedx#1024)

* use Algolia for personalized recommendations
* show personalized recommendations to use that have consented
to functional cookies
* update tests

VAN-1599

* Revert "fix: special characters in redirect url getting decoded to space (openedx#1029)" (openedx#1030)

This reverts commit fc62241.

* feat: update recommendations page design (openedx#1036)

VAN-1598

* feat: add events for recommendations (openedx#1039)

* feat: remove static recommendations

---------

Co-authored-by: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com>
  • Loading branch information
2 people authored and snglth committed Jan 9, 2024
1 parent 959f902 commit a86a8b5
Show file tree
Hide file tree
Showing 34 changed files with 1,200 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SEARCH_CATALOG_URL=''
DISABLE_ENTERPRISE_LOGIN=''
ENABLE_DYNAMIC_REGISTRATION_FIELDS=''
ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN=''
ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS=''
ENABLE_POST_REGISTRATION_RECOMMENDATIONS=''
MARKETING_EMAILS_OPT_IN=''
SHOW_CONFIGURABLE_EDX_FIELDS=''
# ***** Zendesk related keys *****
Expand Down
222 changes: 217 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@optimizely/react-sdk": "^2.9.1",
"@redux-devtools/extension": "3.2.5",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"algoliasearch": "^4.14.3",
"algoliasearch-helper": "^3.14.0",
"classnames": "2.3.2",
"core-js": "3.32.0",
"fastest-levenshtein": "1.0.16",
Expand Down
6 changes: 3 additions & 3 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const configuration = {
DISABLE_ENTERPRISE_LOGIN: process.env.DISABLE_ENTERPRISE_LOGIN || '',
ENABLE_DYNAMIC_REGISTRATION_FIELDS: process.env.ENABLE_DYNAMIC_REGISTRATION_FIELDS || false,
ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN: process.env.ENABLE_PROGRESSIVE_PROFILING_ON_AUTHN || false,
ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS: process.env.ENABLE_POPULAR_AND_TRENDING_RECOMMENDATIONS || false,
ENABLE_POST_REGISTRATION_RECOMMENDATIONS: process.env.ENABLE_POST_REGISTRATION_RECOMMENDATIONS || false,
MARKETING_EMAILS_OPT_IN: process.env.MARKETING_EMAILS_OPT_IN || '',
SHOW_CONFIGURABLE_EDX_FIELDS: process.env.SHOW_CONFIGURABLE_EDX_FIELDS || false,
// Links
Expand All @@ -26,12 +26,12 @@ const configuration = {
BANNER_IMAGE_EXTRA_SMALL: process.env.BANNER_IMAGE_EXTRA_SMALL || '',
// Recommendation constants
GENERAL_RECOMMENDATIONS: process.env.GENERAL_RECOMMENDATIONS || '[]',
POPULAR_PRODUCTS: process.env.POPULAR_PRODUCTS || '[]',
TRENDING_PRODUCTS: process.env.TRENDING_PRODUCTS || '[]',
// Miscellaneous
INFO_EMAIL: process.env.INFO_EMAIL || '',
ZENDESK_KEY: process.env.ZENDESK_KEY,
ZENDESK_LOGO_URL: process.env.ZENDESK_LOGO_URL,
ALGOLIA_APP_ID: process.env.ALGOLIA_APP_ID || '',
ALGOLIA_SEARCH_API_KEY: process.env.ALGOLIA_SEARCH_API_KEY || '',
};

export default configuration;
20 changes: 20 additions & 0 deletions src/data/algolia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getConfig } from '@edx/frontend-platform';
import algoliasearch from 'algoliasearch';

// initialize Algolia workers
const initializeSearchClient = () => algoliasearch(
getConfig().ALGOLIA_APP_ID,
getConfig().ALGOLIA_SEARCH_API_KEY,
);

const getLocationRestrictionFilter = (userCountry) => {
if (userCountry) {
return `NOT blocked_in:"${userCountry}" AND (allowed_in:"null" OR allowed_in:"${userCountry}")`;
}
return '';
};

export {
initializeSearchClient,
getLocationRestrictionFilter,
};
3 changes: 3 additions & 0 deletions src/data/oneTrust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isOneTrustFunctionalCookieEnabled = () => !!window?.OnetrustActiveGroups?.includes('C0003');

export default isOneTrustFunctionalCookieEnabled;
16 changes: 16 additions & 0 deletions src/data/tests/algolia.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getLocationRestrictionFilter } from '../algolia';

describe('algoliaUtilsTests', () => {
it('test getLocationRestrictionFilter returns filter if country is passed', () => {
const countryCode = 'PK';
const filter = getLocationRestrictionFilter(countryCode);
const expectedFilter = `NOT blocked_in:"${countryCode}" AND (allowed_in:"null" OR allowed_in:"${countryCode}")`;
expect(filter).toEqual(expectedFilter);
});
it('test getLocationRestrictionFilter returns empty string if country is not passed', () => {
const countryCode = '';
const filter = getLocationRestrictionFilter(countryCode);
const expectedFilter = '';
expect(filter).toEqual(expectedFilter);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { updatePathWithQueryParams } from './dataUtils';
import { LOGIN_PAGE } from '../constants';
import { updatePathWithQueryParams } from '../utils/dataUtils';

describe('updatePathWithQueryParams', () => {
it('should append query params into the path', () => {
Expand Down

0 comments on commit a86a8b5

Please sign in to comment.