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: implement related-prompts multi-query #1685

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
chore: remove unnecessary code
lauramargar committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 897f03bcb3df414d0f67412671d2f5fbe4316a24
16 changes: 8 additions & 8 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
@@ -371,7 +371,7 @@
:max-groups="1"
:show-only-after-offset="x.totalResults < 50"
class="x-mot-related-prompt-list"
:custom-query="nextQuery"
:query="nextQuery"
>
<BaseVariableColumnGrid
style="--x-size-min-width-grid-item: 150px"
@@ -760,7 +760,7 @@

const { nextQueries } = useState('nextQueries', ['nextQueries']);

const nextQuery = computed(() => nextQueries.value[0]?.query);
const nextQuery = computed(() => nextQueries.value[0]?.query ?? '');

const { relatedPrompts } = useState('relatedPrompts', ['relatedPrompts']);

@@ -770,15 +770,15 @@

const showGrid = ref(true);

x.on('RelatedPromptsLocation', false).subscribe(payload => {
if (payload.location === 'predictive_layer') {
showGrid.value = relatedPrompts.value[payload.query].selectedPrompt === '';
x.on('UserSelectedARelatedPrompt', true).subscribe(event => {
if (event.metadata.location === 'predictive_layer') {
showGrid.value = relatedPrompts.value[event.eventPayload.query].selectedPrompt === '';
}
if (relatedPrompts.value[payload.query].selectedPrompt !== '') {
if (relatedPrompts.value[event.eventPayload.query].selectedPrompt !== '') {
const relatedPromptQueries = (
relatedPrompts as ComputedRef<Dictionary<RelatedPromptsItems>>
).value[payload.query].relatedPromptsProducts.find(
(relatedPrompt: RelatedPrompt) => relatedPrompt.id === selectedPrompt.value
).value[event.eventPayload.query].relatedPromptsProducts.find(
(relatedPrompt: RelatedPrompt) => relatedPrompt.id === event.eventPayload.promptId
);
const queries = relatedPromptQueries?.nextQueries as string[];
relatedPromptsQueriesPreviewInfo.value = queries.map(query => ({ query }));
Original file line number Diff line number Diff line change
@@ -27,13 +27,12 @@
</div>
</template>
<script lang="ts">
import { computed, defineComponent, PropType, inject, isRef, Ref } from 'vue';
import { computed, defineComponent, PropType } from 'vue';
import { RelatedPrompt } from '@empathyco/x-types';
import { relatedPromptsXModule } from '../x-module';
import CrossTinyIcon from '../../../components/icons/cross-tiny.vue';
import PlusIcon from '../../../components/icons/plus.vue';
import { use$x, useState } from '../../../composables/index';
import { FeatureLocation } from '../../../types/index';

/**
* This component shows a suggested related prompt.
@@ -83,13 +82,8 @@
const index = relatedPrompts.value.findIndex(
relatedPrompt => relatedPrompt.id === props.promptId
);

const injectedLocation = inject<Ref<FeatureLocation> | FeatureLocation>('location');
const location = isRef(injectedLocation) ? injectedLocation.value : injectedLocation;

const toggleSuggestion = (promptId: string): void => {
x.emit('UserSelectedARelatedPrompt', { promptId, query: props.query });
x.emit('RelatedPromptsLocation', { location, query: props.query });
};

return {
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { computed, ComputedRef, defineComponent, h, inject, provide, ref, Ref, watch } from 'vue';
import { computed, defineComponent, h, inject, provide, ref, Ref, watch } from 'vue';
import { RelatedPrompt } from '@empathyco/x-types';
import { Dictionary } from '@empathyco/x-utils';
import { AnimationProp } from '../../../types/animation-prop';
import { groupItemsBy } from '../../../utils/array';
import ItemsList from '../../../components/items-list.vue';
@@ -14,7 +13,6 @@
import { relatedPromptsXModule } from '../x-module';
import { useState } from '../../../composables/use-state';
import { RelatedPromptsGroup } from '../types';
import { RelatedPromptsItems } from '../store/index';
import { use$x } from '../../../composables/index';

/**
@@ -70,19 +68,11 @@
type: Boolean,
default: false
},
customQuery: String
query: String
},
setup(props, { slots }) {
const x = use$x();
const { query, status } = useState('relatedPrompts', ['query', 'status']);

/**
* The state related prompts.
*/
const relatedPrompts: ComputedRef<Dictionary<RelatedPromptsItems>> = useState(
'relatedPrompts',
['relatedPrompts']
).relatedPrompts;
const { status, relatedPrompts } = useState('relatedPrompts', ['status', 'relatedPrompts']);

/**
* Injected query, updated when the related request(s) have succeeded.
@@ -92,20 +82,20 @@
const relatedPromptsProducts: Ref<RelatedPrompt[]> = ref([]);

watch(
() => props.customQuery,
() => props.query,
() => {
if (props.customQuery || props.customQuery !== '') {
x.emit('RelatedPromptsCustomQueryProvider', props.customQuery);
if (props.query || props.query !== '') {
x.emit('RelatedPromptsQueryProvided', props.query);
}
}
);

watch(
relatedPrompts,
() => {
if (relatedPrompts.value[props.customQuery ?? query.value]) {
if (relatedPrompts.value[props.query ?? x.query.search]) {
relatedPromptsProducts.value =
relatedPrompts.value[props.customQuery ?? query.value].relatedPromptsProducts;
relatedPrompts.value[props.query ?? x.query.search].relatedPromptsProducts;
}
},
{ deep: true }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { RelatedPromptsRequest } from '@empathyco/x-types';
import { FeatureLocation } from '../../types/index';

/**
* Dictionary of the events of RelatedPrompts XModule, where each key is the event name,
@@ -28,10 +27,5 @@ export interface RelatedPromptsXEvents {
* A custom query to request has been provided.
* Payload: The query to add to the request.
*/
RelatedPromptsCustomQueryProvider: string;
/**
* The current location of the related prompts.
* Payload: The query to request prompts and the location of the related-prompts.
*/
RelatedPromptsLocation: { location: FeatureLocation | undefined; query: string };
RelatedPromptsQueryProvided: string;
}
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ export const relatedPromptsWiring = createWiring({
resetRelatedPromptsStateWire,
resetRelatedPromptsQueryWire
},
RelatedPromptsCustomQueryProvider: {
RelatedPromptsQueryProvided: {
fetchAndSaveRelatedPromptsResponseWire
},
ExtraParamsChanged: {