diff --git a/packages/_vue3-migration-test/src/x-modules/facets/components/test-facets.vue b/packages/_vue3-migration-test/src/x-modules/facets/components/test-facets.vue index 3874309a8a..b9f3dffde1 100644 --- a/packages/_vue3-migration-test/src/x-modules/facets/components/test-facets.vue +++ b/packages/_vue3-migration-test/src/x-modules/facets/components/test-facets.vue @@ -4,14 +4,27 @@

SelectedFilters

@@ -39,6 +52,11 @@ import Facets from '../../../../../x-components/src/x-modules/facets/components/facets/facets.vue'; import SelectedFilters from '../../../../../x-components/src/x-modules/facets/components/lists/selected-filters.vue'; import SelectedFiltersList from '../../../../../x-components/src/x-modules/facets/components/lists/selected-filters-list.vue'; + import SortedFilters from '../../../../../x-components/src/x-modules/facets/components/lists/sorted-filters.vue'; + import SlicedFilters from '../../../../../x-components/src/x-modules/facets/components/lists/sliced-filters.vue'; + import FiltersSearch from '../../../../../x-components/src/x-modules/facets/components/lists/filters-search.vue'; + import ExcludeFiltersWithNoResults from '../../../../../x-components/src/x-modules/facets/components/lists/exclude-filters-with-no-results.vue'; + import FiltersList from '../../../../../x-components/src/x-modules/facets/components/lists/filters-list.vue'; - const facetsIds = ['gender', 'brand']; + const facetsIds = ['gender', 'brand', 'category']; diff --git a/packages/_vue3-migration-test/src/x-modules/facets/x-module.ts b/packages/_vue3-migration-test/src/x-modules/facets/x-module.ts index 9a4ba59efc..6e2c86a0c9 100644 --- a/packages/_vue3-migration-test/src/x-modules/facets/x-module.ts +++ b/packages/_vue3-migration-test/src/x-modules/facets/x-module.ts @@ -16,7 +16,12 @@ const facets: Record = { color: createSimpleFacetStub('color', createFilter => [ createFilter('red', true), createFilter('blue', false) - ]) + ]), + category: createSimpleFacetStub('category', createFilter => + ['dress', 'floral', 'skirt', 'print', 'midi', 'fitted', 'short', 'long'].map((query, index) => + createFilter(query, false, index) + ) + ) }; const filters = arrayToObject( Object.values(facets).flatMap(facet => facet.filters), diff --git a/packages/x-components/src/views/home/aside.vue b/packages/x-components/src/views/home/aside.vue index 81ab1993e8..6b3ffade0e 100644 --- a/packages/x-components/src/views/home/aside.vue +++ b/packages/x-components/src/views/home/aside.vue @@ -35,7 +35,7 @@ - + import { Filter, isBooleanFilter } from '@empathyco/x-types'; - import { CreateElement, VNode } from 'vue'; - import { mixins } from 'vue-class-component'; - import { Component } from 'vue-property-decorator'; - import { xComponentMixin, XProvide } from '../../../../components'; + import { computed, defineComponent, PropType, provide, h } from 'vue'; import { facetsXModule } from '../../x-module'; - import FiltersInjectionMixin from './filters-injection.mixin'; + import { useRegisterXModule } from '../../../../composables/use-register-x-module'; + import { useFiltersInjection } from '../../composables/use-filters-injection'; /** * The `ExcludeFiltersWithNoResults` component filters the provided list of filters, excluding @@ -17,27 +15,47 @@ * * @public */ - @Component({ - mixins: [xComponentMixin(facetsXModule)] - }) - export default class ExcludeFiltersWithNoResults extends mixins(FiltersInjectionMixin) { - /** - * Removes the filters that have exactly 0 results associated. - * - * @returns A sublist of the filters prop, excluding the ones with no results. - * @internal - */ - @XProvide('filters') - public get filtersWithResults(): Filter[] { - return this.renderedFilters.filter( - filter => !isBooleanFilter(filter) || filter.totalResults !== 0 - ); - } + export default defineComponent({ + name: 'ExcludeFiltersWithNoResults', + xModule: facetsXModule.name, + props: { + /** + * The list of filters to be rendered as slots. + * + * @public + */ + filters: Array as PropType, + + /** + * This prop is used in the `HierarchicalFilter` component and only in that case. It is necessary + * to make the `renderedFilters` to return only the filters of each level of the hierarchy. + * + * @public + */ + parentId: { + type: String as PropType + } + }, + setup(props, { slots }) { + useRegisterXModule(facetsXModule); + const renderedFilters = useFiltersInjection(props); + + /** + * Removes the filters that have exactly 0 results associated. + * + * @returns A sublist of the filters prop, excluding the ones with no results. + * @internal + */ + const filtersWithResults = computed((): Filter[] => { + return renderedFilters.value.filter( + filter => !isBooleanFilter(filter) || filter.totalResults !== 0 + ); + }); + provide('filters', filtersWithResults); - render(h: CreateElement): VNode { - return this.$scopedSlots.default?.({ filters: this.filtersWithResults })?.[0] ?? h(); + return () => (slots.default ? slots.default({ filters: filtersWithResults.value }) : h()); } - } + }); diff --git a/packages/x-components/src/x-modules/facets/components/lists/filters-list.vue b/packages/x-components/src/x-modules/facets/components/lists/filters-list.vue index edfd823626..52f1dde2f3 100644 --- a/packages/x-components/src/x-modules/facets/components/lists/filters-list.vue +++ b/packages/x-components/src/x-modules/facets/components/lists/filters-list.vue @@ -23,13 +23,13 @@