@empathyco/x-components 3.0.0-alpha.342 → 3.0.0-alpha.343
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/design-system/full-theme.css +43 -44
- package/docs/API-reference/api/x-components.defaultfacetsservice.clearfilters.md +2 -1
- package/docs/API-reference/api/x-components.defaultfacetsservice.clearfilterswithmetadata.md +25 -0
- package/docs/API-reference/api/x-components.defaultfacetsservice.deselect.md +2 -1
- package/docs/API-reference/api/x-components.defaultfacetsservice.md +3 -2
- package/docs/API-reference/api/x-components.facetsmutations.clearstickyfilters.md +17 -0
- package/docs/API-reference/api/x-components.facetsmutations.md +3 -0
- package/docs/API-reference/api/x-components.facetsmutations.removestickyfilter.md +24 -0
- package/docs/API-reference/api/x-components.facetsmutations.setstickyfilter.md +24 -0
- package/docs/API-reference/api/x-components.facetsservice.clearfilters.md +2 -1
- package/docs/API-reference/api/x-components.facetsservice.clearfilterswithmetadata.md +27 -0
- package/docs/API-reference/api/x-components.facetsservice.deselect.md +2 -1
- package/docs/API-reference/api/x-components.facetsservice.md +4 -3
- package/docs/API-reference/api/x-components.facetsservice.selectpreselectedfilters.md +1 -1
- package/docs/API-reference/api/x-components.facetsstate.md +1 -0
- package/docs/API-reference/api/x-components.facetsstate.stickyfilters.md +13 -0
- package/docs/API-reference/api/x-components.filtersmetadata.keepsticky.md +13 -0
- package/docs/API-reference/api/x-components.filtersmetadata.md +20 -0
- package/docs/API-reference/api/x-components.md +1 -0
- package/js/x-modules/facets/entities/single-select.modifier.js +1 -1
- package/js/x-modules/facets/entities/single-select.modifier.js.map +1 -1
- package/js/x-modules/facets/entities/types.js +3 -2
- package/js/x-modules/facets/entities/types.js.map +1 -1
- package/js/x-modules/facets/service/facets.service.js +7 -4
- package/js/x-modules/facets/service/facets.service.js.map +1 -1
- package/js/x-modules/facets/store/getters/selected-filters.getter.js +10 -1
- package/js/x-modules/facets/store/getters/selected-filters.getter.js.map +1 -1
- package/js/x-modules/facets/store/module.js +13 -1
- package/js/x-modules/facets/store/module.js.map +1 -1
- package/js/x-modules/facets/wiring.js +25 -4
- package/js/x-modules/facets/wiring.js.map +1 -1
- package/js/x-modules/search/store/module.js +1 -1
- package/js/x-modules/search/store/module.js.map +1 -1
- package/package.json +2 -2
- package/report/x-components.api.json +440 -11
- package/report/x-components.api.md +33 -13
- package/types/x-modules/facets/entities/sticky.modifier.d.ts +32 -0
- package/types/x-modules/facets/entities/sticky.modifier.d.ts.map +1 -0
- package/types/x-modules/facets/entities/types.d.ts +10 -7
- package/types/x-modules/facets/entities/types.d.ts.map +1 -1
- package/types/x-modules/facets/service/facets.service.d.ts +8 -3
- package/types/x-modules/facets/service/facets.service.d.ts.map +1 -1
- package/types/x-modules/facets/service/types.d.ts +25 -3
- package/types/x-modules/facets/service/types.d.ts.map +1 -1
- package/types/x-modules/facets/store/getters/selected-filters.getter.d.ts.map +1 -1
- package/types/x-modules/facets/store/module.d.ts.map +1 -1
- package/types/x-modules/facets/store/types.d.ts +19 -0
- package/types/x-modules/facets/store/types.d.ts.map +1 -1
- package/types/x-modules/facets/wiring.d.ts +18 -15
- package/types/x-modules/facets/wiring.d.ts.map +1 -1
- package/types/x-modules/search/store/module.d.ts +0 -1
- package/types/x-modules/search/store/module.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.0-alpha.343](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.342...@empathyco/x-components@3.0.0-alpha.343) (2023-03-31)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add sticky filters (#1113)
|
|
11
|
+
([3b51b60](https://github.com/empathyco/x/commit/3b51b6045a283f9f27dd7c6e16dec7f68a8a2921)),
|
|
12
|
+
closes [EX-8076](https://searchbroker.atlassian.net/browse/EX-8076)
|
|
13
|
+
|
|
14
|
+
# Change Log
|
|
15
|
+
|
|
16
|
+
All notable changes to this project will be documented in this file. See
|
|
17
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
18
|
+
|
|
6
19
|
## [3.0.0-alpha.342](https://github.com/empathyco/x/compare/@empathyco/x-components@3.0.0-alpha.341...@empathyco/x-components@3.0.0-alpha.342) (2023-03-30)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @empathyco/x-components
|
|
@@ -4669,6 +4669,49 @@
|
|
|
4669
4669
|
.x-fill--transparent {
|
|
4670
4670
|
fill: var(--x-color-base-transparent) !important;
|
|
4671
4671
|
}
|
|
4672
|
+
.x-flex-1 {
|
|
4673
|
+
flex: 1 1 0% !important;
|
|
4674
|
+
}
|
|
4675
|
+
|
|
4676
|
+
.x-flex-auto {
|
|
4677
|
+
flex: 1 1 auto !important;
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
.x-flex-initial {
|
|
4681
|
+
flex: 0 1 auto !important;
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
.x-flex-no-shrink {
|
|
4685
|
+
flex: 1 0 auto !important;
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4688
|
+
.x-flex-none {
|
|
4689
|
+
flex: none !important;
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4692
|
+
.x-self-auto {
|
|
4693
|
+
align-self: auto !important;
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
.x-self-start {
|
|
4697
|
+
align-self: flex-start !important;
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4700
|
+
.x-self-end {
|
|
4701
|
+
align-self: flex-end !important;
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4704
|
+
.x-self-center {
|
|
4705
|
+
align-self: center !important;
|
|
4706
|
+
}
|
|
4707
|
+
|
|
4708
|
+
.x-self-stretch {
|
|
4709
|
+
align-self: stretch !important;
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4712
|
+
.x-self-baseline {
|
|
4713
|
+
align-self: baseline !important;
|
|
4714
|
+
}
|
|
4672
4715
|
.x-line-clamp--2 {
|
|
4673
4716
|
overflow: hidden !important;
|
|
4674
4717
|
display: -webkit-box !important;
|
|
@@ -5625,47 +5668,3 @@
|
|
|
5625
5668
|
.x-sticky {
|
|
5626
5669
|
position: sticky !important;
|
|
5627
5670
|
}
|
|
5628
|
-
|
|
5629
|
-
.x-flex-1 {
|
|
5630
|
-
flex: 1 1 0% !important;
|
|
5631
|
-
}
|
|
5632
|
-
|
|
5633
|
-
.x-flex-auto {
|
|
5634
|
-
flex: 1 1 auto !important;
|
|
5635
|
-
}
|
|
5636
|
-
|
|
5637
|
-
.x-flex-initial {
|
|
5638
|
-
flex: 0 1 auto !important;
|
|
5639
|
-
}
|
|
5640
|
-
|
|
5641
|
-
.x-flex-no-shrink {
|
|
5642
|
-
flex: 1 0 auto !important;
|
|
5643
|
-
}
|
|
5644
|
-
|
|
5645
|
-
.x-flex-none {
|
|
5646
|
-
flex: none !important;
|
|
5647
|
-
}
|
|
5648
|
-
|
|
5649
|
-
.x-self-auto {
|
|
5650
|
-
align-self: auto !important;
|
|
5651
|
-
}
|
|
5652
|
-
|
|
5653
|
-
.x-self-start {
|
|
5654
|
-
align-self: flex-start !important;
|
|
5655
|
-
}
|
|
5656
|
-
|
|
5657
|
-
.x-self-end {
|
|
5658
|
-
align-self: flex-end !important;
|
|
5659
|
-
}
|
|
5660
|
-
|
|
5661
|
-
.x-self-center {
|
|
5662
|
-
align-self: center !important;
|
|
5663
|
-
}
|
|
5664
|
-
|
|
5665
|
-
.x-self-stretch {
|
|
5666
|
-
align-self: stretch !important;
|
|
5667
|
-
}
|
|
5668
|
-
|
|
5669
|
-
.x-self-baseline {
|
|
5670
|
-
align-self: baseline !important;
|
|
5671
|
-
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
**Signature:**
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
clearFilters(facetIds?: Array<Facet['id']
|
|
10
|
+
clearFilters(facetIds?: Array<Facet['id']>, metadata?: FiltersMetadata): void;
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
@@ -15,6 +15,7 @@ clearFilters(facetIds?: Array<Facet['id']>): void;
|
|
|
15
15
|
| Parameter | Type | Description |
|
|
16
16
|
| --- | --- | --- |
|
|
17
17
|
| facetIds | Array<Facet\['id'\]> | _(Optional)_ |
|
|
18
|
+
| metadata | [FiltersMetadata](./x-components.filtersmetadata.md) | _(Optional)_ |
|
|
18
19
|
|
|
19
20
|
**Returns:**
|
|
20
21
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [DefaultFacetsService](./x-components.defaultfacetsservice.md) > [clearFiltersWithMetadata](./x-components.defaultfacetsservice.clearfilterswithmetadata.md)
|
|
4
|
+
|
|
5
|
+
## DefaultFacetsService.clearFiltersWithMetadata() method
|
|
6
|
+
|
|
7
|
+
**Signature:**
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
clearFiltersWithMetadata({ facetIds, metadata }?: {
|
|
11
|
+
facetIds?: Array<Facet['id']>;
|
|
12
|
+
metadata?: FiltersMetadata;
|
|
13
|
+
}): void;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Parameters
|
|
17
|
+
|
|
18
|
+
| Parameter | Type | Description |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| { facetIds, metadata } | { facetIds?: Array<Facet\['id'\]>; metadata?: [FiltersMetadata](./x-components.filtersmetadata.md)<!-- -->; } | _(Optional)_ |
|
|
21
|
+
|
|
22
|
+
**Returns:**
|
|
23
|
+
|
|
24
|
+
void
|
|
25
|
+
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
**Signature:**
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
deselect(filter: Filter): void;
|
|
10
|
+
deselect(filter: Filter, metadata?: Dictionary): void;
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
@@ -15,6 +15,7 @@ deselect(filter: Filter): void;
|
|
|
15
15
|
| Parameter | Type | Description |
|
|
16
16
|
| --- | --- | --- |
|
|
17
17
|
| filter | Filter | |
|
|
18
|
+
| metadata | Dictionary | _(Optional)_ |
|
|
18
19
|
|
|
19
20
|
**Returns:**
|
|
20
21
|
|
|
@@ -30,8 +30,9 @@ export declare class DefaultFacetsService implements FacetsService
|
|
|
30
30
|
|
|
31
31
|
| Method | Modifiers | Description |
|
|
32
32
|
| --- | --- | --- |
|
|
33
|
-
| [clearFilters(facetIds)](./x-components.defaultfacetsservice.clearfilters.md) | | |
|
|
34
|
-
| [
|
|
33
|
+
| [clearFilters(facetIds, metadata)](./x-components.defaultfacetsservice.clearfilters.md) | | |
|
|
34
|
+
| [clearFiltersWithMetadata({ facetIds, metadata })](./x-components.defaultfacetsservice.clearfilterswithmetadata.md) | | |
|
|
35
|
+
| [deselect(filter, metadata)](./x-components.defaultfacetsservice.deselect.md) | | |
|
|
35
36
|
| [select(filterOrFilters)](./x-components.defaultfacetsservice.select.md) | | |
|
|
36
37
|
| [selectPreselectedFilters()](./x-components.defaultfacetsservice.selectpreselectedfilters.md) | | |
|
|
37
38
|
| [setFacets(facetsGroup)](./x-components.defaultfacetsservice.setfacets.md) | | |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FacetsMutations](./x-components.facetsmutations.md) > [clearStickyFilters](./x-components.facetsmutations.clearstickyfilters.md)
|
|
4
|
+
|
|
5
|
+
## FacetsMutations.clearStickyFilters() method
|
|
6
|
+
|
|
7
|
+
Removes all the filters from the [sticky filters](./x-components.facetsstate.stickyfilters.md) record.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
clearStickyFilters(): void;
|
|
13
|
+
```
|
|
14
|
+
**Returns:**
|
|
15
|
+
|
|
16
|
+
void
|
|
17
|
+
|
|
@@ -16,13 +16,16 @@ export interface FacetsMutations
|
|
|
16
16
|
|
|
17
17
|
| Method | Description |
|
|
18
18
|
| --- | --- |
|
|
19
|
+
| [clearStickyFilters()](./x-components.facetsmutations.clearstickyfilters.md) | Removes all the filters from the [sticky filters](./x-components.facetsstate.stickyfilters.md) record. |
|
|
19
20
|
| [mutateFilter(payload)](./x-components.facetsmutations.mutatefilter.md) | Updates the state of a filter. |
|
|
20
21
|
| [removeFacet(facet)](./x-components.facetsmutations.removefacet.md) | Removes the facet from the [facets](./x-components.facetsstate.facets.md) record. |
|
|
21
22
|
| [removeFilter(filter)](./x-components.facetsmutations.removefilter.md) | Removes the filter from the [filters](./x-components.facetsstate.filters.md) record. |
|
|
22
23
|
| [removeFilters(filters)](./x-components.facetsmutations.removefilters.md) | Removes a list of filters from the [filters](./x-components.facetsstate.filters.md) record. |
|
|
24
|
+
| [removeStickyFilter(filter)](./x-components.facetsmutations.removestickyfilter.md) | Removes the filter from the [sticky filters](./x-components.facetsstate.stickyfilters.md) record. |
|
|
23
25
|
| [setFacet(facet)](./x-components.facetsmutations.setfacet.md) | Adds the facet to the [facets](./x-components.facetsstate.facets.md) record. |
|
|
24
26
|
| [setFacetGroup(facetGroupEntry)](./x-components.facetsmutations.setfacetgroup.md) | Sets the group id of the facet. |
|
|
25
27
|
| [setFilters(filters)](./x-components.facetsmutations.setfilters.md) | Adds a list of filters to the [filters](./x-components.facetsstate.filters.md) record. |
|
|
26
28
|
| [setPreselectedFilters(filters)](./x-components.facetsmutations.setpreselectedfilters.md) | Adds a list of filters to the [preselectedFilters](./x-components.facetsstate.preselectedfilters.md) record. |
|
|
27
29
|
| [setQuery(query)](./x-components.facetsmutations.setquery.md) | Sets the [FacetsState.query](./x-components.facetsstate.query.md) property. |
|
|
30
|
+
| [setStickyFilter(filter)](./x-components.facetsmutations.setstickyfilter.md) | Adds the filter to the [sticky filters](./x-components.facetsstate.stickyfilters.md) record. |
|
|
28
31
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FacetsMutations](./x-components.facetsmutations.md) > [removeStickyFilter](./x-components.facetsmutations.removestickyfilter.md)
|
|
4
|
+
|
|
5
|
+
## FacetsMutations.removeStickyFilter() method
|
|
6
|
+
|
|
7
|
+
Removes the filter from the [sticky filters](./x-components.facetsstate.stickyfilters.md) record.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
removeStickyFilter(filter: RawFilter): void;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| filter | RawFilter | The filter to set in the store. |
|
|
20
|
+
|
|
21
|
+
**Returns:**
|
|
22
|
+
|
|
23
|
+
void
|
|
24
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FacetsMutations](./x-components.facetsmutations.md) > [setStickyFilter](./x-components.facetsmutations.setstickyfilter.md)
|
|
4
|
+
|
|
5
|
+
## FacetsMutations.setStickyFilter() method
|
|
6
|
+
|
|
7
|
+
Adds the filter to the [sticky filters](./x-components.facetsstate.stickyfilters.md) record.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
setStickyFilter(filter: RawFilter): void;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Type | Description |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| filter | RawFilter | The filter to set in the store. |
|
|
20
|
+
|
|
21
|
+
**Returns:**
|
|
22
|
+
|
|
23
|
+
void
|
|
24
|
+
|
|
@@ -9,7 +9,7 @@ Deselects the selected filters.
|
|
|
9
9
|
**Signature:**
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
clearFilters(facetIds?: Array<Facet['id']
|
|
12
|
+
clearFilters(facetIds?: Array<Facet['id']>, metadata?: FiltersMetadata): void;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -17,6 +17,7 @@ clearFilters(facetIds?: Array<Facet['id']>): void;
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| facetIds | Array<Facet\['id'\]> | _(Optional)_ An optional list of facets ids from whom deselect the filters. |
|
|
20
|
+
| metadata | [FiltersMetadata](./x-components.filtersmetadata.md) | _(Optional)_ An optional object with the event metadata. |
|
|
20
21
|
|
|
21
22
|
**Returns:**
|
|
22
23
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FacetsService](./x-components.facetsservice.md) > [clearFiltersWithMetadata](./x-components.facetsservice.clearfilterswithmetadata.md)
|
|
4
|
+
|
|
5
|
+
## FacetsService.clearFiltersWithMetadata() method
|
|
6
|
+
|
|
7
|
+
Deselects the selected filters. This is intended to be used from the wiring where currently we can only provide one argument.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
clearFiltersWithMetadata(payload?: {
|
|
13
|
+
facetIds?: Array<Facet['id']>;
|
|
14
|
+
metadata?: FiltersMetadata;
|
|
15
|
+
}): void;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Description |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| payload | { facetIds?: Array<Facet\['id'\]>; metadata?: [FiltersMetadata](./x-components.filtersmetadata.md)<!-- -->; } | _(Optional)_ The event payload that can contain the list of facets ids from whom deselect the filters and the event metadata. |
|
|
23
|
+
|
|
24
|
+
**Returns:**
|
|
25
|
+
|
|
26
|
+
void
|
|
27
|
+
|
|
@@ -9,7 +9,7 @@ Deselects filter, adding it to the store if it was not present.
|
|
|
9
9
|
**Signature:**
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
deselect(filter: Filter): void;
|
|
12
|
+
deselect(filter: Filter, metadata?: FiltersMetadata): void;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -17,6 +17,7 @@ deselect(filter: Filter): void;
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| filter | Filter | The filter to deselect. |
|
|
20
|
+
| metadata | [FiltersMetadata](./x-components.filtersmetadata.md) | _(Optional)_ An optional object with the event metadata. |
|
|
20
21
|
|
|
21
22
|
**Returns:**
|
|
22
23
|
|
|
@@ -16,10 +16,11 @@ export interface FacetsService
|
|
|
16
16
|
|
|
17
17
|
| Method | Description |
|
|
18
18
|
| --- | --- |
|
|
19
|
-
| [clearFilters(facetIds)](./x-components.facetsservice.clearfilters.md) | Deselects the selected filters. |
|
|
20
|
-
| [
|
|
19
|
+
| [clearFilters(facetIds, metadata)](./x-components.facetsservice.clearfilters.md) | Deselects the selected filters. |
|
|
20
|
+
| [clearFiltersWithMetadata(payload)](./x-components.facetsservice.clearfilterswithmetadata.md) | Deselects the selected filters. This is intended to be used from the wiring where currently we can only provide one argument. |
|
|
21
|
+
| [deselect(filter, metadata)](./x-components.facetsservice.deselect.md) | Deselects filter, adding it to the store if it was not present. |
|
|
21
22
|
| [select(filter)](./x-components.facetsservice.select.md) | Selects filter/filters, adding it/them to the store if it/they was not present. |
|
|
22
|
-
| [selectPreselectedFilters()](./x-components.facetsservice.selectpreselectedfilters.md) | Selects preselected filter/filters, adding it/them to the store if it/they
|
|
23
|
+
| [selectPreselectedFilters()](./x-components.facetsservice.selectpreselectedfilters.md) | Selects preselected filter/filters, adding it/them to the store if it/they are not present. |
|
|
23
24
|
| [setFacets(facetsGroup)](./x-components.facetsservice.setfacets.md) | Sets the facets of the group. This method just replaces the facets, and keeps the given facet's filters selected state as it is. |
|
|
24
25
|
| [setQuery(query)](./x-components.facetsservice.setquery.md) | Sets the query. |
|
|
25
26
|
| [toggle(filter)](./x-components.facetsservice.toggle.md) | Selects a deselected filter, and deselects a selected filter, adding them to the store in both cases. |
|
|
@@ -21,4 +21,5 @@ export interface FacetsState
|
|
|
21
21
|
| [groups](./x-components.facetsstate.groups.md) | | Record<Facet\['id'\], [GroupId](./x-components.groupid.md)<!-- -->> | Record specifying the group each facet belongs to. |
|
|
22
22
|
| [preselectedFilters](./x-components.facetsstate.preselectedfilters.md) | | RawFilter\[\] | Record of preselected filters indexed by its id. |
|
|
23
23
|
| [query](./x-components.facetsstate.query.md) | | string | The current query [FacetsState.query](./x-components.facetsstate.query.md)<!-- -->. |
|
|
24
|
+
| [stickyFilters](./x-components.facetsstate.stickyfilters.md) | | Record<Filter\['id'\], Filter> | Record of sticky filters indexed by its id. |
|
|
24
25
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FacetsState](./x-components.facetsstate.md) > [stickyFilters](./x-components.facetsstate.stickyfilters.md)
|
|
4
|
+
|
|
5
|
+
## FacetsState.stickyFilters property
|
|
6
|
+
|
|
7
|
+
Record of sticky filters indexed by its id.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
stickyFilters: Record<Filter['id'], Filter>;
|
|
13
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FiltersMetadata](./x-components.filtersmetadata.md) > [keepSticky](./x-components.filtersmetadata.keepsticky.md)
|
|
4
|
+
|
|
5
|
+
## FiltersMetadata.keepSticky property
|
|
6
|
+
|
|
7
|
+
Flag to prevent the clearing of sticky filters.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
keepSticky?: boolean;
|
|
13
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [FiltersMetadata](./x-components.filtersmetadata.md)
|
|
4
|
+
|
|
5
|
+
## FiltersMetadata interface
|
|
6
|
+
|
|
7
|
+
An object containing additional context regarding the filters.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export interface FiltersMetadata
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
| Property | Modifiers | Type | Description |
|
|
18
|
+
| --- | --- | --- | --- |
|
|
19
|
+
| [keepSticky?](./x-components.filtersmetadata.keepsticky.md) | | boolean | _(Optional)_ Flag to prevent the clearing of sticky filters. |
|
|
20
|
+
|
|
@@ -252,6 +252,7 @@ X-Components is a library usable everywhere not only for search experiences.
|
|
|
252
252
|
| [FacetsXEvents](./x-components.facetsxevents.md) | Dictionary of the events of Facets XModule, where each key is the event name, and the value is the event payload type or <code>void</code> if it has no payload. |
|
|
253
253
|
| [FetchAndSaveActions](./x-components.fetchandsaveactions.md) | Actions returned from the [createFetchAndSaveActions()](./x-components.createfetchandsaveactions.md)<!-- -->. |
|
|
254
254
|
| [FetchAndSaveHooks](./x-components.fetchandsavehooks.md) | Options to use with the [createFetchAndSaveActions()](./x-components.createfetchandsaveactions.md) factory. |
|
|
255
|
+
| [FiltersMetadata](./x-components.filtersmetadata.md) | An object containing additional context regarding the filters. |
|
|
255
256
|
| [HistoryQueriesActions](./x-components.historyqueriesactions.md) | HistoryQueries store actions. |
|
|
256
257
|
| [HistoryQueriesConfig](./x-components.historyqueriesconfig.md) | Configuration options for the [HistoryQueriesXModule](./x-components.historyqueriesxmodule.md)<!-- -->. |
|
|
257
258
|
| [HistoryQueriesGetters](./x-components.historyqueriesgetters.md) | HistoryQueries store getters. |
|
|
@@ -13,7 +13,7 @@ class SingleSelectModifier extends BaseFilterEntityModifier {
|
|
|
13
13
|
* @param filter - The filter to select.
|
|
14
14
|
*/
|
|
15
15
|
select(filter) {
|
|
16
|
-
this.getOtherFilters(filter).forEach(this.deselect.bind(this));
|
|
16
|
+
this.getOtherFilters(filter).forEach(filter => this.deselect.bind(this)(filter));
|
|
17
17
|
this.entity.select(filter);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-select.modifier.js","sources":["../../../../../src/x-modules/facets/entities/single-select.modifier.ts"],"sourcesContent":["import {\n isFacetFilter,\n isHierarchicalFilter,\n FacetFilter,\n Facet,\n Filter,\n HierarchicalFilter\n} from '@empathyco/x-types';\nimport { BaseFilterEntityModifier } from './types';\n\n/**\n * Allows only to select only one filter from the same facet at the same time.\n *\n * @internal\n */\nexport class SingleSelectModifier extends BaseFilterEntityModifier {\n /**\n * Selects the passed filter, and then deselects any other filter of the same facet.\n *\n * @param filter - The filter to select.\n */\n select(filter: FacetFilter): void {\n this.getOtherFilters(filter).forEach(this.deselect.bind(this));\n this.entity.select(filter);\n }\n\n /**\n * Retrieves the rest of selected filters of the same facet than the one given.\n *\n * @param filter - The filter to find its relatives.\n * @returns A list of selected filters that belong to the same facet than the filter passed.\n * @remarks It takes into account if the passed filter is an\n * {@link @empathyco/x-types#HierarchicalFilter | HierarchicalFilter} to exclude the ancestors and\n * descendants.\n *\n * @internal\n */\n protected getOtherFilters(filter: FacetFilter): FacetFilter[] {\n /* This check seems dumb, but when you instantiate this modifier using the factory, the types\n `FacetFilter` parameter type is lost, so we should check it to avoid unexpected crashes\n due to a wrong configuration. */\n if (isHierarchicalFilter(filter)) {\n const ancestorsIds = this.getAncestorsIds(filter);\n const descendantsIds = this.getDescendantsIds(filter);\n return this.getFacetFilters(filter.facetId).filter(\n storeFilter =>\n !ancestorsIds.includes(storeFilter.id) && !descendantsIds.includes(storeFilter.id)\n );\n } else if (isFacetFilter(filter)) {\n return this.getFacetFilters(filter.facetId).filter(\n storeFilter => storeFilter.id !== filter.id && storeFilter.selected\n );\n } else {\n // TODO Add a warning in case a non facet filter is passed here.\n return [];\n }\n }\n\n /**\n * Returns the ancestors Filters Ids of the passed filter.\n *\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} which obtain the ancestors from.\n * @param ids - (Optional) an Array with the Ids used to execute the method recursively.\n * @returns An Array with the ancestors ids.\n * @internal\n */\n protected getAncestorsIds(\n filter: HierarchicalFilter,\n ids: Array<Filter['id']> = [filter.id]\n ): Array<Filter['id']> {\n return filter?.parentId\n ? this.getAncestorsIds(\n this.store.state.x.facets.filters[filter.parentId] as HierarchicalFilter,\n [filter.parentId, ...ids]\n )\n : ids;\n }\n\n /**\n * Returns the descendants Filters Ids of the passed filter.\n *\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} which obtain the descendants\n * from.\n * @param ids - (Optional) an Array with the Ids used to execute the method recursively.\n * @returns An Array with the descendants ids.\n * @internal\n */\n protected getDescendantsIds(\n filter: HierarchicalFilter,\n ids: Array<Filter['id']> = [filter.id]\n ): Array<Filter['id']> {\n return filter?.children?.length\n ? filter?.children.reduce(\n (descendantIdsList, descendant) =>\n this.getDescendantsIds(descendant, [descendant.id, ...descendantIdsList]),\n ids\n )\n : ids;\n }\n\n /**\n * Retrieves All the filters from the given facet.\n *\n * @param facetId - The facet id to retrieve its filters.\n * @returns The filters from the given facet.\n * @internal\n */\n protected getFacetFilters(facetId: Facet['id']): FacetFilter[] {\n return (\n ((this.store.getters['x/facets/facets'] as Record<Facet['id'], Facet>)[facetId]\n ?.filters as FacetFilter[]) ?? []\n );\n }\n}\n"],"names":[],"mappings":";;;AAUA;;;;AAIG;AACG,MAAO,oBAAqB,SAAQ,wBAAwB,CAAA;AAChE;;;;AAIG;AACH,IAAA,MAAM,CAAC,MAAmB,EAAA;
|
|
1
|
+
{"version":3,"file":"single-select.modifier.js","sources":["../../../../../src/x-modules/facets/entities/single-select.modifier.ts"],"sourcesContent":["import {\n isFacetFilter,\n isHierarchicalFilter,\n FacetFilter,\n Facet,\n Filter,\n HierarchicalFilter\n} from '@empathyco/x-types';\nimport { BaseFilterEntityModifier } from './types';\n\n/**\n * Allows only to select only one filter from the same facet at the same time.\n *\n * @internal\n */\nexport class SingleSelectModifier extends BaseFilterEntityModifier {\n /**\n * Selects the passed filter, and then deselects any other filter of the same facet.\n *\n * @param filter - The filter to select.\n */\n select(filter: FacetFilter): void {\n this.getOtherFilters(filter).forEach(filter => this.deselect.bind(this)(filter));\n this.entity.select(filter);\n }\n\n /**\n * Retrieves the rest of selected filters of the same facet than the one given.\n *\n * @param filter - The filter to find its relatives.\n * @returns A list of selected filters that belong to the same facet than the filter passed.\n * @remarks It takes into account if the passed filter is an\n * {@link @empathyco/x-types#HierarchicalFilter | HierarchicalFilter} to exclude the ancestors and\n * descendants.\n *\n * @internal\n */\n protected getOtherFilters(filter: FacetFilter): FacetFilter[] {\n /* This check seems dumb, but when you instantiate this modifier using the factory, the types\n `FacetFilter` parameter type is lost, so we should check it to avoid unexpected crashes\n due to a wrong configuration. */\n if (isHierarchicalFilter(filter)) {\n const ancestorsIds = this.getAncestorsIds(filter);\n const descendantsIds = this.getDescendantsIds(filter);\n return this.getFacetFilters(filter.facetId).filter(\n storeFilter =>\n !ancestorsIds.includes(storeFilter.id) && !descendantsIds.includes(storeFilter.id)\n );\n } else if (isFacetFilter(filter)) {\n return this.getFacetFilters(filter.facetId).filter(\n storeFilter => storeFilter.id !== filter.id && storeFilter.selected\n );\n } else {\n // TODO Add a warning in case a non facet filter is passed here.\n return [];\n }\n }\n\n /**\n * Returns the ancestors Filters Ids of the passed filter.\n *\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} which obtain the ancestors from.\n * @param ids - (Optional) an Array with the Ids used to execute the method recursively.\n * @returns An Array with the ancestors ids.\n * @internal\n */\n protected getAncestorsIds(\n filter: HierarchicalFilter,\n ids: Array<Filter['id']> = [filter.id]\n ): Array<Filter['id']> {\n return filter?.parentId\n ? this.getAncestorsIds(\n this.store.state.x.facets.filters[filter.parentId] as HierarchicalFilter,\n [filter.parentId, ...ids]\n )\n : ids;\n }\n\n /**\n * Returns the descendants Filters Ids of the passed filter.\n *\n * @param filter - The {@link @empathyco/x-types#Filter | Filter} which obtain the descendants\n * from.\n * @param ids - (Optional) an Array with the Ids used to execute the method recursively.\n * @returns An Array with the descendants ids.\n * @internal\n */\n protected getDescendantsIds(\n filter: HierarchicalFilter,\n ids: Array<Filter['id']> = [filter.id]\n ): Array<Filter['id']> {\n return filter?.children?.length\n ? filter?.children.reduce(\n (descendantIdsList, descendant) =>\n this.getDescendantsIds(descendant, [descendant.id, ...descendantIdsList]),\n ids\n )\n : ids;\n }\n\n /**\n * Retrieves All the filters from the given facet.\n *\n * @param facetId - The facet id to retrieve its filters.\n * @returns The filters from the given facet.\n * @internal\n */\n protected getFacetFilters(facetId: Facet['id']): FacetFilter[] {\n return (\n ((this.store.getters['x/facets/facets'] as Record<Facet['id'], Facet>)[facetId]\n ?.filters as FacetFilter[]) ?? []\n );\n }\n}\n"],"names":[],"mappings":";;;AAUA;;;;AAIG;AACG,MAAO,oBAAqB,SAAQ,wBAAwB,CAAA;AAChE;;;;AA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AAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAuB,EACxE,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAC,CAC1B;cACD,GAAG,CAAC;KACT;AAED;;;;;;;;AAQG;IACO,iBAAiB,CACzB,MAA0B,EAC1B,GAAA,GAA2B,CAAC,MAAM,CAAC,EAAE,CAAC,EAAA;AAEtC,QAAA,OAAO,MAAM,EAAE,QAAQ,EAAE,MAAM;AAC7B,cAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CACrB,CAAC,iBAAiB,EAAE,UAAU,KAC5B,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,GAAG,iBAAiB,CAAC,CAAC,EAC3E,GAAG,CACJ;cACD,GAAG,CAAC;KACT;AAED;;;;;;AAMG;AACO,IAAA,eAAe,CAAC,OAAoB,EAAA;QAC5C,QACI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAgC,CAAC,OAAO,CAAC;AAC7E,cAAE,OAAyB,IAAI,EAAE,EACnC;KACH;AACF;;;;"}
|
|
@@ -20,9 +20,10 @@ class BaseFilterEntityModifier {
|
|
|
20
20
|
* Deselects the filter passed by parameter.
|
|
21
21
|
*
|
|
22
22
|
* @param filter - The filter to deselect.
|
|
23
|
+
* @param metadata - The event metadata.
|
|
23
24
|
*/
|
|
24
|
-
deselect(filter) {
|
|
25
|
-
this.entity.deselect(filter);
|
|
25
|
+
deselect(filter, metadata) {
|
|
26
|
+
this.entity.deselect(filter, metadata);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../../src/x-modules/facets/entities/types.ts"],"sourcesContent":["import { Store } from 'vuex';\nimport { Filter } from '@empathyco/x-types';\nimport { RootXStoreState } from '../../../store/store.types';\n\n/**\n * Contains business logic to select or deselect a filter of a certain type.\n *\n * @internal\n */\nexport interface FilterEntity {\n /** Selects the filter. */\n select(filter: Filter): void;\n /** Deselects the filter. */\n deselect(filter: Filter): void;\n}\n\n
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../../src/x-modules/facets/entities/types.ts"],"sourcesContent":["import { Store } from 'vuex';\nimport { Filter } from '@empathyco/x-types';\nimport { Dictionary } from '@empathyco/x-utils';\nimport { RootXStoreState } from '../../../store/store.types';\n\n/**\n * Contains business logic to select or deselect a filter of a certain type.\n *\n * @internal\n */\nexport interface FilterEntity<Metadata extends Dictionary = Dictionary<unknown>> {\n /** Selects the filter. */\n select(filter: Filter): void;\n /** Deselects the filter. */\n deselect(filter: Filter, metadata?: Metadata): void;\n}\n\n/**\n * Constructor of a {@link FilterEntity}.\n *\n * @internal\n */\nexport interface FilterEntityConstructor {\n new (store: Store<RootXStoreState>): FilterEntity;\n /**\n * Checks if this class can create an instance with the passed filter DTO.\n *\n * @param filter - The filter to check if this class can create an instance with it.\n * @returns True if this class can create an instance with it. False otherwise.\n */\n accepts(filter: Filter): boolean;\n}\n\n/**\n * The FilterEntityModifier constructor.\n *\n * @param store - The {@link https://vuex.vuejs.org/api/#vuex-store | Vuex Store} that modifier\n * uses.\n * @param entity - The {@link FilterEntity } that the modifier modifies.\n *\n * @internal\n */\nexport interface FilterEntityModifier<Metadata extends Dictionary = Dictionary> {\n new (store: Store<RootXStoreState>, entity: FilterEntity<Metadata>): FilterEntity<Metadata>;\n}\n\n/**\n * The base class for any Modifier. It delegates to the `entity` methods by default.\n *\n * @internal\n */\nexport abstract class BaseFilterEntityModifier<Metadata extends Dictionary = Dictionary>\n implements FilterEntity<Metadata>\n{\n public constructor(protected store: Store<RootXStoreState>, protected entity: FilterEntity) {}\n\n /**\n * Selects the filter passed by parameter.\n *\n * @param filter - The filter to select.\n */\n select(filter: Filter): void {\n this.entity.select(filter);\n }\n\n /**\n * Deselects the filter passed by parameter.\n *\n * @param filter - The filter to deselect.\n * @param metadata - The event metadata.\n */\n deselect(filter: Filter, metadata?: Metadata): void {\n this.entity.deselect(filter, metadata);\n }\n}\n"],"names":[],"mappings":"AA8CA;;;;AAIG;MACmB,wBAAwB,CAAA;IAG5C,WAA6B,CAAA,KAA6B,EAAY,MAAoB,EAAA;QAA7D,IAAK,CAAA,KAAA,GAAL,KAAK,CAAwB;QAAY,IAAM,CAAA,MAAA,GAAN,MAAM,CAAc;KAAI;AAE9F;;;;AAIG;AACH,IAAA,MAAM,CAAC,MAAc,EAAA;AACnB,QAAA,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAC5B;AAED;;;;;AAKG;IACH,QAAQ,CAAC,MAAc,EAAE,QAAmB,EAAA;QAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KACxC;AACF;;;;"}
|
|
@@ -47,13 +47,16 @@ class DefaultFacetsService {
|
|
|
47
47
|
selectPreselectedFilters() {
|
|
48
48
|
this.select(this.store.state.x.facets.preselectedFilters);
|
|
49
49
|
}
|
|
50
|
-
clearFilters(facetIds) {
|
|
50
|
+
clearFilters(facetIds, metadata) {
|
|
51
51
|
this.getSelectedFilters()
|
|
52
52
|
.filter(filter => !facetIds || (isFacetFilter(filter) && facetIds.includes(filter.facetId)))
|
|
53
|
-
.forEach(this.deselect.bind(this));
|
|
53
|
+
.forEach(filter => this.deselect.bind(this)(filter, metadata));
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
this.
|
|
55
|
+
clearFiltersWithMetadata({ facetIds, metadata } = {}) {
|
|
56
|
+
this.clearFilters(facetIds, metadata);
|
|
57
|
+
}
|
|
58
|
+
deselect(filter, metadata) {
|
|
59
|
+
this.getFilterEntity(filter).deselect(filter, metadata);
|
|
57
60
|
}
|
|
58
61
|
select(filterOrFilters) {
|
|
59
62
|
const filters = Array.isArray(filterOrFilters) ? filterOrFilters : [filterOrFilters];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facets.service.js","sources":["../../../../../src/x-modules/facets/service/facets.service.ts"],"sourcesContent":["import { Facet, Filter, isFacetFilter, isHierarchicalFacet } from '@empathyco/x-types';\nimport { Store } from 'vuex';\nimport { XPlugin } from '../../../plugins/index';\nimport { RootXStoreState } from '../../../store/index';\nimport { arrayToObject, groupItemsBy, isArrayEmpty } from '../../../utils/index';\nimport { FilterEntityFactory } from '../entities/filter-entity.factory';\nimport { FilterEntity } from '../entities/types';\nimport { FacetGroupEntry, FacetsGetters } from '../store/types';\nimport { flatHierarchicalFilters } from '../utils';\nimport { FacetsGroup, FacetsService } from './types';\n\n/**\n * Default implementation for the {@link FacetsService}.\n *\n * @public\n */\nexport class DefaultFacetsService implements FacetsService {\n /**\n * Global instance of the {@link FacetsService}.\n */\n public static instance: FacetsService = new DefaultFacetsService();\n\n public constructor(\n protected filterEntityFactory: FilterEntityFactory = FilterEntityFactory.instance\n ) {}\n\n /**\n * The {@link https://vuex.vuejs.org/ | Vuex} store to use in the service.\n *\n * @returns The store.\n * @internal\n */\n protected get store(): Store<RootXStoreState> {\n return XPlugin.store;\n }\n\n setFacets(facetsGroup: FacetsGroup): void {\n const newFilters = this.updateStore(facetsGroup);\n /* Ensures that filters are selected with valid values. For example, you can't set a single\n select facet with 2 or more selected filters */\n this.updateFiltersSelectedState(newFilters);\n }\n\n updateFacets(facetsGroup: FacetsGroup): void {\n const selectedFilters = this.getSelectedFilters();\n const newFilters = this.updateStore(facetsGroup);\n this.updateFiltersSelectedState(newFilters, selectedFilters);\n }\n\n updatePreselectedFilters(filters: Filter[]): void {\n this.setPreselectedFilter(filters);\n }\n\n selectPreselectedFilters(): void {\n this.select(this.store.state.x.facets.preselectedFilters);\n }\n\n clearFilters(facetIds?: Array<Facet['id']>): void {\n this.getSelectedFilters()\n .filter(filter => !facetIds || (isFacetFilter(filter) && facetIds.includes(filter.facetId)))\n .forEach(this.deselect.bind(this));\n }\n\n deselect(filter: Filter): void {\n this.getFilterEntity(filter).deselect(filter);\n }\n\n select(filterOrFilters: Filter | Filter[]): void {\n const filters = Array.isArray(filterOrFilters) ? filterOrFilters : [filterOrFilters];\n filters.forEach(filter => this.getFilterEntity(filter).select(filter));\n }\n\n toggle(filter: Filter): void {\n if (filter.selected) {\n this.deselect(filter);\n } else {\n this.select(filter);\n }\n }\n\n /**\n * Sets the query.\n *\n * @param query - The query searched.\n * @internal\n */\n setQuery(query: string): void {\n this.store.commit('x/facets/setQuery', query);\n }\n\n /**\n * Creates an entity from a filter DTO.\n *\n * @param filter - The filter to create an entity from.\n * @returns The filter entity.\n * @internal\n */\n protected getFilterEntity(filter: Filter): FilterEntity {\n return this.filterEntityFactory.getFilterEntity(this.store, filter);\n }\n\n /**\n * Sets in the store the Facets, the Filters and the FacetsGroup, without applying any logic\n * to the selected state.\n *\n * @param facetsGroup - The {@link FacetsGroup} to set into the store state.\n * @returns An array with the new filters.\n * @internal\n */\n protected updateStore(facetsGroup: FacetsGroup): Filter[] {\n this.removeGroupFacets(facetsGroup.id);\n this.removeGroupFilters(facetsGroup.id);\n facetsGroup.facets.forEach(facet => {\n this.setFacetGroup({ facetId: facet.id, groupId: facetsGroup.id });\n this.setFacet(facet);\n });\n const newFilters = this.flatFilters(facetsGroup);\n this.setFilters(newFilters);\n return newFilters;\n }\n\n /**\n * This function returns the filters of the facets group flattened in an array. It keeps the\n * relations between the filters (parent--children).\n *\n * @privateRemarks If it is necessary to deal with more cases than the hierarchical, we need to\n * refactor this logic and maybe move it to the entities, to not make this service dependant of\n * the facet type. At the moment it is only one `if`, and is ok as long as no more `if`s are\n * needed.\n * @param facetsGroup - The facets group from where extract the filters to flat.\n * @returns An array with the filters flattened.\n * @internal\n */\n protected flatFilters(facetsGroup: FacetsGroup): Filter[] {\n return facetsGroup.facets.flatMap(facet =>\n isHierarchicalFacet(facet) ? flatHierarchicalFilters(facet.filters) : facet.filters\n );\n }\n\n /**\n * Retrieves the selected filters from the store.\n *\n * @returns The list of selected filters of the store.\n * @internal\n */\n protected getSelectedFilters(): FacetsGetters['selectedFilters'] {\n return this.store.getters['x/facets/selectedFilters'];\n }\n\n /**\n * Changes the filters selection state to match the store.\n *\n * @param newFilters - The list of filters to save.\n * @param previousFilters - (Optional) The list of old filters, used to set the `newFilters`\n * selected state.\n */\n protected updateFiltersSelectedState(newFilters: Filter[], previousFilters?: Filter[]): void {\n if (!isArrayEmpty(newFilters)) {\n const newStateFiltersMap = arrayToObject(previousFilters ?? newFilters, 'id');\n newFilters.forEach(filter => {\n const filterEntity = this.getFilterEntity(filter);\n if (newStateFiltersMap[filter.id]?.selected) {\n filterEntity.select(filter);\n } else {\n filterEntity.deselect(filter);\n }\n });\n }\n }\n\n /**\n * Removes the filters that belong to the given group.\n *\n * @param groupId - The id of the group from whom remove the filters that are in the store.\n *\n * @returns The removed filters.\n *\n * @internal\n */\n protected removeGroupFilters(groupId: FacetsGroup['id']): Filter[] {\n const filtersToRemove =\n groupItemsBy(Object.values(this.store.state.x.facets.filters), filter =>\n isFacetFilter(filter)\n ? this.store.state.x.facets.groups[filter.facetId]\n : '__unknown-group__'\n )[groupId] ?? [];\n this.removeFilters(filtersToRemove);\n return filtersToRemove;\n }\n\n /**\n * Removes the facets that belong to the given group.\n *\n * @param groupId - The id of the group from whom remove the facets that are in the store.\n * @returns The removed facets.\n * @internal\n */\n protected removeGroupFacets(groupId: FacetsGroup['id']): Omit<Facet, 'filters'>[] {\n const facetsToRemove = Object.values(this.store.state.x.facets.facets).filter(\n facet => this.store.state.x.facets.groups[facet.id] === groupId\n );\n facetsToRemove.forEach(this.removeFacet.bind(this));\n return facetsToRemove;\n }\n\n /**\n * Sets the group that a facet belongs to.\n *\n * @param facetGroup - The id of the facet, and the group it belongs to.\n * @internal\n */\n protected setFacetGroup(facetGroup: FacetGroupEntry): void {\n this.store.commit('x/facets/setFacetGroup', facetGroup);\n }\n\n /**\n * Sets the Facet to the store facets record.\n *\n * @param facet - The facet to store.\n *\n * @internal\n */\n protected setFacet({ filters, ...restFacet }: Facet): void {\n this.store.commit('x/facets/setFacet', restFacet);\n }\n\n /**\n * Removes a facet from the store.\n *\n * @param facet - The facet to remove.\n * @internal\n */\n protected removeFacet(facet: Omit<Facet, 'filters'>): void {\n this.store.commit('x/facets/removeFacet', facet);\n }\n\n /**\n * Saves a list of filters to the store without any state change logic applied.\n *\n * @param filters - The filters to save.\n * @internal\n */\n protected setFilters(filters: Filter[]): void {\n this.store.commit('x/facets/setFilters', filters);\n }\n\n /**\n * Saves a list of preselected filters to the store without any state change logic applied.\n *\n * @param filters - The filters to save.\n * @internal\n */\n protected setPreselectedFilter(filters: Filter[]): void {\n this.store.commit('x/facets/setPreselectedFilters', filters);\n }\n\n /**\n * Removes a list of filters from the store.\n *\n * @param filters - The filters to remove.\n * @internal\n */\n protected removeFilters(filters: Filter[]): void {\n this.store.commit('x/facets/removeFilters', filters);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAWA;;;;AAIG;MACU,oBAAoB,CAAA;IAM/B,WACY,CAAA,mBAAA,GAA2C,mBAAmB,CAAC,QAAQ,EAAA;QAAvE,IAAmB,CAAA,mBAAA,GAAnB,mBAAmB,CAAoD;KAC/E;AAEJ;;;;;AAKG;AACH,IAAA,IAAc,KAAK,GAAA;QACjB,OAAO,OAAO,CAAC,KAAK,CAAC;KACtB;AAED,IAAA,SAAS,CAAC,WAAwB,EAAA;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;AACjD;AACgD;AAChD,QAAA,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;KAC7C;AAED,IAAA,YAAY,CAAC,WAAwB,EAAA;AACnC,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAClD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;AACjD,QAAA,IAAI,CAAC,0BAA0B,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;K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],"sourcesContent":["import { Facet, Filter, isFacetFilter, isHierarchicalFacet } from '@empathyco/x-types';\nimport { Store } from 'vuex';\nimport { Dictionary } from '@empathyco/x-utils';\nimport { XPlugin } from '../../../plugins/index';\nimport { RootXStoreState } from '../../../store/index';\nimport { arrayToObject, groupItemsBy, isArrayEmpty } from '../../../utils/index';\nimport { FilterEntityFactory } from '../entities/filter-entity.factory';\nimport { FilterEntity } from '../entities/types';\nimport { FacetGroupEntry, FacetsGetters } from '../store/types';\nimport { flatHierarchicalFilters } from '../utils';\nimport { FacetsGroup, FacetsService, FiltersMetadata } from './types';\n\n/**\n * Default implementation for the {@link FacetsService}.\n *\n * @public\n */\nexport class DefaultFacetsService implements FacetsService {\n /**\n * Global instance of the {@link FacetsService}.\n */\n public static instance: FacetsService = new DefaultFacetsService();\n\n public constructor(\n protected filterEntityFactory: FilterEntityFactory = FilterEntityFactory.instance\n ) {}\n\n /**\n * The {@link https://vuex.vuejs.org/ | Vuex} store to use in the service.\n *\n * @returns The store.\n * @internal\n */\n protected get store(): Store<RootXStoreState> {\n return XPlugin.store;\n }\n\n setFacets(facetsGroup: FacetsGroup): void {\n const newFilters = this.updateStore(facetsGroup);\n /* Ensures that filters are selected with valid values. For example, you can't set a single\n select facet with 2 or more selected filters */\n this.updateFiltersSelectedState(newFilters);\n }\n\n updateFacets(facetsGroup: FacetsGroup): void {\n const selectedFilters = this.getSelectedFilters();\n const newFilters = this.updateStore(facetsGroup);\n this.updateFiltersSelectedState(newFilters, selectedFilters);\n }\n\n updatePreselectedFilters(filters: Filter[]): void {\n this.setPreselectedFilter(filters);\n }\n\n selectPreselectedFilters(): void {\n this.select(this.store.state.x.facets.preselectedFilters);\n }\n\n clearFilters(facetIds?: Array<Facet['id']>, metadata?: FiltersMetadata): void {\n this.getSelectedFilters()\n .filter(filter => !facetIds || (isFacetFilter(filter) && facetIds.includes(filter.facetId)))\n .forEach(filter => this.deselect.bind(this)(filter, metadata));\n }\n\n clearFiltersWithMetadata({\n facetIds,\n metadata\n }: { facetIds?: Array<Facet['id']>; metadata?: FiltersMetadata } = {}): void {\n this.clearFilters(facetIds, metadata);\n }\n\n deselect(filter: Filter, metadata?: Dictionary): void {\n this.getFilterEntity(filter).deselect(filter, metadata);\n }\n\n select(filterOrFilters: Filter | Filter[]): void {\n const filters = Array.isArray(filterOrFilters) ? filterOrFilters : [filterOrFilters];\n filters.forEach(filter => this.getFilterEntity(filter).select(filter));\n }\n\n toggle(filter: Filter): void {\n if (filter.selected) {\n this.deselect(filter);\n } else {\n this.select(filter);\n }\n }\n\n /**\n * Sets the query.\n *\n * @param query - The query searched.\n * @internal\n */\n setQuery(query: string): void {\n this.store.commit('x/facets/setQuery', query);\n }\n\n /**\n * Creates an entity from a filter DTO.\n *\n * @param filter - The filter to create an entity from.\n * @returns The filter entity.\n * @internal\n */\n protected getFilterEntity(filter: Filter): FilterEntity {\n return this.filterEntityFactory.getFilterEntity(this.store, filter);\n }\n\n /**\n * Sets in the store the Facets, the Filters and the FacetsGroup, without applying any logic\n * to the selected state.\n *\n * @param facetsGroup - The {@link FacetsGroup} to set into the store state.\n * @returns An array with the new filters.\n * @internal\n */\n protected updateStore(facetsGroup: FacetsGroup): Filter[] {\n this.removeGroupFacets(facetsGroup.id);\n this.removeGroupFilters(facetsGroup.id);\n facetsGroup.facets.forEach(facet => {\n this.setFacetGroup({ facetId: facet.id, groupId: facetsGroup.id });\n this.setFacet(facet);\n });\n const newFilters = this.flatFilters(facetsGroup);\n this.setFilters(newFilters);\n return newFilters;\n }\n\n /**\n * This function returns the filters of the facets group flattened in an array. It keeps the\n * relations between the filters (parent--children).\n *\n * @privateRemarks If it is necessary to deal with more cases than the hierarchical, we need to\n * refactor this logic and maybe move it to the entities, to not make this service dependant of\n * the facet type. At the moment it is only one `if`, and is ok as long as no more `if`s are\n * needed.\n * @param facetsGroup - The facets group from where extract the filters to flat.\n * @returns An array with the filters flattened.\n * @internal\n */\n protected flatFilters(facetsGroup: FacetsGroup): Filter[] {\n return facetsGroup.facets.flatMap(facet =>\n isHierarchicalFacet(facet) ? flatHierarchicalFilters(facet.filters) : facet.filters\n );\n }\n\n /**\n * Retrieves the selected filters from the store.\n *\n * @returns The list of selected filters of the store.\n * @internal\n */\n protected getSelectedFilters(): FacetsGetters['selectedFilters'] {\n return this.store.getters['x/facets/selectedFilters'];\n }\n\n /**\n * Changes the filters selection state to match the store.\n *\n * @param newFilters - The list of filters to save.\n * @param previousFilters - (Optional) The list of old filters, used to set the `newFilters`\n * selected state.\n */\n protected updateFiltersSelectedState(newFilters: Filter[], previousFilters?: Filter[]): void {\n if (!isArrayEmpty(newFilters)) {\n const newStateFiltersMap = arrayToObject(previousFilters ?? newFilters, 'id');\n newFilters.forEach(filter => {\n const filterEntity = this.getFilterEntity(filter);\n if (newStateFiltersMap[filter.id]?.selected) {\n filterEntity.select(filter);\n } else {\n filterEntity.deselect(filter);\n }\n });\n }\n }\n\n /**\n * Removes the filters that belong to the given group.\n *\n * @param groupId - The id of the group from whom remove the filters that are in the store.\n *\n * @returns The removed filters.\n *\n * @internal\n */\n protected removeGroupFilters(groupId: FacetsGroup['id']): Filter[] {\n const filtersToRemove =\n groupItemsBy(Object.values(this.store.state.x.facets.filters), filter =>\n isFacetFilter(filter)\n ? this.store.state.x.facets.groups[filter.facetId]\n : '__unknown-group__'\n )[groupId] ?? [];\n this.removeFilters(filtersToRemove);\n return filtersToRemove;\n }\n\n /**\n * Removes the facets that belong to the given group.\n *\n * @param groupId - The id of the group from whom remove the facets that are in the store.\n * @returns The removed facets.\n * @internal\n */\n protected removeGroupFacets(groupId: FacetsGroup['id']): Omit<Facet, 'filters'>[] {\n const facetsToRemove = Object.values(this.store.state.x.facets.facets).filter(\n facet => this.store.state.x.facets.groups[facet.id] === groupId\n );\n facetsToRemove.forEach(this.removeFacet.bind(this));\n return facetsToRemove;\n }\n\n /**\n * Sets the group that a facet belongs to.\n *\n * @param facetGroup - The id of the facet, and the group it belongs to.\n * @internal\n */\n protected setFacetGroup(facetGroup: FacetGroupEntry): void {\n this.store.commit('x/facets/setFacetGroup', facetGroup);\n }\n\n /**\n * Sets the Facet to the store facets record.\n *\n * @param facet - The facet to store.\n *\n * @internal\n */\n protected setFacet({ filters, ...restFacet }: Facet): void {\n this.store.commit('x/facets/setFacet', restFacet);\n }\n\n /**\n * Removes a facet from the store.\n *\n * @param facet - The facet to remove.\n * @internal\n */\n protected removeFacet(facet: Omit<Facet, 'filters'>): void {\n this.store.commit('x/facets/removeFacet', facet);\n }\n\n /**\n * Saves a list of filters to the store without any state change logic applied.\n *\n * @param filters - The filters to save.\n * @internal\n */\n protected setFilters(filters: Filter[]): void {\n this.store.commit('x/facets/setFilters', filters);\n }\n\n /**\n * Saves a list of preselected filters to the store without any state change logic applied.\n *\n * @param filters - The filters to save.\n * @internal\n */\n protected setPreselectedFilter(filters: Filter[]): void {\n this.store.commit('x/facets/setPreselectedFilters', filters);\n }\n\n /**\n * Removes a list of filters from the store.\n *\n * @param filters - The filters to remove.\n * @internal\n */\n protected removeFilters(filters: Filter[]): void {\n this.store.commit('x/facets/removeFilters', filters);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAYA;;;;AAIG;MACU,oBAAoB,CAAA;IAM/B,WACY,CAAA,mBAAA,GAA2C,mBAAmB,CAAC,QAAQ,EAAA;QAAvE,IAAmB,CAAA,mBAAA,GAAnB,mBAAmB,CAAoD;KAC/E;AAEJ;;;;;AAKG;AACH,IAAA,IAAc,KAAK,GAAA;QACjB,OAAO,OAAO,CAAC,KAAK,CAAC;KACtB;AAED,IAAA,SAAS,CAAC,WAAwB,EAAA;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;AACjD;AACgD;AAChD,QAAA,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;KAC7C;AAED,IAAA,YAAY,CAAC,WAAwB,EAAA;AACnC,QAAA,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC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AAA;QAC9C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,gCAAgC,EAAE,OAAO,CAAC,CAAC;KAC9D;AAED;;;;;AAKG;AACO,IAAA,aAAa,CAAC,OAAiB,EAAA;QACvC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;KACtD;;AA9PD;;AAEG;AACW,oBAAA,CAAA,QAAQ,GAAkB,IAAI,oBAAoB,EAAE;;;;"}
|
|
@@ -8,7 +8,16 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
const selectedFilters = state =>
|
|
11
|
+
const selectedFilters = state => {
|
|
12
|
+
const selectedFilters = Object.values(state.filters).filter(filter => filter.selected);
|
|
13
|
+
Object.keys(state.stickyFilters).forEach(stickyFilterId => {
|
|
14
|
+
const isSelected = selectedFilters.some(selectedFilter => selectedFilter.id === stickyFilterId);
|
|
15
|
+
if (!isSelected) {
|
|
16
|
+
selectedFilters.push(state.stickyFilters[stickyFilterId]);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return selectedFilters;
|
|
20
|
+
};
|
|
12
21
|
|
|
13
22
|
export { selectedFilters };
|
|
14
23
|
//# sourceMappingURL=selected-filters.getter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selected-filters.getter.js","sources":["../../../../../../src/x-modules/facets/store/getters/selected-filters.getter.ts"],"sourcesContent":["import { FacetsXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link FacetsGetters.selectedFilters} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the facets\n * module.\n *\n * @returns A list containing the selected filters.\n *\n * @public\n */\nexport const selectedFilters: FacetsXStoreModule['getters']['selectedFilters'] = state
|
|
1
|
+
{"version":3,"file":"selected-filters.getter.js","sources":["../../../../../../src/x-modules/facets/store/getters/selected-filters.getter.ts"],"sourcesContent":["import { FacetsXStoreModule } from '../types';\n\n/**\n * Default implementation for the {@link FacetsGetters.selectedFilters} getter.\n *\n * @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the facets\n * module.\n *\n * @returns A list containing the selected filters.\n *\n * @public\n */\nexport const selectedFilters: FacetsXStoreModule['getters']['selectedFilters'] = state => {\n const selectedFilters = Object.values(state.filters).filter(filter => filter.selected);\n Object.keys(state.stickyFilters).forEach(stickyFilterId => {\n const isSelected = selectedFilters.some(selectedFilter => selectedFilter.id === stickyFilterId);\n if (!isSelected) {\n selectedFilters.push(state.stickyFilters[stickyFilterId]);\n }\n });\n return selectedFilters;\n};\n"],"names":[],"mappings":"AAEA;;;;;;;;;AASG;AACU,MAAA,eAAe,GAAqD,KAAK,IAAG;IACvF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvF,IAAA,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,cAAc,IAAG;AACxD,QAAA,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,EAAE,KAAK,cAAc,CAAC,CAAC;QAChG,IAAI,CAAC,UAAU,EAAE;YACf,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3D,SAAA;AACH,KAAC,CAAC,CAAC;AACH,IAAA,OAAO,eAAe,CAAC;AACzB;;;;"}
|