Skip to content

Commit

Permalink
fix: search was broken due to missing corpuschooserchange event
Browse files Browse the repository at this point in the history
since last commit f3593d6
  • Loading branch information
arildm committed Nov 13, 2024
1 parent f3593d6 commit f948a2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
31 changes: 18 additions & 13 deletions app/scripts/components/corpus-chooser/corpus-chooser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,17 @@ angular.module("korpApp").component("corpusChooser", {
$ctrl.totalCount = $ctrl.root.numberOfChildren
$ctrl.totalNumberOfTokens = $ctrl.root.tokens
$ctrl.updateLimitedAccess()
select(corpusIds)
select(corpusIds, true)

// Sync when corpus selection is modified elsewhere.
$rootScope.$watch(
() => $location.search().corpus,
(corpusIdsComma) => {
const corpusIds = corpusIdsComma ? corpusIdsComma.split(",") : []
select(corpusIds)
}
)
$rootScope.$on("corpuschooserchange", (e, selected) => select(selected))
})

$ctrl.updateSelectedCount = (selection) => {
Expand Down Expand Up @@ -223,12 +233,17 @@ angular.module("korpApp").component("corpusChooser", {
}
}

function select(corporaIds: string[], quiet = false) {
function select(corporaIds: string[], force?: boolean) {
// Exit if no actual change
const selectedIds = settings.corpusListing.mapSelectedCorpora((corpus) => corpus.id)
if (!force && _.isEqual(corporaIds, selectedIds)) return

const selection = filterCorporaOnCredentials(
Object.values(settings.corpora),
corporaIds,
$ctrl.credentials
)

recalcFolderStatus($ctrl.root)
$ctrl.updateSelectedCount(selection)
// used when there is only one corpus selected to show name
Expand All @@ -237,20 +252,10 @@ angular.module("korpApp").component("corpusChooser", {
}

settings.corpusListing.select(selection)
$rootScope.$broadcast("corpuschooserchange", selection)
$location.search("corpus", selection.join(","))
}

// Sync when corpus selection is modified elsewhere.
$rootScope.$watch(
() => $location.search().corpus,
(corpusIdsComma) => {
const corpusIds = corpusIdsComma ? corpusIdsComma.split(",") : []
const selectedIds = settings.corpusListing.mapSelectedCorpora((corpus) => corpus.id)
if (!_.isEqual(corpusIds, selectedIds)) $rootScope.$broadcast("corpuschooserchange", corpusIds)
}
)
$rootScope.$on("corpuschooserchange", (e, selected) => select(selected, true))

$ctrl.onShowInfo = (node: ChooserFolderSub | CorpusTransformed) => {
$ctrl.showInfoBox = node.id != $ctrl.infoNode?.id
$ctrl.infoNode = $ctrl.showInfoBox ? node : undefined
Expand Down
5 changes: 0 additions & 5 deletions app/scripts/components/search-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ export default angular.module("korpApp").component("searchExamples", {
}

$ctrl.setSearch = (params: HashParams) => {
if (params.corpus) {
const corpora = params.corpus.split(",")
settings.corpusListing.select(corpora)
$rootScope.$broadcast("corpuschooserchange", corpora)
}
if (params.cqp) {
statemachine.send("SEARCH_CQP", { cqp: params.cqp })
}
Expand Down

0 comments on commit f948a2e

Please sign in to comment.