Compare commits
300 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2540bc3a0 | ||
|
|
ffb5a765e2 | ||
|
|
952e543217 | ||
|
|
45a1da9f5e | ||
|
|
022515d1d2 | ||
|
|
2d737aae7f | ||
|
|
4c4db14eac | ||
|
|
911cea6a0e | ||
|
|
a52ddfd9bd | ||
|
|
8175ba897a | ||
|
|
cfda72b2e2 | ||
|
|
4483a734bc | ||
|
|
db1903cdce | ||
|
|
71851b13a6 | ||
|
|
6efa31092d | ||
|
|
c3541a3d79 | ||
|
|
dad01fcd78 | ||
|
|
30e6eed60d | ||
|
|
de69ed3dd9 | ||
|
|
1d55df323f | ||
|
|
4e718f85de | ||
|
|
a211547a1d | ||
|
|
784e9afccf | ||
|
|
4b23d8c4e4 | ||
|
|
6d02e63d08 | ||
|
|
b1feed2443 | ||
|
|
cabf4e3f27 | ||
|
|
78a40d47c1 | ||
|
|
c7178afe6b | ||
|
|
18a6840037 | ||
|
|
583a487c38 | ||
|
|
3276496523 | ||
|
|
7ab55175b5 | ||
|
|
72e82005c0 | ||
|
|
c4df727178 | ||
|
|
1f6766175d | ||
|
|
2ac8988a9b | ||
|
|
642be093c7 | ||
|
|
86939a2559 | ||
|
|
8ed18f3d69 | ||
|
|
061746da9f | ||
|
|
de77aa5f0c | ||
|
|
7034d10536 | ||
|
|
4ce7311809 | ||
|
|
e76f5b6937 | ||
|
|
f8fc794458 | ||
|
|
a5069edd94 | ||
|
|
2543926c95 | ||
|
|
c5eb43a2a5 | ||
|
|
256fa5c9d8 | ||
|
|
267cce9f89 | ||
|
|
4f59c80a12 | ||
|
|
59afd596ab | ||
|
|
0c83268163 | ||
|
|
c5f5fa9281 | ||
|
|
e247aee372 | ||
|
|
f6ae5a4bdd | ||
|
|
057d16d3c1 | ||
|
|
93bb38d0bd | ||
|
|
01405eaff9 | ||
|
|
59fa6e2a35 | ||
|
|
9fc3a0e835 | ||
|
|
22e157adf6 | ||
|
|
6b81f69eba | ||
|
|
cefa84006c | ||
|
|
a54309dd63 | ||
|
|
aeb0fd2be7 | ||
|
|
26eb2bb4c7 | ||
|
|
8083079954 | ||
|
|
d4fc8489ea | ||
|
|
4020a81bd4 | ||
|
|
acf1adba80 | ||
|
|
a204ff8c03 | ||
|
|
e8ccc4b707 | ||
|
|
4d86780c73 | ||
|
|
fdbb83f51e | ||
|
|
f6e4664d37 | ||
|
|
65177fcdcc | ||
|
|
7601249fb6 | ||
|
|
c8ef3dad93 | ||
|
|
b02fe00c71 | ||
|
|
4404aede33 | ||
|
|
1b0edb10c4 | ||
|
|
546adff45e | ||
|
|
94b14fd618 | ||
|
|
5b8a9a587b | ||
|
|
2650cb59b3 | ||
|
|
bc2b13175a | ||
|
|
85e8094833 | ||
|
|
aff8dda3ee | ||
|
|
51b505552d | ||
|
|
3648f1b6be | ||
|
|
c78b6964b9 | ||
|
|
664d05134b | ||
|
|
b969522cd0 | ||
|
|
0cd8210ea7 | ||
|
|
1c763c2102 | ||
|
|
073003284a | ||
|
|
92fdf85c9a | ||
|
|
5ee8a8c75c | ||
|
|
536d67404f | ||
|
|
9d99bfcec6 | ||
|
|
3180c9d973 | ||
|
|
1645274d9f | ||
|
|
84e43cb038 | ||
|
|
994b21c0c1 | ||
|
|
940b45ba7e | ||
|
|
4efa0a07ae | ||
|
|
2bd6879bda | ||
|
|
b479f0b376 | ||
|
|
dfdcbc0a8d | ||
|
|
c3b02a2946 | ||
|
|
f6c1a8bcc1 | ||
|
|
6c02962e0d | ||
|
|
acaf98f0b1 | ||
|
|
90351083aa | ||
|
|
6f75684ad9 | ||
|
|
a54f099d68 | ||
|
|
02d081dd26 | ||
|
|
468acc80f0 | ||
|
|
90fdd13fbc | ||
|
|
faf1b8522a | ||
|
|
e8a28b09bc | ||
|
|
c611df3f69 | ||
|
|
ab371f1c3a | ||
|
|
fb2002a004 | ||
|
|
f955ec4434 | ||
|
|
d529e00d7b | ||
|
|
e0cbbf7da1 | ||
|
|
ba209fd050 | ||
|
|
ae7004e95d | ||
|
|
de9eb63b07 | ||
|
|
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 | ||
|
|
64f55150b6 | ||
|
|
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 | ||
|
|
0d64b19ac4 | ||
|
|
9415709b81 | ||
|
|
003d8ee1a7 | ||
|
|
18dd01d3d2 | ||
|
|
bdb1e03e4e | ||
|
|
5662e5daa3 | ||
|
|
9306ce0783 | ||
|
|
f58ef0ace6 |
@@ -1,12 +1,15 @@
|
|||||||
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
|
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
|
||||||
|
ACCOUNT_PROFILE_URL=http://localhost:1995
|
||||||
|
ACCOUNT_SETTINGS_URL=http://localhost:1997
|
||||||
BASE_URL=localhost:8080
|
BASE_URL=localhost:8080
|
||||||
CREDENTIALS_BASE_URL=http://localhost:18150
|
CREDENTIALS_BASE_URL=http://localhost:18150
|
||||||
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
|
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
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
const { createConfig } = require('@edx/frontend-build');
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
module.exports = createConfig('eslint');
|
module.exports = createConfig('eslint');
|
||||||
|
|||||||
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 }}
|
||||||
20
.github/workflows/add-remove-label-on-comment.yml
vendored
Normal file
20
.github/workflows/add-remove-label-on-comment.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# This workflow runs when a comment is made on the ticket
|
||||||
|
# If the comment starts with "label: " it tries to apply
|
||||||
|
# the label indicated in rest of comment.
|
||||||
|
# If the comment starts with "remove label: ", it tries
|
||||||
|
# to remove the indicated label.
|
||||||
|
# Note: Labels are allowed to have spaces and this script does
|
||||||
|
# not parse spaces (as often a space is legitimate), so the command
|
||||||
|
# "label: really long lots of words label" will apply the
|
||||||
|
# label "really long lots of words label"
|
||||||
|
|
||||||
|
name: Allows for the adding and removing of labels via comment
|
||||||
|
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
add_remove_labels:
|
||||||
|
uses: openedx/.github/.github/workflows/add-remove-label-on-comment.yml@master
|
||||||
|
|
||||||
22
.github/workflows/ci.yml
vendored
22
.github/workflows/ci.yml
vendored
@@ -1,17 +1,25 @@
|
|||||||
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
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
- name: Setup Nodejs Env
|
||||||
|
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||||
- name: Setup Nodejs
|
- name: Setup Nodejs
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 12
|
node-version: ${{ env.NODE_VER }}
|
||||||
- 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 +28,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@v3
|
||||||
|
|||||||
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
|
||||||
13
.github/workflows/lockfileversion-check.yml
vendored
Normal file
13
.github/workflows/lockfileversion-check.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#check package-lock file version
|
||||||
|
|
||||||
|
name: lockfileVersion check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
version-check:
|
||||||
|
uses: openedx/.github/.github/workflows/lockfileversion-check-v3.yml@master
|
||||||
60
.github/workflows/release.yml
vendored
60
.github/workflows/release.yml
vendored
@@ -2,36 +2,40 @@ 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@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Node.js
|
- name: Setup Nodejs Env
|
||||||
uses: actions/setup-node@v1
|
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||||
with:
|
- name: Setup Node.js
|
||||||
node-version: 12
|
uses: actions/setup-node@v3
|
||||||
- name: Install dependencies
|
with:
|
||||||
run: npm ci
|
node-version: ${{ env.NODE_VER }}
|
||||||
- name: Validate package-lock.json changes
|
- name: Install dependencies
|
||||||
run: make validate-no-uncommitted-package-lock-changes
|
run: npm ci
|
||||||
- name: Lint
|
- name: Validate package-lock.json changes
|
||||||
run: npm run lint
|
run: make validate-no-uncommitted-package-lock-changes
|
||||||
- name: Test
|
- name: Lint
|
||||||
run: npm run test
|
run: npm run lint
|
||||||
- name: i18n_extract
|
- name: Test
|
||||||
run: npm run i18n_extract
|
run: npm run test
|
||||||
- name: Coverage
|
- name: i18n_extract
|
||||||
uses: codecov/codecov-action@v1
|
run: npm run i18n_extract
|
||||||
- name: Build
|
- name: Coverage
|
||||||
run: npm run build
|
uses: codecov/codecov-action@v3
|
||||||
- name: Release
|
- name: Build
|
||||||
env:
|
run: npm run build
|
||||||
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
- name: Release
|
||||||
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
uses: cycjimmy/semantic-release-action@v3
|
||||||
run: npx semantic-release
|
with:
|
||||||
|
semantic_version: 16
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
||||||
|
|||||||
12
.github/workflows/self-assign-issue.yml
vendored
Normal file
12
.github/workflows/self-assign-issue.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# This workflow runs when a comment is made on the ticket
|
||||||
|
# If the comment starts with "assign me" it assigns the author to the
|
||||||
|
# ticket (case insensitive)
|
||||||
|
|
||||||
|
name: Assign comment author to ticket if they say "assign me"
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
self_assign_by_comment:
|
||||||
|
uses: openedx/.github/.github/workflows/self-assign-issue.yml@master
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,3 +6,6 @@ node_modules
|
|||||||
temp
|
temp
|
||||||
src/i18n/transifex_input.json
|
src/i18n/transifex_input.json
|
||||||
module.config.js
|
module.config.js
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
14
Makefile
14
Makefile
@@ -1,11 +1,9 @@
|
|||||||
transifex_resource = frontend-component-header
|
export TRANSIFEX_RESOURCE = frontend-component-header
|
||||||
transifex_langs = "ar,fr,es_419,zh_CN"
|
transifex_langs = "ar,fr,es_419,zh_CN,pt,it,de,uk,ru,hi,fr_CA"
|
||||||
|
|
||||||
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
||||||
i18n = ./src/i18n
|
i18n = ./src/i18n
|
||||||
transifex_input = $(i18n)/transifex_input.json
|
transifex_input = $(i18n)/transifex_input.json
|
||||||
tx_url1 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/translation/en/strings/
|
|
||||||
tx_url2 = https://www.transifex.com/api/2/project/edx-platform/resource/$(transifex_resource)/source/
|
|
||||||
|
|
||||||
# This directory must match .babelrc .
|
# This directory must match .babelrc .
|
||||||
transifex_temp = ./temp/babel-plugin-react-intl
|
transifex_temp = ./temp/babel-plugin-react-intl
|
||||||
@@ -42,15 +40,15 @@ push_translations:
|
|||||||
# Pushing strings to Transifex...
|
# Pushing strings to Transifex...
|
||||||
tx push -s
|
tx push -s
|
||||||
# Fetching hashes from Transifex...
|
# Fetching hashes from Transifex...
|
||||||
./node_modules/reactifex/bash_scripts/get_hashed_strings.sh $(tx_url1)
|
./node_modules/@edx/reactifex/bash_scripts/get_hashed_strings_v3.sh
|
||||||
# Writing out comments to file...
|
# Writing out comments to file...
|
||||||
$(transifex_utils) $(transifex_temp) --comments
|
$(transifex_utils) $(transifex_temp) --comments --v3-scripts-path
|
||||||
# Pushing comments to Transifex...
|
# Pushing comments to Transifex...
|
||||||
./node_modules/reactifex/bash_scripts/put_comments.sh $(tx_url2)
|
./node_modules/@edx/reactifex/bash_scripts/put_comments_v3.sh
|
||||||
|
|
||||||
# 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:
|
||||||
|
|||||||
76
README.rst
76
README.rst
@@ -1,11 +1,79 @@
|
|||||||
|
#########################
|
||||||
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.
|
||||||
|
* ``ACCOUNT_PROFILE_URL`` - The URL of the account profile page.
|
||||||
|
* ``ACCOUNT_SETTINGS_URL`` - The URL of the account settings 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 ci
|
||||||
|
|
||||||
|
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'],
|
|
||||||
};
|
|
||||||
@@ -4,7 +4,8 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { initialize, getConfig, subscribe, APP_READY } from '@edx/frontend-platform';
|
import { initialize, getConfig, subscribe, APP_READY } from '@edx/frontend-platform';
|
||||||
import { AppContext, AppProvider } from '@edx/frontend-platform/react';
|
import { AppContext, AppProvider } from '@edx/frontend-platform/react';
|
||||||
import Header from '@edx/frontend-component-header';
|
// import Header from '@edx/frontend-component-header';
|
||||||
|
import { LearningHeader as Header } from '@edx/frontend-component-header';
|
||||||
|
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
45789
package-lock.json
generated
45789
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
75
package.json
75
package.json
@@ -19,53 +19,64 @@
|
|||||||
],
|
],
|
||||||
"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",
|
"@edx/brand": "npm:@edx/brand-openedx@1.2.0",
|
||||||
"@commitlint/config-angular": "8.2.0",
|
"@edx/browserslist-config": "^1.1.1",
|
||||||
"@commitlint/prompt": "8.2.0",
|
"@edx/frontend-build": "12.8.57",
|
||||||
"@commitlint/prompt-cli": "8.2.0",
|
"@edx/frontend-platform": "4.5.1",
|
||||||
"@edx/brand": "npm:@edx/brand-openedx@1.1.0",
|
"@edx/reactifex": "^2.1.1",
|
||||||
"@edx/frontend-build": "5.4.0",
|
"@testing-library/dom": "9.3.1",
|
||||||
"@edx/frontend-platform": "1.8.0",
|
"@testing-library/jest-dom": "5.16.5",
|
||||||
"@edx/paragon": "12.0.5",
|
"@testing-library/react": "10.4.9",
|
||||||
"codecov": "3.7.2",
|
"enzyme": "3.11.0",
|
||||||
"enzyme": "3.10.0",
|
"enzyme-adapter-react-16": "1.15.7",
|
||||||
"enzyme-adapter-react-16": "1.14.0",
|
"husky": "8.0.3",
|
||||||
"husky": "3.0.9",
|
"jest": "29.5.0",
|
||||||
"prop-types": "15.7.2",
|
"jest-chain": "1.1.6",
|
||||||
"react": "16.9.0",
|
"prop-types": "15.8.1",
|
||||||
"react-dom": "16.9.0",
|
"react": "16.14.0",
|
||||||
"react-redux": "7.1.1",
|
"react-dom": "16.14.0",
|
||||||
"react-router-dom": "5.1.2",
|
"react-redux": "7.2.9",
|
||||||
"react-test-renderer": "16.9.0",
|
"react-test-renderer": "16.14.0",
|
||||||
"reactifex": "1.1.1",
|
"redux": "4.2.1",
|
||||||
"redux": "4.0.4",
|
"redux-saga": "1.2.3"
|
||||||
"redux-saga": "1.1.1"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@edx/paragon": "20.45.0",
|
||||||
|
"@fortawesome/fontawesome-svg-core": "6.3.0",
|
||||||
|
"@fortawesome/free-brands-svg-icons": "6.3.0",
|
||||||
|
"@fortawesome/free-regular-svg-icons": "6.3.0",
|
||||||
|
"@fortawesome/free-solid-svg-icons": "6.3.0",
|
||||||
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
||||||
|
"@reduxjs/toolkit": "1.9.5",
|
||||||
|
"axios-mock-adapter": "1.21.5",
|
||||||
"babel-polyfill": "6.26.0",
|
"babel-polyfill": "6.26.0",
|
||||||
"react-responsive": "8.0.3",
|
"classnames": "2.3.2",
|
||||||
"react-transition-group": "4.3.0"
|
"lodash": "4.17.21",
|
||||||
|
"react-redux": "7.2.9",
|
||||||
|
"react-responsive": "8.2.0",
|
||||||
|
"react-router-dom": "5.3.4",
|
||||||
|
"react-transition-group": "4.4.5",
|
||||||
|
"rosie": "2.1.0",
|
||||||
|
"timeago.js": "4.0.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@edx/frontend-platform": "^1.8.0",
|
"@edx/frontend-platform": "^4.0.0",
|
||||||
"@edx/paragon": "^7.0.0",
|
|
||||||
"prop-types": "^15.5.10",
|
"prop-types": "^15.5.10",
|
||||||
"react": "^16.9.0",
|
"react": "^16.9.0 || ^17.0.0",
|
||||||
"react-dom": "^16.9.0"
|
"react-dom": "^16.9.0 || ^17.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,33 @@
|
|||||||
{
|
{
|
||||||
"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
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchPackagePatterns": ["@edx"],
|
||||||
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"timezone": "America/New_York"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
import { AvatarIcon } from './Icons';
|
import { AvatarIcon } from './Icons';
|
||||||
|
|
||||||
function Avatar({
|
const Avatar = ({
|
||||||
size,
|
size,
|
||||||
src,
|
src,
|
||||||
alt,
|
alt,
|
||||||
className,
|
className,
|
||||||
}) {
|
}) => {
|
||||||
const avatar = src ? (
|
const avatar = src ? (
|
||||||
<img className="d-block w-100 h-100" src={src} alt={alt} />
|
<img className="d-block w-100 h-100" src={src} alt={alt} />
|
||||||
) : (
|
) : (
|
||||||
@@ -23,7 +23,7 @@ function Avatar({
|
|||||||
{avatar}
|
{avatar}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
Avatar.propTypes = {
|
Avatar.propTypes = {
|
||||||
src: PropTypes.string,
|
src: PropTypes.string,
|
||||||
|
|||||||
@@ -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,15 +21,16 @@ 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, () => {
|
||||||
mergeConfig({
|
mergeConfig({
|
||||||
LOGISTRATION_MINIMAL_HEADER: !!process.env.LOGISTRATION_MINIMAL_HEADER,
|
AUTHN_MINIMAL_HEADER: !!process.env.AUTHN_MINIMAL_HEADER,
|
||||||
}, 'Header additional config');
|
}, 'Header additional config');
|
||||||
});
|
});
|
||||||
|
|
||||||
function Header({ intl }) {
|
const Header = ({ intl }) => {
|
||||||
const { authenticatedUser, config } = useContext(AppContext);
|
const { authenticatedUser, config } = useContext(AppContext);
|
||||||
|
|
||||||
const mainMenu = [
|
const mainMenu = [
|
||||||
@@ -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',
|
||||||
@@ -48,12 +55,12 @@ function Header({ intl }) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'item',
|
type: 'item',
|
||||||
href: `${config.LMS_BASE_URL}/u/${authenticatedUser.username}`,
|
href: `${config.ACCOUNT_PROFILE_URL}/u/${authenticatedUser.username}`,
|
||||||
content: intl.formatMessage(messages['header.user.menu.profile']),
|
content: intl.formatMessage(messages['header.user.menu.profile']),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'item',
|
type: 'item',
|
||||||
href: `${config.LMS_BASE_URL}/account/settings`,
|
href: config.ACCOUNT_SETTINGS_URL,
|
||||||
content: intl.formatMessage(messages['header.user.menu.account.settings']),
|
content: intl.formatMessage(messages['header.user.menu.account.settings']),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -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,14 +91,13 @@ 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,
|
||||||
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
|
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
|
||||||
mainMenu: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : mainMenu,
|
mainMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : mainMenu,
|
||||||
userMenu: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : userMenu,
|
userMenu: getConfig().AUTHN_MINIMAL_HEADER ? [] : userMenu,
|
||||||
loggedOutItems: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : loggedOutItems,
|
loggedOutItems: getConfig().AUTHN_MINIMAL_HEADER ? [] : loggedOutItems,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -99,7 +110,7 @@ function Header({ intl }) {
|
|||||||
</Responsive>
|
</Responsive>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
Header.propTypes = {
|
Header.propTypes = {
|
||||||
intl: intlShape.isRequired,
|
intl: intlShape.isRequired,
|
||||||
|
|||||||
@@ -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,33 +1,51 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
import TestRenderer from 'react-test-renderer';
|
import TestRenderer from 'react-test-renderer';
|
||||||
import { AppContext } from '@edx/frontend-platform/react';
|
import { AppContext, AppProvider } from '@edx/frontend-platform/react';
|
||||||
import { Context as ResponsiveContext } from 'react-responsive';
|
import { Context as ResponsiveContext } from 'react-responsive';
|
||||||
|
import { initializeMockApp } from '@edx/frontend-platform';
|
||||||
|
import store from './store';
|
||||||
|
|
||||||
import Header from './index';
|
import Header from './index';
|
||||||
|
|
||||||
|
const HeaderComponent = ({ width, contextValue }) => (
|
||||||
|
<ResponsiveContext.Provider value={width}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppProvider store={store}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={contextValue}
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</AppProvider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ResponsiveContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
describe('<Header />', () => {
|
describe('<Header />', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
initializeMockApp({
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: '123abc',
|
||||||
|
username: 'testuser',
|
||||||
|
administrator: false,
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
it('renders correctly for anonymous desktop', () => {
|
it('renders correctly for anonymous desktop', () => {
|
||||||
const component = (
|
const contextValue = {
|
||||||
<ResponsiveContext.Provider value={{ width: 1280 }}>
|
authenticatedUser: null,
|
||||||
<IntlProvider locale="en" messages={{}}>
|
config: {
|
||||||
<AppContext.Provider
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
value={{
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
authenticatedUser: null,
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
config: {
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
},
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
};
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
const component = <HeaderComponent width={{ width: 1280 }} contextValue={contextValue} />;
|
||||||
LOGO_URL: process.env.LOGO_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Header />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
@@ -35,31 +53,22 @@ describe('<Header />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly for authenticated desktop', () => {
|
it('renders correctly for authenticated desktop', () => {
|
||||||
const component = (
|
const contextValue = {
|
||||||
<ResponsiveContext.Provider value={{ width: 1280 }}>
|
authenticatedUser: {
|
||||||
<IntlProvider locale="en" messages={{}}>
|
userId: 'abc123',
|
||||||
<AppContext.Provider
|
username: 'edX',
|
||||||
value={{
|
roles: [],
|
||||||
authenticatedUser: {
|
administrator: false,
|
||||||
userId: 'abc123',
|
},
|
||||||
username: 'edX',
|
config: {
|
||||||
roles: [],
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
administrator: false,
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
},
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
config: {
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
},
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
};
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
const component = <HeaderComponent width={{ width: 1280 }} contextValue={contextValue} />;
|
||||||
LOGO_URL: process.env.LOGO_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Header />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
@@ -67,26 +76,17 @@ describe('<Header />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly for anonymous mobile', () => {
|
it('renders correctly for anonymous mobile', () => {
|
||||||
const component = (
|
const contextValue = {
|
||||||
<ResponsiveContext.Provider value={{ width: 500 }}>
|
authenticatedUser: null,
|
||||||
<IntlProvider locale="en" messages={{}}>
|
config: {
|
||||||
<AppContext.Provider
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
value={{
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
authenticatedUser: null,
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
config: {
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
},
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
};
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
const component = <HeaderComponent width={{ width: 500 }} contextValue={contextValue} />;
|
||||||
LOGO_URL: process.env.LOGO_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Header />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
@@ -94,31 +94,22 @@ describe('<Header />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly for authenticated mobile', () => {
|
it('renders correctly for authenticated mobile', () => {
|
||||||
const component = (
|
const contextValue = {
|
||||||
<ResponsiveContext.Provider value={{ width: 500 }}>
|
authenticatedUser: {
|
||||||
<IntlProvider locale="en" messages={{}}>
|
userId: 'abc123',
|
||||||
<AppContext.Provider
|
username: 'edX',
|
||||||
value={{
|
roles: [],
|
||||||
authenticatedUser: {
|
administrator: false,
|
||||||
userId: 'abc123',
|
},
|
||||||
username: 'edX',
|
config: {
|
||||||
roles: [],
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
administrator: false,
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
},
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
config: {
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
},
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
};
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
const component = <HeaderComponent width={{ width: 500 }} contextValue={contextValue} />;
|
||||||
LOGO_URL: process.env.LOGO_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Header />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
export const MenuIcon = props => (
|
export const MenuIcon = (props) => (
|
||||||
<svg
|
<svg
|
||||||
width="24px"
|
width="24px"
|
||||||
height="24px"
|
height="24px"
|
||||||
@@ -14,7 +14,7 @@ export const MenuIcon = props => (
|
|||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const AvatarIcon = props => (
|
export const AvatarIcon = (props) => (
|
||||||
<svg
|
<svg
|
||||||
width="24px"
|
width="24px"
|
||||||
height="24px"
|
height="24px"
|
||||||
@@ -29,7 +29,7 @@ export const AvatarIcon = props => (
|
|||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const CaretIcon = props => (
|
export const CaretIcon = (props) => (
|
||||||
<svg
|
<svg
|
||||||
width="16px"
|
width="16px"
|
||||||
height="16px"
|
height="16px"
|
||||||
|
|||||||
22
src/Logo.jsx
22
src/Logo.jsx
@@ -1,29 +1,25 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
function Logo({ src, alt, ...attributes }) {
|
const Logo = ({ src, alt, ...attributes }) => (
|
||||||
return (
|
<img src={src} alt={alt} {...attributes} />
|
||||||
<img src={src} alt={alt} {...attributes} />
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logo.propTypes = {
|
Logo.propTypes = {
|
||||||
src: PropTypes.string.isRequired,
|
src: PropTypes.string.isRequired,
|
||||||
alt: PropTypes.string.isRequired,
|
alt: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function LinkedLogo({
|
const LinkedLogo = ({
|
||||||
href,
|
href,
|
||||||
src,
|
src,
|
||||||
alt,
|
alt,
|
||||||
...attributes
|
...attributes
|
||||||
}) {
|
}) => (
|
||||||
return (
|
<a href={href} {...attributes}>
|
||||||
<a href={href} {...attributes}>
|
<img className="d-block" src={src} alt={alt} />
|
||||||
<img className="d-block" src={src} alt={alt} />
|
</a>
|
||||||
</a>
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedLogo.propTypes = {
|
LinkedLogo.propTypes = {
|
||||||
href: PropTypes.string.isRequired,
|
href: PropTypes.string.isRequired,
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ import React from 'react';
|
|||||||
import { CSSTransition } from 'react-transition-group';
|
import { CSSTransition } from 'react-transition-group';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
function MenuTrigger({ tag, className, ...attributes }) {
|
const MenuTrigger = ({ tag, className, ...attributes }) => React.createElement(tag, {
|
||||||
return React.createElement(tag, {
|
className: `menu-trigger ${className}`,
|
||||||
className: `menu-trigger ${className}`,
|
...attributes,
|
||||||
...attributes,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
MenuTrigger.propTypes = {
|
MenuTrigger.propTypes = {
|
||||||
tag: PropTypes.string,
|
tag: PropTypes.string,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
@@ -18,12 +16,10 @@ MenuTrigger.defaultProps = {
|
|||||||
};
|
};
|
||||||
const MenuTriggerType = <MenuTrigger />.type;
|
const MenuTriggerType = <MenuTrigger />.type;
|
||||||
|
|
||||||
function MenuContent({ tag, className, ...attributes }) {
|
const MenuContent = ({ tag, className, ...attributes }) => React.createElement(tag, {
|
||||||
return React.createElement(tag, {
|
className: ['menu-content', className].join(' '),
|
||||||
className: ['menu-content', className].join(' '),
|
...attributes,
|
||||||
...attributes,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
MenuContent.propTypes = {
|
MenuContent.propTypes = {
|
||||||
tag: PropTypes.string,
|
tag: PropTypes.string,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
71
src/Notifications/NotificationRowItem.jsx
Normal file
71
src/Notifications/NotificationRowItem.jsx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Icon } from '@edx/paragon';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import * as timeago from 'timeago.js';
|
||||||
|
import { getIconByType } from './utils';
|
||||||
|
import { markNotificationsAsRead } from './data/thunks';
|
||||||
|
import messages from './messages';
|
||||||
|
import timeLocale from '../common/time-locale';
|
||||||
|
|
||||||
|
const NotificationRowItem = ({
|
||||||
|
id, type, contentUrl, content, courseName, createdAt, lastRead,
|
||||||
|
}) => {
|
||||||
|
timeago.register('time-locale', timeLocale);
|
||||||
|
const intl = useIntl();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
const handleMarkAsRead = useCallback(() => {
|
||||||
|
dispatch(markNotificationsAsRead(id));
|
||||||
|
}, [dispatch, id]);
|
||||||
|
|
||||||
|
const { icon: iconComponent, class: iconClass } = getIconByType(type);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
target="_blank"
|
||||||
|
className="d-flex mb-2 align-items-center text-decoration-none"
|
||||||
|
to={contentUrl}
|
||||||
|
onClick={handleMarkAsRead}
|
||||||
|
>
|
||||||
|
<Icon src={iconComponent} className={`${iconClass} mr-4 notification-icon`} />
|
||||||
|
<div className="d-flex w-100">
|
||||||
|
<div className="d-flex align-items-center w-100">
|
||||||
|
<div className="py-10px w-100 px-0 cursor-pointer">
|
||||||
|
<span
|
||||||
|
className="line-height-24 text-gray-700 mb-2 notification-item-content overflow-hidden content"
|
||||||
|
// eslint-disable-next-line react/no-danger
|
||||||
|
dangerouslySetInnerHTML={{ __html: content }}
|
||||||
|
/>
|
||||||
|
<div className="py-0 d-flex">
|
||||||
|
<span className="font-size-12 text-gray-500 line-height-20">
|
||||||
|
<span>{courseName}</span>
|
||||||
|
<span className="text-light-700 px-1.5">{intl.formatMessage(messages.fullStop)}</span>
|
||||||
|
<span>{timeago.format(createdAt, 'time-locale')}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{!lastRead && (
|
||||||
|
<div className="d-flex py-1.5 px-1.5 ml-2 cursor-pointer">
|
||||||
|
<span className="bg-brand-500 rounded unread" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationRowItem.propTypes = {
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
type: PropTypes.string.isRequired,
|
||||||
|
contentUrl: PropTypes.string.isRequired,
|
||||||
|
content: PropTypes.node.isRequired,
|
||||||
|
courseName: PropTypes.string.isRequired,
|
||||||
|
createdAt: PropTypes.string.isRequired,
|
||||||
|
lastRead: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(NotificationRowItem);
|
||||||
81
src/Notifications/NotificationSections.jsx
Normal file
81
src/Notifications/NotificationSections.jsx
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import React, { useCallback, useMemo } from 'react';
|
||||||
|
import { Button } from '@edx/paragon';
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
import messages from './messages';
|
||||||
|
import NotificationRowItem from './NotificationRowItem';
|
||||||
|
import { markAllNotificationsAsRead } from './data/thunks';
|
||||||
|
import { selectNotificationsByIds, selectPaginationData, selectSelectedAppName } from './data/selectors';
|
||||||
|
import { splitNotificationsByTime } from './utils';
|
||||||
|
import { updatePaginationRequest } from './data/slice';
|
||||||
|
|
||||||
|
const NotificationSections = () => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const selectedAppName = useSelector(selectSelectedAppName());
|
||||||
|
const notifications = useSelector(selectNotificationsByIds(selectedAppName));
|
||||||
|
const { currentPage, numPages } = useSelector(selectPaginationData());
|
||||||
|
const { today = [], earlier = [] } = useMemo(
|
||||||
|
() => splitNotificationsByTime(notifications),
|
||||||
|
[notifications],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMarkAllAsRead = useCallback(() => {
|
||||||
|
dispatch(markAllNotificationsAsRead(selectedAppName));
|
||||||
|
}, [dispatch, selectedAppName]);
|
||||||
|
|
||||||
|
const updatePagination = useCallback(() => {
|
||||||
|
dispatch(updatePaginationRequest());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
const renderNotificationSection = (section, items) => {
|
||||||
|
if (isEmpty(items)) { return null; }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="pb-2">
|
||||||
|
<div className="d-flex justify-content-between align-items-center py-10px mb-2">
|
||||||
|
<span className="text-gray-500 line-height-10">
|
||||||
|
{section === 'today' && intl.formatMessage(messages.notificationTodayHeading)}
|
||||||
|
{section === 'earlier' && intl.formatMessage(messages.notificationEarlierHeading)}
|
||||||
|
</span>
|
||||||
|
{notifications?.length > 0 && (section === 'earlier' ? today.length === 0 : true) && (
|
||||||
|
<Button
|
||||||
|
variant="link"
|
||||||
|
className="text-info-500 font-size-14 line-height-10 text-decoration-none p-0 border-0"
|
||||||
|
onClick={handleMarkAllAsRead}
|
||||||
|
>
|
||||||
|
{intl.formatMessage(messages.notificationMarkAsRead)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{items.map((notification) => (
|
||||||
|
<NotificationRowItem
|
||||||
|
key={notification.id}
|
||||||
|
id={notification.id}
|
||||||
|
type={notification.type}
|
||||||
|
contentUrl={notification.contentUrl}
|
||||||
|
content={notification.content}
|
||||||
|
courseName={notification.courseName}
|
||||||
|
createdAt={notification.createdAt}
|
||||||
|
lastRead={notification.lastRead}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-4 px-4">
|
||||||
|
{renderNotificationSection('today', today)}
|
||||||
|
{renderNotificationSection('earlier', earlier)}
|
||||||
|
{currentPage < numPages && (
|
||||||
|
<Button variant="primary" className="w-100 bg-primary-500" onClick={updatePagination}>
|
||||||
|
{intl.formatMessage(messages.loadMoreNotifications)}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(NotificationSections);
|
||||||
52
src/Notifications/NotificationTabs.jsx
Normal file
52
src/Notifications/NotificationTabs.jsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
import React, { useCallback, useEffect, useMemo } from 'react';
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
import { Tab, Tabs } from '@edx/paragon';
|
||||||
|
import NotificationSections from './NotificationSections';
|
||||||
|
import { fetchNotificationList, markNotificationsAsSeen } from './data/thunks';
|
||||||
|
import {
|
||||||
|
selectNotificationTabs, selectNotificationTabsCount, selectPaginationData, selectSelectedAppName,
|
||||||
|
} from './data/selectors';
|
||||||
|
import { updateAppNameRequest } from './data/slice';
|
||||||
|
|
||||||
|
const NotificationTabs = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const selectedAppName = useSelector(selectSelectedAppName());
|
||||||
|
const notificationUnseenCounts = useSelector(selectNotificationTabsCount());
|
||||||
|
const notificationTabs = useSelector(selectNotificationTabs());
|
||||||
|
const { currentPage } = useSelector(selectPaginationData());
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchNotificationList({ appName: selectedAppName, page: currentPage, pageSize: 10 }));
|
||||||
|
if (selectedAppName) { dispatch(markNotificationsAsSeen(selectedAppName)); }
|
||||||
|
}, [currentPage, selectedAppName]);
|
||||||
|
|
||||||
|
const handleActiveTab = useCallback((appName) => {
|
||||||
|
dispatch(updateAppNameRequest({ appName }));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const tabArray = useMemo(() => notificationTabs?.map((appName) => (
|
||||||
|
<Tab
|
||||||
|
key={appName}
|
||||||
|
eventKey={appName}
|
||||||
|
title={appName}
|
||||||
|
notification={notificationUnseenCounts[appName]}
|
||||||
|
tabClassName="pt-0 pb-10px px-2.5 d-flex border-top-0 mb-0 align-items-center line-height-24 text-capitalize"
|
||||||
|
>
|
||||||
|
{appName === selectedAppName && (<NotificationSections />)}
|
||||||
|
</Tab>
|
||||||
|
)), [notificationUnseenCounts, selectedAppName, notificationTabs]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs
|
||||||
|
variant="tabs"
|
||||||
|
defaultActiveKey={selectedAppName}
|
||||||
|
onSelect={handleActiveTab}
|
||||||
|
className="px-2.5 text-primary-500"
|
||||||
|
>
|
||||||
|
{tabArray}
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.memo(NotificationTabs);
|
||||||
1
src/Notifications/data/__factories__/index.js
Normal file
1
src/Notifications/data/__factories__/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import './notifications.factory';
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Factory } from 'rosie';
|
||||||
|
|
||||||
|
Factory.define('notificationsCount')
|
||||||
|
.attr('count', 45)
|
||||||
|
.attr('countByAppName', {
|
||||||
|
reminders: 10,
|
||||||
|
discussions: 20,
|
||||||
|
grades: 10,
|
||||||
|
authoring: 5,
|
||||||
|
})
|
||||||
|
.attr('showNotificationsTray', true);
|
||||||
|
|
||||||
|
Factory.define('notification')
|
||||||
|
.sequence('id')
|
||||||
|
.attr('type', 'post')
|
||||||
|
.sequence('content', ['id'], (idx, notificationId) => `<p><b>User ${idx}</b> posts <b>Hello and welcome to SC0x
|
||||||
|
${notificationId}!</b></p>`)
|
||||||
|
.attr('course_name', 'Supply Chain Analytics')
|
||||||
|
.sequence('content_url', (idx) => `https://example.com/${idx}`)
|
||||||
|
.attr('last_read', null)
|
||||||
|
.attr('last_seen', null)
|
||||||
|
.sequence('created_at', ['createdDate'], (idx, date) => date);
|
||||||
44
src/Notifications/data/api.js
Normal file
44
src/Notifications/data/api.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { getConfig, snakeCaseObject } from '@edx/frontend-platform';
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
|
||||||
|
export const getNotificationsCountApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/count/`;
|
||||||
|
export const getNotificationsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/`;
|
||||||
|
export const markNotificationsSeenApiUrl = (appName) => `${getConfig().LMS_BASE_URL}/api/notifications/mark-notifications-unseen/${appName}/`;
|
||||||
|
export const markNotificationAsReadApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/read/`;
|
||||||
|
|
||||||
|
export async function getNotifications(appName, page, pageSize) {
|
||||||
|
const params = snakeCaseObject({ page, pageSize });
|
||||||
|
const { data } = await getAuthenticatedHttpClient().get(getNotificationsApiUrl(), { params });
|
||||||
|
|
||||||
|
const startIndex = (page - 1) * pageSize;
|
||||||
|
const endIndex = startIndex + pageSize;
|
||||||
|
|
||||||
|
const notifications = data.slice(startIndex, endIndex);
|
||||||
|
return { notifications, numPages: 2, currentPage: page };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getNotificationCounts() {
|
||||||
|
const { data } = await getAuthenticatedHttpClient().get(getNotificationsCountApiUrl());
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function markNotificationSeen(appName) {
|
||||||
|
const { data } = await getAuthenticatedHttpClient().put(`${markNotificationsSeenApiUrl(appName)}`);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function markAllNotificationRead(appName) {
|
||||||
|
const params = snakeCaseObject({ appName });
|
||||||
|
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function markNotificationRead(notificationId) {
|
||||||
|
const params = snakeCaseObject({ notificationId });
|
||||||
|
const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params });
|
||||||
|
|
||||||
|
return { data, id: notificationId };
|
||||||
|
}
|
||||||
150
src/Notifications/data/api.test.js
Normal file
150
src/Notifications/data/api.test.js
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
import { Factory } from 'rosie';
|
||||||
|
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
import { initializeMockApp } from '@edx/frontend-platform/testing';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getNotificationsApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
|
||||||
|
getNotificationCounts, getNotifications, markNotificationSeen, markAllNotificationRead, markNotificationRead,
|
||||||
|
} from './api';
|
||||||
|
|
||||||
|
import './__factories__';
|
||||||
|
|
||||||
|
const notificationCountsApiUrl = getNotificationsCountApiUrl();
|
||||||
|
const notificationsApiUrl = getNotificationsApiUrl();
|
||||||
|
const markedAllNotificationsAsSeenApiUrl = markNotificationsSeenApiUrl('discussions');
|
||||||
|
const markedAllNotificationsAsReadApiUrl = markNotificationAsReadApiUrl();
|
||||||
|
|
||||||
|
let axiosMock = null;
|
||||||
|
|
||||||
|
describe('Notifications API', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
initializeMockApp({
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: '123abc',
|
||||||
|
username: 'testuser',
|
||||||
|
administrator: false,
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||||
|
Factory.resetAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
axiosMock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully get notification counts for different tabs.', async () => {
|
||||||
|
axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
|
||||||
|
|
||||||
|
const { count, countByAppName } = await getNotificationCounts();
|
||||||
|
|
||||||
|
expect(count).toEqual(45);
|
||||||
|
expect(countByAppName.reminders).toEqual(10);
|
||||||
|
expect(countByAppName.discussions).toEqual(20);
|
||||||
|
expect(countByAppName.grades).toEqual(10);
|
||||||
|
expect(countByAppName.authoring).toEqual(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, message: 'Failed to get notification counts.' },
|
||||||
|
{ statusCode: 403, message: 'Denied to get notification counts.' },
|
||||||
|
])('%s for notification counts API.', async ({ statusCode, message }) => {
|
||||||
|
axiosMock.onGet(notificationCountsApiUrl).reply(statusCode, { message });
|
||||||
|
try {
|
||||||
|
await getNotificationCounts();
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.response.status).toEqual(statusCode);
|
||||||
|
expect(error.response.data.message).toEqual(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully get notifications.', async () => {
|
||||||
|
axiosMock.onGet(notificationsApiUrl).reply(
|
||||||
|
200,
|
||||||
|
(Factory.buildList('notification', 2, null, { createdDate: new Date().toISOString() })),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { notifications } = await getNotifications('discussions', 1, 10);
|
||||||
|
|
||||||
|
expect(notifications).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, message: 'Failed to get notifications.' },
|
||||||
|
{ statusCode: 403, message: 'Denied to get notifications.' },
|
||||||
|
])('%s for notification API.', async ({ statusCode, message }) => {
|
||||||
|
axiosMock.onGet(notificationsApiUrl).reply(statusCode, { message });
|
||||||
|
try {
|
||||||
|
await getNotifications({ page: 1, pageSize: 10 });
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.response.status).toEqual(statusCode);
|
||||||
|
expect(error.response.data.message).toEqual(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked all notifications as seen for selected app.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(200, { message: 'Notifications marked seen.' });
|
||||||
|
|
||||||
|
const { message } = await markNotificationSeen('discussions');
|
||||||
|
|
||||||
|
expect(message).toEqual('Notifications marked seen.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, message: 'Failed to mark all notifications as seen for selected app.' },
|
||||||
|
{ statusCode: 403, message: 'Denied to mark all notifications as seen for selected app.' },
|
||||||
|
])('%s for notification mark as seen API.', async ({ statusCode, message }) => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(statusCode, { message });
|
||||||
|
try {
|
||||||
|
await markNotificationSeen('discussions');
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.response.status).toEqual(statusCode);
|
||||||
|
expect(error.response.data.message).toEqual(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked all notifications as read for selected app.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200, { message: 'Notifications marked read.' });
|
||||||
|
|
||||||
|
const { message } = await markAllNotificationRead('discussions');
|
||||||
|
|
||||||
|
expect(message).toEqual('Notifications marked read.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, message: 'Failed to mark all notifications as read for selected app.' },
|
||||||
|
{ statusCode: 403, message: 'Denied to mark all notifications as read for selected app.' },
|
||||||
|
])('%s for notification mark all as read API.', async ({ statusCode, message }) => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(statusCode, { message });
|
||||||
|
try {
|
||||||
|
await markAllNotificationRead('discussions');
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.response.status).toEqual(statusCode);
|
||||||
|
expect(error.response.data.message).toEqual(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked notification as read.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200, { message: 'Notification marked read.' });
|
||||||
|
|
||||||
|
const { data } = await markNotificationRead(1);
|
||||||
|
|
||||||
|
expect(data.message).toEqual('Notification marked read.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, message: 'Failed to mark notification as read.' },
|
||||||
|
{ statusCode: 403, message: 'Denied to mark notification as read.' },
|
||||||
|
])('%s for notification mark as read API.', async ({ statusCode, message }) => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(statusCode, { message });
|
||||||
|
try {
|
||||||
|
await markAllNotificationRead(1);
|
||||||
|
} catch (error) {
|
||||||
|
expect(error.response.status).toEqual(statusCode);
|
||||||
|
expect(error.response.data.message).toEqual(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
11
src/Notifications/data/hook.js
Normal file
11
src/Notifications/data/hook.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { breakpoints, useWindowSize } from '@edx/paragon';
|
||||||
|
|
||||||
|
export function useIsOnMediumScreen() {
|
||||||
|
const windowSize = useWindowSize();
|
||||||
|
return breakpoints.large.maxWidth > windowSize.width && windowSize.width >= breakpoints.medium.minWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useIsOnLargeScreen() {
|
||||||
|
const windowSize = useWindowSize();
|
||||||
|
return windowSize.width >= breakpoints.extraLarge.minWidth;
|
||||||
|
}
|
||||||
1
src/Notifications/data/index.js
Normal file
1
src/Notifications/data/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './slice';
|
||||||
134
src/Notifications/data/notifications.json
Normal file
134
src/Notifications/data/notifications.json
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"type": "post",
|
||||||
|
"content": "<p><b>SCM_Lead</b> posts <b>Hello and welcome to SC0x!</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:46:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"type": "help",
|
||||||
|
"content": "<p><b>MITx_Learner</b> asked <b>What grade does a student need to get in order to pass the course and earn a certificate?</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"type": "post",
|
||||||
|
"content": "<p><b>SCM_Lead</b> posts <b>Hello and welcome to SC0x!</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:46:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"type": "respond",
|
||||||
|
"content": "<p><b>MITx_Learner</b> responded <b>Can't find linear regression in section 3 review</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"type": "comment",
|
||||||
|
"content": "<p><b>MITx_Learner</b> commented on <b>MITx_Expert's</b> response on a post your following <b>Can't find linear regression in section 3 review</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"type": "question",
|
||||||
|
"content": "<p><b>MITx_Learner</b> commented <b>Examples of quadratic equations in supply chains</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"type": "answer",
|
||||||
|
"content": "<p><b>MITx_Expert</b> answered <b>Examples of quadratic equations in supply chains</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-05T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"type": "comment",
|
||||||
|
"content": "<p><b>MITx_Learner</b> commented <b>Examples of quadratic equations in supply chains</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"type": "comment",
|
||||||
|
"content": "<p><b>MITx_Learner</b> commented on <b>MITx_Expert's</b>what grade does a student need to get in order to pass the course and earn a certificate?</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"type": "comment",
|
||||||
|
"content": "<p><b>MITx_Learner</b> commented on your response in <b>Convexity of f(x)=1/x , x>1</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"type": "answer",
|
||||||
|
"content": "<p><b>SCM_Lead’s</b> response has been marked as answer in your post <b>Quiz in section 3 - Please explain the F-Significance value</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 12,
|
||||||
|
"type": "endorsed",
|
||||||
|
"content": "<p>Your response has been endorsed in <b>Quiz in section 3 - Please explain the F-Significance value</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 13,
|
||||||
|
"type": "reported",
|
||||||
|
"content": "<p><b>MITx Learner’s</b> post has been reported <b>“Here are the exam answers. Question 1 - CSA stands for Compliance Safety Ac...”</b></p>",
|
||||||
|
"course_name": "Supply Chain Analytics",
|
||||||
|
"content_url": "",
|
||||||
|
"last_read": null,
|
||||||
|
"last_seen": null,
|
||||||
|
"created_at": "2023-06-01T00:36:11.979531Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
164
src/Notifications/data/redux.test.js
Normal file
164
src/Notifications/data/redux.test.js
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
import { Factory } from 'rosie';
|
||||||
|
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
import { initializeMockApp } from '@edx/frontend-platform/testing';
|
||||||
|
|
||||||
|
import { initializeStore } from '../../store';
|
||||||
|
import executeThunk from '../../test-utils';
|
||||||
|
import {
|
||||||
|
getNotificationsApiUrl, getNotificationsCountApiUrl, markNotificationAsReadApiUrl, markNotificationsSeenApiUrl,
|
||||||
|
} from './api';
|
||||||
|
import {
|
||||||
|
fetchAppsNotificationCount, fetchNotificationList, markNotificationsAsRead, markAllNotificationsAsRead,
|
||||||
|
resetNotificationState, markNotificationsAsSeen,
|
||||||
|
} from './thunks';
|
||||||
|
|
||||||
|
import './__factories__';
|
||||||
|
|
||||||
|
const notificationCountsApiUrl = getNotificationsCountApiUrl();
|
||||||
|
const notificationsApiUrl = getNotificationsApiUrl();
|
||||||
|
const markedAllNotificationsAsReadApiUrl = markNotificationAsReadApiUrl();
|
||||||
|
const markedAllNotificationsAsSeenApiUrl = markNotificationsSeenApiUrl('discussions');
|
||||||
|
|
||||||
|
let axiosMock;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
describe('Notification Redux', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
initializeMockApp({
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: '123abc',
|
||||||
|
username: 'testuser',
|
||||||
|
administrator: false,
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||||
|
Factory.resetAll();
|
||||||
|
store = initializeStore();
|
||||||
|
|
||||||
|
axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
|
||||||
|
axiosMock.onGet(notificationsApiUrl).reply(
|
||||||
|
200,
|
||||||
|
(Factory.buildList('notification', 2, null, { createdDate: new Date().toISOString() })),
|
||||||
|
);
|
||||||
|
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
|
||||||
|
await executeThunk(fetchNotificationList({ page: 1, pageSize: 10 }), store.dispatch, store.getState);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
axiosMock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully loaded initial notification states in the redux.', async () => {
|
||||||
|
executeThunk(resetNotificationState(), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications } = store.getState();
|
||||||
|
|
||||||
|
expect(notifications.notificationStatus).toEqual('idle');
|
||||||
|
expect(notifications.appName).toEqual('discussions');
|
||||||
|
expect(notifications.appsId).toHaveLength(0);
|
||||||
|
expect(notifications.apps).toEqual({});
|
||||||
|
expect(notifications.notifications).toEqual({});
|
||||||
|
expect(notifications.tabsCount).toEqual({});
|
||||||
|
expect(notifications.showNotificationsTray).toEqual(false);
|
||||||
|
expect(notifications.pagination.count).toEqual(10);
|
||||||
|
expect(notifications.pagination.numPages).toEqual(1);
|
||||||
|
expect(notifications.pagination.currentPage).toEqual(1);
|
||||||
|
expect(notifications.pagination.nextPage).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully loaded notifications list in the redux.', async () => {
|
||||||
|
const { notifications: { notifications } } = store.getState();
|
||||||
|
|
||||||
|
expect(Object.keys(notifications)).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, status: 'failed' },
|
||||||
|
{ statusCode: 403, status: 'denied' },
|
||||||
|
])('%s to load notifications list in the redux.', async ({ statusCode, status }) => {
|
||||||
|
axiosMock.onGet(notificationsApiUrl).reply(statusCode);
|
||||||
|
await executeThunk(fetchNotificationList({ page: 1, pageSize: 10 }), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus } } = store.getState();
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully loaded notification counts in the redux.', async () => {
|
||||||
|
const { notifications: { tabsCount } } = store.getState();
|
||||||
|
|
||||||
|
expect(tabsCount.count).toEqual(25);
|
||||||
|
expect(tabsCount.reminders).toEqual(10);
|
||||||
|
expect(tabsCount.discussions).toEqual(0);
|
||||||
|
expect(tabsCount.grades).toEqual(10);
|
||||||
|
expect(tabsCount.authoring).toEqual(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, status: 'failed' },
|
||||||
|
{ statusCode: 403, status: 'denied' },
|
||||||
|
])('%s to load notification counts in the redux.', async ({ statusCode, status }) => {
|
||||||
|
axiosMock.onGet(notificationCountsApiUrl).reply(statusCode);
|
||||||
|
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus } } = store.getState();
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked all notifications as seen for selected app.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(200);
|
||||||
|
await executeThunk(markNotificationsAsSeen('discussions'), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
expect(store.getState().notifications.notificationStatus).toEqual('successful');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, status: 'failed' },
|
||||||
|
{ statusCode: 403, status: 'denied' },
|
||||||
|
])('%s to mark all notifications as seen for selected app.', async ({ statusCode, status }) => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsSeenApiUrl).reply(statusCode);
|
||||||
|
await executeThunk(markNotificationsAsSeen('discussions'), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus } } = store.getState();
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual(status);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked all notifications as read for selected app in the redux.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200);
|
||||||
|
await executeThunk(markAllNotificationsAsRead('discussions'), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus, notifications } } = store.getState();
|
||||||
|
const firstNotification = Object.values(notifications)[0];
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual('successful');
|
||||||
|
expect(firstNotification.lastRead).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Successfully marked notification as read in the redux.', async () => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(200);
|
||||||
|
await executeThunk(markNotificationsAsRead(1), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus, notifications } } = store.getState();
|
||||||
|
const firstNotification = Object.values(notifications)[0];
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual('successful');
|
||||||
|
expect(firstNotification.lastRead).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{ statusCode: 404, status: 'failed' },
|
||||||
|
{ statusCode: 403, status: 'denied' },
|
||||||
|
])('%s to marked notification as read in the redux.', async ({ statusCode, status }) => {
|
||||||
|
axiosMock.onPut(markedAllNotificationsAsReadApiUrl).reply(statusCode);
|
||||||
|
await executeThunk(markNotificationsAsRead(1), store.dispatch, store.getState);
|
||||||
|
|
||||||
|
const { notifications: { notificationStatus } } = store.getState();
|
||||||
|
|
||||||
|
expect(notificationStatus).toEqual(status);
|
||||||
|
});
|
||||||
|
});
|
||||||
126
src/Notifications/data/selector.test.jsx
Normal file
126
src/Notifications/data/selector.test.jsx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
import { Factory } from 'rosie';
|
||||||
|
|
||||||
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||||
|
import { initializeMockApp } from '@edx/frontend-platform/testing';
|
||||||
|
|
||||||
|
import { initializeStore } from '../../store';
|
||||||
|
import executeThunk from '../../test-utils';
|
||||||
|
import { getNotificationsApiUrl, getNotificationsCountApiUrl } from './api';
|
||||||
|
import {
|
||||||
|
selectNotifications,
|
||||||
|
selectNotificationsByIds,
|
||||||
|
selectNotificationStatus,
|
||||||
|
selectNotificationTabs,
|
||||||
|
selectNotificationTabsCount,
|
||||||
|
selectPaginationData,
|
||||||
|
selectSelectedAppName,
|
||||||
|
selectSelectedAppNotificationIds,
|
||||||
|
selectShowNotificationTray,
|
||||||
|
} from './selectors';
|
||||||
|
import { fetchAppsNotificationCount, fetchNotificationList } from './thunks';
|
||||||
|
|
||||||
|
import './__factories__';
|
||||||
|
|
||||||
|
const notificationCountsApiUrl = getNotificationsCountApiUrl();
|
||||||
|
const notificationsApiUrl = getNotificationsApiUrl();
|
||||||
|
|
||||||
|
let axiosMock;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
describe('Notification Selectors', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
initializeMockApp({
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: '123abc',
|
||||||
|
username: 'testuser',
|
||||||
|
administrator: false,
|
||||||
|
roles: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||||
|
Factory.resetAll();
|
||||||
|
store = initializeStore();
|
||||||
|
|
||||||
|
axiosMock.onGet(notificationCountsApiUrl).reply(200, (Factory.build('notificationsCount')));
|
||||||
|
axiosMock.onGet(notificationsApiUrl).reply(
|
||||||
|
200,
|
||||||
|
(Factory.buildList('notification', 2, null, { createdDate: new Date().toISOString() })),
|
||||||
|
);
|
||||||
|
await executeThunk(fetchAppsNotificationCount(), store.dispatch, store.getState);
|
||||||
|
await executeThunk(fetchNotificationList({ page: 1, pageSize: 10 }), store.dispatch, store.getState);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
axiosMock.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return notification status.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const status = selectNotificationStatus()(state);
|
||||||
|
|
||||||
|
expect(status).toEqual('successful');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return notification tabs count.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const tabsCount = selectNotificationTabsCount()(state);
|
||||||
|
|
||||||
|
expect(tabsCount.count).toEqual(25);
|
||||||
|
expect(tabsCount.reminders).toEqual(10);
|
||||||
|
expect(tabsCount.discussions).toEqual(0);
|
||||||
|
expect(tabsCount.grades).toEqual(10);
|
||||||
|
expect(tabsCount.authoring).toEqual(5);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return notification tabs.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const tabs = selectNotificationTabs()(state);
|
||||||
|
|
||||||
|
expect(tabs).toHaveLength(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return selected app notification ids.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const notificationIds = selectSelectedAppNotificationIds('discussions')(state);
|
||||||
|
|
||||||
|
expect(notificationIds).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return show notification tray status.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const showNotificationTrayStatus = selectShowNotificationTray()(state);
|
||||||
|
|
||||||
|
expect(showNotificationTrayStatus).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return notifications.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const notifications = selectNotifications()(state);
|
||||||
|
|
||||||
|
expect(Object.keys(notifications)).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return notifications from Ids.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const notifications = selectNotificationsByIds('discussions')(state);
|
||||||
|
|
||||||
|
expect(notifications).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return selected app name.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const appName = selectSelectedAppName()(state);
|
||||||
|
|
||||||
|
expect(appName).toEqual('discussions');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return pagination data.', async () => {
|
||||||
|
const state = store.getState();
|
||||||
|
const paginationData = selectPaginationData()(state);
|
||||||
|
|
||||||
|
expect(paginationData.count).toEqual(10);
|
||||||
|
expect(paginationData.currentPage).toEqual(1);
|
||||||
|
expect(paginationData.numPages).toEqual(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
23
src/Notifications/data/selectors.js
Normal file
23
src/Notifications/data/selectors.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
export const selectNotificationStatus = () => state => state.notifications.notificationStatus;
|
||||||
|
|
||||||
|
export const selectNotificationTabsCount = () => state => state.notifications.tabsCount;
|
||||||
|
|
||||||
|
export const selectNotificationTabs = () => state => state.notifications.appsId;
|
||||||
|
|
||||||
|
export const selectSelectedAppNotificationIds = (appName) => state => state.notifications.apps[appName] ?? [];
|
||||||
|
|
||||||
|
export const selectShowNotificationTray = () => state => state.notifications.showNotificationsTray;
|
||||||
|
|
||||||
|
export const selectNotifications = () => state => state.notifications.notifications;
|
||||||
|
|
||||||
|
export const selectNotificationsByIds = (appName) => createSelector(
|
||||||
|
selectNotifications(),
|
||||||
|
selectSelectedAppNotificationIds(appName),
|
||||||
|
(notifications, notificationIds) => notificationIds.map((notificationId) => notifications[notificationId]) || [],
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectSelectedAppName = () => state => state.notifications.appName;
|
||||||
|
|
||||||
|
export const selectPaginationData = () => state => state.notifications.pagination;
|
||||||
154
src/Notifications/data/slice.js
Normal file
154
src/Notifications/data/slice.js
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
/* eslint-disable no-param-reassign */
|
||||||
|
import { createSlice } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
export const RequestStatus = {
|
||||||
|
IDLE: 'idle',
|
||||||
|
LOADING: 'in-progress',
|
||||||
|
LOADED: 'successful',
|
||||||
|
FAILED: 'failed',
|
||||||
|
DENIED: 'denied',
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
notificationStatus: 'idle',
|
||||||
|
appName: 'discussions',
|
||||||
|
appsId: [],
|
||||||
|
apps: {},
|
||||||
|
notifications: {},
|
||||||
|
tabsCount: {},
|
||||||
|
showNotificationsTray: false,
|
||||||
|
pagination: {
|
||||||
|
count: 10,
|
||||||
|
numPages: 1,
|
||||||
|
currentPage: 1,
|
||||||
|
nextPage: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const slice = createSlice({
|
||||||
|
name: 'notifications',
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
fetchNotificationDenied: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.DENIED;
|
||||||
|
},
|
||||||
|
fetchNotificationFailure: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.FAILED;
|
||||||
|
},
|
||||||
|
fetchNotificationRequest: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADING;
|
||||||
|
},
|
||||||
|
fetchNotificationSuccess: (state, { payload }) => {
|
||||||
|
const {
|
||||||
|
newNotificationIds, notificationsKeyValuePair, numPages, currentPage,
|
||||||
|
} = payload;
|
||||||
|
const existingNotificationIds = state.apps[state.appName];
|
||||||
|
|
||||||
|
state.apps[state.appName] = Array.from(new Set([...existingNotificationIds, ...newNotificationIds]));
|
||||||
|
state.notifications = { ...state.notifications, ...notificationsKeyValuePair };
|
||||||
|
state.tabsCount.count -= state.tabsCount[state.appName];
|
||||||
|
state.tabsCount[state.appName] = 0;
|
||||||
|
state.notificationStatus = RequestStatus.LOADED;
|
||||||
|
state.pagination.numPages = numPages;
|
||||||
|
state.pagination.currentPage = currentPage;
|
||||||
|
},
|
||||||
|
fetchNotificationsCountDenied: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.DENIED;
|
||||||
|
},
|
||||||
|
fetchNotificationsCountFailure: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.FAILED;
|
||||||
|
},
|
||||||
|
fetchNotificationsCountRequest: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADING;
|
||||||
|
},
|
||||||
|
fetchNotificationsCountSuccess: (state, { payload }) => {
|
||||||
|
const {
|
||||||
|
countByAppName, appIds, apps, count, showNotificationsTray,
|
||||||
|
} = payload;
|
||||||
|
state.tabsCount = { count, ...countByAppName };
|
||||||
|
state.appsId = appIds;
|
||||||
|
state.apps = apps;
|
||||||
|
state.showNotificationsTray = showNotificationsTray;
|
||||||
|
state.notificationStatus = RequestStatus.LOADED;
|
||||||
|
},
|
||||||
|
markNotificationsAsSeenRequest: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADING;
|
||||||
|
},
|
||||||
|
markNotificationsAsSeenSuccess: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADED;
|
||||||
|
},
|
||||||
|
markNotificationsAsSeenDenied: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.DENIED;
|
||||||
|
},
|
||||||
|
markNotificationsAsSeenFailure: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.FAILED;
|
||||||
|
},
|
||||||
|
markAllNotificationsAsReadRequest: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADING;
|
||||||
|
},
|
||||||
|
markAllNotificationsAsReadSuccess: (state) => {
|
||||||
|
const updatedNotifications = Object.fromEntries(
|
||||||
|
Object.entries(state.notifications).map(([key, notification]) => [
|
||||||
|
key, { ...notification, lastRead: new Date().toISOString() },
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
state.notifications = updatedNotifications;
|
||||||
|
state.notificationStatus = RequestStatus.LOADED;
|
||||||
|
},
|
||||||
|
markAllNotificationsAsReadDenied: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.DENIED;
|
||||||
|
},
|
||||||
|
markAllNotificationsAsReadFailure: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.FAILED;
|
||||||
|
},
|
||||||
|
markNotificationsAsReadRequest: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.LOADING;
|
||||||
|
},
|
||||||
|
markNotificationsAsReadSuccess: (state, { payload }) => {
|
||||||
|
const date = new Date().toISOString();
|
||||||
|
state.notifications[payload.id] = { ...state.notifications[payload.id], lastRead: date };
|
||||||
|
state.notificationStatus = RequestStatus.LOADED;
|
||||||
|
},
|
||||||
|
markNotificationsAsReadDenied: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.DENIED;
|
||||||
|
},
|
||||||
|
markNotificationsAsReadFailure: (state) => {
|
||||||
|
state.notificationStatus = RequestStatus.FAILED;
|
||||||
|
},
|
||||||
|
resetNotificationStateRequest: () => initialState,
|
||||||
|
updateAppNameRequest: (state, { payload }) => {
|
||||||
|
state.appName = payload.appName;
|
||||||
|
state.pagination.currentPage = 1;
|
||||||
|
},
|
||||||
|
updatePaginationRequest: (state) => {
|
||||||
|
state.pagination.currentPage += 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const {
|
||||||
|
fetchNotificationDenied,
|
||||||
|
fetchNotificationFailure,
|
||||||
|
fetchNotificationRequest,
|
||||||
|
fetchNotificationSuccess,
|
||||||
|
fetchNotificationsCountDenied,
|
||||||
|
fetchNotificationsCountFailure,
|
||||||
|
fetchNotificationsCountRequest,
|
||||||
|
fetchNotificationsCountSuccess,
|
||||||
|
markNotificationsAsSeenRequest,
|
||||||
|
markNotificationsAsSeenSuccess,
|
||||||
|
markNotificationsAsSeenFailure,
|
||||||
|
markNotificationsAsSeenDenied,
|
||||||
|
markAllNotificationsAsReadDenied,
|
||||||
|
markAllNotificationsAsReadRequest,
|
||||||
|
markAllNotificationsAsReadSuccess,
|
||||||
|
markAllNotificationsAsReadFailure,
|
||||||
|
markNotificationsAsReadDenied,
|
||||||
|
markNotificationsAsReadRequest,
|
||||||
|
markNotificationsAsReadSuccess,
|
||||||
|
markNotificationsAsReadFailure,
|
||||||
|
resetNotificationStateRequest,
|
||||||
|
updateAppNameRequest,
|
||||||
|
updatePaginationRequest,
|
||||||
|
} = slice.actions;
|
||||||
|
|
||||||
|
export const notificationsReducer = slice.reducer;
|
||||||
130
src/Notifications/data/thunks.js
Normal file
130
src/Notifications/data/thunks.js
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import { camelCaseObject } from '@edx/frontend-platform';
|
||||||
|
import {
|
||||||
|
fetchNotificationSuccess,
|
||||||
|
fetchNotificationRequest,
|
||||||
|
fetchNotificationFailure,
|
||||||
|
fetchNotificationDenied,
|
||||||
|
fetchNotificationsCountFailure,
|
||||||
|
fetchNotificationsCountRequest,
|
||||||
|
fetchNotificationsCountSuccess,
|
||||||
|
fetchNotificationsCountDenied,
|
||||||
|
markNotificationsAsSeenRequest,
|
||||||
|
markNotificationsAsSeenSuccess,
|
||||||
|
markNotificationsAsSeenFailure,
|
||||||
|
markNotificationsAsSeenDenied,
|
||||||
|
markNotificationsAsReadDenied,
|
||||||
|
resetNotificationStateRequest,
|
||||||
|
markAllNotificationsAsReadRequest,
|
||||||
|
markAllNotificationsAsReadSuccess,
|
||||||
|
markAllNotificationsAsReadFailure,
|
||||||
|
markAllNotificationsAsReadDenied,
|
||||||
|
markNotificationsAsReadRequest,
|
||||||
|
markNotificationsAsReadSuccess,
|
||||||
|
markNotificationsAsReadFailure,
|
||||||
|
} from './slice';
|
||||||
|
import {
|
||||||
|
getNotifications, getNotificationCounts, markNotificationSeen, markAllNotificationRead, markNotificationRead,
|
||||||
|
} from './api';
|
||||||
|
import { getHttpErrorStatus } from '../utils';
|
||||||
|
|
||||||
|
const normalizeNotificationCounts = ({ countByAppName, count, showNotificationsTray }) => {
|
||||||
|
const appIds = Object.keys(countByAppName);
|
||||||
|
const apps = appIds.reduce((acc, appId) => { acc[appId] = []; return acc; }, {});
|
||||||
|
return {
|
||||||
|
countByAppName, appIds, apps, count, showNotificationsTray,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const normalizeNotifications = ({ notifications }) => {
|
||||||
|
const newNotificationIds = notifications.map(notification => notification.id.toString());
|
||||||
|
const notificationsKeyValuePair = notifications.reduce((acc, obj) => { acc[obj.id] = obj; return acc; }, {});
|
||||||
|
return {
|
||||||
|
newNotificationIds, notificationsKeyValuePair,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchNotificationList = ({ appName, page, pageSize }) => (
|
||||||
|
async (dispatch) => {
|
||||||
|
try {
|
||||||
|
dispatch(fetchNotificationRequest({ appName }));
|
||||||
|
const data = await getNotifications(appName, page, pageSize);
|
||||||
|
const normalisedData = normalizeNotifications((camelCaseObject(data)));
|
||||||
|
dispatch(fetchNotificationSuccess({ ...normalisedData, numPages: data.numPages, currentPage: data.currentPage }));
|
||||||
|
} catch (error) {
|
||||||
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
dispatch(fetchNotificationDenied(appName));
|
||||||
|
} else {
|
||||||
|
dispatch(fetchNotificationFailure(appName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const fetchAppsNotificationCount = () => (
|
||||||
|
async (dispatch) => {
|
||||||
|
try {
|
||||||
|
dispatch(fetchNotificationsCountRequest());
|
||||||
|
const data = await getNotificationCounts();
|
||||||
|
const normalisedData = normalizeNotificationCounts((camelCaseObject(data)));
|
||||||
|
dispatch(fetchNotificationsCountSuccess({ ...normalisedData }));
|
||||||
|
} catch (error) {
|
||||||
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
dispatch(fetchNotificationsCountDenied());
|
||||||
|
} else {
|
||||||
|
dispatch(fetchNotificationsCountFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const markAllNotificationsAsRead = (appName) => (
|
||||||
|
async (dispatch) => {
|
||||||
|
try {
|
||||||
|
dispatch(markAllNotificationsAsReadRequest({ appName }));
|
||||||
|
const data = await markAllNotificationRead(appName);
|
||||||
|
dispatch(markAllNotificationsAsReadSuccess(camelCaseObject(data)));
|
||||||
|
} catch (error) {
|
||||||
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
dispatch(markAllNotificationsAsReadDenied());
|
||||||
|
} else {
|
||||||
|
dispatch(markAllNotificationsAsReadFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const markNotificationsAsRead = (notificationId) => (
|
||||||
|
async (dispatch) => {
|
||||||
|
try {
|
||||||
|
dispatch(markNotificationsAsReadRequest({ notificationId }));
|
||||||
|
const data = await markNotificationRead(notificationId);
|
||||||
|
dispatch(markNotificationsAsReadSuccess(camelCaseObject(data)));
|
||||||
|
} catch (error) {
|
||||||
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
dispatch(markNotificationsAsReadDenied());
|
||||||
|
} else {
|
||||||
|
dispatch(markNotificationsAsReadFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const markNotificationsAsSeen = (appName) => (
|
||||||
|
async (dispatch) => {
|
||||||
|
try {
|
||||||
|
dispatch(markNotificationsAsSeenRequest({ appName }));
|
||||||
|
const data = await markNotificationSeen(appName);
|
||||||
|
dispatch(markNotificationsAsSeenSuccess(camelCaseObject(data)));
|
||||||
|
} catch (error) {
|
||||||
|
if (getHttpErrorStatus(error) === 403) {
|
||||||
|
dispatch(markNotificationsAsSeenDenied());
|
||||||
|
} else {
|
||||||
|
dispatch(markNotificationsAsSeenFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const resetNotificationState = () => (
|
||||||
|
async (dispatch) => { dispatch(resetNotificationStateRequest()); }
|
||||||
|
);
|
||||||
101
src/Notifications/index.jsx
Normal file
101
src/Notifications/index.jsx
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
|
import React, {
|
||||||
|
useCallback, useEffect, useRef, useState,
|
||||||
|
} from 'react';
|
||||||
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
|
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import {
|
||||||
|
Badge, Icon, IconButton, OverlayTrigger, Popover,
|
||||||
|
} from '@edx/paragon';
|
||||||
|
import { NotificationsNone, Settings } from '@edx/paragon/icons';
|
||||||
|
import { selectNotificationTabsCount } from './data/selectors';
|
||||||
|
import { resetNotificationState } from './data/thunks';
|
||||||
|
import { useIsOnLargeScreen, useIsOnMediumScreen } from './data/hook';
|
||||||
|
import NotificationTabs from './NotificationTabs';
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
|
const Notifications = () => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const popoverRef = useRef(null);
|
||||||
|
const buttonRef = useRef(null);
|
||||||
|
const [enableNotificationTray, setEnableNotificationTray] = useState(false);
|
||||||
|
const notificationCounts = useSelector(selectNotificationTabsCount());
|
||||||
|
const isOnMediumScreen = useIsOnMediumScreen();
|
||||||
|
const isOnLargeScreen = useIsOnLargeScreen();
|
||||||
|
|
||||||
|
const hideNotificationTray = useCallback(() => {
|
||||||
|
setEnableNotificationTray(prevState => !prevState);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleClickOutsideNotificationTray = useCallback((event) => {
|
||||||
|
if (!popoverRef.current?.contains(event.target) && !buttonRef.current?.contains(event.target)) {
|
||||||
|
setEnableNotificationTray(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.addEventListener('mousedown', handleClickOutsideNotificationTray);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutsideNotificationTray);
|
||||||
|
dispatch(resetNotificationState());
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<OverlayTrigger
|
||||||
|
trigger="click"
|
||||||
|
key="bottom"
|
||||||
|
placement="bottom"
|
||||||
|
id="notificationTray"
|
||||||
|
show={enableNotificationTray}
|
||||||
|
overlay={(
|
||||||
|
<Popover
|
||||||
|
id="notificationTray"
|
||||||
|
data-testid="notificationTray"
|
||||||
|
className={classNames('overflow-auto rounded-0 border-0', {
|
||||||
|
'w-100': !isOnMediumScreen && !isOnLargeScreen,
|
||||||
|
'medium-screen': isOnMediumScreen,
|
||||||
|
'large-screen': isOnLargeScreen,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div ref={popoverRef}>
|
||||||
|
<Popover.Title as="h2" className="d-flex justify-content-between p-0 m-4 border-0 text-primary-500 font-size-18 line-height-24">
|
||||||
|
{intl.formatMessage(messages.notificationTitle)}
|
||||||
|
<Icon src={Settings} className="icon-size-20" />
|
||||||
|
</Popover.Title>
|
||||||
|
<Popover.Content className="notification-content p-0">
|
||||||
|
<NotificationTabs />
|
||||||
|
</Popover.Content>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div ref={buttonRef}>
|
||||||
|
<IconButton
|
||||||
|
isActive={enableNotificationTray}
|
||||||
|
alt="notification bell icon"
|
||||||
|
onClick={hideNotificationTray}
|
||||||
|
src={NotificationsNone}
|
||||||
|
iconAs={Icon}
|
||||||
|
variant="light"
|
||||||
|
iconClassNames="text-primary-500"
|
||||||
|
className="ml-4 mr-1 my-3 notification-button"
|
||||||
|
/>
|
||||||
|
{notificationCounts?.count > 0 && (
|
||||||
|
<Badge
|
||||||
|
pill
|
||||||
|
variant="danger"
|
||||||
|
className="font-weight-normal px-1 notification-badge"
|
||||||
|
>
|
||||||
|
{notificationCounts.count}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</OverlayTrigger>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Notifications;
|
||||||
36
src/Notifications/messages.js
Normal file
36
src/Notifications/messages.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
notificationTitle: {
|
||||||
|
id: 'notification.title',
|
||||||
|
defaultMessage: 'Notifications',
|
||||||
|
description: 'Notifications',
|
||||||
|
},
|
||||||
|
notificationTodayHeading: {
|
||||||
|
id: 'notification.today.heading',
|
||||||
|
defaultMessage: 'Last 24 hours',
|
||||||
|
description: 'Today Notifications',
|
||||||
|
},
|
||||||
|
notificationEarlierHeading: {
|
||||||
|
id: 'notification.earlier.heading',
|
||||||
|
defaultMessage: 'Earlier',
|
||||||
|
description: 'Earlier Notifications',
|
||||||
|
},
|
||||||
|
notificationMarkAsRead: {
|
||||||
|
id: 'notification.mark.as.read',
|
||||||
|
defaultMessage: 'Mark all as read',
|
||||||
|
description: 'Mark all Notifications as read',
|
||||||
|
},
|
||||||
|
fullStop: {
|
||||||
|
id: 'notification.fullStop',
|
||||||
|
defaultMessage: '•',
|
||||||
|
description: 'Fullstop shown to users to indicate who edited a post.',
|
||||||
|
},
|
||||||
|
loadMoreNotifications: {
|
||||||
|
id: 'notification.load.more.notifications',
|
||||||
|
defaultMessage: 'Load more notifications',
|
||||||
|
description: 'Load more button to load more notifications',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default messages;
|
||||||
52
src/Notifications/utils.js
Normal file
52
src/Notifications/utils.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import {
|
||||||
|
CheckCircle, HelpOutline, QuestionAnswerOutline, Verified, Report, EditOutline, ThumbUpOutline, PostOutline,
|
||||||
|
} from '@edx/paragon/icons';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get HTTP Error status from generic error.
|
||||||
|
* @param error Generic caught error.
|
||||||
|
* @returns {number|null}
|
||||||
|
*/
|
||||||
|
export const getHttpErrorStatus = error => error?.customAttributes?.httpErrorStatus ?? error?.response?.status;
|
||||||
|
|
||||||
|
export const splitNotificationsByTime = (notificationList) => {
|
||||||
|
let splittedData = [];
|
||||||
|
if (notificationList.length > 0) {
|
||||||
|
const currentTime = Date.now();
|
||||||
|
const twentyFourHoursAgo = currentTime - (24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
splittedData = notificationList.reduce(
|
||||||
|
(result, notification) => {
|
||||||
|
if (notification) {
|
||||||
|
const objectTime = new Date(notification.createdAt).getTime();
|
||||||
|
if (objectTime >= twentyFourHoursAgo && objectTime <= currentTime) {
|
||||||
|
result.today.push(notification);
|
||||||
|
} else {
|
||||||
|
result.earlier.push(notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
{ today: [], earlier: [] },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { today, earlier } = splittedData;
|
||||||
|
return { today, earlier };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getIconByType = (type) => {
|
||||||
|
const iconMap = {
|
||||||
|
post: { icon: PostOutline, class: 'text-primary-500' },
|
||||||
|
help: { icon: HelpOutline, class: 'text-primary-500' },
|
||||||
|
respond: { icon: QuestionAnswerOutline, class: 'text-primary-500' },
|
||||||
|
comment: { icon: QuestionAnswerOutline, class: 'text-primary-500' },
|
||||||
|
question: { icon: QuestionAnswerOutline, class: 'text-primary-500' },
|
||||||
|
answer: { icon: CheckCircle, class: 'text-success' },
|
||||||
|
endorsed: { icon: Verified, class: 'text-primary-500' },
|
||||||
|
reported: { icon: Report, class: 'text-danger-500' },
|
||||||
|
postLiked: { icon: ThumbUpOutline, class: 'text-primary-500' },
|
||||||
|
commentLiked: { icon: ThumbUpOutline, class: 'text-primary-500' },
|
||||||
|
edited: { icon: EditOutline, class: 'text-primary-500' },
|
||||||
|
};
|
||||||
|
return iconMap[type] || { icon: PostOutline, class: 'text-primary-500' };
|
||||||
|
};
|
||||||
200
src/StudioHeader.jsx
Normal file
200
src/StudioHeader.jsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
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,
|
||||||
|
getConfig,
|
||||||
|
mergeConfig,
|
||||||
|
subscribe,
|
||||||
|
} from '@edx/frontend-platform';
|
||||||
|
import { ActionRow } from '@edx/paragon';
|
||||||
|
|
||||||
|
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||||
|
import Avatar from './Avatar';
|
||||||
|
import { LinkedLogo, Logo } from './Logo';
|
||||||
|
|
||||||
|
import { CaretIcon } from './Icons';
|
||||||
|
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
class StudioDesktopHeaderBase extends React.Component {
|
||||||
|
constructor(props) { // eslint-disable-line no-useless-constructor
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderUserMenu() {
|
||||||
|
const {
|
||||||
|
userMenu,
|
||||||
|
avatar,
|
||||||
|
username,
|
||||||
|
intl,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Menu transitionClassName="menu-dropdown" transitionTimeout={250}>
|
||||||
|
<MenuTrigger
|
||||||
|
tag="button"
|
||||||
|
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
|
||||||
|
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
|
>
|
||||||
|
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
|
||||||
|
{username} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||||
|
</MenuTrigger>
|
||||||
|
<MenuContent className="mb-0 dropdown-menu show dropdown-menu-right pin-right shadow py-2">
|
||||||
|
{userMenu.map(({ type, href, content }) => (
|
||||||
|
<a className={`dropdown-${type}`} key={`${type}-${content}`} href={href}>{content}</a>
|
||||||
|
))}
|
||||||
|
</MenuContent>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderLoggedOutItems() {
|
||||||
|
const { loggedOutItems } = this.props;
|
||||||
|
|
||||||
|
return loggedOutItems.map((item, i, arr) => (
|
||||||
|
<a
|
||||||
|
key={`${item.type}-${item.content}`}
|
||||||
|
className={i < arr.length - 1 ? 'btn mr-2 btn-link' : 'btn mr-2 btn-outline-primary'}
|
||||||
|
href={item.href}
|
||||||
|
>
|
||||||
|
{item.content}
|
||||||
|
</a>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
logo,
|
||||||
|
logoAltText,
|
||||||
|
logoDestination,
|
||||||
|
loggedIn,
|
||||||
|
intl,
|
||||||
|
actionRowContent,
|
||||||
|
} = this.props;
|
||||||
|
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||||
|
const logoClasses = getConfig().AUTHN_MINIMAL_HEADER ? 'mw-100' : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="site-header-desktop">
|
||||||
|
<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">
|
||||||
|
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
||||||
|
<ActionRow>
|
||||||
|
{actionRowContent}
|
||||||
|
<nav
|
||||||
|
aria-label={intl.formatMessage(messages['header.label.secondary.nav'])}
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
{loggedIn ? this.renderUserMenu() : this.renderLoggedOutItems()}
|
||||||
|
</nav>
|
||||||
|
</ActionRow>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StudioDesktopHeaderBase.propTypes = {
|
||||||
|
userMenu: PropTypes.arrayOf(PropTypes.shape({
|
||||||
|
type: PropTypes.oneOf(['item', 'menu']),
|
||||||
|
href: PropTypes.string,
|
||||||
|
content: PropTypes.string,
|
||||||
|
})),
|
||||||
|
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({
|
||||||
|
type: PropTypes.oneOf(['item', 'menu']),
|
||||||
|
href: PropTypes.string,
|
||||||
|
content: PropTypes.string,
|
||||||
|
})),
|
||||||
|
logo: PropTypes.string,
|
||||||
|
logoAltText: PropTypes.string,
|
||||||
|
logoDestination: PropTypes.string,
|
||||||
|
avatar: PropTypes.string,
|
||||||
|
username: PropTypes.string,
|
||||||
|
loggedIn: PropTypes.bool,
|
||||||
|
actionRowContent: PropTypes.element,
|
||||||
|
|
||||||
|
// i18n
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioDesktopHeaderBase.defaultProps = {
|
||||||
|
userMenu: [],
|
||||||
|
loggedOutItems: [],
|
||||||
|
logo: null,
|
||||||
|
logoAltText: null,
|
||||||
|
logoDestination: null,
|
||||||
|
avatar: null,
|
||||||
|
username: null,
|
||||||
|
loggedIn: false,
|
||||||
|
actionRowContent: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const StudioDesktopHeader = injectIntl(StudioDesktopHeaderBase);
|
||||||
|
|
||||||
|
const StudioHeader = ({ intl, actionRowContent }) => {
|
||||||
|
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,
|
||||||
|
actionRowContent,
|
||||||
|
userMenu,
|
||||||
|
loggedOutItems: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
return <StudioDesktopHeader {...props} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioHeader.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
|
actionRowContent: PropTypes.element,
|
||||||
|
};
|
||||||
|
|
||||||
|
StudioHeader.defaultProps = {
|
||||||
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
||||||
|
actionRowContent: <></>,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default injectIntl(StudioHeader);
|
||||||
108
src/StudioHeader.test.jsx
Normal file
108
src/StudioHeader.test.jsx
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
import TestRenderer from 'react-test-renderer';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
import {
|
||||||
|
ActionRow,
|
||||||
|
Button,
|
||||||
|
Dropdown,
|
||||||
|
} from '@edx/paragon';
|
||||||
|
|
||||||
|
import { StudioHeader } from './index';
|
||||||
|
|
||||||
|
const StudioHeaderComponent = ({ contextValue, appMenu = null, mainMenu = [] }) => (
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={contextValue}
|
||||||
|
>
|
||||||
|
<StudioHeader appMenu={appMenu} mainMenu={mainMenu} />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const StudioHeaderContext = ({ actionRowContent = null }) => {
|
||||||
|
const headerContextValue = useMemo(() => ({
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}), []);
|
||||||
|
return (
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={headerContextValue}
|
||||||
|
>
|
||||||
|
<StudioHeader actionRowContent={actionRowContent} />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('<StudioHeader />', () => {
|
||||||
|
it('renders correctly', () => {
|
||||||
|
const contextValue = {
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const component = <StudioHeaderComponent contextValue={contextValue} />;
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly with optional action row content', () => {
|
||||||
|
const actionRowContent = (
|
||||||
|
<>
|
||||||
|
<Dropdown>
|
||||||
|
<Dropdown.Toggle variant="outline-primary" id="library-header-menu-dropdown">
|
||||||
|
Settings
|
||||||
|
</Dropdown.Toggle>
|
||||||
|
<Dropdown.Menu>
|
||||||
|
<Dropdown.Item as={Link} to="#">Dropdown Item 1</Dropdown.Item>
|
||||||
|
<Dropdown.Item as={Link} to="#">Dropdown Item 2</Dropdown.Item>
|
||||||
|
<Dropdown.Item as={Link} to="#">Dropdown Item 3</Dropdown.Item>
|
||||||
|
</Dropdown.Menu>
|
||||||
|
</Dropdown>
|
||||||
|
<ActionRow.Spacer />
|
||||||
|
<Button
|
||||||
|
variant="tertiary"
|
||||||
|
href="#"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
title="Help Button"
|
||||||
|
>Help
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const component = <StudioHeaderContext actionRowContent={actionRowContent} />;
|
||||||
|
|
||||||
|
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"
|
||||||
>
|
>
|
||||||
|
|||||||
226
src/__snapshots__/StudioHeader.test.jsx.snap
Normal file
226
src/__snapshots__/StudioHeader.test.jsx.snap
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
// 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"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="pgn__action-row"
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<StudioHeader /> renders correctly with optional action row content 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"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="pgn__action-row"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="pgn__dropdown pgn__dropdown-light dropdown"
|
||||||
|
data-testid="dropdown"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup={true}
|
||||||
|
className="dropdown-toggle btn btn-outline-primary"
|
||||||
|
disabled={false}
|
||||||
|
id="library-header-menu-dropdown"
|
||||||
|
onClick={[Function]}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Settings
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
className="pgn__action-row-spacer"
|
||||||
|
/>
|
||||||
|
<a
|
||||||
|
className="btn btn-tertiary"
|
||||||
|
href="#"
|
||||||
|
onClick={[Function]}
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
role="button"
|
||||||
|
target="_blank"
|
||||||
|
title="Help Button"
|
||||||
|
>
|
||||||
|
Help
|
||||||
|
</a>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
18
src/common/time-locale.js
Normal file
18
src/common/time-locale.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
export default function timeLocale(number, index) {
|
||||||
|
return [
|
||||||
|
['just now', 'right now'],
|
||||||
|
['%ss', 'in %s seconds'],
|
||||||
|
['1m', 'in 1 minute'],
|
||||||
|
['%sm', 'in %s minutes'],
|
||||||
|
['1h', 'in 1 hour'],
|
||||||
|
['%sh', 'in %s hours'],
|
||||||
|
['1d', 'in 1 day'],
|
||||||
|
['%sd', 'in %s days'],
|
||||||
|
['1w', 'in 1 week'],
|
||||||
|
['%sw', 'in %s weeks'],
|
||||||
|
['4w', 'in 1 month'],
|
||||||
|
[`${number * 4}w`, 'in %s months'],
|
||||||
|
['1y', 'in 1 year'],
|
||||||
|
['%sy', 'in %s years'],
|
||||||
|
][index];
|
||||||
|
}
|
||||||
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,18 +1,28 @@
|
|||||||
import arMessages from './messages/ar.json';
|
import arMessages from './messages/ar.json';
|
||||||
// no need to import en messages-- they are in the defaultMessage field
|
|
||||||
import es419Messages from './messages/es_419.json';
|
|
||||||
import frMessages from './messages/fr.json';
|
import frMessages from './messages/fr.json';
|
||||||
import kokrMessages from './messages/ko_KR.json';
|
import es419Messages from './messages/es_419.json';
|
||||||
import ptbrMessages from './messages/pt_BR.json';
|
|
||||||
import zhcnMessages from './messages/zh_CN.json';
|
import zhcnMessages from './messages/zh_CN.json';
|
||||||
|
import ptMessages from './messages/pt.json';
|
||||||
|
import itMessages from './messages/it.json';
|
||||||
|
import ukMessages from './messages/uk.json';
|
||||||
|
import deMessages from './messages/de.json';
|
||||||
|
import ruMessages from './messages/ru.json';
|
||||||
|
import hiMessages from './messages/hi.json';
|
||||||
|
import frCAMessages from './messages/fr_CA.json';
|
||||||
|
// no need to import en messages-- they are in the defaultMessage field
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
ar: arMessages,
|
ar: arMessages,
|
||||||
'es-419': es419Messages,
|
'es-419': es419Messages,
|
||||||
fr: frMessages,
|
fr: frMessages,
|
||||||
'zh-cn': zhcnMessages,
|
'zh-cn': zhcnMessages,
|
||||||
'ko-kr': kokrMessages,
|
pt: ptMessages,
|
||||||
'pt-br': ptbrMessages,
|
it: itMessages,
|
||||||
|
de: deMessages,
|
||||||
|
hi: hiMessages,
|
||||||
|
'fr-ca': frCAMessages,
|
||||||
|
ru: ruMessages,
|
||||||
|
uk: ukMessages,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default messages;
|
export default messages;
|
||||||
|
|||||||
@@ -1,2 +1,39 @@
|
|||||||
{
|
{
|
||||||
}
|
"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": "تسجيل الخروج",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
39
src/i18n/messages/de.json
Normal file
39
src/i18n/messages/de.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -1,2 +1,39 @@
|
|||||||
{
|
{
|
||||||
}
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -1,2 +1,39 @@
|
|||||||
{
|
{
|
||||||
}
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
39
src/i18n/messages/fr_CA.json
Normal file
39
src/i18n/messages/fr_CA.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Dernières 24 heures",
|
||||||
|
"notification.earlier.heading": "Plus tôt",
|
||||||
|
"notification.mark.as.read": "tout marquer comme lu",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Charger plus de notifications"
|
||||||
|
}
|
||||||
39
src/i18n/messages/hi.json
Normal file
39
src/i18n/messages/hi.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
39
src/i18n/messages/it.json
Normal file
39
src/i18n/messages/it.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
{
|
|
||||||
}
|
|
||||||
39
src/i18n/messages/pt.json
Normal file
39
src/i18n/messages/pt.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
{
|
|
||||||
}
|
|
||||||
39
src/i18n/messages/ru.json
Normal file
39
src/i18n/messages/ru.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
39
src/i18n/messages/uk.json
Normal file
39
src/i18n/messages/uk.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"general.register.sentenceCase": "Register",
|
||||||
|
"general.signIn.sentenceCase": "Увійти",
|
||||||
|
"header.links.courses": "Курси",
|
||||||
|
"header.links.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": "Меню облікового запису",
|
||||||
|
"header.label.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": "Перейти до головного змісту",
|
||||||
|
"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": "Перейти до головного змісту.",
|
||||||
|
"header.menu.signOut.label": "Sign Out",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -1,2 +1,39 @@
|
|||||||
{
|
{
|
||||||
}
|
"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",
|
||||||
|
"notification.title": "Notifications",
|
||||||
|
"notification.today.heading": "Last 24 hours",
|
||||||
|
"notification.earlier.heading": "Earlier",
|
||||||
|
"notification.mark.as.read": "Mark all as read",
|
||||||
|
"notification.fullStop": "•",
|
||||||
|
"notification.load.more.notifications": "Load more notifications"
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
161
src/index.scss
161
src/index.scss
@@ -1,7 +1,10 @@
|
|||||||
$spacer: 1rem;
|
$spacer: 1rem;
|
||||||
$blue: #007db8;
|
$blue: #007db8;
|
||||||
$white: #fff;
|
$white: #fff;
|
||||||
|
@import "@edx/brand/paragon/fonts.scss";
|
||||||
|
@import "@edx/brand/paragon/variables.scss";
|
||||||
|
@import "@edx/paragon/scss/core/core.scss";
|
||||||
|
@import "@edx/brand/paragon/overrides.scss";
|
||||||
@import './Menu/menu.scss';
|
@import './Menu/menu.scss';
|
||||||
|
|
||||||
.dropdown-item a {
|
.dropdown-item a {
|
||||||
@@ -25,6 +28,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;
|
||||||
@@ -94,3 +121,135 @@ $white: #fff;
|
|||||||
border-radius: $rounded-pill;
|
border-radius: $rounded-pill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
b {
|
||||||
|
color: #00262B !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-size-18 {
|
||||||
|
font-size: 18px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-size-12 {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.font-size-14 {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.py-10px {
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pb-10px {
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-height-24 {
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-height-20 {
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-height-10 {
|
||||||
|
line-height: 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-size-20 {
|
||||||
|
width: 20px !important;
|
||||||
|
height: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cursor-pointer {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-button {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-icon{
|
||||||
|
height: 23.33px !important;
|
||||||
|
width: 23.33px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-badge {
|
||||||
|
position: absolute;
|
||||||
|
margin-top: 18px;
|
||||||
|
margin-left: -21px;
|
||||||
|
border: 2px solid #FFFFFF;
|
||||||
|
font-size: 9px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popover {
|
||||||
|
max-height: calc(100% - 68px);
|
||||||
|
min-height: 1220px;
|
||||||
|
filter: none;
|
||||||
|
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15), 0px 2px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
|
||||||
|
&.medium-screen {
|
||||||
|
min-width: 24.313rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.large-screen {
|
||||||
|
min-width: 34.313rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-toggle::after {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.expandable {
|
||||||
|
position: relative !important;
|
||||||
|
margin-left: 4px;
|
||||||
|
padding: 2px 5px;
|
||||||
|
border-radius: 10rem;
|
||||||
|
font-size: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-toggle {
|
||||||
|
font-size: 14px;
|
||||||
|
padding-top: 0px !important;
|
||||||
|
padding-bottom: 12px !important;
|
||||||
|
|
||||||
|
div {
|
||||||
|
min-height: 6px !important;
|
||||||
|
min-width: 6px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-content {
|
||||||
|
.notification-item-content {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
b {
|
||||||
|
color: #00262B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.unread {
|
||||||
|
height: 10px;
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
32
src/learning-header/AnonymousUserMenu.jsx
Normal file
32
src/learning-header/AnonymousUserMenu.jsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
const AnonymousUserMenu = ({ intl }) => (
|
||||||
|
<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);
|
||||||
73
src/learning-header/AuthenticatedUserDropdown.jsx
Normal file
73
src/learning-header/AuthenticatedUserDropdown.jsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import React, { useEffect } 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 { useSelector, useDispatch } from 'react-redux';
|
||||||
|
import Notifications from '../Notifications';
|
||||||
|
import { selectShowNotificationTray, selectNotificationStatus } from '../Notifications/data/selectors';
|
||||||
|
import { fetchAppsNotificationCount } from '../Notifications/data/thunks';
|
||||||
|
import { RequestStatus } from '../Notifications/data/slice';
|
||||||
|
|
||||||
|
import messages from './messages';
|
||||||
|
|
||||||
|
const AuthenticatedUserDropdown = ({ intl, username }) => {
|
||||||
|
const showNotificationsTray = useSelector(selectShowNotificationTray());
|
||||||
|
const notificationStatus = useSelector(selectNotificationStatus());
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (notificationStatus === RequestStatus.IDLE) {
|
||||||
|
dispatch(fetchAppsNotificationCount());
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [notificationStatus]);
|
||||||
|
|
||||||
|
const dashboardMenuItem = (
|
||||||
|
<Dropdown.Item href={`${getConfig().LMS_BASE_URL}/dashboard`}>
|
||||||
|
{intl.formatMessage(messages.dashboard)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<a className="text-gray-700" href={`${getConfig().SUPPORT_URL}`}>{intl.formatMessage(messages.help)}</a>
|
||||||
|
{showNotificationsTray && <Notifications />}
|
||||||
|
<Dropdown className="user-dropdown ml-3">
|
||||||
|
<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().ACCOUNT_PROFILE_URL}/u/${username}`}>
|
||||||
|
{intl.formatMessage(messages.profile)}
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item href={getConfig().ACCOUNT_SETTINGS_URL}>
|
||||||
|
{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);
|
||||||
82
src/learning-header/LearningHeader.jsx
Normal file
82
src/learning-header/LearningHeader.jsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
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, AppProvider } from '@edx/frontend-platform/react';
|
||||||
|
|
||||||
|
import AnonymousUserMenu from './AnonymousUserMenu';
|
||||||
|
import AuthenticatedUserDropdown from './AuthenticatedUserDropdown';
|
||||||
|
import messages from './messages';
|
||||||
|
import store from '../store';
|
||||||
|
|
||||||
|
const LinkedLogo = ({
|
||||||
|
href,
|
||||||
|
src,
|
||||||
|
alt,
|
||||||
|
...attributes
|
||||||
|
}) => (
|
||||||
|
<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,
|
||||||
|
};
|
||||||
|
|
||||||
|
const 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 (
|
||||||
|
<AppProvider store={store}>
|
||||||
|
<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>
|
||||||
|
</AppProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
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.getByText(authenticatedUser.username)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
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,14 +1,29 @@
|
|||||||
/* 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() });
|
||||||
|
|
||||||
// These configuration values are usually set in webpack's EnvironmentPlugin however
|
// These configuration values are usually set in webpack's EnvironmentPlugin however
|
||||||
// Jest does not use webpack so we need to set these so for testing
|
// Jest does not use webpack so we need to set these so for testing
|
||||||
process.env.ACCESS_TOKEN_COOKIE_NAME = 'edx-jwt-cookie-header-payload';
|
process.env.ACCESS_TOKEN_COOKIE_NAME = 'edx-jwt-cookie-header-payload';
|
||||||
|
process.env.ACCOUNT_PROFILE_URL = 'http://localhost:1995';
|
||||||
|
process.env.ACCOUNT_SETTINGS_URL = 'http://localhost:1997';
|
||||||
process.env.BASE_URL = 'localhost:1995';
|
process.env.BASE_URL = 'localhost:1995';
|
||||||
process.env.CREDENTIALS_BASE_URL = 'http://localhost:18150';
|
process.env.CREDENTIALS_BASE_URL = 'http://localhost:18150';
|
||||||
process.env.CSRF_TOKEN_API_PATH = '/csrf/api/v1/token';
|
process.env.CSRF_TOKEN_API_PATH = '/csrf/api/v1/token';
|
||||||
@@ -16,7 +31,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 +42,88 @@ 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
|
||||||
|
} = {},
|
||||||
|
) {
|
||||||
|
const Wrapper = ({ children }) => (
|
||||||
|
// 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,
|
||||||
|
};
|
||||||
|
|||||||
16
src/store.js
Normal file
16
src/store.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { configureStore } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
|
import { notificationsReducer } from './Notifications/data';
|
||||||
|
|
||||||
|
export function initializeStore(preloadedState = undefined) {
|
||||||
|
return configureStore({
|
||||||
|
reducer: {
|
||||||
|
notifications: notificationsReducer,
|
||||||
|
},
|
||||||
|
preloadedState,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = initializeStore();
|
||||||
|
|
||||||
|
export default store;
|
||||||
6
src/test-utils.js
Normal file
6
src/test-utils.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
const executeThunk = async (thunk, dispatch, getState) => {
|
||||||
|
await thunk(dispatch, getState);
|
||||||
|
await new Promise(setImmediate);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default executeThunk;
|
||||||
Reference in New Issue
Block a user