Skip to content

Commit 2fe757c

Browse files
authored
Merge pull request guardian#4319 from bbc/t1837-restrictions-text-focus-bug
Fix issue that led to restrictions textarea in metadata editor to lose focus on data input
2 parents 665422e + 5550269 commit 2fe757c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

kahuna/public/js/usage-rights/usage-rights-editor.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ usageRightsEditor.controller(
3737
const usageRights$ = observe$($scope, () => ctrl.usageRights);
3838

3939
// @return Stream.<Array.<Category>>
40-
const categories$ = Rx.Observable.fromPromise(editsApi.getUsageRightsCategories());
40+
const allCategories$ = Rx.Observable.fromPromise(editsApi.getUsageRightsCategories());
4141
const filteredCategories$ = Rx.Observable.fromPromise(editsApi.getFilteredUsageRightsCategories());
42-
43-
// @return Stream.<Array.<Category>>
44-
const displayCategories$ = usageRights$.combineLatest(filteredCategories$, categories$, (urs, filCats, allCats) => {
42+
const categories$ = usageRights$.combineLatest(filteredCategories$, allCategories$, (urs, filCats, allCats) => {
4543
const uniqueCats = getUniqueCats(urs);
4644
if (uniqueCats.length === 1) {
45+
if (allCats.length === filCats.length) {
46+
return allCats;
47+
}
4748
const mtchCats = filCats.filter(c => c.value === uniqueCats[0]);
4849
const extraCats = allCats.filter(c => c.value === uniqueCats[0]);
4950
if (mtchCats.length === 0 && extraCats.length === 1) {
@@ -52,7 +53,17 @@ usageRightsEditor.controller(
5253
return filCats;
5354
}
5455
} else {
55-
return [multiCat].concat(filCats);
56+
return filCats;
57+
}
58+
});
59+
60+
// @return Stream.<Array.<Category>>
61+
const displayCategories$ = usageRights$.combineLatest(categories$, (urs, cats) => {
62+
const uniqueCats = getUniqueCats(urs);
63+
if (uniqueCats.length === 1) {
64+
return cats;
65+
} else {
66+
return [multiCat].concat(cats);
5667
}
5768
});
5869

0 commit comments

Comments
 (0)