Skip to content

Commit 58cc9e5

Browse files
authored
fix: 🐛 Fix filters sometimes not being displayed (#3050)
One of the changes that was made was not retrieving all resources for the dropdown filters. This had an unintended consequence when displaying the selected filters as it's possible for the selected filter to not be in the list of allFilters. There's two main scenarios this happens (the prerequisite is having more filter options than we display which is 250): * When filtering down the dropdown filters which means it might not be in the allFilters options. This was fixed by keeping track of all the searched options to be able to display. * A user uses a query string or bookmarked a URL and goes to it directly. If the option isn't in the initial load, we won't have the actual option. In this case, I changed it to at least just display the ID instead of not showing up at all. Otherwise I'd have to load these selected options separately from the initial load which doesn't seem worth for this edge case.
1 parent 189a453 commit 58cc9e5

File tree

3 files changed

+52
-13
lines changed
  • addons/core
  • ui/admin/app/controllers/scopes/scope/session-recordings

3 files changed

+52
-13
lines changed

addons/core/addon/components/filter-tags/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,27 @@ export default class FilterTagsIndexComponent extends Component {
1717

1818
get filters() {
1919
const { allFilters, selectedFilters } = this.args.filters;
20-
return Object.entries(allFilters).flatMap(([key, value]) => {
21-
assert(`Tags must be an array for key ${key}`, Array.isArray(value));
22-
const paramsSet = new Set(selectedFilters[key]);
23-
const filters = value.filter((item) => paramsSet.has(item.id));
20+
return Object.entries(allFilters).flatMap(([key, values]) => {
21+
assert(`Tags must be an array for key ${key}`, Array.isArray(values));
22+
const uniqueSelectedFilters = [...new Set(selectedFilters[key])];
23+
if (!uniqueSelectedFilters.length) {
24+
return [];
25+
}
2426

25-
return filters.map((item) => ({
26-
id: item.id,
27-
name: item.name,
28-
type: key,
29-
}));
27+
const valueMap = new Map(values.map((value) => [value.id, value.name]));
28+
29+
return uniqueSelectedFilters.filter(Boolean).map((item) => {
30+
const filter = {
31+
id: item,
32+
type: key,
33+
};
34+
35+
if (valueMap.has(item)) {
36+
filter.name = valueMap.get(item);
37+
}
38+
39+
return filter;
40+
});
3041
});
3142
}
3243

addons/core/tests/integration/components/filter-tags/index-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ module('Integration | Component | filter-tags/index', function (hooks) {
2222

2323
assert.dom('.hds-tag__text').hasText('Project 1');
2424
});
25+
26+
test('it renders id if allFilter does not have corresponding value', async function (assert) {
27+
this.set('filter', {
28+
allFilters: { scopes: [{ id: '2', name: 'Project 2' }] },
29+
selectedFilters: { scopes: ['1'] },
30+
});
31+
await render(hbs`<FilterTags @filters={{this.filter}} />`);
32+
33+
assert.dom('.hds-tag__text').hasText('1');
34+
});
2535
});

ui/admin/app/controllers/scopes/scope/session-recordings/index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,25 @@ import { restartableTask } from 'ember-concurrency';
1212

1313
class FilterOptions {
1414
@tracked search;
15-
@tracked options = [];
15+
@tracked _options = [];
16+
#allOptions = new Map();
17+
18+
get options() {
19+
return this._options;
20+
}
21+
22+
set options(newOptions) {
23+
this._options = newOptions;
24+
newOptions.forEach((option) => {
25+
this.#allOptions.set(option.id, option);
26+
});
27+
}
28+
29+
// Keep track of all filter options that are loaded so they can be
30+
// displayed in the selected filters regardless of search input
31+
get allOptions() {
32+
return Array.from(this.#allOptions.values());
33+
}
1634
}
1735

1836
export default class ScopesScopeSessionRecordingsIndexController extends Controller {
@@ -60,9 +78,9 @@ export default class ScopesScopeSessionRecordingsIndexController extends Control
6078
return {
6179
allFilters: {
6280
time: this.timeOptions,
63-
users: this.userFilters.options,
64-
scopes: this.scopeFilters.options,
65-
targets: this.targetFilters.options,
81+
users: this.userFilters.allOptions,
82+
scopes: this.scopeFilters.allOptions,
83+
targets: this.targetFilters.allOptions,
6684
},
6785
selectedFilters: {
6886
time: [this.time],

0 commit comments

Comments
 (0)