Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit b071f0a

Browse files
authored
Merge pull request #1245 from creativecommons/develop
2 parents 4179e8d + 5a3472b commit b071f0a

27 files changed

+10179
-39356
lines changed

.eslintrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ module.exports = {
1414
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
1515
'plugin:vue/recommended',
1616
'plugin:prettier/recommended',
17-
'plugin:vue-a11y/base',
17+
'plugin:vuejs-accessibility/recommended',
1818
],
1919
// required to lint *.vue files
20-
plugins: ['vue', 'cypress', 'vue-a11y'],
20+
plugins: ['vue', 'cypress', 'vuejs-accessibility'],
2121
// add your custom rules here
2222
rules: {
2323
semi: [2, 'never'],
@@ -28,7 +28,6 @@ module.exports = {
2828
'vue/html-closing-bracket-newline': 'off',
2929
'vue/html-indent': 'off',
3030
'vue/singleline-html-element-content-newline': 'off',
31-
'vue-a11y/click-events-have-key-events': 'warn',
3231
'vue/component-name-in-template-casing': [
3332
'error',
3433
'PascalCase',
@@ -46,5 +45,6 @@ module.exports = {
4645
math: 'always',
4746
},
4847
],
48+
'vuejs-accessibility/aria-role': 'warn',
4949
},
5050
}

