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: Integrated Optimizely Prompt Experiment #52

Merged
merged 13 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Default CI
on:
on:
push:
branches:
- 'main'
Expand Down Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Lint
run: npm run lint
- name: Test
run: npm run test
run: npm run test:ci
- name: Build
run: npm run build
- name: i18n_extract
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Test
run: npm run test
run: npm run test:ci
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
68 changes: 52 additions & 16 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .",
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
"test": "fedx-scripts jest --coverage --passWithNoTests"
"test": "fedx-scripts jest --coverage --passWithNoTests",
"test:ci": "fedx-scripts jest --silent --coverage --passWithNoTests"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reduces CI checks log file size from 30KB to 8KB by silencing warnings.
At some point warnings should be reduced, but we are not taking them into account on the CI, so we just might just remove them.

Copy link
Member Author

@rijuma rijuma Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, some warnings are caused by external libraries, like @openedx/paragon icons for example. When testing, the library renders the icons as <IconMock /> by the use of a string reference rather than a component causing the following warning:

    Warning: <IconMock /> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
        at IconMock
        at button
        at /Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/react-bootstrap/cjs/Button.js:28:23
        at children (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/@openedx/paragon/src/Button/index.jsx:12:3)
        at div
        at isOpen (/Users/marcos/edx/src/frontend-lib-learning-assistant/src/components/ToggleXpertButton/index.jsx:20:3)
        at Provider (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/react-redux/lib/components/Provider.js:21:20)
        at IntlProvider (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/react-intl/src/components/provider.js:33:47)
        at children (/Users/marcos/edx/src/frontend-lib-learning-assistant/src/utils/utils.test.jsx:19:22)

This warning stacks up for every render.

},
"files": [
"/dist"
Expand Down Expand Up @@ -72,6 +73,7 @@
"@reduxjs/toolkit": "1.8.1",
"@testing-library/jest-dom": "6.4.5",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"glob": "7.2.3",
"husky": "7.0.4",
Expand Down
28 changes: 15 additions & 13 deletions src/components/Disclosure/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ const Disclosure = ({ children }) => (
</ul>
</div>
</div>
<p className="disclaimer text-light-100 py-3">
<strong>Note: </strong>
This chat is AI generated (powered by ChatGPT). Mistakes are possible.
By using it you agree that edX may create a record of this chat.
Your personal data will be used as described in our&nbsp;
<Hyperlink
className="privacy-policy-link text-light-100"
destination={getConfig().PRIVACY_POLICY_URL}
>
privacy policy
</Hyperlink>
.
</p>
{getConfig().PRIVACY_POLICY_URL ? (
<p className="disclaimer text-light-100 py-3">
<strong>Note: </strong>
This chat is AI generated (powered by ChatGPT). Mistakes are possible.
By using it you agree that edX may create a record of this chat.
Your personal data will be used as described in our&nbsp;
<Hyperlink
className="privacy-policy-link text-light-100"
destination={getConfig().PRIVACY_POLICY_URL}
>
privacy policy
</Hyperlink>
.
</p>
) : null }
Copy link
Member Author

@rijuma rijuma Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves a warning in the tests. Since getConfig().PRIVACY_POLICY_URL is undefined on the test environment, it throws a warning since destination is a required prop for <Hyperlink>.

The full warning was:

Warning: Failed prop type: The prop `destination` is marked as required in `ForwardRef`, but its value is `undefined`.
        at className (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/@openedx/paragon/src/Hyperlink/index.jsx:15:5)
        at _classCallCheck (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/@openedx/paragon/src/withDeprecatedProps.tsx:28:27)
        at p
        at div
        at children (/Users/marcos/edx/src/frontend-lib-learning-assistant/src/components/Disclosure/index.jsx:10:23)
        at div
        at courseId (/Users/marcos/edx/src/frontend-lib-learning-assistant/src/components/Sidebar/index.jsx:23:3)
        at Provider (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/react-redux/lib/components/Provider.js:21:20)
        at IntlProvider (/Users/marcos/edx/src/frontend-lib-learning-assistant/node_modules/react-intl/src/components/provider.js:33:47)
        at children (/Users/marcos/edx/src/frontend-lib-learning-assistant/src/utils/utils.test.jsx:19:22)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it seems like this config value is effectively required for this component maybe we want to make use of ensureConfig()? https://github.com/openedx/frontend-platform/blob/b0ac45329f0ed9022541abea4fe30abf49fde0b1/src/config.js#L264

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I wasn't familiar with all the config options. Updated and it's much cleaner now. Thanks for the suggestion.

{children}
</div>
);
Expand Down
27 changes: 18 additions & 9 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
} from '@openedx/paragon';
import { Close } from '@openedx/paragon/icons';

