Skip to content

Commit f7f98c8

Browse files
committed
Enonic UI: Add Filter Panel component #4185
1 parent c1f7324 commit f7f98c8

18 files changed

+995
-212
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"fix": "eslint . --fix --cache"
2222
},
2323
"dependencies": {
24-
"@enonic/ui": "~0.12.0",
24+
"@enonic/ui": "~0.13.0",
2525
"dompurify": "~3.2.7",
2626
"fine-uploader": "^5.16.2",
2727
"jquery": "^3.7.1",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
export class Aggregation {
22

3-
private name: string;
3+
private readonly name: string;
44

5-
constructor(name: string) {
5+
private readonly displayName: string;
6+
7+
constructor(name: string, displayName?: string) {
68
this.name = name;
9+
this.displayName = displayName ?? name;
710
}
811

9-
public getName(): string {
12+
getName(): string {
1013
return this.name;
1114
}
1215

16+
getDisplayName(): string {
17+
return this.displayName;
18+
}
19+
1320
}

src/main/resources/assets/admin/common/js/aggregation/AggregationGroupView.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {BucketAggregationView} from './BucketAggregationView';
1+
import {BucketAggregationView} from '../ui2/BucketAggregationView';
22
import {AggregationSelection} from './AggregationSelection';
33
import {DivEl} from '../dom/DivEl';
4-
import {AggregationView} from './AggregationView';
54
import {H2El} from '../dom/H2El';
65
import {Aggregation} from './Aggregation';
76
import {Bucket} from './Bucket';
@@ -15,7 +14,7 @@ export class AggregationGroupView
1514

1615
private readonly displayName: string;
1716

18-
protected aggregationViews: AggregationView[] = [];
17+
protected aggregationViews: BucketAggregationView[] = [];
1918

2019
private titleEl: H2El = new H2El();
2120

@@ -39,7 +38,7 @@ export class AggregationGroupView
3938
// must be implemented by children
4039
}
4140

42-
getAggregationViews(): AggregationView[] {
41+
getAggregationViews(): BucketAggregationView[] {
4342
return this.aggregationViews;
4443
}
4544

@@ -61,8 +60,7 @@ export class AggregationGroupView
6160
const selectedBuckets: Bucket[] = bucketAggregationView.getSelectedValues();
6261

6362
if (selectedBuckets != null) {
64-
const aggregationSelection: AggregationSelection = new AggregationSelection(bucketAggregationView.getName());
65-
aggregationSelection.setValues(selectedBuckets);
63+
const aggregationSelection: AggregationSelection = new AggregationSelection(bucketAggregationView.getName(), selectedBuckets);
6664

6765
aggregationSelections.push(aggregationSelection);
6866
}
@@ -83,7 +81,7 @@ export class AggregationGroupView
8381
}
8482

8583
deselectGroup(supressEvent?: boolean) {
86-
this.aggregationViews.forEach((aggregationView: AggregationView) => {
84+
this.aggregationViews.forEach((aggregationView: BucketAggregationView) => {
8785
aggregationView.deselectFacet(supressEvent);
8886
});
8987
}
@@ -104,24 +102,24 @@ export class AggregationGroupView
104102
}
105103

106104
update(aggregations: Aggregation[]) {
107-
aggregations.forEach((aggregation: Aggregation) => {
108-
const aggregationView: AggregationView =
105+
aggregations.forEach((aggregation: BucketAggregation) => {
106+
const aggregationView =
109107
this.getAggregationView(aggregation.getName()) || this.addAggregationView(aggregation);
110108

111109
aggregationView.update(aggregation);
112110
});
113111
}
114112

115-
private addAggregationView(aggregation: Aggregation): AggregationView {
116-
const aggregationView: AggregationView = this.createAggregationView(aggregation);
113+
private addAggregationView(aggregation: Aggregation): BucketAggregationView {
114+
const aggregationView = this.createAggregationView(aggregation);
117115

118116
this.appendChild(aggregationView);
119117
this.aggregationViews.push(aggregationView);
120118

121119
return aggregationView;
122120
}
123121

124-
protected createAggregationView(aggregation: Aggregation): AggregationView {
122+
protected createAggregationView(aggregation: Aggregation): BucketAggregationView {
125123
if (aggregation instanceof BucketAggregation) {
126124
const bucketAggregationView: BucketAggregationView = new BucketAggregationView(aggregation);
127125

@@ -135,7 +133,7 @@ export class AggregationGroupView
135133
}
136134
}
137135

138-
private getAggregationView(name: string): AggregationView {
139-
return this.aggregationViews.find((aggregationView: AggregationView) => aggregationView.getName() === name);
136+
private getAggregationView(name: string): BucketAggregationView {
137+
return this.aggregationViews.find((aggregationView) => aggregationView.getName() === name);
140138
}
141139
}

src/main/resources/assets/admin/common/js/aggregation/AggregationSelection.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import {Bucket} from './Bucket';
22

33
export class AggregationSelection {
44

5-
name: string;
6-
selectedBuckets: Bucket[];
5+
private readonly name: string;
6+
private readonly selectedBuckets: Bucket[];
77

8-
constructor(name: string) {
8+
constructor(name: string, selectedBuckets: Bucket[]) {
99
this.name = name;
10-
}
11-
12-
public setValues(selectedBuckets: Bucket[]) {
1310
this.selectedBuckets = selectedBuckets;
1411
}
1512

src/main/resources/assets/admin/common/js/aggregation/BucketAggregation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {i18n} from '../util/Messages';
12
import {Bucket} from './Bucket';
23
import {BucketAggregationJson} from './BucketAggregationJson';
34
import {BucketWrapperJson} from './BucketWrapperJson';
@@ -32,7 +33,7 @@ export class BucketAggregation
3233

3334
public static fromJson(json: BucketAggregationJson): BucketAggregation {
3435

35-
let bucketAggregation: BucketAggregation = new BucketAggregation(json.name);
36+
let bucketAggregation: BucketAggregation = new BucketAggregation(json.name, i18n(`field.${json.name}`));
3637

3738
json.buckets.forEach((bucketWrapper: BucketWrapperJson) => {
3839
bucketAggregation.addBucket(BucketFactory.createFromJson(bucketWrapper));

src/main/resources/assets/admin/common/js/aggregation/BucketAggregationView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class BucketAggregationView
106106
protected addBucketView(bucketView: BucketView): void {
107107
bucketView.onSelectionChanged((event: BucketViewSelectionChangedEvent) => {
108108
const bucketSelection: SelectionChange<Bucket> = {selected: [], deselected: []};
109-
const bucket: Bucket = event.getBucketView().getBucket();
109+
const bucket: Bucket = event.getBucket();
110110

111111
if (event.getNewValue()) {
112112
bucketSelection.selected.push(bucket);

src/main/resources/assets/admin/common/js/aggregation/BucketView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class BucketView
2727
label: this.resolveLabelValue(),
2828
onCheckedChange: (checked) => {
2929
const isChecked = checked === true;
30-
const event = new BucketViewSelectionChangedEvent(!isChecked, isChecked, this);
30+
const event = new BucketViewSelectionChangedEvent(!isChecked, isChecked, this.getBucket());
3131
this.selectionChangedListeners.forEach(l => l(event));
3232
}
3333
});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {BucketView} from './BucketView';
1+
import {Bucket} from './Bucket';
22

33
export class BucketViewSelectionChangedEvent {
44

55
private oldValue: boolean;
66

77
private newValue: boolean;
88

9-
private bucketView: BucketView;
9+
private bucket: Bucket;
1010

11-
constructor(oldValue: boolean, newValue: boolean, bucketView: BucketView) {
11+
constructor(oldValue: boolean, newValue: boolean, bucket: Bucket) {
1212
this.oldValue = oldValue;
1313
this.newValue = newValue;
14-
this.bucketView = bucketView;
14+
this.bucket = bucket;
1515
}
1616

1717
getOldValue(): boolean {
@@ -22,7 +22,7 @@ export class BucketViewSelectionChangedEvent {
2222
return this.newValue;
2323
}
2424

25-
getBucketView(): BucketView {
26-
return this.bucketView;
25+
getBucket(): Bucket {
26+
return this.bucket;
2727
}
2828
}

src/main/resources/assets/admin/common/js/aggregation/BucketsContainer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {DivEl} from '../dom/DivEl';
2-
import {BucketView} from './BucketView';
32
import {Button} from '../ui/button/Button';
3+
import {BucketView} from '../ui2/BucketView';
44
import {i18n} from '../util/Messages';
55

66
export class BucketsContainer

0 commit comments

Comments
 (0)