Skip to content

Commit

Permalink
refactor: add early return in getWitnessesHtmlEl()
Browse files Browse the repository at this point in the history
  • Loading branch information
malkja committed Oct 15, 2024
1 parent 0dc91d7 commit 76364d1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ export function getWitnessesHtmlEl(selector) {
// we aim to get the html element which contains the 'witnesses chips' related to the target.
// this html element which contains the 'witnesses chips' is located before the target element
const targetHtmlEl = document.querySelector(selector)
if(!targetHtmlEl) return null

const parentEl = targetHtmlEl.parentElement
const indexOfTarget = [].slice.call(parentEl.children).indexOf(targetHtmlEl)
if(indexOfTarget < 1) return null
const witnessesHtmlEl = parentEl.children[indexOfTarget-1]

return witnessesHtmlEl
Expand All @@ -315,6 +318,8 @@ export function getWitnessesHtmlEl(selector) {
export function getWitnessesList(witnessesHtml) {
// returns the list of witnesses(<string>) which are already selected
let witnessesList= []
if(Array.from(witnessesHtml.children).length === 0) return witnessesList;

Array.from(witnessesHtml.children).forEach((witnessHtml) => {
witnessesList.push(witnessHtml.innerHTML)
})
Expand Down

0 comments on commit 76364d1

Please sign in to comment.