Skip to content

Commit a7597d5

Browse files
committed
Fix bug when selecting ND from the dropdown would activate unnecessary steps
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent be42999 commit a7597d5

File tree

3 files changed

+86
-71
lines changed

3 files changed

+86
-71
lines changed

src/components/Stepper.vue

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import FirstStep from './FirstStep'
7070
import AttributionDetailsStep from './AttributionDetailsStep'
7171
import CopyrightWaiverStep from './CopyrightWaiverStep'
7272
import DropdownStep from './DropdownStep'
73-
import { disabledSetters, visibleSetters } from '../utils/license-utilities'
73+
import { updateVisibleEnabledStatus } from '../utils/license-utilities'
7474
7575
export default {
7676
name: 'Stepper',
@@ -166,7 +166,7 @@ export default {
166166
}
167167
}
168168
this.$set(this.steps, stepId, { ...this.steps[stepId], selected: isSelected })
169-
this.updateDisabledAndVisibleSteps(stepName, isSelected)
169+
this.updateDisabledAndVisibleSteps()
170170
},
171171
handleNext(stepName) {
172172
/**
@@ -247,21 +247,22 @@ export default {
247247
}
248248
})
249249
},
250-
setStepsDisabled(stepsToSetDisabled) {
250+
setStepsEnabled(stepsToSetEnabled, disabledDue) {
251251
// sets steps in stepsToSetDisabled array enabled properties to false
252252
this.steps.forEach((step) => {
253-
if (stepsToSetDisabled.indexOf(step.name) > -1 && step.enabled) {
254-
this.$set(this.steps, step.id, { ...step, enabled: false })
255-
} else if (stepsToSetDisabled.indexOf(step.name) === -1 && !step.enabled) {
256-
this.$set(this.steps, step.id, { ...step, enabled: true })
253+
// step is currently enabled, but should be disabled
254+
if (stepsToSetEnabled.indexOf(step.name) === -1 && step.enabled) {
255+
this.$set(this.steps, step.id, { ...step, enabled: false, disabledDue: disabledDue })
256+
} else if (stepsToSetEnabled.indexOf(step.name) > -1 && !step.enabled) {
257+
// step is currently disabled, but should be set enabled
258+
this.$set(this.steps, step.id, { ...step, enabled: true, disabledDue: '' })
257259
}
258260
})
259261
},
260-
updateDisabledAndVisibleSteps(stepName, isStepSelected) {
262+
updateDisabledAndVisibleSteps() {
261263
/**
262-
* Creates an array of steps that should be set visible/disabled
263-
* based on the step that was selected/unselected,
264-
* and updates their visible/enabled properties
264+
* Creates an array of steps that should be visible/enalbed based on data from steps array
265+
* and updates the steps array
265266
*/
266267
if (stepName in visibleSetters) {
267268
let visible = []
@@ -294,9 +295,6 @@ export default {
294295
set(newVal) {
295296
this.$emit('input', newVal)
296297
}
297-
},
298-
useDropdownForSelection() {
299-
return this.steps[0].selected
300298
}
301299
},
302300
created: function() {
@@ -357,6 +355,9 @@ export default {
357355
position:relative;
358356
margin: 24px 24px 8px;
359357
}
358+
.stepper-card-header:hover {
359+
cursor: pointer;
360+
}
360361
.stepper-card-header .stepper-header-h5 {
361362
margin-left: 45px;
362363
}
@@ -401,7 +402,6 @@ export default {
401402
.previous.disabled {
402403
color: #B0B0B0;
403404
}
404-
405405
.previous.disabled .vocab-h5b,
406406
.inactive .vocab.h5b {
407407
color: #B0B0B0;
@@ -412,30 +412,30 @@ export default {
412412
.stepper-card .b-radio.radio:hover input[type=radio]:not(:disabled) + .check {
413413
border: 4px solid #0464E1;
414414
}
415-
.step-navigation {
416-
margin: 13px 0 13px -4px;
417-
}
418-
.pagination-next {
419-
background-color: #04A635;
420-
color: white!important;
421-
font-family: Roboto Condensed,sans-serif;
422-
font-style: normal;
423-
font-weight: 500;
424-
font-size: 18px;
425-
line-height: 24px;
426-
}
427-
.pagination-next.disabled {
428-
background-color: #D8D8D8;
429-
}
430-
.pagination-next.disabled:hover,
431-
.pagination-next.disabled:active {
432-
box-shadow: none;
433-
border: 1px solid transparent;
434-
}
435-
.slide-enter-active {
436-
/*transition: all .3s ease;*/
437-
animation: slide-down .5s;
415+
.step-navigation {
416+
margin: 13px 0 13px -4px;
417+
}
418+
.pagination-next {
419+
background-color: #04A635;
420+
color: white!important;
421+
font-family: Roboto Condensed,sans-serif;
422+
font-style: normal;
423+
font-weight: 500;
424+
font-size: 18px;
425+
line-height: 24px;
426+
}
427+
.pagination-next.disabled {
428+
background-color: #D8D8D8;
429+
}
430+
.pagination-next.disabled:hover,
431+
.pagination-next.disabled:active {
432+
box-shadow: none;
433+
border: 1px solid transparent;
438434
}
435+
.slide-enter-active {
436+
/*transition: all .3s ease;*/
437+
animation: slide-down .3s;
438+
}
439439
.slide-leave-active {
440440
/*transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);*/
441441
animation: slide-down .5s reverse;
@@ -460,4 +460,9 @@ export default {
460460
/*transform: scaleY(1);*/
461461
}
462462
}
463+
@media (max-width: 860px) {
464+
.stepper-card:last-of-type {
465+
margin-bottom: 1rem;
466+
}
467+
}
463468
</style>

src/store/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export default new Vuex.Store({
1212
creatorProfileUrl: '',
1313
workTitle: '',
1414
workUrl: ''
15-
},
16-
useDropdownForSelection: undefined
15+
}
1716
},
1817
getters: {
1918
isLicenseSelected: state => {
@@ -39,15 +38,12 @@ export default new Vuex.Store({
3938
},
4039
mutations: {
4140
setSelected(state, { stepName, isSelected }) {
42-
// When a Radio button is selected, either useDropdownForSelection or
43-
// currentLicenseAttribute 'selected' attribute is updated
41+
// When a Radio button is selected, currentLicenseAttribute 'selected' attribute is updated
4442
if (['BY', 'NC', 'ND', 'SA'].indexOf(stepName) > -1) {
4543
state.currentLicenseAttributes = {
4644
...state.currentLicenseAttributes,
4745
[stepName]: isSelected
4846
}
49-
} else if (stepName === 'FS') {
50-
state.useDropdownForSelection = !state.useDropdownForSelection
5147
}
5248
},
5349
updateAttributesFromShort(state, shortName) {

src/utils/license-utilities.js

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
const CC0Attributes = { BY: false, NC: false, ND: false, SA: false }
22
const CCBYAttributes = { BY: true, NC: false, ND: false, SA: false }
33
const defaultAttributes = { BY: undefined, NC: undefined, ND: undefined, SA: undefined }
4-
const visibleSetters = {
5-
FSCC0: ['FS', 'DD', 'CW', 'AD'],
6-
FSBY: ['FS', 'DD', 'AD'],
7-
FS: {
8-
true: ['FS', 'DD', 'AD'],
9-
false: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
10-
},
11-
BY: {
12-
true: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD'],
13-
false: ['FS', 'BY', 'NC', 'ND', 'SA', 'CW', 'AD']
14-
},
15-
ND: {
16-
true: ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
17-
}
18-
}
19-
const disabledSetters = {
20-
// Steps that should be disabled if other steps are selected/not selected
21-
BY: {
22-
false: ['NC', 'ND', 'SA']
23-
},
24-
ND: {
25-
true: ['SA']
26-
}
27-
}
284

295
function shortToAttr(shortLicenseName) {
306
const short = shortLicenseName
@@ -98,6 +74,45 @@ function licenseIconsArr(licenseAttributes) {
9874
return iconsArray
9975
}
10076

77+
function updateVisibleEnabledStatus(stepStatusData) {
78+
let visible = []
79+
let enabled = []
80+
let stepsDisabledDue = ''
81+
if (stepStatusData.FS) {
82+
// User will select from the dropdown
83+
if (stepStatusData.BY === false) {
84+
// User selected a license from the dropdown a CC0 license
85+
// First step, dropdown and attribution details should be visible and enabled
86+
visible = ['FS', 'DD', 'CW', 'AD']
87+
enabled = ['FS', 'DD', 'CW', 'AD']
88+
stepsDisabledDue = 'CC0'
89+
} else {
90+
// User hasn't selected anything yet, or selected a BY license
91+
// First step, dropdown and attribution details should be visible and enabled
92+
visible = ['FS', 'DD', 'AD']
93+
enabled = ['FS', 'DD', 'AD']
94+
}
95+
} else {
96+
// User uses the stepper for license selection
97+
if (stepStatusData.BY === false) {
98+
// User selects a CC0 license
99+
visible = ['FS', 'BY', 'NC', 'ND', 'SA', 'CW', 'AD']
100+
enabled = ['FS', 'BY', 'CW', 'AD']
101+
stepsDisabledDue = 'CC0'
102+
} else if (stepStatusData.ND) {
103+
// User selects an ND license: SA step is disabled
104+
visible = ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
105+
enabled = ['FS', 'BY', 'NC', 'ND', 'AD']
106+
stepsDisabledDue = 'CC0'
107+
} else {
108+
// User selects a non-ND BY license from the stepper
109+
visible = ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
110+
enabled = ['FS', 'BY', 'NC', 'ND', 'SA', 'AD']
111+
}
112+
}
113+
return { visible, enabled, stepsDisabledDue }
114+
}
115+
101116
function generateHTML(attributionDetails, shortLicenseName) {
102117
const dataForHtmlGeneration = {
103118
htmlString: '',
@@ -138,7 +153,6 @@ function generateHTML(attributionDetails, shortLicenseName) {
138153
return dataForHtmlGeneration
139154
}
140155
export {
141-
defaultAttributes, CC0Attributes, CCBYAttributes, visibleSetters, disabledSetters,
142-
shortToAttr, attrToShort, attrToFull, licenseUrl, licenseSlug, licenseIconsArr,
143-
generateHTML
156+
defaultAttributes, CC0Attributes, CCBYAttributes, shortToAttr, attrToShort,
157+
attrToFull, licenseUrl, licenseSlug, licenseIconsArr, generateHTML, updateVisibleEnabledStatus
144158
}

0 commit comments

Comments
 (0)