Compare commits
172 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02d081dd26 | ||
|
|
468acc80f0 | ||
|
|
90fdd13fbc | ||
|
|
faf1b8522a | ||
|
|
e8a28b09bc | ||
|
|
c611df3f69 | ||
|
|
ab371f1c3a | ||
|
|
fb2002a004 | ||
|
|
f955ec4434 | ||
|
|
d529e00d7b | ||
|
|
e0cbbf7da1 | ||
|
|
ba209fd050 | ||
|
|
ae7004e95d | ||
|
|
bf64a829cc | ||
|
|
1e1b06dfa5 | ||
|
|
469a93bd9c | ||
|
|
0645761f05 | ||
|
|
20e9881546 | ||
|
|
42b347058f | ||
|
|
b097535580 | ||
|
|
d06929ca2b | ||
|
|
0a9316c407 | ||
|
|
d7704799fe | ||
|
|
cc26f750e8 | ||
|
|
8ac22515a6 | ||
|
|
b4a8d0afdc | ||
|
|
c131842139 | ||
|
|
acf5398b31 | ||
|
|
871e35d53a | ||
|
|
c8fb2ded56 | ||
|
|
01ffe0b945 | ||
|
|
092c61dada | ||
|
|
cc43299932 | ||
|
|
9086b96313 | ||
|
|
86b9d4a061 | ||
|
|
36fd9cb89a | ||
|
|
5aec913cd6 | ||
|
|
5da9cc3ce4 | ||
|
|
97e8c69345 | ||
|
|
a410ec8ed6 | ||
|
|
7e197e2315 | ||
|
|
6373bc726f | ||
|
|
1ccf3214f0 | ||
|
|
137701d10c | ||
|
|
37d39dba95 | ||
|
|
5d297a0d00 | ||
|
|
1aa6e80274 | ||
|
|
15778a5e4a | ||
|
|
48c41a7757 | ||
|
|
28ee7518f4 | ||
|
|
c35df7ef60 | ||
|
|
a8d5a0b62a | ||
|
|
9ac38762eb | ||
|
|
72077302c0 | ||
|
|
f1a54ededf | ||
|
|
709844a459 | ||
|
|
032c68edf2 | ||
|
|
be8b6fba01 | ||
|
|
541fe55d6e | ||
|
|
28a62cf263 | ||
|
|
6e7584c89c | ||
|
|
49b03689a0 | ||
|
|
fdb00ce1f5 | ||
|
|
5d1d73a6b6 | ||
|
|
b292ee39ad | ||
|
|
c5f13022de | ||
|
|
47a3962118 | ||
|
|
b55d0d6bea | ||
|
|
8cb19859aa | ||
|
|
bafa6452ca | ||
|
|
3ab658ffa0 | ||
|
|
72b6a2c2a0 | ||
|
|
a479556795 | ||
|
|
8f03fa84ac | ||
|
|
990d82be6a | ||
|
|
b90db977a0 | ||
|
|
093452860e | ||
|
|
8ac9a2dc3c | ||
|
|
440eacbce4 | ||
|
|
725fa982c7 | ||
|
|
fe41fbc0b1 | ||
|
|
0de0a3f07f | ||
|
|
b0009fef42 | ||
|
|
8bfae8bf2f | ||
|
|
abe0bbbf51 | ||
|
|
c6e971ef1d | ||
|
|
2f0a07b7eb | ||
|
|
56593df3bd | ||
|
|
45735231aa | ||
|
|
eb1b914e84 | ||
|
|
2db0fd5c33 | ||
|
|
7e33da45c2 | ||
|
|
632938f354 | ||
|
|
540fe28dc0 | ||
|
|
b5671cc84e | ||
|
|
56963c2eb1 | ||
|
|
1099fcaa74 | ||
|
|
cea6e4814e | ||
|
|
4a6da6bde0 | ||
|
|
3da27f829c | ||
|
|
d45e26d70a | ||
|
|
35731f6cb9 | ||
|
|
4aa29ffafe | ||
|
|
f73df420c8 | ||
|
|
fd13828590 | ||
|
|
0160cbb7e3 | ||
|
|
e82bf4de14 | ||
|
|
4218ea0126 | ||
|
|
72ef660feb | ||
|
|
5a262f5d2f | ||
|
|
ca5a094332 | ||
|
|
8ca2a43835 | ||
|
|
03ce864782 | ||
|
|
25558d995d | ||
|
|
ccdcea7c20 | ||
|
|
f45c238ce2 | ||
|
|
8bec10bbeb | ||
|
|
7cd2e11395 | ||
|
|
bcc0e9afb4 | ||
|
|
5a5ae1eb31 | ||
|
|
334793cb81 | ||
|
|
171d820d60 | ||
|
|
7399c9b6cb | ||
|
|
ff4aaf163b | ||
|
|
72195a63f2 | ||
|
|
7654ad5192 | ||
|
|
c6443d414b | ||
|
|
0057de55bd | ||
|
|
af563a1794 | ||
|
|
a5a66c1f5c | ||
|
|
61ce560c80 | ||
|
|
a9605b576b | ||
|
|
bde691da06 | ||
|
|
c6eb62557e | ||
|
|
20649f06d9 | ||
|
|
f2632fb449 | ||
|
|
d4bf756993 | ||
|
|
076a7c8832 | ||
|
|
ee53d4dfb8 | ||
|
|
42668c6d5a | ||
|
|
5645dd4491 | ||
|
|
2bb3febc39 | ||
|
|
2fb9804b91 | ||
|
|
a09317aaae | ||
|
|
080621bcea | ||
|
|
37e9ef0434 | ||
|
|
df1b6ff941 | ||
|
|
52b8b7ca11 | ||
|
|
9ed0af96ca | ||
|
|
8d0bd0ca05 | ||
|
|
de83d5f20f | ||
|
|
54ff71b0ec | ||
|
|
a8347625ae | ||
|
|
305ae120c6 | ||
|
|
e1468b5396 | ||
|
|
10767bdaac | ||
|
|
484d6af4d9 | ||
|
|
8ba7153806 | ||
|
|
334bdb34f3 | ||
|
|
12b63c5583 | ||
|
|
3726792df2 | ||
|
|
cc252e32e6 | ||
|
|
0c58362b49 | ||
|
|
b00e018105 | ||
|
|
02464f9c09 | ||
|
|
67c1fb2cda | ||
|
|
e84843d83a | ||
|
|
20606c2880 | ||
|
|
3ba52a586e | ||
|
|
9eafcc9ca0 | ||
|
|
61ecf93785 | ||
|
|
917e748fc5 |
@@ -5,8 +5,9 @@ CSRF_TOKEN_API_PATH=/csrf/api/v1/token
|
|||||||
ECOMMERCE_BASE_URL=http://localhost:18130
|
ECOMMERCE_BASE_URL=http://localhost:18130
|
||||||
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
|
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
|
||||||
LMS_BASE_URL=http://localhost:18000
|
LMS_BASE_URL=http://localhost:18000
|
||||||
|
STUDIO_BASE_URL=http://localhost:18010
|
||||||
LOGIN_URL=http://localhost:18000/login
|
LOGIN_URL=http://localhost:18000/login
|
||||||
LOGOUT_URL=http://localhost:18000/login
|
LOGOUT_URL=http://localhost:18000/logout
|
||||||
MARKETING_SITE_BASE_URL=http://localhost:18000
|
MARKETING_SITE_BASE_URL=http://localhost:18000
|
||||||
ORDER_HISTORY_URL=localhost:1996/orders
|
ORDER_HISTORY_URL=localhost:1996/orders
|
||||||
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
|
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
|
||||||
|
|||||||
19
.github/workflows/add-depr-ticket-to-depr-board.yml
vendored
Normal file
19
.github/workflows/add-depr-ticket-to-depr-board.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Run the workflow that adds new tickets that are either:
|
||||||
|
# - labelled "DEPR"
|
||||||
|
# - title starts with "[DEPR]"
|
||||||
|
# - body starts with "Proposal Date" (this is the first template field)
|
||||||
|
# to the org-wide DEPR project board
|
||||||
|
|
||||||
|
name: Add newly created DEPR issues to the DEPR project board
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
routeissue:
|
||||||
|
uses: openedx/.github/.github/workflows/add-depr-ticket-to-depr-board.yml@master
|
||||||
|
secrets:
|
||||||
|
GITHUB_APP_ID: ${{ secrets.GRAPHQL_AUTH_APP_ID }}
|
||||||
|
GITHUB_APP_PRIVATE_KEY: ${{ secrets.GRAPHQL_AUTH_APP_PEM }}
|
||||||
|
SLACK_BOT_TOKEN: ${{ secrets.SLACK_ISSUE_BOT_TOKEN }}
|
||||||
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
@@ -1,17 +1,26 @@
|
|||||||
name: Default CI
|
name: Default CI
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node: [16]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Nodejs
|
- name: Setup Nodejs
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 12
|
node-version: ${{ matrix.node }}
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Validate package-lock.json changes
|
- name: Validate package-lock.json changes
|
||||||
@@ -20,7 +29,9 @@ jobs:
|
|||||||
run: npm run lint
|
run: npm run lint
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
- name: i18n_extract
|
- name: i18n_extract
|
||||||
run: npm run i18n_extract
|
run: npm run i18n_extract
|
||||||
- name: Coverage
|
- name: Coverage
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v2
|
||||||
|
|||||||
10
.github/workflows/commitlint.yml
vendored
Normal file
10
.github/workflows/commitlint.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Run commitlint on the commit messages in a pull request.
|
||||||
|
|
||||||
|
name: Lint Commit Messages
|
||||||
|
|
||||||
|
on:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
commitlint:
|
||||||
|
uses: openedx/.github/.github/workflows/commitlint.yml@master
|
||||||
14
.github/workflows/lockfileversion-check.yml
vendored
Normal file
14
.github/workflows/lockfileversion-check.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#check package-lock file version
|
||||||
|
|
||||||
|
name: lockfileVersion check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
version-check:
|
||||||
|
uses: openedx/.github/.github/workflows/lockfileversion-check.yml@master
|
||||||
|
|
||||||
58
.github/workflows/release.yml
vendored
58
.github/workflows/release.yml
vendored
@@ -2,36 +2,38 @@ name: Release CI
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 12
|
node-version: 16
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: Validate package-lock.json changes
|
- name: Validate package-lock.json changes
|
||||||
run: make validate-no-uncommitted-package-lock-changes
|
run: make validate-no-uncommitted-package-lock-changes
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
- name: i18n_extract
|
- name: i18n_extract
|
||||||
run: npm run i18n_extract
|
run: npm run i18n_extract
|
||||||
- name: Coverage
|
- name: Coverage
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v2
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: Release
|
- name: Release
|
||||||
env:
|
uses: cycjimmy/semantic-release-action@v2
|
||||||
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
with:
|
||||||
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
semantic_version: 16
|
||||||
run: npx semantic-release
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@ node_modules
|
|||||||
temp
|
temp
|
||||||
src/i18n/transifex_input.json
|
src/i18n/transifex_input.json
|
||||||
module.config.js
|
module.config.js
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[main]
|
[main]
|
||||||
host = https://www.transifex.com
|
host = https://www.transifex.com
|
||||||
|
|
||||||
[edx-platform.frontend-component-header]
|
[o:open-edx:p:edx-platform:r:frontend-component-header]
|
||||||
file_filter = src/i18n/messages/<lang>.json
|
file_filter = src/i18n/messages/<lang>.json
|
||||||
source_file = src/i18n/transifex_input.json
|
source_file = src/i18n/transifex_input.json
|
||||||
source_lang = en
|
source_lang = en
|
||||||
type = KEYVALUEJSON
|
type = KEYVALUEJSON
|
||||||
|
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -1,5 +1,5 @@
|
|||||||
transifex_resource = frontend-component-header
|
transifex_resource = frontend-component-header
|
||||||
transifex_langs = "ar,fr,es_419,zh_CN"
|
transifex_langs = "ar,fr,fr_CA,es_419,zh_CN"
|
||||||
|
|
||||||
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
||||||
i18n = ./src/i18n
|
i18n = ./src/i18n
|
||||||
@@ -50,7 +50,7 @@ push_translations:
|
|||||||
|
|
||||||
# Pulls translations from Transifex.
|
# Pulls translations from Transifex.
|
||||||
pull_translations:
|
pull_translations:
|
||||||
tx pull -f --mode reviewed --language=$(transifex_langs)
|
tx pull -t -f --mode reviewed --languages=$(transifex_langs)
|
||||||
|
|
||||||
# This target is used by Travis.
|
# This target is used by Travis.
|
||||||
validate-no-uncommitted-package-lock-changes:
|
validate-no-uncommitted-package-lock-changes:
|
||||||
|
|||||||
74
README.rst
74
README.rst
@@ -1,11 +1,77 @@
|
|||||||
|
#########################
|
||||||
frontend-component-header
|
frontend-component-header
|
||||||
=========================
|
#########################
|
||||||
|
|
||||||
|Build Status| |Codecov| |npm_version| |npm_downloads| |license| |semantic-release|
|
|Build Status| |Codecov| |npm_version| |npm_downloads| |license| |semantic-release|
|
||||||
|
|
||||||
This is the standard Open edX header for use in React applications. It has two exports:
|
********
|
||||||
- **default**: The Header Component
|
Overview
|
||||||
- **messages**: for i18n in the form of ``{ locale: { key: translatedString } }``
|
********
|
||||||
|
|
||||||
|
A generic header for Open edX micro-frontend applications.
|
||||||
|
|
||||||
|
************
|
||||||
|
Requirements
|
||||||
|
************
|
||||||
|
|
||||||
|
This component uses ``@edx/frontend-platform`` services such as i18n, analytics, configuration, and the ``AppContext`` React component, and expects that it has been loaded into a micro-frontend that has been properly initialized via ``@edx/frontend-platform``'s ``initialize`` function. `Please visit the frontend template application to see an example. <https://github.com/openedx/frontend-template-application/blob/master/src/index.jsx>`_
|
||||||
|
|
||||||
|
Environment Variables
|
||||||
|
=====================
|
||||||
|
|
||||||
|
* ``LMS_BASE_URL`` - The URL of the LMS of your Open edX instance.
|
||||||
|
* ``LOGOUT_URL`` - The URL of the API endpoint which performs a user logout.
|
||||||
|
* ``LOGIN_URL`` - The URL of the login page where a user can sign into their account.
|
||||||
|
* ``SITE_NAME`` - The user-facing name of the site, used as `alt` text on the logo in the header.
|
||||||
|
Defaults to "localhost" in development.
|
||||||
|
* ``LOGO_URL`` - The URL of the site's logo. This logo is displayed in the header.
|
||||||
|
* ``ORDER_HISTORY_URL`` - The URL of the order history page.
|
||||||
|
* ``AUTHN_MINIMAL_HEADER`` - A boolean flag which hides the main menu, user menu, and logged-out
|
||||||
|
menu items when truthy. This is intended to be used in micro-frontends like
|
||||||
|
frontend-app-authentication in which these menus are considered distractions from the user's task.
|
||||||
|
|
||||||
|
************
|
||||||
|
Installation
|
||||||
|
************
|
||||||
|
|
||||||
|
To install this header into your Open edX micro-frontend, run the following command in your MFE:
|
||||||
|
|
||||||
|
``npm i --save @edx/frontend-component-header``
|
||||||
|
|
||||||
|
This will make the component available to be imported into your application.
|
||||||
|
|
||||||
|
*****
|
||||||
|
Usage
|
||||||
|
*****
|
||||||
|
|
||||||
|
This library has the following exports:
|
||||||
|
|
||||||
|
* ``(default)``: The header as a React component.
|
||||||
|
* ``messages``: Internationalization messages suitable for use with `@edx/frontend-platform/i18n <https://edx.github.io/frontend-platform/module-Internationalization.html>`_
|
||||||
|
* ``dist/index.scss``: A SASS file which contains style information for the component. It should be imported into the micro-frontend's own SCSS file.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
========
|
||||||
|
|
||||||
|
* `An example of component and messages usage. <https://github.com/openedx/frontend-template-application/blob/3355bb3a96232390e9056f35b06ffa8f105ed7ca/src/index.jsx#L21>`_
|
||||||
|
* `An example of SCSS file usage. <https://github.com/openedx/frontend-template-application/blob/3cd5485bf387b8c479baf6b02bf59e3061dc3465/src/index.scss#L8>`_
|
||||||
|
|
||||||
|
|
||||||
|
***********
|
||||||
|
Development
|
||||||
|
***********
|
||||||
|
|
||||||
|
Install dependencies::
|
||||||
|
|
||||||
|
npm i
|
||||||
|
|
||||||
|
Start the development server::
|
||||||
|
|
||||||
|
npm start
|
||||||
|
|
||||||
|
Build a production distribution::
|
||||||
|
|
||||||
|
npm run build
|
||||||
|
|
||||||
.. |Build Status| image:: https://api.travis-ci.com/edx/frontend-component-header.svg?branch=master
|
.. |Build Status| image:: https://api.travis-ci.com/edx/frontend-component-header.svg?branch=master
|
||||||
:target: https://travis-ci.com/edx/frontend-component-header
|
:target: https://travis-ci.com/edx/frontend-component-header
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
extends: ['@commitlint/config-angular'],
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const { createConfig } = require('@edx/frontend-build');
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
module.exports = createConfig('jest', {
|
module.exports = createConfig('jest', {
|
||||||
setupFiles: [
|
setupFilesAfterEnv: [
|
||||||
'<rootDir>/src/setupTest.js',
|
'<rootDir>/src/setupTest.js',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
50266
package-lock.json
generated
50266
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
61
package.json
61
package.json
@@ -19,51 +19,56 @@
|
|||||||
],
|
],
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "npm run lint",
|
"pre-commit": "npm run lint"
|
||||||
"commit-msg": "commitlint -e $GIT_PARAMS"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/edx/frontend-component-header.git"
|
"url": "git+https://github.com/openedx/frontend-component-header.git"
|
||||||
},
|
},
|
||||||
"author": "edX",
|
"author": "edX",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/edx/frontend-component-header/issues"
|
"url": "https://github.com/openedx/frontend-component-header/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/edx/frontend-component-header#readme",
|
"homepage": "https://github.com/openedx/frontend-component-header#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "8.2.0",
|
|
||||||
"@commitlint/config-angular": "8.2.0",
|
|
||||||
"@commitlint/prompt": "8.2.0",
|
|
||||||
"@commitlint/prompt-cli": "8.2.0",
|
|
||||||
"@edx/brand": "npm:@edx/brand-openedx@1.1.0",
|
"@edx/brand": "npm:@edx/brand-openedx@1.1.0",
|
||||||
"@edx/frontend-build": "5.4.0",
|
"@edx/frontend-build": "11.0.2",
|
||||||
"@edx/frontend-platform": "1.8.1",
|
"@edx/frontend-platform": "2.6.2",
|
||||||
"@edx/paragon": "12.0.5",
|
"@edx/paragon": "19.25.3",
|
||||||
"codecov": "3.7.2",
|
"codecov": "3.8.3",
|
||||||
"enzyme": "3.10.0",
|
"enzyme": "3.11.0",
|
||||||
"enzyme-adapter-react-16": "1.14.0",
|
"enzyme-adapter-react-16": "1.15.6",
|
||||||
"husky": "3.0.9",
|
"husky": "7.0.4",
|
||||||
"prop-types": "15.7.2",
|
"prop-types": "15.8.1",
|
||||||
"react": "16.9.0",
|
"react": "16.14.0",
|
||||||
"react-dom": "16.9.0",
|
"react-dom": "16.14.0",
|
||||||
"react-redux": "7.1.3",
|
"react-redux": "7.2.9",
|
||||||
"react-router-dom": "5.1.2",
|
"react-router-dom": "5.3.4",
|
||||||
"react-test-renderer": "16.9.0",
|
"react-test-renderer": "16.14.0",
|
||||||
"reactifex": "1.1.1",
|
"reactifex": "1.1.1",
|
||||||
"redux": "4.0.4",
|
"redux": "4.2.0",
|
||||||
"redux-saga": "1.1.1"
|
"redux-saga": "1.1.3",
|
||||||
|
"@testing-library/dom": "8.18.1",
|
||||||
|
"@testing-library/jest-dom": "5.16.5",
|
||||||
|
"jest": "28.1.3",
|
||||||
|
"jest-chain": "1.1.6",
|
||||||
|
"@testing-library/react": "10.4.9"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-polyfill": "6.26.0",
|
"babel-polyfill": "6.26.0",
|
||||||
"react-responsive": "8.0.3",
|
"react-responsive": "8.2.0",
|
||||||
"react-transition-group": "4.3.0"
|
"react-transition-group": "4.4.5",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "1.2.36",
|
||||||
|
"@fortawesome/free-brands-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/free-regular-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "5.15.4",
|
||||||
|
"@fortawesome/react-fontawesome": "^0.2.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-platform": "^1.8.0",
|
"@edx/frontend-platform": "^2.0.0",
|
||||||
"@edx/paragon": "^7.0.0",
|
"@edx/paragon": ">= 7.0.0 < 21.0.0",
|
||||||
"prop-types": "^15.5.10",
|
"prop-types": "^15.5.10",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0",
|
||||||
"react-dom": "^16.9.0"
|
"react-dom": "^16.9.0"
|
||||||
|
|||||||
@@ -1,9 +1,28 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:base"
|
"config:base",
|
||||||
|
"schedule:weekly",
|
||||||
|
":automergeLinters",
|
||||||
|
":automergeMinor",
|
||||||
|
":automergeTesters",
|
||||||
|
":enableVulnerabilityAlerts",
|
||||||
|
":rebaseStalePrs",
|
||||||
|
":semanticCommits",
|
||||||
|
":updateNotScheduled"
|
||||||
],
|
],
|
||||||
"patch": {
|
"packageRules": [
|
||||||
"automerge": true
|
{
|
||||||
},
|
"matchDepTypes": [
|
||||||
"rebaseStalePrs": true
|
"devDependencies"
|
||||||
|
],
|
||||||
|
"matchUpdateTypes": [
|
||||||
|
"lockFileMaintenance",
|
||||||
|
"minor",
|
||||||
|
"patch",
|
||||||
|
"pin"
|
||||||
|
],
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"timezone": "America/New_York"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
// Local Components
|
// Local Components
|
||||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||||
@@ -53,6 +54,24 @@ class DesktopHeader extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renders an optional App Menu for
|
||||||
|
renderAppMenu() {
|
||||||
|
const { appMenu } = this.props;
|
||||||
|
const { content: appMenuContent, menuItems } = appMenu;
|
||||||
|
return (
|
||||||
|
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
|
||||||
|
<MenuTrigger tag="a" className="nav-link d-inline-flex align-items-center">
|
||||||
|
{appMenuContent} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||||
|
</MenuTrigger>
|
||||||
|
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
|
||||||
|
{menuItems.map(({ type, href, content }) => (
|
||||||
|
<a className={`dropdown-${type}`} key={`${type}-${content}`} href={href}>{content}</a>
|
||||||
|
))}
|
||||||
|
</MenuContent>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderUserMenu() {
|
renderUserMenu() {
|
||||||
const {
|
const {
|
||||||
userMenu,
|
userMenu,
|
||||||
@@ -101,12 +120,15 @@ class DesktopHeader extends React.Component {
|
|||||||
logoDestination,
|
logoDestination,
|
||||||
loggedIn,
|
loggedIn,
|
||||||
intl,
|
intl,
|
||||||
|
appMenu,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||||
|
const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'mw-100' : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="site-header-desktop">
|
<header className="site-header-desktop">
|
||||||
<div className="container-fluid">
|
<a className="nav-skip sr-only sr-only-focusable" href="#main">{intl.formatMessage(messages['header.label.skip.nav'])}</a>
|
||||||
|
<div className={`container-fluid ${logoClasses}`}>
|
||||||
<div className="nav-container position-relative d-flex align-items-center">
|
<div className="nav-container position-relative d-flex align-items-center">
|
||||||
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
||||||
<nav
|
<nav
|
||||||
@@ -115,6 +137,14 @@ class DesktopHeader extends React.Component {
|
|||||||
>
|
>
|
||||||
{this.renderMainMenu()}
|
{this.renderMainMenu()}
|
||||||
</nav>
|
</nav>
|
||||||
|
{appMenu ? (
|
||||||
|
<nav
|
||||||
|
aria-label={intl.formatMessage(messages['header.label.app.nav'])}
|
||||||
|
className="nav app-nav"
|
||||||
|
>
|
||||||
|
{this.renderAppMenu()}
|
||||||
|
</nav>
|
||||||
|
) : null}
|
||||||
<nav
|
<nav
|
||||||
aria-label={intl.formatMessage(messages['header.label.secondary.nav'])}
|
aria-label={intl.formatMessage(messages['header.label.secondary.nav'])}
|
||||||
className="nav secondary-menu-container align-items-center ml-auto"
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
@@ -152,6 +182,20 @@ DesktopHeader.propTypes = {
|
|||||||
|
|
||||||
// i18n
|
// i18n
|
||||||
intl: intlShape.isRequired,
|
intl: intlShape.isRequired,
|
||||||
|
|
||||||
|
// appMenu
|
||||||
|
appMenu: PropTypes.shape(
|
||||||
|
{
|
||||||
|
content: PropTypes.string,
|
||||||
|
menuItems: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
type: PropTypes.string,
|
||||||
|
href: PropTypes.string,
|
||||||
|
content: PropTypes.string,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
DesktopHeader.defaultProps = {
|
DesktopHeader.defaultProps = {
|
||||||
@@ -164,6 +208,7 @@ DesktopHeader.defaultProps = {
|
|||||||
avatar: null,
|
avatar: null,
|
||||||
username: null,
|
username: null,
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
|
appMenu: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default injectIntl(DesktopHeader);
|
export default injectIntl(DesktopHeader);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ ensureConfig([
|
|||||||
'LOGIN_URL',
|
'LOGIN_URL',
|
||||||
'SITE_NAME',
|
'SITE_NAME',
|
||||||
'LOGO_URL',
|
'LOGO_URL',
|
||||||
|
'ORDER_HISTORY_URL',
|
||||||
], 'Header component');
|
], 'Header component');
|
||||||
|
|
||||||
subscribe(APP_CONFIG_INITIALIZED, () => {
|
subscribe(APP_CONFIG_INITIALIZED, () => {
|
||||||
@@ -40,6 +41,12 @@ function Header({ intl }) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const orderHistoryItem = {
|
||||||
|
type: 'item',
|
||||||
|
href: config.ORDER_HISTORY_URL,
|
||||||
|
content: intl.formatMessage(messages['header.user.menu.order.history']),
|
||||||
|
};
|
||||||
|
|
||||||
const userMenu = authenticatedUser === null ? [] : [
|
const userMenu = authenticatedUser === null ? [] : [
|
||||||
{
|
{
|
||||||
type: 'item',
|
type: 'item',
|
||||||
@@ -63,6 +70,11 @@ function Header({ intl }) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Users should only see Order History if have a ORDER_HISTORY_URL define in the environment.
|
||||||
|
if (config.ORDER_HISTORY_URL) {
|
||||||
|
userMenu.splice(-1, 0, orderHistoryItem);
|
||||||
|
}
|
||||||
|
|
||||||
const loggedOutItems = [
|
const loggedOutItems = [
|
||||||
{
|
{
|
||||||
type: 'item',
|
type: 'item',
|
||||||
@@ -79,7 +91,6 @@ function Header({ intl }) {
|
|||||||
const props = {
|
const props = {
|
||||||
logo: config.LOGO_URL,
|
logo: config.LOGO_URL,
|
||||||
logoAltText: config.SITE_NAME,
|
logoAltText: config.SITE_NAME,
|
||||||
siteName: config.SITE_NAME,
|
|
||||||
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
|
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
|
||||||
loggedIn: authenticatedUser !== null,
|
loggedIn: authenticatedUser !== null,
|
||||||
username: authenticatedUser !== null ? authenticatedUser.username : null,
|
username: authenticatedUser !== null ? authenticatedUser.username : null,
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ const messages = defineMessages({
|
|||||||
defaultMessage: 'Sign Up',
|
defaultMessage: 'Sign Up',
|
||||||
description: 'Link to registration',
|
description: 'Link to registration',
|
||||||
},
|
},
|
||||||
|
'header.user.menu.studio.home': {
|
||||||
|
id: 'header.user.menu.studio.home',
|
||||||
|
defaultMessage: 'Studio Home',
|
||||||
|
description: 'Link to the Studio Home',
|
||||||
|
},
|
||||||
|
'header.user.menu.studio.maintenance': {
|
||||||
|
id: 'header.user.menu.studio.maintenance',
|
||||||
|
defaultMessage: 'Maintenance',
|
||||||
|
description: 'Link to the Studio Maintenance',
|
||||||
|
},
|
||||||
'header.label.account.nav': {
|
'header.label.account.nav': {
|
||||||
id: 'header.label.account.nav',
|
id: 'header.label.account.nav',
|
||||||
defaultMessage: 'Account',
|
defaultMessage: 'Account',
|
||||||
@@ -91,6 +101,16 @@ const messages = defineMessages({
|
|||||||
defaultMessage: 'Secondary',
|
defaultMessage: 'Secondary',
|
||||||
description: 'The aria label for the seconary nav',
|
description: 'The aria label for the seconary nav',
|
||||||
},
|
},
|
||||||
|
'header.label.skip.nav': {
|
||||||
|
id: 'header.label.skip.nav',
|
||||||
|
defaultMessage: 'Skip to main content',
|
||||||
|
description: 'A link used by screen readers to allow users to skip to the main content of the page.',
|
||||||
|
},
|
||||||
|
'header.label.app.nav': {
|
||||||
|
id: 'header.label.app.nav',
|
||||||
|
defaultMessage: 'App',
|
||||||
|
description: 'The aria label for the app Nav',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default messages;
|
export default messages;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
|
||||||
// Local Components
|
// Local Components
|
||||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||||
@@ -96,14 +97,17 @@ class MobileHeader extends React.Component {
|
|||||||
} = this.props;
|
} = this.props;
|
||||||
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||||
const stickyClassName = stickyOnMobile ? 'sticky-top' : '';
|
const stickyClassName = stickyOnMobile ? 'sticky-top' : '';
|
||||||
|
const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'justify-content-left pl-3' : 'justify-content-center';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header
|
<header
|
||||||
aria-label={intl.formatMessage(messages['header.label.main.header'])}
|
aria-label={intl.formatMessage(messages['header.label.main.header'])}
|
||||||
className={`site-header-mobile d-flex justify-content-between align-items-center shadow ${stickyClassName}`}
|
className={`site-header-mobile d-flex justify-content-between align-items-center shadow ${stickyClassName}`}
|
||||||
>
|
>
|
||||||
<div className="w-100 d-flex justify-content-start">
|
<a className="nav-skip sr-only sr-only-focusable" href="#main">{intl.formatMessage(messages['header.label.skip.nav'])}</a>
|
||||||
{mainMenu.length > 0 ? (
|
{mainMenu.length > 0 ? (
|
||||||
|
<div className="w-100 d-flex justify-content-start">
|
||||||
|
|
||||||
<Menu className="position-static">
|
<Menu className="position-static">
|
||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
tag="button"
|
tag="button"
|
||||||
@@ -121,13 +125,13 @@ class MobileHeader extends React.Component {
|
|||||||
{this.renderMainMenu()}
|
{this.renderMainMenu()}
|
||||||
</MenuContent>
|
</MenuContent>
|
||||||
</Menu>
|
</Menu>
|
||||||
) : null}
|
</div>
|
||||||
</div>
|
) : null}
|
||||||
<div className="w-100 d-flex justify-content-center">
|
<div className={`w-100 d-flex ${logoClasses}`}>
|
||||||
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
|
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-100 d-flex justify-content-end align-items-center">
|
{userMenu.length > 0 || loggedOutItems.length > 0 ? (
|
||||||
{userMenu.length > 0 || loggedOutItems.length > 0 ? (
|
<div className="w-100 d-flex justify-content-end align-items-center">
|
||||||
<Menu tag="nav" aria-label={intl.formatMessage(messages['header.label.secondary.nav'])} className="position-static">
|
<Menu tag="nav" aria-label={intl.formatMessage(messages['header.label.secondary.nav'])} className="position-static">
|
||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
tag="button"
|
tag="button"
|
||||||
@@ -141,8 +145,8 @@ class MobileHeader extends React.Component {
|
|||||||
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
|
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
|
||||||
</MenuContent>
|
</MenuContent>
|
||||||
</Menu>
|
</Menu>
|
||||||
) : null}
|
</div>
|
||||||
</div>
|
) : null}
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
99
src/StudioHeader.jsx
Normal file
99
src/StudioHeader.jsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
import {
|
||||||
|
APP_CONFIG_INITIALIZED,
|
||||||
|
ensureConfig,
|
||||||
|
mergeConfig,
|
||||||
|
subscribe,
|
||||||
|
} from '@edx/frontend-platform';
|
||||||
|
|
||||||
|
import DesktopHeader from './DesktopHeader';
|
||||||
|
|
||||||
|
import messages from './Header.messages';
|
||||||
|
|
||||||
|
ensureConfig([
|
||||||
|
'STUDIO_BASE_URL',
|
||||||
|
'LOGOUT_URL',
|
||||||
|
'LOGIN_URL',
|
||||||
|
'SITE_NAME',
|
||||||
|
'LOGO_URL',
|
||||||
|
'ORDER_HISTORY_URL',
|
||||||
|
], 'StudioHeader component');
|
||||||
|
|
||||||
|
subscribe(APP_CONFIG_INITIALIZED, () => {
|
||||||
|
mergeConfig({
|
||||||
|
AUTHN_MINIMAL_HEADER: !!process.env.AUTHN_MINIMAL_HEADER,
|
||||||
|
}, 'StudioHeader additional config');
|
||||||
|
});
|
||||||
|
|
||||||
|
function StudioHeader({ intl, mainMenu, appMenu }) {
|
||||||
|
const { authenticatedUser, config } = useContext(AppContext);
|
||||||
|
|
||||||
|
const userMenu = authenticatedUser === null ? [] : [
|
||||||
|
{
|
||||||
|
type: 'item',
|
||||||
|
href: `${config.STUDIO_BASE_URL}`,
|
||||||
|
content: intl.formatMessage(messages['header.user.menu.studio.home']),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'item',
|
||||||
|
href: `${config.STUDIO_BASE_URL}/maintenance`,
|
||||||
|
content: intl.formatMessage(messages['header.user.menu.studio.maintenance']),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'item',
|
||||||
|
href: config.LOGOUT_URL,
|
||||||
|
content: intl.formatMessage(messages['header.user.menu.logout']),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
logo: config.LOGO_URL,
|
||||||
|
logoAltText: config.SITE_NAME,
|
||||||
|
logoDestination: config.STUDIO_BASE_URL,
|
||||||
|
loggedIn: authenticatedUser !== null,
|
||||||
|
username: authenticatedUser !== null ? authenticatedUser.username : null,
|
||||||
|
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
|
||||||
|
mainMenu,
|
||||||
|
userMenu,
|
||||||
|
appMenu,
|
||||||
|
loggedOutItems: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
return <DesktopHeader {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
StudioHeader.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
appMenu: PropTypes.shape(
|
||||||
|
{
|
||||||
|
content: PropTypes.string,
|
||||||
|
href: PropTypes.string,
|
||||||
|
menuItems: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
type: PropTypes.string,
|
||||||
|
href: PropTypes.string,
|
||||||
|
content: PropTypes.string,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
mainMenu: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape(
|
||||||
|
{
|
||||||
|
type: PropTypes.string,
|
||||||
|
href: PropTypes.string,
|
||||||
|
content: PropTypes.string,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioHeader.defaultProps = {
|
||||||
|
appMenu: null,
|
||||||
|
mainMenu: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default injectIntl(StudioHeader);
|
||||||
135
src/StudioHeader.test.jsx
Normal file
135
src/StudioHeader.test.jsx
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
import TestRenderer from 'react-test-renderer';
|
||||||
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
|
||||||
|
import { StudioHeader } from './index';
|
||||||
|
|
||||||
|
describe('<StudioHeader />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const component = (
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'edX',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<StudioHeader />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with the optional app menu', () => {
|
||||||
|
const appMenu = {
|
||||||
|
content: 'App Menu',
|
||||||
|
menuItems: [
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 3',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const component = (
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'edX',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<StudioHeader appMenu={appMenu} />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with the optional main menu', () => {
|
||||||
|
const mainMenu = [
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dropdown',
|
||||||
|
href: 'https://menu-href-url.org',
|
||||||
|
content: 'Content 3',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const component = (
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'edX',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<StudioHeader mainMenu={mainMenu} />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,8 +4,14 @@ exports[`<Header /> renders correctly for anonymous desktop 1`] = `
|
|||||||
<header
|
<header
|
||||||
className="site-header-desktop"
|
className="site-header-desktop"
|
||||||
>
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
<div
|
<div
|
||||||
className="container-fluid"
|
className="container-fluid null"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="nav-container position-relative d-flex align-items-center"
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
@@ -58,6 +64,12 @@ exports[`<Header /> renders correctly for anonymous mobile 1`] = `
|
|||||||
aria-label="Main"
|
aria-label="Main"
|
||||||
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
||||||
>
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
<div
|
<div
|
||||||
className="w-100 d-flex justify-content-start"
|
className="w-100 d-flex justify-content-start"
|
||||||
>
|
>
|
||||||
@@ -188,8 +200,14 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
|
|||||||
<header
|
<header
|
||||||
className="site-header-desktop"
|
className="site-header-desktop"
|
||||||
>
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
<div
|
<div
|
||||||
className="container-fluid"
|
className="container-fluid null"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="nav-container position-relative d-flex align-items-center"
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
@@ -292,6 +310,12 @@ exports[`<Header /> renders correctly for authenticated mobile 1`] = `
|
|||||||
aria-label="Main"
|
aria-label="Main"
|
||||||
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
||||||
>
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
<div
|
<div
|
||||||
className="w-100 d-flex justify-content-start"
|
className="w-100 d-flex justify-content-start"
|
||||||
>
|
>
|
||||||
|
|||||||
425
src/__snapshots__/StudioHeader.test.jsx.snap
Normal file
425
src/__snapshots__/StudioHeader.test.jsx.snap
Normal file
@@ -0,0 +1,425 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`<StudioHeader /> renders correctly 1`] = `
|
||||||
|
<header
|
||||||
|
className="site-header-desktop"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
|
<div
|
||||||
|
className="container-fluid null"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="logo"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
<nav
|
||||||
|
aria-label="Main"
|
||||||
|
className="nav main-nav"
|
||||||
|
/>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu null"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account menu for edX"
|
||||||
|
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle mr-2"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
edX
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<StudioHeader /> renders correctly with the optional app menu 1`] = `
|
||||||
|
<header
|
||||||
|
className="site-header-desktop"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
|
<div
|
||||||
|
className="container-fluid null"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="logo"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
<nav
|
||||||
|
aria-label="Main"
|
||||||
|
className="nav main-nav"
|
||||||
|
/>
|
||||||
|
<nav
|
||||||
|
aria-label="App"
|
||||||
|
className="nav app-nav"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu null"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
className="menu-trigger nav-link d-inline-flex align-items-center"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
App Menu
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu null"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account menu for edX"
|
||||||
|
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle mr-2"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
edX
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<StudioHeader /> renders correctly with the optional main menu 1`] = `
|
||||||
|
<header
|
||||||
|
className="site-header-desktop"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="nav-skip sr-only sr-only-focusable"
|
||||||
|
href="#main"
|
||||||
|
>
|
||||||
|
Skip to main content
|
||||||
|
</a>
|
||||||
|
<div
|
||||||
|
className="container-fluid null"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="logo"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
<nav
|
||||||
|
aria-label="Main"
|
||||||
|
className="nav main-nav"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu nav-item"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
className="menu-trigger nav-link d-inline-flex align-items-center"
|
||||||
|
href="https://menu-href-url.org"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
Content 1
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="menu nav-item"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
className="menu-trigger nav-link d-inline-flex align-items-center"
|
||||||
|
href="https://menu-href-url.org"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
Content 2
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="menu nav-item"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
className="menu-trigger nav-link d-inline-flex align-items-center"
|
||||||
|
href="https://menu-href-url.org"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
Content 3
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu null"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account menu for edX"
|
||||||
|
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle mr-2"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
edX
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
16
src/generic/messages.js
Normal file
16
src/generic/messages.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
registerSentenceCase: {
|
||||||
|
id: 'general.register.sentenceCase',
|
||||||
|
defaultMessage: 'Register',
|
||||||
|
description: 'Text in a button, prompting the user to register.',
|
||||||
|
},
|
||||||
|
signInSentenceCase: {
|
||||||
|
id: 'general.signIn.sentenceCase',
|
||||||
|
defaultMessage: 'Sign in',
|
||||||
|
description: 'Text in a button, prompting the user to log in.',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default messages;
|
||||||
@@ -1,4 +1,13 @@
|
|||||||
import arMessages from './messages/ar.json';
|
import arMessages from './messages/ar.json';
|
||||||
|
|
||||||
|
import caMessages from './messages/ca.json';
|
||||||
|
import heMessages from './messages/he.json';
|
||||||
|
import idMessages from './messages/id.json';
|
||||||
|
import plMessages from './messages/pl.json';
|
||||||
|
import ruMessages from './messages/ru.json';
|
||||||
|
import thMessages from './messages/th.json';
|
||||||
|
import ukMessages from './messages/uk.json';
|
||||||
|
|
||||||
// no need to import en messages-- they are in the defaultMessage field
|
// no need to import en messages-- they are in the defaultMessage field
|
||||||
import es419Messages from './messages/es_419.json';
|
import es419Messages from './messages/es_419.json';
|
||||||
import frMessages from './messages/fr.json';
|
import frMessages from './messages/fr.json';
|
||||||
@@ -8,6 +17,13 @@ import zhcnMessages from './messages/zh_CN.json';
|
|||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
ar: arMessages,
|
ar: arMessages,
|
||||||
|
ca: caMessages,
|
||||||
|
he: heMessages,
|
||||||
|
id: idMessages,
|
||||||
|
pl: plMessages,
|
||||||
|
ru: ruMessages,
|
||||||
|
th: thMessages,
|
||||||
|
uk: ukMessages,
|
||||||
'es-419': es419Messages,
|
'es-419': es419Messages,
|
||||||
fr: frMessages,
|
fr: frMessages,
|
||||||
'zh-cn': zhcnMessages,
|
'zh-cn': zhcnMessages,
|
||||||
|
|||||||
@@ -1,2 +1,33 @@
|
|||||||
{
|
{
|
||||||
}
|
"general.register.sentenceCase": "التسجيل",
|
||||||
|
"general.signIn.sentenceCase": "تسجيل الدخول",
|
||||||
|
"header.links.courses": "المساقات",
|
||||||
|
"header.links.programs": "البرامج",
|
||||||
|
"header.links.content.search": "اكتشف الجديد",
|
||||||
|
"header.links.schools": "المدارس و الشركاء",
|
||||||
|
"header.user.menu.dashboard": "لوحة المعلومات",
|
||||||
|
"header.user.menu.profile": "الملف الشخصي",
|
||||||
|
"header.user.menu.account.settings": "الحساب",
|
||||||
|
"header.user.menu.order.history": "سجل الطلبيات",
|
||||||
|
"header.user.menu.logout": "تسجيل الخروج",
|
||||||
|
"header.user.menu.login": "تسجيل الدخول",
|
||||||
|
"header.user.menu.register": "التسجيل",
|
||||||
|
"header.user.menu.studio.home": "صفحة الاستوديو الرئيسية",
|
||||||
|
"header.user.menu.studio.maintenance": "الصيانة",
|
||||||
|
"header.label.account.nav": "الحساب",
|
||||||
|
"header.label.account.menu": "قائمة الحساب",
|
||||||
|
"header.label.account.menu.for": "قائمة حساب المستخدم {username}",
|
||||||
|
"header.label.main.nav": "القا|مة الرئيسية",
|
||||||
|
"header.label.main.menu": "القائمة الرئيسية",
|
||||||
|
"header.label.main.header": "الرئيسية",
|
||||||
|
"header.label.secondary.nav": "القائمة الثانوية",
|
||||||
|
"header.label.skip.nav": "التخطي إلى المحتوى الرئيسي",
|
||||||
|
"header.label.app.nav": "تطبيق",
|
||||||
|
"header.menu.dashboard.label": "لوحة المعلومات",
|
||||||
|
"header.help.label": "المساعدة",
|
||||||
|
"header.menu.profile.label": "الملف الشخصي",
|
||||||
|
"header.menu.account.label": "الحساب",
|
||||||
|
"header.menu.orderHistory.label": "سجل الطلبيات",
|
||||||
|
"header.navigation.skipNavLink": "التخطي إلى المحتوى الرئيسي",
|
||||||
|
"header.menu.signOut.label": "تسجيل الخروج"
|
||||||
|
}
|
||||||
1
src/i18n/messages/ca.json
Normal file
1
src/i18n/messages/ca.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -1,2 +1,33 @@
|
|||||||
{
|
{
|
||||||
}
|
"general.register.sentenceCase": "Registrarse",
|
||||||
|
"general.signIn.sentenceCase": "Iniciar sesión",
|
||||||
|
"header.links.courses": "Cursos",
|
||||||
|
"header.links.programs": "Programas",
|
||||||
|
"header.links.content.search": "Encontrar nuevo",
|
||||||
|
"header.links.schools": "Escuelas y Socios",
|
||||||
|
"header.user.menu.dashboard": "Panel de Control",
|
||||||
|
"header.user.menu.profile": "Perfil",
|
||||||
|
"header.user.menu.account.settings": "Cuenta",
|
||||||
|
"header.user.menu.order.history": "Historial de órdenes",
|
||||||
|
"header.user.menu.logout": "Cerrar sesión",
|
||||||
|
"header.user.menu.login": "Login",
|
||||||
|
"header.user.menu.register": "Registrarse",
|
||||||
|
"header.user.menu.studio.home": "Inicio Studio",
|
||||||
|
"header.user.menu.studio.maintenance": "Mantenimiento",
|
||||||
|
"header.label.account.nav": "Cuenta",
|
||||||
|
"header.label.account.menu": "Menú de la cuenta",
|
||||||
|
"header.label.account.menu.for": "Menú de la cuenta para {username}",
|
||||||
|
"header.label.main.nav": "Principal",
|
||||||
|
"header.label.main.menu": "Menú Principal",
|
||||||
|
"header.label.main.header": "Principal",
|
||||||
|
"header.label.secondary.nav": "Secondary",
|
||||||
|
"header.label.skip.nav": "Ir al contenido principal",
|
||||||
|
"header.label.app.nav": "Aplicación",
|
||||||
|
"header.menu.dashboard.label": "Panel de Control",
|
||||||
|
"header.help.label": "Ayuda",
|
||||||
|
"header.menu.profile.label": "Perfil",
|
||||||
|
"header.menu.account.label": "Cuenta",
|
||||||
|
"header.menu.orderHistory.label": "Historial de órdenes",
|
||||||
|
"header.navigation.skipNavLink": "Dirígete al contenido principal.",
|
||||||
|
"header.menu.signOut.label": "Cerrar sesión"
|
||||||
|
}
|
||||||
@@ -1,2 +1,33 @@
|
|||||||
{
|
{
|
||||||
}
|
"general.register.sentenceCase": "S'inscrire",
|
||||||
|
"general.signIn.sentenceCase": "Connectez-vous",
|
||||||
|
"header.links.courses": "Cours",
|
||||||
|
"header.links.programs": "Programmes",
|
||||||
|
"header.links.content.search": "Explorer les cours",
|
||||||
|
"header.links.schools": "Écoles et partenaires",
|
||||||
|
"header.user.menu.dashboard": "Tableau de bord",
|
||||||
|
"header.user.menu.profile": "Profil",
|
||||||
|
"header.user.menu.account.settings": "Compte",
|
||||||
|
"header.user.menu.order.history": "Historique des commandes",
|
||||||
|
"header.user.menu.logout": "Déconnexion",
|
||||||
|
"header.user.menu.login": "Connexion",
|
||||||
|
"header.user.menu.register": "S'inscrire",
|
||||||
|
"header.user.menu.studio.home": "Accueil Studio",
|
||||||
|
"header.user.menu.studio.maintenance": "Maintenance",
|
||||||
|
"header.label.account.nav": "Compte",
|
||||||
|
"header.label.account.menu": "Menu du compte",
|
||||||
|
"header.label.account.menu.for": "Menu du compte pour {username}",
|
||||||
|
"header.label.main.nav": "Principal",
|
||||||
|
"header.label.main.menu": "Menu Principal",
|
||||||
|
"header.label.main.header": "Principal",
|
||||||
|
"header.label.secondary.nav": "Secondaire",
|
||||||
|
"header.label.skip.nav": "Passer au contenu principal",
|
||||||
|
"header.label.app.nav": "Application",
|
||||||
|
"header.menu.dashboard.label": "Tableau de bord",
|
||||||
|
"header.help.label": "Aide",
|
||||||
|
"header.menu.profile.label": "Profil",
|
||||||
|
"header.menu.account.label": "Compte",
|
||||||
|
"header.menu.orderHistory.label": "Historique des commandes",
|
||||||
|
"header.navigation.skipNavLink": "Passer au contenu principal",
|
||||||
|
"header.menu.signOut.label": "Se déconnecter"
|
||||||
|
}
|
||||||
33
src/i18n/messages/fr_CA.json
Normal file
33
src/i18n/messages/fr_CA.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"general.register.sentenceCase": "Inscription",
|
||||||
|
"general.signIn.sentenceCase": "Connexion",
|
||||||
|
"header.links.courses": "Cours",
|
||||||
|
"header.links.programs": "Programmes",
|
||||||
|
"header.links.content.search": "Découvrir les nouveautés",
|
||||||
|
"header.links.schools": "Écoles et Partenaires",
|
||||||
|
"header.user.menu.dashboard": "Tableau de bord",
|
||||||
|
"header.user.menu.profile": "Profil",
|
||||||
|
"header.user.menu.account.settings": "Compte",
|
||||||
|
"header.user.menu.order.history": "Historique des commandes",
|
||||||
|
"header.user.menu.logout": "Déconnexion",
|
||||||
|
"header.user.menu.login": "Connexion",
|
||||||
|
"header.user.menu.register": "S'inscrire",
|
||||||
|
"header.user.menu.studio.home": "Accueil Studio",
|
||||||
|
"header.user.menu.studio.maintenance": "Entretien",
|
||||||
|
"header.label.account.nav": "Compte",
|
||||||
|
"header.label.account.menu": "Menu de compte",
|
||||||
|
"header.label.account.menu.for": "Menu de compte pour {username}",
|
||||||
|
"header.label.main.nav": "Principal",
|
||||||
|
"header.label.main.menu": "Menu principal",
|
||||||
|
"header.label.main.header": "Principal",
|
||||||
|
"header.label.secondary.nav": "Secondaire",
|
||||||
|
"header.label.skip.nav": "Passer au contenu de cette vue",
|
||||||
|
"header.label.app.nav": "Application",
|
||||||
|
"header.menu.dashboard.label": "Tableau de bord",
|
||||||
|
"header.help.label": "Aide",
|
||||||
|
"header.menu.profile.label": "Profil",
|
||||||
|
"header.menu.account.label": "Compte",
|
||||||
|
"header.menu.orderHistory.label": "Historique des commandes",
|
||||||
|
"header.navigation.skipNavLink": "Passer au contenu principal.",
|
||||||
|
"header.menu.signOut.label": "Se déconnecter"
|
||||||
|
}
|
||||||
1
src/i18n/messages/he.json
Normal file
1
src/i18n/messages/he.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
src/i18n/messages/id.json
Normal file
1
src/i18n/messages/id.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
src/i18n/messages/pl.json
Normal file
1
src/i18n/messages/pl.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
src/i18n/messages/ru.json
Normal file
1
src/i18n/messages/ru.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
src/i18n/messages/th.json
Normal file
1
src/i18n/messages/th.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
src/i18n/messages/uk.json
Normal file
1
src/i18n/messages/uk.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -1,2 +1,33 @@
|
|||||||
{
|
{
|
||||||
}
|
"general.register.sentenceCase": "Register",
|
||||||
|
"general.signIn.sentenceCase": "Sign in",
|
||||||
|
"header.links.courses": "Courses",
|
||||||
|
"header.links.programs": "Programs",
|
||||||
|
"header.links.content.search": "Discover New",
|
||||||
|
"header.links.schools": "Schools & Partners",
|
||||||
|
"header.user.menu.dashboard": "Dashboard",
|
||||||
|
"header.user.menu.profile": "Profile",
|
||||||
|
"header.user.menu.account.settings": "Account",
|
||||||
|
"header.user.menu.order.history": "Order History",
|
||||||
|
"header.user.menu.logout": "Logout",
|
||||||
|
"header.user.menu.login": "Login",
|
||||||
|
"header.user.menu.register": "Sign Up",
|
||||||
|
"header.user.menu.studio.home": "Studio Home",
|
||||||
|
"header.user.menu.studio.maintenance": "Maintenance",
|
||||||
|
"header.label.account.nav": "Account",
|
||||||
|
"header.label.account.menu": "Account Menu",
|
||||||
|
"header.label.account.menu.for": "Account menu for {username}",
|
||||||
|
"header.label.main.nav": "Main",
|
||||||
|
"header.label.main.menu": "Main Menu",
|
||||||
|
"header.label.main.header": "Main",
|
||||||
|
"header.label.secondary.nav": "Secondary",
|
||||||
|
"header.label.skip.nav": "Skip to main content",
|
||||||
|
"header.label.app.nav": "App",
|
||||||
|
"header.menu.dashboard.label": "Dashboard",
|
||||||
|
"header.help.label": "Help",
|
||||||
|
"header.menu.profile.label": "Profile",
|
||||||
|
"header.menu.account.label": "Account",
|
||||||
|
"header.menu.orderHistory.label": "Order History",
|
||||||
|
"header.navigation.skipNavLink": "Skip to main content.",
|
||||||
|
"header.menu.signOut.label": "Sign Out"
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
|
import LearningHeader from './learning-header/LearningHeader';
|
||||||
import messages from './i18n/index';
|
import messages from './i18n/index';
|
||||||
|
import StudioHeader from './StudioHeader';
|
||||||
|
|
||||||
export { messages };
|
export { LearningHeader, messages, StudioHeader };
|
||||||
|
|
||||||
export default Header;
|
export default Header;
|
||||||
|
|||||||
@@ -25,6 +25,30 @@ $white: #fff;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.learning-header {
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
.course-title-lockup {
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
span {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
padding-bottom: 0.1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-dropdown {
|
||||||
|
.btn {
|
||||||
|
height: 3rem;
|
||||||
|
@media (max-width: -1 + map-get($grid-breakpoints, "sm")) {
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.site-header-mobile,
|
.site-header-mobile,
|
||||||
.site-header-desktop {
|
.site-header-desktop {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
34
src/learning-header/AnonymousUserMenu.jsx
Normal file
34
src/learning-header/AnonymousUserMenu.jsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
import { getLoginRedirectUrl } from '@edx/frontend-platform/auth';
|
||||||
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { Button } from '@edx/paragon';
|
||||||
|
|
||||||
|
import genericMessages from '../generic/messages';
|
||||||
|
|
||||||
|
function AnonymousUserMenu({ intl }) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
className="mr-3"
|
||||||
|
variant="outline-primary"
|
||||||
|
href={`${getConfig().LMS_BASE_URL}/register?next=${encodeURIComponent(global.location.href)}`}
|
||||||
|
>
|
||||||
|
{intl.formatMessage(genericMessages.registerSentenceCase)}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
href={`${getLoginRedirectUrl(global.location.href)}`}
|
||||||
|
>
|
||||||
|
{intl.formatMessage(genericMessages.signInSentenceCase)}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnonymousUserMenu.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default injectIntl(AnonymousUserMenu);
|
||||||
57
src/learning-header/AuthenticatedUserDropdown.jsx
Normal file
57
src/learning-header/AuthenticatedUserDropdown.jsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import { faUserCircle } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { Dropdown } from '@edx/paragon';
|
||||||
|
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
|
function AuthenticatedUserDropdown({ intl, username }) {
|
||||||
|
const dashboardMenuItem = (
|
||||||
|
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
|
||||||
|
{intl.formatMessage(messages.dashboard)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<a className="text-gray-700 mr-3" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
|
||||||
|
<Dropdown className="user-dropdown">
|
||||||
|
<Dropdown.Toggle variant="outline-primary">
|
||||||
|
<FontAwesomeIcon icon={faUserCircle} className="d-md-none" size="lg" />
|
||||||
|
<span data-hj-suppress className="d-none d-md-inline">
|
||||||
|
{username}
|
||||||
|
</span>
|
||||||
|
</Dropdown.Toggle>
|
||||||
|
<Dropdown.Menu className="dropdown-menu-right">
|
||||||
|
{dashboardMenuItem}
|
||||||
|
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/u/${username}`}>
|
||||||
|
{intl.formatMessage(messages.profile)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/account/settings`}>
|
||||||
|
{intl.formatMessage(messages.account)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
{ getConfig().ORDER_HISTORY_URL && (
|
||||||
|
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}>
|
||||||
|
{intl.formatMessage(messages.orderHistory)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
)}
|
||||||
|
<Dropdown.Item href={getConfig().LOGOUT_URL}>
|
||||||
|
{intl.formatMessage(messages.signOut)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
</Dropdown.Menu>
|
||||||
|
</Dropdown>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthenticatedUserDropdown.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
username: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default injectIntl(AuthenticatedUserDropdown);
|
||||||
81
src/learning-header/LearningHeader.jsx
Normal file
81
src/learning-header/LearningHeader.jsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { getConfig } from '@edx/frontend-platform';
|
||||||
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
|
||||||
|
import AnonymousUserMenu from './AnonymousUserMenu';
|
||||||
|
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown';
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
|
function LinkedLogo({
|
||||||
|
href,
|
||||||
|
src,
|
||||||
|
alt,
|
||||||
|
...attributes
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<a href={href} {...attributes}>
|
||||||
|
<img className="d-block" src={src} alt={alt} />
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkedLogo.propTypes = {
|
||||||
|
href: PropTypes.string.isRequired,
|
||||||
|
src: PropTypes.string.isRequired,
|
||||||
|
alt: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function LearningHeader({
|
||||||
|
courseOrg, courseNumber, courseTitle, intl, showUserDropdown,
|
||||||
|
}) {
|
||||||
|
const { authenticatedUser } = useContext(AppContext);
|
||||||
|
|
||||||
|
const headerLogo = (
|
||||||
|
<LinkedLogo
|
||||||
|
className="logo"
|
||||||
|
href={`${getConfig().LMS_BASE_URL}/dashboard`}
|
||||||
|
src={getConfig().LOGO_URL}
|
||||||
|
alt={getConfig().SITE_NAME}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="learning-header">
|
||||||
|
<a className="sr-only sr-only-focusable" href="#main-content">{intl.formatMessage(messages.skipNavLink)}</a>
|
||||||
|
<div className="container-xl py-2 d-flex align-items-center">
|
||||||
|
{headerLogo}
|
||||||
|
<div className="flex-grow-1 course-title-lockup" style={{ lineHeight: 1 }}>
|
||||||
|
<span className="d-block small m-0">{courseOrg} {courseNumber}</span>
|
||||||
|
<span className="d-block m-0 font-weight-bold course-title">{courseTitle}</span>
|
||||||
|
</div>
|
||||||
|
{showUserDropdown && authenticatedUser && (
|
||||||
|
<AuthenticatedUserDropdown
|
||||||
|
username={authenticatedUser.username}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{showUserDropdown && !authenticatedUser && (
|
||||||
|
<AnonymousUserMenu />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
LearningHeader.propTypes = {
|
||||||
|
courseOrg: PropTypes.string,
|
||||||
|
courseNumber: PropTypes.string,
|
||||||
|
courseTitle: PropTypes.string,
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
showUserDropdown: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
LearningHeader.defaultProps = {
|
||||||
|
courseOrg: null,
|
||||||
|
courseNumber: null,
|
||||||
|
courseTitle: null,
|
||||||
|
showUserDropdown: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default injectIntl(LearningHeader);
|
||||||
29
src/learning-header/LearningHeader.test.jsx
Normal file
29
src/learning-header/LearningHeader.test.jsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
authenticatedUser, initializeMockApp, render, screen,
|
||||||
|
} from '../setupTest';
|
||||||
|
import { LearningHeader as Header } from '../index';
|
||||||
|
|
||||||
|
describe('Header', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
// We need to mock AuthService to implicitly use `getAuthenticatedUser` within `AppContext.Provider`.
|
||||||
|
await initializeMockApp();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays user button', () => {
|
||||||
|
render(<Header />);
|
||||||
|
expect(screen.getByRole('button')).toHaveTextContent(authenticatedUser.username);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays course data', () => {
|
||||||
|
const courseData = {
|
||||||
|
courseOrg: 'course-org',
|
||||||
|
courseNumber: 'course-number',
|
||||||
|
courseTitle: 'course-title',
|
||||||
|
};
|
||||||
|
render(<Header {...courseData} />);
|
||||||
|
|
||||||
|
expect(screen.getByText(`${courseData.courseOrg} ${courseData.courseNumber}`)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(courseData.courseTitle)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
41
src/learning-header/messages.js
Normal file
41
src/learning-header/messages.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
dashboard: {
|
||||||
|
id: 'header.menu.dashboard.label',
|
||||||
|
defaultMessage: 'Dashboard',
|
||||||
|
description: 'The text for the user menu Dashboard navigation link.',
|
||||||
|
},
|
||||||
|
help: {
|
||||||
|
id: 'header.help.label',
|
||||||
|
defaultMessage: 'Help',
|
||||||
|
description: 'The text for the link to the Help Center',
|
||||||
|
},
|
||||||
|
profile: {
|
||||||
|
id: 'header.menu.profile.label',
|
||||||
|
defaultMessage: 'Profile',
|
||||||
|
description: 'The text for the user menu Profile navigation link.',
|
||||||
|
},
|
||||||
|
account: {
|
||||||
|
id: 'header.menu.account.label',
|
||||||
|
defaultMessage: 'Account',
|
||||||
|
description: 'The text for the user menu Account navigation link.',
|
||||||
|
},
|
||||||
|
orderHistory: {
|
||||||
|
id: 'header.menu.orderHistory.label',
|
||||||
|
defaultMessage: 'Order History',
|
||||||
|
description: 'The text for the user menu Order History navigation link.',
|
||||||
|
},
|
||||||
|
skipNavLink: {
|
||||||
|
id: 'header.navigation.skipNavLink',
|
||||||
|
defaultMessage: 'Skip to main content.',
|
||||||
|
description: 'A link used by screen readers to allow users to skip to the main content of the page.',
|
||||||
|
},
|
||||||
|
signOut: {
|
||||||
|
id: 'header.menu.signOut.label',
|
||||||
|
defaultMessage: 'Sign Out',
|
||||||
|
description: 'The label for the user menu Sign Out action.',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default messages;
|
||||||
102
src/setupTest.js
102
src/setupTest.js
@@ -1,8 +1,21 @@
|
|||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
|
|
||||||
import Enzyme from 'enzyme';
|
import Enzyme from 'enzyme';
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import Adapter from 'enzyme-adapter-react-16';
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import '@testing-library/jest-dom/extend-expect';
|
||||||
import 'babel-polyfill';
|
import 'babel-polyfill';
|
||||||
|
import 'jest-chain';
|
||||||
|
import { getConfig, mergeConfig } from '@edx/frontend-platform';
|
||||||
|
import { configure as configureLogging } from '@edx/frontend-platform/logging';
|
||||||
|
import { configure as configureI18n } from '@edx/frontend-platform/i18n';
|
||||||
|
import { configure as configureAuth, MockAuthService } from '@edx/frontend-platform/auth';
|
||||||
|
import { render as rtlRender } from '@testing-library/react';
|
||||||
|
import { IntlProvider } from 'react-intl';
|
||||||
|
import AppProvider from '@edx/frontend-platform/react/AppProvider';
|
||||||
|
import appMessages from './i18n';
|
||||||
|
|
||||||
Enzyme.configure({ adapter: new Adapter() });
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
@@ -16,7 +29,7 @@ process.env.ECOMMERCE_BASE_URL = 'http://localhost:18130';
|
|||||||
process.env.LANGUAGE_PREFERENCE_COOKIE_NAME = 'openedx-language-preference';
|
process.env.LANGUAGE_PREFERENCE_COOKIE_NAME = 'openedx-language-preference';
|
||||||
process.env.LMS_BASE_URL = 'http://localhost:18000';
|
process.env.LMS_BASE_URL = 'http://localhost:18000';
|
||||||
process.env.LOGIN_URL = 'http://localhost:18000/login';
|
process.env.LOGIN_URL = 'http://localhost:18000/login';
|
||||||
process.env.LOGOUT_URL = 'http://localhost:18000/login';
|
process.env.LOGOUT_URL = 'http://localhost:18000/logout';
|
||||||
process.env.MARKETING_SITE_BASE_URL = 'http://localhost:18000';
|
process.env.MARKETING_SITE_BASE_URL = 'http://localhost:18000';
|
||||||
process.env.ORDER_HISTORY_URL = 'localhost:1996/orders';
|
process.env.ORDER_HISTORY_URL = 'localhost:1996/orders';
|
||||||
process.env.REFRESH_ACCESS_TOKEN_ENDPOINT = 'http://localhost:18000/login_refresh';
|
process.env.REFRESH_ACCESS_TOKEN_ENDPOINT = 'http://localhost:18000/login_refresh';
|
||||||
@@ -27,3 +40,90 @@ process.env.LOGO_URL = 'https://edx-cdn.org/v3/default/logo.svg';
|
|||||||
process.env.LOGO_TRADEMARK_URL = 'https://edx-cdn.org/v3/default/logo-trademark.svg';
|
process.env.LOGO_TRADEMARK_URL = 'https://edx-cdn.org/v3/default/logo-trademark.svg';
|
||||||
process.env.LOGO_WHITE_URL = 'https://edx-cdn.org/v3/default/logo-white.svg';
|
process.env.LOGO_WHITE_URL = 'https://edx-cdn.org/v3/default/logo-white.svg';
|
||||||
process.env.FAVICON_URL = 'https://edx-cdn.org/v3/default/favicon.ico';
|
process.env.FAVICON_URL = 'https://edx-cdn.org/v3/default/favicon.ico';
|
||||||
|
|
||||||
|
class MockLoggingService {
|
||||||
|
logInfo = jest.fn();
|
||||||
|
|
||||||
|
logError = jest.fn();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const authenticatedUser = {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'Mock User',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function initializeMockApp() {
|
||||||
|
mergeConfig({
|
||||||
|
INSIGHTS_BASE_URL: process.env.INSIGHTS_BASE_URL || null,
|
||||||
|
STUDIO_BASE_URL: process.env.STUDIO_BASE_URL || null,
|
||||||
|
TWITTER_URL: process.env.TWITTER_URL || null,
|
||||||
|
BASE_URL: process.env.BASE_URL || null,
|
||||||
|
LMS_BASE_URL: process.env.LMS_BASE_URL || null,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL || null,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL || null,
|
||||||
|
REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT || null,
|
||||||
|
ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME || null,
|
||||||
|
CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH || null,
|
||||||
|
LOGO_URL: process.env.LOGO_URL || null,
|
||||||
|
SITE_NAME: process.env.SITE_NAME || null,
|
||||||
|
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'Mock User',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const loggingService = configureLogging(MockLoggingService, {
|
||||||
|
config: getConfig(),
|
||||||
|
});
|
||||||
|
const authService = configureAuth(MockAuthService, {
|
||||||
|
config: getConfig(),
|
||||||
|
loggingService,
|
||||||
|
});
|
||||||
|
|
||||||
|
// i18n doesn't have a service class to return.
|
||||||
|
configureI18n({
|
||||||
|
config: getConfig(),
|
||||||
|
loggingService,
|
||||||
|
messages: [appMessages],
|
||||||
|
});
|
||||||
|
|
||||||
|
return { loggingService, authService };
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(
|
||||||
|
ui,
|
||||||
|
{
|
||||||
|
store = null,
|
||||||
|
...renderOptions
|
||||||
|
} = {},
|
||||||
|
) {
|
||||||
|
function Wrapper({ children }) {
|
||||||
|
return (
|
||||||
|
// eslint-disable-next-line react/jsx-filename-extension
|
||||||
|
<IntlProvider locale="en">
|
||||||
|
<AppProvider store={store}>
|
||||||
|
{children}
|
||||||
|
</AppProvider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Wrapper.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-export everything.
|
||||||
|
export * from '@testing-library/react';
|
||||||
|
|
||||||
|
// Override `render` method.
|
||||||
|
export {
|
||||||
|
render,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user