-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathadmin-filter.js
More file actions
87 lines (72 loc) · 2.04 KB
/
admin-filter.js
File metadata and controls
87 lines (72 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
/**
<AdminFilter
@filterName={{string}}
@onUpdate={{function}}
/>
Admin filter expects the subOptions to be an object with the following structure:
{
val1: {type: 'list', inputId, maxItems, ...},
val2: {type: 'checkbox', options: [{value, icon, label}, {value, icon, label, etc...]}
*/
export default class AdminFilterComponent extends Component {
@service('utility-methods') utils;
@service inputState;
@tracked dropdownSelections = [];
get initialMainSelection() {
return [this.mainOptions?.[0]?.value ?? null];
}
get hasCurrentSelections() {
return this.dropdownSelections.length > 0;
}
get mainOptions() {
return this.inputState.getOptions(this.args.filterName);
}
get mainSelection() {
return this.inputState.getSelection(this.args.filterName);
}
get subOptions() {
return this.inputState.getSubOptions(this.args.filterName);
}
get subSelections() {
return this.inputState.getSubSelections(this.args.filterName);
}
@action
handleUpdateMain(val) {
this.inputState.setSelection(this.args.filterName, val);
this.dropdownSelections = [];
if (this.args.onUpdate) {
this.args.onUpdate();
}
}
@action
updateMultiSelect(val, $item) {
if (!val) return;
const isRemoval = !$item;
if (isRemoval) {
this.dropdownSelections = this.dropdownSelections.filter(
(item) => item !== val
);
} else {
this.dropdownSelections = [...this.dropdownSelections, val];
}
this.inputState.setListState(this.args.filterName, this.dropdownSelections);
if (this.args.onUpdate) {
this.args.onUpdate();
}
}
@action
toggleSubOption(option) {
this.inputState.setSubSelection(
this.args.filterName,
option.value,
!this.subSelections.includes(option.value)
);
if (this.args.onUpdate) {
this.args.onUpdate();
}
}
}