-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure selected idp list works right (#1074)
Prior to this change deleting a selected idp was not possible. While it was visually removed, returning to the wave later showed it was still there. This change ensures the behaviour is as expected: - hitting delete button truly deletes it - returning to the wave without a hard refresh will show the correct list of already selected idps, even if returning via the backbutton [Issue discovered as part of fixing tickets for the latest feedback round](https://wiki.surfnet.nl/display/coininfra/Bevindingen+nav+tests+door+supportteam)
- Loading branch information
Koen Cornelis
authored
Feb 1, 2021
1 parent
6abcb30
commit 492e156
Showing
16 changed files
with
131 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 11 additions & 13 deletions
24
theme/base/javascripts/wayf/deleteDisable/addSelectedIdp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import {savePreviousSelection} from './savePreviousSelection'; | ||
import {configurationId} from '../../selectors'; | ||
import * as Cookies from 'js-cookie'; | ||
|
||
/** | ||
* Add the selected idp to the list of previouslyselected idps and save it to the cookie. | ||
* | ||
* @param isPreviouslySelectedList | ||
* @param element | ||
*/ | ||
export const addSelectedIdp = (isPreviouslySelectedList, element) => { | ||
const configuration = JSON.parse(document.getElementById(configurationId).innerHTML); | ||
const cookieName = configuration.previousSelectionCookieName; | ||
let previouslySelectedIdps = configuration.previousSelectionList; | ||
export const addSelectedIdp = (element) => { | ||
const cookieName = JSON.parse(document.getElementById(configurationId).innerHTML).previousSelectionCookieName; | ||
const entityId = element.getAttribute('data-entityid'); | ||
const count = Number(element.getAttribute('data-count')); | ||
let alreadyInCookie = false; | ||
let cookie = Cookies.get(cookieName) || []; | ||
|
||
if (isPreviouslySelectedList) { | ||
previouslySelectedIdps.forEach(idp => { | ||
if (idp.entityId === entityId) { | ||
if (cookie.length) { | ||
cookie = JSON.parse(cookie); | ||
cookie.forEach(idp => { | ||
if (idp.idp === entityId) { | ||
idp.count += 1; | ||
savePreviousSelection(previouslySelectedIdps, cookieName); | ||
savePreviousSelection(cookie, cookieName); | ||
alreadyInCookie = true; | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
if (!alreadyInCookie) { | ||
previouslySelectedIdps = [...previouslySelectedIdps, { entityId: entityId, count: (count + 1) }]; | ||
cookie = [...cookie, { idp: entityId, count: 1 }]; | ||
savePreviousSelection(cookie, cookieName); | ||
} | ||
|
||
savePreviousSelection(previouslySelectedIdps, cookieName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
theme/base/javascripts/wayf/matchPreviouslySelectedWithCookie.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {configurationId, deleteButtonTemplateId, idpContentClass, idpDeleteSelector, idpDeleteDisabledSelector, remainingIdpSelector, selectedIdpsListSelector, selectedIdpsSelector, selectedIdpsLiSelector} from '../selectors'; | ||
import * as Cookies from 'js-cookie'; | ||
import {sortIdpList} from './utility/sortIdpList'; | ||
import {getData} from '../utility/getData'; | ||
|
||
export const matchPreviouslySelectedWithCookie = () => { | ||
const cookieName = JSON.parse(document.getElementById(configurationId).innerHTML).previousSelectionCookieName; | ||
const selectedIdps = document.querySelectorAll(selectedIdpsSelector); | ||
const selectedIdpList = document.querySelector(selectedIdpsListSelector); | ||
let cookie = Cookies.get(cookieName); | ||
let listMustBeSorted = false; | ||
|
||
if (cookie) { | ||
if (selectedIdps) { | ||
for (const idp of selectedIdps) { | ||
const id = getData(idp, 'entityid'); | ||
|
||
// check if idp is in cookie, if not remove it from the list | ||
if (cookie && cookie.indexOf(id) === -1) { | ||
idp.parentElement.remove(); | ||
listMustBeSorted = true; | ||
} | ||
} | ||
} | ||
|
||
cookie = JSON.parse(cookie); | ||
|
||
// check if each idp in the cookie is in the list, if not add it | ||
cookie.forEach(idp => { | ||
const id = `[data-entityid="${idp.idp}"]`; | ||
const inPreviouslySelected = document.querySelector(`${selectedIdpsSelector}${id}`); | ||
|
||
if (!inPreviouslySelected) { | ||
const deleteButtonTemplate = document.getElementById(deleteButtonTemplateId); | ||
const clone = document.querySelector(`${remainingIdpSelector}${id}`).parentElement.cloneNode(true); | ||
const hasDeleteDisabledButton = clone.querySelector(idpDeleteDisabledSelector); | ||
|
||
// disabled idps | ||
if (hasDeleteDisabledButton) { | ||
clone.querySelector(idpDeleteDisabledSelector).appendChild(deleteButtonTemplate.querySelector(idpDeleteSelector).cloneNode(true)); | ||
} | ||
|
||
// non-disabled idps | ||
if (!hasDeleteDisabledButton) { | ||
clone.querySelector(`.${idpContentClass}`).appendChild(deleteButtonTemplate.content.cloneNode(true)); | ||
} | ||
|
||
selectedIdpList.appendChild(clone); | ||
listMustBeSorted = true; | ||
} | ||
|
||
if (inPreviouslySelected) { | ||
const count = getData(inPreviouslySelected, 'count'); | ||
if (count !== idp.count) { | ||
inPreviouslySelected.setAttribute('data-count', idp.count); | ||
} | ||
} | ||
}); | ||
|
||
if (listMustBeSorted) { | ||
const selectedIdpLis = document.querySelectorAll(selectedIdpsLiSelector); | ||
sortIdpList(selectedIdpLis, 'previous'); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.