nuxt.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ export default {
127127
ttl: process.env.MICROCACHE_DURATION || 60,
128128
},
129129
},
130-
modern: 'client',
131130
srcDir: 'src/',
132-
// buildDir: 'dist/',
131+
modern: 'client',
133132
server: { port: process.env.PORT || 8443 },
134133
components: true,
135-
plugins: ['~/plugins/i18n.js', { src: '~plugins/ga.js', mode: 'client' }],
134+
plugins: [
135+
'~/plugins/i18n.js',
136+
{ src: '~/plugins/ab-test-init.js', mode: 'client' },
137+
{ src: '~plugins/ga.js', mode: 'client' },
138+
],
136139
css: [
137140
'@creativecommons/vocabulary/scss/vocabulary.scss',
138141
'~/styles/global.scss',

package-lock.json

Lines changed: 9919 additions & 39038 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cccatalog-frontend",
3-
"version": "2020.10.1",
3+
"version": "2020.10.2",
44
"description": "Common Creative search",
55
"repository": {
66
"type": "git",
@@ -49,15 +49,15 @@
4949
"lodash.isempty": "^4.4.0",
5050
"lodash.sortby": "^4.7.0",
5151
"node-sass": "^4.14.1",
52-
"nuxt": "^2.14.6",
52+
"nuxt": "^2.14.7",
5353
"nuxt-ssr-cache": "^1.5.2",
5454
"patch-package": "^6.2.2",
5555
"sass-loader": "^10.0.1",
56-
"sixpack-client": "^2.1.0",
5756
"uuid": "^8.3.1",
5857
"vue-i18n": "^8.21.0"
5958
},
6059
"devDependencies": {
60+
"@nuxt/types": "^2.14.7",
6161
"@nuxtjs/eslint-module": "^2.0.0",
6262
"@types/jest": "^26.0.10",
6363
"@vue/test-utils": "^1.0.4",
@@ -68,7 +68,7 @@
6868
"eslint-plugin-cypress": "^2.11.1",
6969
"eslint-plugin-prettier": "^3.1.4",
7070
"eslint-plugin-vue": "^6.2.2",
71-
"eslint-plugin-vue-a11y": "0.0.31",
71+
"eslint-plugin-vuejs-accessibility": "^0.5.1",
7272
"glob": "^7.1.6",
7373
"husky": "^4.2.5",
7474
"jest": "^26.4.2",
@@ -78,8 +78,8 @@
7878
"vue-jest": "^3.0.6"
7979
},
8080
"engines": {
81-
"node": ">= 6.0.0",
82-
"npm": ">= 3.0.0"
81+
"node": ">= 12.0.0",
82+
"npm": ">= 6.0.0"
8383
},
8484
"browserslist": [
8585
"> 1%",
@@ -94,5 +94,9 @@
9494
"lint-staged": {
9595
"*.{js,vue}": "eslint --cache --fix",
9696
"*.{js,vue,css,md}": "prettier --write"
97+
},
98+
"volta": {
99+
"node": "12.19.0",
100+
"npm": "6.14.8"
97101
}
98102
}
Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,11 @@
1-
const EXPERIMENT_NAME = 'donation_language'
2-
const DONATION_GENERAL_CASE = 'donation_general'
3-
const DONATION_PERCENTAGE_CASE = 'donation_percentage'
4-
5-
/**
6-
* Joins the experiment.
7-
*
8-
* Returns a Promise, which resolves with the experiment name and selected experiment case.
9-
* In case of failure, it rejects with the error, the experiment name and a default experiment case
10-
* @param {*} session Sixpack session object
11-
*/
12-
const joinExperiment = (session) => {
13-
const resultPromise = new Promise((resolve, reject) => {
14-
session.participate(
15-
EXPERIMENT_NAME,
16-
[DONATION_GENERAL_CASE, DONATION_PERCENTAGE_CASE],
17-
(err, res) => {
18-
if (err || res.error) {
19-
reject({
20-
error: err,
21-
name: EXPERIMENT_NAME,
22-
case: DONATION_GENERAL_CASE,
23-
session,
24-
})
25-
}
26-
const experimentCase = res.alternative.name
27-
28-
resolve({
29-
name: EXPERIMENT_NAME,
30-
case: experimentCase,
31-
session,
32-
})
33-
}
34-
)
35-
})
36-
37-
return resultPromise
38-
}
39-
40-
export default joinExperiment
41-
export const ExperimentData = {
42-
EXPERIMENT_NAME,
43-
DONATION_GENERAL_CASE,
44-
DONATION_PERCENTAGE_CASE,
1+
export const DONATION_GENERAL_CASE = 'donation_general'
2+
export const DONATION_PERCENTAGE_CASE = 'donation_percentage'
3+
4+
export default {
5+
name: 'donation_language_revised',
6+
defaultCase: DONATION_GENERAL_CASE,
7+
cases: {
8+
DONATION_GENERAL_CASE,
9+
DONATION_PERCENTAGE_CASE,
10+
},
4511
}

src/abTests/experiments/filterExpansion.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/abTests/index.js

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
import { JOINED_AB_TEST_EXPERIMENT } from '~/store-modules/mutation-types'
2-
import createSixpackSession from './lib/createSixpackSession'
32
import donationLanguage from '~/abTests/experiments/donationLanguage'
3+
import { participate } from '~/utils/sixpack'
44

55
/**
66
* Attach each a/b test (aka "experiment") to the sixpack session
7-
* and commit a vuex mutation for each joined experiment
7+
* and commit a vuex mutation for each joined experiment.
8+
*
9+
* Each experiment is a simple object with the following structure:
10+
*
11+
* ```js
12+
* {
13+
* name: 'experiment_name',
14+
* defaultCase: 'experiment_default_case_name',
15+
* cases: {
16+
* 'experiment_default_case_name',
17+
* 'any_other_case_names',
18+
* 'any_other_case_names',
19+
* },
20+
* traffic_fraction: .10 // an optional number between 0 and 1 (100%)
21+
* }
22+
* ```
823
*/
9-
const setupExperiments = (store) => {
10-
const session = createSixpackSession(store.state.abSessionId)
24+
const abTests = (store) => {
25+
const activeExperiments = [donationLanguage]
1126

12-
// List all active experiments here
13-
const experimentPromises = [donationLanguage(session)]
14-
return (
15-
Promise.all(experimentPromises)
16-
.then((experiments) =>
17-
experiments.map((experiment) =>
18-
store.commit(JOINED_AB_TEST_EXPERIMENT, {
19-
name: experiment.name,
20-
case: experiment.case,
21-
session: experiment.session,
22-
})
23-
)
24-
)
25-
// In the case of an error, the user joins the default version of an experiment
26-
.catch((error) =>
27-
store.commit(JOINED_AB_TEST_EXPERIMENT, {
28-
name: error.name,
29-
case: error.case,
30-
session: error.session,
31-
})
32-
)
33-
)
27+
// commit each experiment to Vuex
28+
const commitExperiments = (experiments) => {
29+
experiments.map((experiment) => {
30+
store.commit(JOINED_AB_TEST_EXPERIMENT, {
31+
name: experiment.name,
32+
case: experiment.case,
33+
session: experiment.session,
34+
})
35+
})
36+
}
37+
38+
return Promise.all(
39+
activeExperiments.map((experiment) =>
40+
participate(experiment, { sessionId: store.state.abSessionId })
41+
)
42+
).then(commitExperiments)
3443
}
3544

36-
export default setupExperiments
45+
export default abTests

src/abTests/lib/createSixpackSession.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/components/AppModal.vue

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<template>
2-
<div
3-
v-if="visible"
4-
class="overlay"
5-
@click.self="$emit('close')"
6-
@keyup="checkKey"
7-
>
2+
<!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events -->
3+
<div ref="modal" class="overlay app-modal" @click.self="$emit('close')">
84
<FocusTrap :active="true">
95
<div class="modal relative" aria-modal="true" role="dialog">
106
<header
@@ -19,7 +15,7 @@
1915
class="close-button has-color-gray is-size-6 is-size-4-touch"
2016
:aria-label="$t('browse-page.aria.close')"
2117
@click="$emit('close')"
22-
@keyup.enter="$emit('close')"
18+
@keypress.enter="$emit('close')"
2319
>
2420
<i class="icon cross" />
2521
</button>
@@ -31,42 +27,32 @@
3127
</template>
3228

3329
<script>
30+
import { FocusTrap } from 'focus-trap-vue'
31+
3432
/**
3533
* @todo: This entire component should be moved to vue-vocabulary
3634
*/
37-
38-
import { FocusTrap } from 'focus-trap-vue'
39-
4035
export default {
4136
name: 'AppModal',
4237
components: {
4338
FocusTrap,
4439
},
4540
props: {
46-
visible: Boolean,
47-
title: String, // required for titlebar AND close button to show
41+
/** Required for titlebar AND close button to show */
42+
title: String,
4843
subTitle: String,
4944
},
50-
watch: {
51-
visible: {
52-
handler(to) {
53-
if (typeof document !== 'undefined') {
54-
if (to) {
55-
document.addEventListener('keyup', this.checkKey)
56-
} else {
57-
document.removeEventListener('keyup', this.checkKey)
58-
}
59-
}
60-
},
61-
immediate: true,
62-
},
45+
mounted() {
46+
document.addEventListener('keyup', this.closeOnEsc)
6347
},
6448
destroyed() {
65-
document.removeEventListener('keyup', this.checkKey)
49+
document.removeEventListener('keyup', this.closeOnEsc)
6650
},
6751
methods: {
68-
checkKey(e) {
69-
if (e.keyCode === 27) this.$emit('close')
52+
closeOnEsc(e) {
53+
if (e.keyCode === 27) {
54+
this.$emit('close')
55+
}
7056
},
7157
},
7258
}

0 commit comments

Comments
 (0)