From abd13329b4d4eeaeab85ce36e8edf45dd7e37781 Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 20 Feb 2024 16:44:25 +0100 Subject: [PATCH 01/24] feat: WIP refactor component EMP-3378 --- .../facets/components/preselected-filters.vue | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 5c935c51fa..e6f1477550 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -1,9 +1,9 @@ From 8e7bb4547f80ba450cacfa7d8ee3a935ff09c4cd Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 20 Feb 2024 16:45:05 +0100 Subject: [PATCH 02/24] test: WIP type mounted Component EMP-3378 --- .../facets/components/__tests__/preselected-filters.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts index 0909e8a206..4ae152d5f2 100644 --- a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts @@ -1,4 +1,5 @@ import { mount } from '@vue/test-utils'; +import Vue, { ComponentOptions } from 'vue'; import { createRawFilters } from '../../../../utils/filters'; import { baseSnippetConfig } from '../../../../views/base-config'; import PreselectedFilters from '../preselected-filters.vue'; @@ -8,7 +9,7 @@ function renderPreselectedFilters({ snippetFilters }: RenderPreselectedFiltersOptions = {}): RenderPreselectedFiltersAPI { const emit = jest.fn(); - mount(PreselectedFilters, { + mount(PreselectedFilters as ComponentOptions, { provide: { snippetConfig: { ...baseSnippetConfig, filters: snippetFilters } }, From ff2d75bb8d4acb187bb3cb599cf148db6547417d Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 20 Feb 2024 17:04:57 +0100 Subject: [PATCH 03/24] feat: useNoElementRender composable in component EMP-3378 --- .../x-modules/facets/components/preselected-filters.vue | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index e6f1477550..693ed13695 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -3,7 +3,7 @@ import { createRawFilters } from '../../../utils/filters'; import { isArrayEmpty } from '../../../utils/array'; import { SnippetConfig } from '../../../x-installer/api/api.types'; - import { use$x } from '../../../composables/index'; + import { use$x, useNoElementRender } from '../../../composables/index'; /** * This component emits {@link FacetsXEvents.PreselectedFiltersProvided} when a preselected filter @@ -27,7 +27,7 @@ default: () => [] } }, - setup(props) { + setup(props, { slots }) { const $x = use$x(); /** * Injects {@link SnippetConfig} provided by an ancestor as snippetConfig. @@ -45,9 +45,8 @@ } }); - return { - props - }; + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + return () => useNoElementRender(slots); } }); From 91f5246d69c6f77b59c447ce246ad255ddd5cac8 Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 21 Feb 2024 12:43:17 +0100 Subject: [PATCH 04/24] chore: rm unused EMP-3378 --- .../facets/components/preselbackup.vue | 126 ------------------ 1 file changed, 126 deletions(-) delete mode 100644 packages/x-components/src/x-modules/facets/components/preselbackup.vue diff --git a/packages/x-components/src/x-modules/facets/components/preselbackup.vue b/packages/x-components/src/x-modules/facets/components/preselbackup.vue deleted file mode 100644 index 90faa54dba..0000000000 --- a/packages/x-components/src/x-modules/facets/components/preselbackup.vue +++ /dev/null @@ -1,126 +0,0 @@ - - - -## Events - -A list of events that the component will emit: - -[`PreselectedFiltersProvided`](https://github.com/empathyco/x/blob/main/packages/x-components/src/wiring/events.types.ts). - -## See it in action - -_See how the event is triggered when the component is rendered._ - -```vue - - - -``` - -### Play with props - -In this example, the preselected filters have been configured to use a list of configured filters by -prop: - -```vue - - - -``` - From 1facf0fa6f7156c0aaec2274ee5b7997f106b5a1 Mon Sep 17 00:00:00 2001 From: anna condal Date: Mon, 26 Feb 2024 08:30:59 +0100 Subject: [PATCH 05/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../src/x-modules/facets/components/preselected-filters.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 0d08a0dc62..1d02d09aa0 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -61,9 +61,7 @@ * Emits the {@link FacetsXEvents.PreselectedFiltersProvided} when the * computed prop changes. */ - watch(preselectedFilters, () => { - emitPreselectedFilters(); - }); + watch(preselectedFilters, emitPreselectedFilters); /** * Emits the {@link FacetsXEvents.PreselectedFiltersProvided} when the From c882abeff8f9c1dc2243404525e5d105181202d0 Mon Sep 17 00:00:00 2001 From: anna condal Date: Mon, 26 Feb 2024 08:43:56 +0100 Subject: [PATCH 06/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../src/x-modules/facets/components/preselected-filters.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 1d02d09aa0..b30468156f 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -44,7 +44,7 @@ * @returns An array of filter's ids. */ const preselectedFilters: ComputedRef = computed(() => { - return snippetConfig?.filters ?? props.filters; + return snippetConfig?.value?.filters ?? props.filters; }); /** From b905727a283585d8f478bb6d95773a44a8ebdfdf Mon Sep 17 00:00:00 2001 From: anna condal Date: Mon, 26 Feb 2024 08:44:07 +0100 Subject: [PATCH 07/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../src/x-modules/facets/components/preselected-filters.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index b30468156f..1bff3f5447 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -35,7 +35,7 @@ * * @internal */ - const snippetConfig = inject('snippetConfig'); + const snippetConfig = useHybridInject('snippetConfig'); /** * Gets the provided preselected filters prioritizing the {@link SnippetConfig} over the From 0cd0688bf2263fc6e051326f88f48c89db21ff3c Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 26 Feb 2024 10:00:48 +0100 Subject: [PATCH 08/24] feat: use XBus Composable EMP-3378 --- .../facets/components/preselected-filters.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 1bff3f5447..5a4568543c 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -1,9 +1,10 @@ From 619b397c1e6eed0bbba480e8f91fcf9b137204ab Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 4 Mar 2024 09:56:38 +0100 Subject: [PATCH 13/24] feat: set the injected snippet as a ref to get it sync when it changes EMP-3378 --- .../facets/components/preselected-filters.vue | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 9a497501cf..3e7797f23d 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -2,11 +2,22 @@
From 1532f214d51d6ef8fcc468756abf7a490b329e31 Mon Sep 17 00:00:00 2001 From: anna condal Date: Tue, 5 Mar 2024 10:54:35 +0100 Subject: [PATCH 17/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../src/x-modules/facets/components/preselected-filters.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 13f42e300f..a7152a2c75 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -39,7 +39,7 @@ * * @internal */ - const snippetConfig = ref(useHybridInject('snippetConfig', baseSnippetConfig)); + const snippetConfig = ref(useHybridInject('snippetConfig')); /** * Gets the provided preselected filters prioritizing the {@link SnippetConfig} over the From 42ec2037a9c65eec0c5c4d1069ceca09aa7a073d Mon Sep 17 00:00:00 2001 From: anna condal Date: Tue, 5 Mar 2024 10:54:44 +0100 Subject: [PATCH 18/24] Update packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts Co-authored-by: Guillermo Cacheda --- .../facets/components/__tests__/preselected-filters.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts index 64b221c6b9..a52028a4cd 100644 --- a/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts +++ b/packages/x-components/src/x-modules/facets/components/__tests__/preselected-filters.spec.ts @@ -73,7 +73,7 @@ describe('testing Preselected filters component', () => { expect(emit).toHaveBeenCalledWith( 'PreselectedFiltersProvided', createRawFilters(snippetFilters), - eventMetadata + expect.any(Object) ); }); From 2e54d17180a899093d1e23e1fb18228611edf008 Mon Sep 17 00:00:00 2001 From: anna condal Date: Tue, 5 Mar 2024 10:55:23 +0100 Subject: [PATCH 19/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../src/x-modules/facets/components/preselected-filters.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index a7152a2c75..3f92961c58 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -47,7 +47,7 @@ * * @returns An array of filter's ids. */ - const preselectedFilters: ComputedRef = computed(() => { + const preselectedFilters = computed(() => { return snippetConfig.value?.filters ?? props.filters; }); From 0c98c955fc2f460c2a8c9d0429c24a4d6151afaa Mon Sep 17 00:00:00 2001 From: anna condal Date: Tue, 5 Mar 2024 10:56:35 +0100 Subject: [PATCH 20/24] Update packages/x-components/src/x-modules/facets/components/preselected-filters.vue Co-authored-by: Guillermo Cacheda --- .../facets/components/preselected-filters.vue | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 3f92961c58..e6bda34b28 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -65,15 +65,7 @@ * Emits the {@link FacetsXEvents.PreselectedFiltersProvided} when the * computed prop changes. */ - watch(preselectedFilters, emitPreselectedFilters); - - /** - * Emits the {@link FacetsXEvents.PreselectedFiltersProvided} when the - * component is mounted. - */ - onMounted(() => { - emitPreselectedFilters(); - }); + watch(preselectedFilters, emitPreselectedFilters, { immediate: true }); return () => useNoElementRender(slots); } From b1c518f04e726027f92491d7cb15f74619e1abed Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 5 Mar 2024 11:05:37 +0100 Subject: [PATCH 21/24] chore: rm unused imports EMP-3378 --- .../src/x-modules/facets/components/preselected-filters.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index e6bda34b28..e129359845 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -1,11 +1,10 @@ From 1b3350984626da6339c6b4b0e591cadce6117817 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Wed, 13 Mar 2024 09:20:28 +0100 Subject: [PATCH 24/24] don't destructure composable and add internal fields to doc --- .../x-modules/facets/components/preselected-filters.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue index 8e578eefae..d4b92ca77d 100644 --- a/packages/x-components/src/x-modules/facets/components/preselected-filters.vue +++ b/packages/x-components/src/x-modules/facets/components/preselected-filters.vue @@ -29,8 +29,7 @@ } }, setup(props) { - // eslint-disable-next-line @typescript-eslint/unbound-method - const { emit } = useXBus(); + const xBus = useXBus(); /** * Injects {@link SnippetConfig} provided by an ancestor as snippetConfig @@ -45,6 +44,7 @@ * filters prop. * * @returns An array of filter's ids. + * @internal */ const preselectedFilters = computed(() => { return snippetConfig.value?.filters ?? props.filters; @@ -53,10 +53,12 @@ /** * Emits the {@link FacetsXEvents.PreselectedFiltersProvided} to save * the provided filters in the state. + * + * @internal */ const emitPreselectedFilters = (): void => { if (!isArrayEmpty(preselectedFilters.value)) { - emit('PreselectedFiltersProvided', createRawFilters(preselectedFilters.value)); + xBus.emit('PreselectedFiltersProvided', createRawFilters(preselectedFilters.value)); } };