Some code cleanup and frontend bug fix

d5489c5d908b0c9023eab65a314c0d92bee53111

Tucker McKnight <tmcknight@instructure.com> | Sat Jun 20 2026

Some code cleanup and frontend bug fix

DRY up the search results function. Also, I had not yet changed
the frontend call to also include the reltype, so there was a bug
when switching between the name and date filters radio buttons.
frontend/main.js:100
Before
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

const dropdownBranchesAndTagsList = document.getElementById('branches-and-tags-list')

const searchBox = document.getElementById('dropdownBranchSearch')

searchBox?.addEventListener('input', (event) => {
  const searchTerm = event.target.value
  let branches = window.branchesWithHrefs.branches.filter((branch) => {
    return branch.name.includes(searchTerm)
  })
  let tags = window.branchesWithHrefs.tags.filter((tag) => {
    return tag.name.includes(searchTerm)
  })

  dropdownBranchesAndTagsList.innerHTML = branchesAndTagsResults({branches, tags}, window.defaultBranch, window.currentBranch, sortDirection)
})

const dropdownTabs = document.querySelector('.rel-dropdown')
const dropdownTabsNavLinks = document.querySelectorAll('.rel-dropdown .nav-link')
dropdownTabsNavLinks.forEach((element) => {
After
99
100
101














102
103

const dropdownBranchesAndTagsList = document.getElementById('branches-and-tags-list')

⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
const dropdownTabs = document.querySelector('.rel-dropdown')
const dropdownTabsNavLinks = document.querySelectorAll('.rel-dropdown .nav-link')
dropdownTabsNavLinks.forEach((element) => {
frontend/main.js:127
Before
126
127
128
129



130
131
132
133
134



135

136
137
138



139
140

let sortDirection = document.querySelector("[name=branchSort]:checked")?.value || 'date'

const showBranchesResults = (searchTerm) => {
⁣
⁣
⁣
  let branches = window.branchesWithHrefs.branches.filter((branch) => {
    return branch.name.includes(searchTerm)
  })
  let tags = window.branchesWithHrefs.tags.filter((tag) => {
    return tag.name.includes(searchTerm)
⁣
⁣
⁣
  })
⁣
  dropdownBranchesAndTagsList.innerHTML = branchesListItems({branches, tags}, window.defaultBranch, window.currentBranch, sortDirection)
}

⁣
⁣
⁣
document.querySelectorAll('.sort-filter').forEach((element) => {
  element.addEventListener('change', (event) => {
    sortDirection = event.target.value
After
126
127
128
129
130
131
132


133

134
135
136
137
138
139
140
141
142
143
144
145
146
147

let sortDirection = document.querySelector("[name=branchSort]:checked")?.value || 'date'

const getSearchTermResults = (searchTerm) => {
  const allRefs = window.branchesWithHrefs

  return {
⁣
⁣
    branches: allRefs.branches.filter(branch => branch.name.includes(searchTerm)),    tags: allRefs.tags.filter(tag => tag.name.includes(searchTerm))
  }
}

const showBranchesResults = (searchTerm) => {
  const results = getSearchTermResults(searchTerm)
  dropdownBranchesAndTagsList.innerHTML = branchesAndTagsResults(results, window.defaultBranch, window.currentRef, window.currentRefType, sortDirection)
}

const searchBox = document.getElementById('dropdownBranchSearch')

// .sort-filter elements are the radio buttons for sorting by Name or Date
document.querySelectorAll('.sort-filter').forEach((element) => {
  element.addEventListener('change', (event) => {
    sortDirection = event.target.value
frontend/main.js:144
Before
143
144
145





146
147
  })
})

⁣
⁣
⁣
⁣
⁣
const bootstrap = window.bootstrap
const jsVars = window.jsVars
window.popovers ||= []
After
143
144
145
146
147
148
149
150
151
152
  })
})

searchBox?.addEventListener('input', (event) => {
  const searchTerm = event.target.value
  showBranchesResults(searchTerm)
})

const bootstrap = window.bootstrap
const jsVars = window.jsVars
window.popovers ||= []
js_templates/common/htmlPage.ts:46
Before
45
46
47
48

49
50
      m('script', m.trust(`
        window.branchesWithHrefs = ${JSON.stringify(branchesWithHrefs)};
        window.defaultBranch = "${repo.defaultBranch}";
        window.currentBranch = "${ref.name}";
⁣
        window.cloneUrl = "${repo.cloneUrl}";
      `)),
      m('link', {
After
45
46
47
48
49
50
51
      m('script', m.trust(`
        window.branchesWithHrefs = ${JSON.stringify(branchesWithHrefs)};
        window.defaultBranch = "${repo.defaultBranch}";
        window.currentRef = "${ref.name}";
        window.currentRefType = "${ref.type}";
        window.cloneUrl = "${repo.cloneUrl}";
      `)),
      m('link', {