import { clearMessages } from '../../data/thunks';
import { PROMPT_EXPERIMENT_FLAG, PROMPT_EXPERIMENT_KEY } from '../../constants/experiments';
import { showControlSurvey, showVariationSurvey } from '../../utils/surveyMonkey';

import APIError from '../APIError';
import ChatBox from '../ChatBox';
import Disclosure from '../Disclosure';
import MessageForm from '../MessageForm';
import './Sidebar.scss';
import {
clearMessages,
} from '../../data/thunks';

const Sidebar = ({
courseId,
Expand All @@ -28,7 +29,9 @@ const Sidebar = ({
apiError,
disclosureAcknowledged,
messageList,
experiments,
} = useSelector(state => state.learningAssistant);
const { variationKey } = experiments?.[PROMPT_EXPERIMENT_FLAG] || {};
const chatboxContainerRef = useRef(null);
const dispatch = useDispatch();

Expand Down Expand Up @@ -69,17 +72,20 @@ const Sidebar = ({
const handleClick = () => {
setIsOpen(false);

// check to see if hotjar is available, then trigger hotjar event if user has sent and received a message
const hasWindow = typeof window !== 'undefined';
if (hasWindow && window.hj && messageList.length >= 2) {
window.hj('event', 'ocm_learning_assistant_chat_closed');
if (messageList.length >= 2) {
if (variationKey === PROMPT_EXPERIMENT_KEY) {
showVariationSurvey();
} else {
showControlSurvey();
}
}
};

const handleClearMessages = () => {
dispatch(clearMessages());
sendTrackEvent('edx.ui.lms.learning_assistant.clear', {
course_id: courseId,
...(variationKey ? { experiment_name: PROMPT_EXPERIMENT_FLAG, variation_key: variationKey } : {}),
});
};

Expand All @@ -88,7 +94,7 @@ const Sidebar = ({
);

const getSidebar = () => (
<div className="h-100 d-flex flex-column justify-content-stretch">
<div className="h-100 d-flex flex-column justify-content-stretch" data-testid="sidebar-xpert">
<div className="d-flex flex-column align-items-center p-3">
<h1 className="font-weight-bold mb-3">
Hi, I&apos;m Xpert!
Expand Down Expand Up @@ -119,6 +125,7 @@ const Sidebar = ({
aria-label="clear"
variant="primary"
type="button"
data-testid="sidebar-clear-btn"
>
Clear
</Button>
Expand All @@ -130,16 +137,18 @@ const Sidebar = ({
isOpen && (
<div
className="sidebar position-fixed"
data-testid="sidebar"
>
<IconButton
className="chat-close position-absolute m-2 border-0"
src={Close}
iconAs={Icon}
data-testid="close-button"
onClick={handleClick}
alt="close"
aria-label="close"
variant="primary"
invertColors={!disclosureAcknowledged}
data-testid="close-button"
/>
{disclosureAcknowledged ? (getSidebar()) : (<Disclosure>{getMessageForm()}</Disclosure>)}
</div>
Expand Down
Loading
Loading