Skip to content

Commit

Permalink
hfix: disable ask cohere search (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujitm authored Aug 15, 2024
1 parent d0ef388 commit 50ef250
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/ui/app/src/search/SearchHits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useSetAtom } from "jotai";
import { useRouter } from "next/router";
import React, { PropsWithChildren, useEffect, useMemo, useRef, useState } from "react";
import { useInfiniteHits, useInstantSearch } from "react-instantsearch";
import { COHERE_ASK_AI, COHERE_INITIAL_MESSAGE, useBasePath, useCloseSearchDialog, useDomain } from "../atoms";
import { COHERE_ASK_AI, COHERE_INITIAL_MESSAGE, useBasePath, useCloseSearchDialog, useFeatureFlags } from "../atoms";
import { SearchHit } from "./SearchHit";
import { AskCohereHit } from "./cohere/AskCohereHit";

Expand All @@ -16,7 +16,7 @@ export const EmptyStateView: React.FC<PropsWithChildren> = ({ children }) => {
const COHERE_AI_HIT_ID = "cohere-ai-hit";

export const SearchHits: React.FC = () => {
const isCohere = useDomain().includes("cohere");
const { isAiChatbotEnabledInPreview } = useFeatureFlags();
const basePath = useBasePath();
const { hits } = useInfiniteHits<SearchRecord>();
const search = useInstantSearch();
Expand Down Expand Up @@ -48,17 +48,17 @@ export const SearchHits: React.FC = () => {
useEffect(() => {
const [firstHit] = hits;
if (firstHit != null) {
setHoveredSearchHitId((id) => id ?? (isCohere ? COHERE_AI_HIT_ID : firstHit.objectID));
setHoveredSearchHitId((id) => id ?? (isAiChatbotEnabledInPreview ? COHERE_AI_HIT_ID : firstHit.objectID));
}
}, [hits, isCohere]);
}, [hits, isAiChatbotEnabledInPreview]);

useKeyboardPress({
key: "Up",
onPress: () => {
if (hoveredSearchHit == null) {
setHoveredSearchHitId(null);
return;
} else if (hoveredSearchHit.index === 0 && isCohere) {
} else if (hoveredSearchHit.index === 0 && isAiChatbotEnabledInPreview) {
setHoveredSearchHitId(COHERE_AI_HIT_ID);
return;
}
Expand All @@ -82,7 +82,7 @@ export const SearchHits: React.FC = () => {
return;
}

if (hoveredSearchHit == null && isCohere) {
if (hoveredSearchHit == null && isAiChatbotEnabledInPreview) {
setHoveredSearchHitId(COHERE_AI_HIT_ID);
return;
}
Expand All @@ -107,7 +107,11 @@ export const SearchHits: React.FC = () => {

const navigateToHoveredHit = async () => {
if (hoveredSearchHit == null) {
if (isCohere && hoveredSearchHitId === COHERE_AI_HIT_ID && search.results.query.length > 0) {
if (
isAiChatbotEnabledInPreview &&
hoveredSearchHitId === COHERE_AI_HIT_ID &&
search.results.query.length > 0
) {
closeSearchDialog();
openCohere();
}
Expand Down Expand Up @@ -136,7 +140,7 @@ export const SearchHits: React.FC = () => {
capture: true,
});

if ((hits.length === 0 && !isCohere) || search.results.query.length === 0) {
if ((hits.length === 0 && !isAiChatbotEnabledInPreview) || search.results.query.length === 0) {
return null;
}

Expand All @@ -146,7 +150,7 @@ export const SearchHits: React.FC = () => {
className="p-2"
scrollbars="vertical"
>
{isCohere && (
{isAiChatbotEnabledInPreview && (
<AskCohereHit
setRef={(elem) => {
if (elem != null) {
Expand Down Expand Up @@ -176,7 +180,7 @@ export const SearchHits: React.FC = () => {
};

export const SearchMobileHits: React.FC<PropsWithChildren> = ({ children }) => {
const isCohere = useDomain().includes("cohere");
const { isAiChatbotEnabledInPreview } = useFeatureFlags();
const { hits } = useInfiniteHits<SearchRecord>();
const search = useInstantSearch();

Expand All @@ -193,7 +197,7 @@ export const SearchMobileHits: React.FC<PropsWithChildren> = ({ children }) => {

return (
<FernScrollArea className="mask-grad-top-4 px-2 pt-4">
{isCohere && (
{isAiChatbotEnabledInPreview && (
<AskCohereHit
setRef={(elem) => {
if (elem != null) {
Expand Down

0 comments on commit 50ef250

Please sign in to comment.