From cf615e7dad52c17578a758f873bed0b5afbe6f83 Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 6 Nov 2023 12:44:31 +0100 Subject: [PATCH 01/15] feat(nextQueries): set maxNextQueriesPerGroup using xControls EMP-2722 --- src/components/search/results/results.vue | 16 +++++++-- .../use-experience-controls.composable.ts | 35 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/composables/use-experience-controls.composable.ts diff --git a/src/components/search/results/results.vue b/src/components/search/results/results.vue index a027c07a..a40f23fd 100644 --- a/src/components/search/results/results.vue +++ b/src/components/search/results/results.vue @@ -5,7 +5,7 @@ diff --git a/src/composables/use-experience-controls.composable.ts b/src/composables/use-experience-controls.composable.ts new file mode 100644 index 00000000..707dcce0 --- /dev/null +++ b/src/composables/use-experience-controls.composable.ts @@ -0,0 +1,35 @@ +import { computed, ComputedRef, inject } from 'vue'; +import { Dictionary } from '@empathyco/x-utils'; + +type ExperienceControlsHelpers = { + maxItems: ComputedRef; +}; + +/** + * Experience controls values per x-modules. + * + * @param xmodule - The name of the x-module whose config will be set with xControls. + * @param prop - The name of the property that will be configured. + * @param defaultValue - A default value to set if xControls value is unavailable. + * + * @returns The experience controls utils. + */ +export const useExperienceControlsHelpers = ({ + xmodule, + prop, + defaultValue +}: { + xmodule: string; + prop: string; + defaultValue?: string | number | boolean; +}): ExperienceControlsHelpers => { + const experienceControls = inject('experienceControls', {}); + + const maxItems = computed(() => { + return experienceControls.value?.controls?.[xmodule]?.[prop] ?? (defaultValue as number); + }); + + return { + maxItems + }; +}; From 554f8ef95c25a744345196b5c47434a06c3f2f67 Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 6 Nov 2023 13:01:02 +0100 Subject: [PATCH 02/15] feat(layout): set columns using xControls EMP-2722 --- src/components/column-picker.vue | 9 ++++++++- src/components/search/results/results.vue | 2 +- .../use-experience-controls.composable.ts | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/components/column-picker.vue b/src/components/column-picker.vue index f0aa012f..02801654 100644 --- a/src/components/column-picker.vue +++ b/src/components/column-picker.vue @@ -24,6 +24,7 @@ Grid4ColIcon } from '@empathyco/x-components'; import { useDevice } from '../composables/use-device.composable'; + import { useExperienceControlsHelpers } from '../composables/use-experience-controls.composable'; export default defineComponent({ components: { @@ -34,8 +35,14 @@ }, setup() { const { isMobile } = useDevice(); + const { columns } = useExperienceControlsHelpers({ + controls: 'layout', + prop: 'columnSelector', + defaultValue: [4, 2] + }); + return { - values: computed(() => (isMobile.value ? [2, 1] : [4, 2])), + values: computed(() => (isMobile.value ? [2, 1] : columns)), icons: { 1: 'Grid1ColIcon', 2: 'Grid2ColIcon', 4: 'Grid4ColIcon' } }; } diff --git a/src/components/search/results/results.vue b/src/components/search/results/results.vue index a40f23fd..659736a1 100644 --- a/src/components/search/results/results.vue +++ b/src/components/search/results/results.vue @@ -78,7 +78,7 @@ setup() { const { isMobile } = useDevice(); const { maxItems } = useExperienceControlsHelpers({ - xmodule: 'nextQueries', + controls: 'nextQueries', prop: 'maxItems', defaultValue: 1 }); diff --git a/src/composables/use-experience-controls.composable.ts b/src/composables/use-experience-controls.composable.ts index 707dcce0..a837c12a 100644 --- a/src/composables/use-experience-controls.composable.ts +++ b/src/composables/use-experience-controls.composable.ts @@ -3,33 +3,39 @@ import { Dictionary } from '@empathyco/x-utils'; type ExperienceControlsHelpers = { maxItems: ComputedRef; + columns: ComputedRef>; }; /** * Experience controls values per x-modules. * - * @param xmodule - The name of the x-module whose config will be set with xControls. + * @param controls - The name of the xControls controls object that will be used. * @param prop - The name of the property that will be configured. * @param defaultValue - A default value to set if xControls value is unavailable. * * @returns The experience controls utils. */ export const useExperienceControlsHelpers = ({ - xmodule, + controls, prop, defaultValue }: { - xmodule: string; + controls: string; prop: string; - defaultValue?: string | number | boolean; + defaultValue?: string | number | boolean | number[]; }): ExperienceControlsHelpers => { const experienceControls = inject('experienceControls', {}); const maxItems = computed(() => { - return experienceControls.value?.controls?.[xmodule]?.[prop] ?? (defaultValue as number); + return experienceControls.value?.controls?.[controls]?.[prop] ?? (defaultValue as number); + }); + + const columns = computed(() => { + return experienceControls.value?.controls?.[controls]?.[prop] ?? (defaultValue as number[]); }); return { - maxItems + maxItems, + columns }; }; From de13239cf708fbb5270dd553ec855c0b42d22053 Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 6 Nov 2023 13:52:57 +0100 Subject: [PATCH 03/15] chore: rename export in composable to avoid large length imports EMP-2722 --- src/components/column-picker.vue | 4 ++-- src/components/search/results/results.vue | 5 ++--- src/composables/use-experience-controls.composable.ts | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/column-picker.vue b/src/components/column-picker.vue index 02801654..79831b09 100644 --- a/src/components/column-picker.vue +++ b/src/components/column-picker.vue @@ -24,7 +24,7 @@ Grid4ColIcon } from '@empathyco/x-components'; import { useDevice } from '../composables/use-device.composable'; - import { useExperienceControlsHelpers } from '../composables/use-experience-controls.composable'; + import { useXControlsHelpers } from '../composables/use-experience-controls.composable'; export default defineComponent({ components: { @@ -35,7 +35,7 @@ }, setup() { const { isMobile } = useDevice(); - const { columns } = useExperienceControlsHelpers({ + const { columns } = useXControlsHelpers({ controls: 'layout', prop: 'columnSelector', defaultValue: [4, 2] diff --git a/src/components/search/results/results.vue b/src/components/search/results/results.vue index 659736a1..b461e062 100644 --- a/src/components/search/results/results.vue +++ b/src/components/search/results/results.vue @@ -55,8 +55,7 @@ import { NextQueriesList } from '@empathyco/x-components/next-queries'; import { useDevice } from '../../../composables/use-device.composable'; import Result from '../../results/result.vue'; - // eslint-disable-next-line max-len - import { useExperienceControlsHelpers } from '../../../composables/use-experience-controls.composable'; + import { useXControlsHelpers } from '../../../composables/use-experience-controls.composable'; import NextQueryPreview from './custom-next-query-preview.vue'; export default defineComponent({ @@ -77,7 +76,7 @@ }, setup() { const { isMobile } = useDevice(); - const { maxItems } = useExperienceControlsHelpers({ + const { maxItems } = useXControlsHelpers({ controls: 'nextQueries', prop: 'maxItems', defaultValue: 1 diff --git a/src/composables/use-experience-controls.composable.ts b/src/composables/use-experience-controls.composable.ts index a837c12a..fd4ff5f4 100644 --- a/src/composables/use-experience-controls.composable.ts +++ b/src/composables/use-experience-controls.composable.ts @@ -15,7 +15,7 @@ type ExperienceControlsHelpers = { * * @returns The experience controls utils. */ -export const useExperienceControlsHelpers = ({ +export const useXControlsHelpers = ({ controls, prop, defaultValue From 293c79a7fadca4c077adeba0948c93123d2f753c Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 6 Nov 2023 13:54:15 +0100 Subject: [PATCH 04/15] feat: use xControls composable in semantics EMP-2722 --- .../search/custom-semantic-queries.vue | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/search/custom-semantic-queries.vue b/src/components/search/custom-semantic-queries.vue index e183ebed..2f8923aa 100644 --- a/src/components/search/custom-semantic-queries.vue +++ b/src/components/search/custom-semantic-queries.vue @@ -41,12 +41,12 @@