Skip to content

Commit

Permalink
feat: apply experience controls for the semantic queries (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes authored Oct 16, 2023
1 parent 8567c40 commit 4326f6f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 39 deletions.
55 changes: 28 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"prepare": "husky install"
},
"dependencies": {
"@empathyco/x-adapter": "^8.0.0-alpha.33",
"@empathyco/x-adapter-platform": "^1.0.0-alpha.83",
"@empathyco/x-archetype-utils": "^1.0.0-alpha.3",
"@empathyco/x-components": "^3.0.0-alpha.414",
"@empathyco/x-deep-merge": "^1.3.0-alpha.29",
"@empathyco/x-types": "^10.0.0-alpha.72",
"@empathyco/x-utils": "^1.0.0-alpha.20",
"@empathyco/x-adapter": "^8.0.0-alpha.34",
"@empathyco/x-adapter-platform": "^1.0.0-alpha.88",
"@empathyco/x-archetype-utils": "^1.0.0-alpha.4",
"@empathyco/x-components": "^3.0.0-alpha.422",
"@empathyco/x-deep-merge": "^1.3.0-alpha.34",
"@empathyco/x-types": "^10.0.0-alpha.75",
"@empathyco/x-utils": "^1.0.0-alpha.23",
"tslib": "~2.4.1",
"vue": "~2.7.14",
"vue-class-component": "~7.2.6",
Expand Down
8 changes: 8 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
<SnippetCallbacks />
<Tagging />
<UrlHandler />
<ExperienceControls />
<MainModal v-if="isOpen" />
</div>
</template>

<script lang="ts">
import { SnippetCallbacks, SnippetConfig, XOn, XProvide } from '@empathyco/x-components';
import { ExperienceControls } from '@empathyco/x-components/experience-controls';
import { Tagging } from '@empathyco/x-components/tagging';
import { QueryPreviewInfo } from '@empathyco/x-components/queries-preview';
import { UrlHandler } from '@empathyco/x-components/url';
Expand All @@ -25,6 +27,7 @@
SnippetConfigExtraParams,
Tagging,
UrlHandler,
ExperienceControls,
MainModal: () => import('./components/custom-main-modal.vue').then(m => m.default)
}
})
Expand Down Expand Up @@ -58,6 +61,11 @@
return this.snippetConfig.queriesPreview;
}
@XProvide('experienceControls')
public get experienceControls(): QueryPreviewInfo[] | undefined {
return this.$store.state.x.experienceControls.controls;
}
@Watch('snippetConfig.uiLang')
syncLang(uiLang: string): void {
this.$setLocale(uiLang);
Expand Down
31 changes: 29 additions & 2 deletions src/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import {
PlatformResult,
recommendationsRequestSchema,
resultSchema,
semanticQueriesRequestSchema
semanticQueriesRequestSchema,
experienceControlsResponseSchema,
PlatformExperienceControlsResponse
} from '@empathyco/x-adapter-platform';
import { RecommendationsRequest, Result, SemanticQueriesRequest } from '@empathyco/x-types';
import {
ExperienceControlsResponse,
RecommendationsRequest,
Result,
SemanticQueriesRequest
} from '@empathyco/x-types';

export const adapter = platformAdapter;

Expand Down Expand Up @@ -53,3 +60,23 @@ semanticQueriesRequestSchema.$override<
};
}
});

// TODO: Remove when the endpoint is propery created in the platform adapter
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const experienceControlsAdapter = adapter.experienceControls.extends({
endpoint: 'https://config-service.internal.test.empathy.co/public/configs'
});
platformAdapter.experienceControls = experienceControlsAdapter;

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
experienceControlsResponseSchema.$override<
PlatformExperienceControlsResponse,
Partial<ExperienceControlsResponse>
>({
events: {
SemanticQueriesConfigProvided: {
maxItemsToRequest: 'controls.semanticQueries.numberOfCarousels',
resultsPerCarousel: 'controls.semanticQueries.resultsPerCarousels'
}
}
});
17 changes: 14 additions & 3 deletions src/components/search/custom-semantic-queries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<DisplayClickProvider resultFeature="semantics">
<div class="x-flex x-gap-16 x-pt-16 max-desktop:x-px-16">
<Result
v-for="result in results"
v-for="result in results.slice(0, resultsPerCarousel)"
:key="result.id"
:result="result"
class="x-w-[calc(38vw-16px)] desktop:x-w-[216px]"
Expand All @@ -41,9 +41,10 @@

<script lang="ts">
import { ArrowRightIcon } from '@empathyco/x-components';
import { defineComponent } from 'vue';
import { computed, defineComponent, inject } from 'vue';
import { SemanticQueries, SemanticQuery } from '@empathyco/x-components/semantic-queries';
import { QueryPreviewList, useQueriesPreview } from '@empathyco/x-components/queries-preview';
import { Dictionary } from '@empathyco/x-utils';
import CustomSlidingPanel from '../custom-sliding-panel.vue';
import Result from '../results/result.vue';
import DisplayClickProvider from './display-click-provider.vue';
Expand All @@ -61,8 +62,18 @@
setup() {
const { isAnyQueryLoadedInPreview } = useQueriesPreview();
const experienceControls = inject<Dictionary>('experienceControls', {});
const resultsPerCarousel = computed(() => {
const resultsPerCarousel: number =
experienceControls.value?.controls?.semanticQueries?.resultsPerCarousels;
return resultsPerCarousel ?? undefined;
});
return {
isAnyQueryLoadedInPreview
isAnyQueryLoadedInPreview,
resultsPerCarousel
};
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/shims-x-components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SemanticQueriesConfig } from '@empathyco/x-components/semantic-queries';

declare module '@empathyco/x-components' {
interface XEventsTypes {
SemanticQueriesConfigProvided: SemanticQueriesConfig;
}
}
7 changes: 7 additions & 0 deletions src/x-components/plugin.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import * as messages from '../i18n/messages';
import store from '../store';
import { adapter } from '../adapter/adapter';
import { useDevice } from '../composables/use-device.composable';
import { mergeSemanticQueriesConfigWire } from './wiring/semantic-queries.wiring';

const device = useDevice();

export const installXOptions: InstallXOptions = {
adapter,
store,
Expand All @@ -22,6 +24,11 @@ export const installXOptions: InstallXOptions = {
config: {
threshold: 50,
maxItemsToRequest: 10
},
wiring: {
SemanticQueriesConfigProvided: {
mergeSemanticQueriesConfigWire
}
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions src/x-components/wiring/semantic-queries.wiring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { namespacedWireCommit } from '@empathyco/x-components';

const moduleName = 'semanticQueries';

const wireCommit = namespacedWireCommit(moduleName);

export const mergeSemanticQueriesConfigWire = wireCommit('mergeConfig');

0 comments on commit 4326f6f

Please sign in to comment.