Skip to content

Commit

Permalink
Merge pull request guardian#4319 from bbc/t1837-restrictions-text-foc…
Browse files Browse the repository at this point in the history
…us-bug

Fix issue that led to restrictions textarea in metadata editor to lose focus on data input
  • Loading branch information
andrew-nowak authored Aug 19, 2024
2 parents 665422e + 5550269 commit 2fe757c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions kahuna/public/js/usage-rights/usage-rights-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ usageRightsEditor.controller(
const usageRights$ = observe$($scope, () => ctrl.usageRights);

// @return Stream.<Array.<Category>>
const categories$ = Rx.Observable.fromPromise(editsApi.getUsageRightsCategories());
const allCategories$ = Rx.Observable.fromPromise(editsApi.getUsageRightsCategories());
const filteredCategories$ = Rx.Observable.fromPromise(editsApi.getFilteredUsageRightsCategories());

// @return Stream.<Array.<Category>>
const displayCategories$ = usageRights$.combineLatest(filteredCategories$, categories$, (urs, filCats, allCats) => {
const categories$ = usageRights$.combineLatest(filteredCategories$, allCategories$, (urs, filCats, allCats) => {
const uniqueCats = getUniqueCats(urs);
if (uniqueCats.length === 1) {
if (allCats.length === filCats.length) {
return allCats;
}
const mtchCats = filCats.filter(c => c.value === uniqueCats[0]);
const extraCats = allCats.filter(c => c.value === uniqueCats[0]);
if (mtchCats.length === 0 && extraCats.length === 1) {
Expand All @@ -52,7 +53,17 @@ usageRightsEditor.controller(
return filCats;
}
} else {
return [multiCat].concat(filCats);
return filCats;
}
});

// @return Stream.<Array.<Category>>
const displayCategories$ = usageRights$.combineLatest(categories$, (urs, cats) => {
const uniqueCats = getUniqueCats(urs);
if (uniqueCats.length === 1) {
return cats;
} else {
return [multiCat].concat(cats);
}
});

Expand Down

0 comments on commit 2fe757c

Please sign in to comment.