Skip to content

Commit

Permalink
chore: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
annacv committed Nov 9, 2023
1 parent 8b41dca commit 879ef27
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
7 changes: 2 additions & 5 deletions src/components/column-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Grid4ColIcon
} from '@empathyco/x-components';
import { useDevice } from '../composables/use-device.composable';
import { useXControls } from '../composables/use-experience-controls.composable';
import { useExperienceControls } from '../composables/use-experience-controls.composable';
export default defineComponent({
components: {
Expand All @@ -35,10 +35,7 @@
},
setup() {
const { isMobile } = useDevice();
const columns = useXControls({
path: 'layout.columnSelector' as never,
defaultValue: [4, 2]
});
const columns = useExperienceControls().getControlFromPath('layout.columnSelector', [4, 2]);
return {
values: computed(() => (isMobile.value ? [2, 1] : columns)),
Expand Down
8 changes: 4 additions & 4 deletions src/components/search/custom-semantic-queries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import { QueryPreviewList, useQueriesPreview } from '@empathyco/x-components/queries-preview';
import CustomSlidingPanel from '../custom-sliding-panel.vue';
import Result from '../results/result.vue';
import { useXControls } from '../../composables/use-experience-controls.composable';
import { useExperienceControls } from '../../composables/use-experience-controls.composable';
import DisplayClickProvider from './display-click-provider.vue';
export default defineComponent({
Expand All @@ -61,9 +61,9 @@
},
setup() {
const { isAnyQueryLoadedInPreview } = useQueriesPreview();
const maxItems = useXControls({
path: 'semanticQueries.resultsPerCarousels' as never
});
const maxItems = useExperienceControls().getControlFromPath(
'semanticQueries.resultsPerCarousels'
);
return {
isAnyQueryLoadedInPreview,
Expand Down
7 changes: 2 additions & 5 deletions src/components/search/results/results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import { NextQueriesList } from '@empathyco/x-components/next-queries';
import { useDevice } from '../../../composables/use-device.composable';
import Result from '../../results/result.vue';
import { useXControls } from '../../../composables/use-experience-controls.composable';
import { useExperienceControls } from '../../../composables/use-experience-controls.composable';
import NextQueryPreview from './custom-next-query-preview.vue';
export default defineComponent({
Expand All @@ -76,10 +76,7 @@
},
setup() {
const { isMobile } = useDevice();
const maxItems = useXControls({
path: 'nextQueries.maxItems' as never,
defaultValue: 1
});
const maxItems = useExperienceControls().getControlFromPath('nextQueries.maxItems', 1);
return {
staggeredFadeAndSlide: StaggeredFadeAndSlide,
Expand Down
11 changes: 4 additions & 7 deletions src/composables/use-experience-controls.composable.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { computed, ComputedRef } from 'vue';
import { getSafePropertyChain } from '@empathyco/x-utils';
import { ExtractPath, getSafePropertyChain } from '@empathyco/x-utils';
import { ExperienceControlsState } from '@empathyco/x-components/experience-controls';
import { useStore } from './use-store.composable';

/**
* Given a controls' object property chain, gets the experience controls values from the response.
* A defaultValue can be set as a safeguard in case the controls response was empty.
*
* @param path - The chain of properties in an xControls object.
* @param defaultValue - A default value to set if xControls one is unavailable.
*
* @returns The experience controls property value.
* @returns An object containing the function to search for a configuration
* and set the experience controls property value.
*/
// Rename
export const useExperienceControls = (): {
getControlFromPath: <SomeType>(path: string, defaultValue?: SomeType) => ComputedRef<SomeType>;
} => {
const experienceControls = (useStore('experienceControls') as ExperienceControlsState).controls
.controls;

// extracted the current logic to a function. The function can be typed so the return type is known and also it infers the return type from the default value
const getControlFromPath = <SomeType>(
path: string,
defaultValue?: SomeType
Expand Down
1 change: 1 addition & 0 deletions src/composables/use-store.composable.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Change when useStore composable is added in x-components
import { getCurrentInstance } from 'vue';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { RootXStoreState, StatusState, XModuleName, XModulesTree } from '@empathyco/x-components';
Expand Down

0 comments on commit 879ef27

Please sign in to comment.