Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build a Vue3 test search component #1540

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/_vue3-migration-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "vue-tsc && vite build"
},
"dependencies": {
"@empathyco/x-adapter-platform": "^1.1.0-alpha.3",
"@empathyco/x-bus": "^1.0.3-alpha.1",
"@empathyco/x-types": "^10.1.0-alpha.3",
"@empathyco/x-utils": "^1.0.3-alpha.1",
Expand Down
11 changes: 10 additions & 1 deletion packages/_vue3-migration-test/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
</div>
</template>

<script setup lang="ts"></script>
<script setup lang="ts">
import { provide } from 'vue';
import { baseSnippetConfig } from '../../x-components/src/views/base-config';

/**
* TODO: remove when x-instaler is migrated and used in this Playground.
* X-instaler's `createApp` fn should provide the snippet config.
*/
provide('snippetConfig', baseSnippetConfig);
</script>

<style lang="scss" scoped>
#app {
Expand Down
1 change: 1 addition & 0 deletions packages/_vue3-migration-test/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { default as TestBaseKeyboardNavigation } from './test-base-keyboard-navi
export { default as TestBaseEventsModal } from './modals/test-base-events-modal.vue';
export { default as TestBaseIdModal } from './modals/test-base-id-modal.vue';
export { default as TestExtraParams } from './extra-params/test-extra-params.vue';
export { default as TestSearch } from './test-search.vue';
45 changes: 45 additions & 0 deletions packages/_vue3-migration-test/src/components/test-search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<SnippetConfigExtraParams />
<SearchInput />
<ClearSearchInput />
<SearchButton />
<!-- No Results Message -->
<div
v-if="_$x.noResults && !_$x.fromNoResultsWithFilters"
class="x-p-28 x-flex x-flex-col x-gap-8 x-items-center x-bg-lead-25 x-my-8"
data-test="no-results-message"
>
<p>
There are no results for
<span class="x-font-bold">{{ _$x.query.search }}</span>
</p>
</div>
<ResultsList>
<BaseVariableColumnGrid
style="--x-size-min-width-grid-item: 150px"
class="x-gap-12"
:columns="4"
>
<template #result="{ item: result }">
<BaseResultLink :result="result">
<h1 class="x-text1 x-text1-lg">{{ result.name }}</h1>
</BaseResultLink>
</template>
</BaseVariableColumnGrid>
</ResultsList>
</template>

<script setup lang="ts">
import SnippetConfigExtraParams from '../../../x-components/src/x-modules/extra-params/components/snippet-config-extra-params.vue';
import SearchInput from '../../../x-components/src/x-modules/search-box/components/search-input.vue';
import ResultsList from '../../../x-components/src/x-modules/search/components/results-list.vue';
import BaseResultLink from '../../../x-components/src/components/result/base-result-link.vue';
import BaseVariableColumnGrid from '../../../x-components/src/components/base-variable-column-grid.vue';
import ClearSearchInput from '../../../x-components/src/x-modules/search-box/components/clear-search-input.vue';
import SearchButton from '../../../x-components/src/x-modules/search-box/components/search-button.vue';
import { use$x } from '../../../x-components/src/composables/use-$x';
// TODO `$x` name cannot be used while XPlugin defines its own `this.$x` in the mixin
const _$x = use$x();
</script>

<style lang="scss" scoped></style>
22 changes: 5 additions & 17 deletions packages/_vue3-migration-test/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { QuerySuggestionsRequest, XComponentsAdapter } from '@empathyco/x-types';
import { Component, configureCompat, createApp } from 'vue';
import { createStore } from 'vuex';
import { platformAdapter } from '@empathyco/x-adapter-platform';
import { getRelatedTagsStub } from '../../x-components/src/__stubs__/related-tags-stubs.factory';
import { getQuerySuggestionsStub } from '../../x-components/src/__stubs__/query-suggestions-stubs.factory';
import {
createResultStub,
createRedirectionStub,
getBannersStub,
getNextQueriesStub,
getPromotedsStub,
getResultsStub
} from '../../x-components/src/__stubs__/index';
import { XInstaller } from '../../x-components/src/x-installer/x-installer/x-installer';
import { baseSnippetConfig } from '../../x-components/src/views/base-config';
import App from './App.vue';
import router from './router';
import {
Expand Down Expand Up @@ -46,6 +45,7 @@ if (VUE_COMPAT_MODE === 2) {
}

const adapter = {
...platformAdapter,
relatedTags: () =>
new Promise(resolve => {
resolve({ relatedTags: getRelatedTagsStub(10) });
Expand All @@ -70,16 +70,6 @@ const adapter = {
]
});
}),
search: () =>
new Promise(resolve => {
resolve({
results: getResultsStub(10),
totalResults: 50,
promoteds: getPromotedsStub(),
banners: getBannersStub(),
redirections: [createRedirectionStub('redirection')]
});
}),
identifierResults: () =>
new Promise(resolve =>
resolve({ results: ['123A', '123B', '123C', '123D'].map(id => createResultStub(id)) })
Expand All @@ -93,10 +83,8 @@ createApp(App as Component)
.use(store)
.mount('#app');

window.initX = {
instance: 'empathy',
lang: 'en'
};
window.initX = baseSnippetConfig;

new XInstaller({
adapter,
store,
Expand Down
8 changes: 7 additions & 1 deletion packages/_vue3-migration-test/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ import {
TestNextQueries,
TestIdentifierResults,
TestRedirection,
TestExtraParams
TestExtraParams,
TestSearch
} from './';

const routes = [
{
path: '/',
name: 'Home',
component: TestSearch
},
{
path: '/animate-width',
name: 'AnimateWidth',
Expand Down
Loading
Loading