Skip to content

Commit e25fc01

Browse files
authored
Merge pull request #8803 from jrjohnson/6458-missing-badges
Hide Unmatched Sessions in Search
2 parents d86ab7c + bca9419 commit e25fc01

2 files changed

Lines changed: 101 additions & 42 deletions

File tree

packages/frontend/app/components/course-search-result.gjs

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import FaIcon from 'ilios-common/components/fa-icon';
1212
export default class CourseSearchResultComponent extends Component {
1313
@tracked showMore = false;
1414

15-
get sessions() {
15+
get filteredSessions() {
1616
const { sessions } = this.args.course;
17-
return this.showMore ? sessions : sessions.slice(0, 3);
17+
return sessions.filter((s) => s.matchedIn.length);
18+
}
19+
20+
get sessions() {
21+
return this.showMore ? this.filteredSessions : this.filteredSessions.slice(0, 3);
1822
}
1923
<template>
2024
<li class="course-search-result" data-test-course-search-result ...attributes>
@@ -29,48 +33,50 @@ export default class CourseSearchResultComponent extends Component {
2933
{{t "general.course"}}
3034
</span>
3135
<GlobalSearchTags @tags={{@course.matchedIn}} />
32-
<ul>
33-
<li class="sessions">
34-
{{t "general.sessions"}}:
35-
</li>
36-
{{#each this.sessions as |session|}}
37-
<li class="session-row">
38-
<LinkTo
39-
@route="session"
40-
@models={{array @course.id session.id}}
41-
class="session-title-link"
42-
>
43-
{{session.title}}
44-
</LinkTo>
45-
<GlobalSearchTags @tags={{session.matchedIn}} />
36+
{{#if this.sessions}}
37+
<ul>
38+
<li class="sessions">
39+
{{t "general.sessions"}}:
4640
</li>
47-
{{/each}}
48-
{{#if (gt @course.sessions.length 3)}}
49-
{{#if this.showMore}}
50-
<li>
51-
<button
52-
class="show-less link-button"
53-
type="button"
54-
{{on "click" (set this "showMore" false)}}
55-
>
56-
<FaIcon @icon="angle-up" />
57-
{{t "general.showLess"}}
58-
</button>
59-
</li>
60-
{{else}}
61-
<li>
62-
<button
63-
class="show-more link-button"
64-
type="button"
65-
{{on "click" (set this "showMore" true)}}
41+
{{#each this.sessions as |session|}}
42+
<li class="session-row">
43+
<LinkTo
44+
@route="session"
45+
@models={{array @course.id session.id}}
46+
class="session-title-link"
6647
>
67-
<FaIcon @icon="angle-down" />
68-
{{t "general.showMore"}}
69-
</button>
48+
{{session.title}}
49+
</LinkTo>
50+
<GlobalSearchTags @tags={{session.matchedIn}} />
7051
</li>
52+
{{/each}}
53+
{{#if (gt this.filteredSessions.length 3)}}
54+
{{#if this.showMore}}
55+
<li>
56+
<button
57+
class="show-less link-button"
58+
type="button"
59+
{{on "click" (set this "showMore" false)}}
60+
>
61+
<FaIcon @icon="angle-up" />
62+
{{t "general.showLess"}}
63+
</button>
64+
</li>
65+
{{else}}
66+
<li>
67+
<button
68+
class="show-more link-button"
69+
type="button"
70+
{{on "click" (set this "showMore" true)}}
71+
>
72+
<FaIcon @icon="angle-down" />
73+
{{t "general.showMore"}}
74+
</button>
75+
</li>
76+
{{/if}}
7177
{{/if}}
72-
{{/if}}
73-
</ul>
78+
</ul>
79+
{{/if}}
7480
</li>
7581
</template>
7682
}

packages/frontend/tests/integration/components/course-search-result-test.gjs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,27 @@ module('Integration | Component | course-search-result', function (hooks) {
1919
{
2020
id: 1,
2121
title: 'Session 1',
22+
matchedIn: ['title'],
2223
},
2324
{
2425
id: 2,
2526
title: 'Session 2',
27+
matchedIn: ['title'],
2628
},
2729
{
2830
id: 3,
2931
title: 'Session 3',
32+
matchedIn: [],
3033
},
3134
{
3235
id: 4,
3336
title: 'Session 4',
37+
matchedIn: ['title'],
38+
},
39+
{
40+
id: 4,
41+
title: 'Session 5',
42+
matchedIn: ['title'],
3443
},
3544
],
3645
};
@@ -40,7 +49,7 @@ module('Integration | Component | course-search-result', function (hooks) {
4049
assert.strictEqual(component.schoolTitle, 'Medicine');
4150
assert.strictEqual(component.sessions[0].text, 'Session 1');
4251
assert.strictEqual(component.sessions[1].text, 'Session 2');
43-
assert.strictEqual(component.sessions[2].text, 'Session 3');
52+
assert.strictEqual(component.sessions[2].text, 'Session 4');
4453
assert.strictEqual(component.sessions.length, 3);
4554

4655
assert.notOk(component.showLessIsVisible);
@@ -49,12 +58,56 @@ module('Integration | Component | course-search-result', function (hooks) {
4958

5059
assert.ok(component.showLessIsVisible);
5160
assert.notOk(component.showMoreIsVisible);
52-
assert.strictEqual(component.sessions[3].text, 'Session 4');
61+
assert.strictEqual(component.sessions[3].text, 'Session 5');
5362
assert.strictEqual(component.sessions.length, 4);
5463

5564
await component.showLess();
5665
assert.notOk(component.showLessIsVisible);
5766
assert.ok(component.showMoreIsVisible);
5867
assert.strictEqual(component.sessions.length, 3);
5968
});
69+
70+
test('no show more link when sessions are filtered out', async function (assert) {
71+
assert.expect(8);
72+
73+
const course = {
74+
id: 1,
75+
title: 'Course 1',
76+
school: 'Medicine',
77+
year: '1980',
78+
sessions: [
79+
{
80+
id: 1,
81+
title: 'Session 1',
82+
matchedIn: ['title'],
83+
},
84+
{
85+
id: 2,
86+
title: 'Session 2',
87+
matchedIn: ['title'],
88+
},
89+
{
90+
id: 3,
91+
title: 'Session 3',
92+
matchedIn: [],
93+
},
94+
{
95+
id: 4,
96+
title: 'Session 4',
97+
matchedIn: ['title'],
98+
},
99+
],
100+
};
101+
this.set('course', course);
102+
await render(<template><CourseSearchResult @course={{this.course}} /></template>);
103+
assert.strictEqual(component.courseTitle, '1980 Course 1');
104+
assert.strictEqual(component.schoolTitle, 'Medicine');
105+
assert.strictEqual(component.sessions[0].text, 'Session 1');
106+
assert.strictEqual(component.sessions[1].text, 'Session 2');
107+
assert.strictEqual(component.sessions[2].text, 'Session 4');
108+
assert.strictEqual(component.sessions.length, 3);
109+
110+
assert.notOk(component.showLessIsVisible);
111+
assert.notOk(component.showMoreIsVisible);
112+
});
60113
});

0 commit comments

Comments
 (0)