Skip to content

Commit

Permalink
fix: Disable Cohere Main Page Sidebar Only (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava authored Aug 14, 2024
1 parent 3f6f53e commit 9bc0ce0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/ui/app/src/atoms/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
useMdxBundler: false,
isBatchStreamToggleDisabled: false,
isAuthEnabledInDocs: false,
isAiChatbotEnabledInPreview: false,
};

const EMPTY_DOCS_STATE: DocsProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/app/src/atoms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FeatureFlags {
useMdxBundler: boolean;
isBatchStreamToggleDisabled: boolean;
isAuthEnabledInDocs: boolean;
isAiChatbotEnabledInPreview: boolean;
}

export interface NavigationProps {
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/app/src/search/SearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CURRENT_VERSION_ATOM,
IS_MOBILE_SCREEN_ATOM,
SEARCH_DIALOG_OPEN_ATOM,
useDomain,
useFeatureFlags,
useSidebarNodes,
} from "../atoms";
import { useSearchConfig } from "../services/useSearchService";
Expand All @@ -27,8 +27,8 @@ const CohereChatButton = dynamic(

export const SearchDialog = (): ReactElement | null => {
const setSearchDialogState = useSetAtom(SEARCH_DIALOG_OPEN_ATOM);
const domain = useDomain();
useSearchTrigger(setSearchDialogState);
const { isAiChatbotEnabledInPreview } = useFeatureFlags();

const [config] = useSearchConfig();

Expand All @@ -40,7 +40,7 @@ export const SearchDialog = (): ReactElement | null => {
return (
<>
<AlgoliaSearchDialog />
{domain.includes("cohere") && <CohereChatButton />}
{isAiChatbotEnabledInPreview && <CohereChatButton />}
</>
);
} else {
Expand Down
12 changes: 12 additions & 0 deletions packages/ui/app/src/sidebar/SidebarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CURRENT_TAB_INDEX_ATOM,
DOCS_LAYOUT_ATOM,
MOBILE_SIDEBAR_ENABLED_ATOM,
SEARCHBAR_PLACEMENT_ATOM,
SIDEBAR_SCROLL_CONTAINER_ATOM,
TABS_ATOM,
useIsMobileSidebarOpen,
Expand All @@ -31,6 +32,17 @@ const UnmemoizedSidebarContainer = forwardRef<HTMLElement, SidebarContainerProps
const isScrolled = useIsScrolled({ current: scrollRef });
const isMobileSidebarEnabled = useAtomValue(MOBILE_SIDEBAR_ENABLED_ATOM);
const isMobileSidebarOpen = useIsMobileSidebarOpen();
const showSearchBar = useAtomValue(SEARCHBAR_PLACEMENT_ATOM) === "SIDEBAR";

if (
tabs.length > 0 &&
layout?.disableHeader !== true &&
layout?.tabsPlacement === "HEADER" &&
!showSearchBar &&
(sidebar == null || sidebar?.children.length === 0)
) {
return null;
}

return (
<nav aria-label="secondary" ref={ref} {...props} className={clsx("fern-sidebar-container", props.className)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const FEATURE_FLAGS = [
"use-mdx-bundler" as const,
"batch-stream-toggle-disabled" as const,
"enabled-auth-in-generated-docs" as const,
"ai-chat-preview" as const,
];

type FeatureFlag = (typeof FEATURE_FLAGS)[number];
Expand Down Expand Up @@ -61,6 +62,8 @@ export async function getFeatureFlags(domain: string): Promise<FeatureFlags> {
const useMdxBundler = checkDomainMatchesCustomers(domain, config["use-mdx-bundler"]);
const isBatchStreamToggleDisabled = checkDomainMatchesCustomers(domain, config["batch-stream-toggle-disabled"]);
const isAuthEnabledInDocs = checkDomainMatchesCustomers(domain, config["enabled-auth-in-generated-docs"]);
const isAiChatbotEnabledInPreview = checkDomainMatchesCustomers(domain, config["ai-chat-preview"]);

return {
isApiPlaygroundEnabled: isApiPlaygroundEnabledOverrides(domain) || isApiPlaygroundEnabled,
isApiScrollingDisabled,
Expand All @@ -79,6 +82,7 @@ export async function getFeatureFlags(domain: string): Promise<FeatureFlags> {
useMdxBundler,
isBatchStreamToggleDisabled,
isAuthEnabledInDocs,
isAiChatbotEnabledInPreview,
};
} catch (e) {
// eslint-disable-next-line no-console
Expand All @@ -101,11 +105,15 @@ export async function getFeatureFlags(domain: string): Promise<FeatureFlags> {
useMdxBundler: false,
isBatchStreamToggleDisabled: false,
isAuthEnabledInDocs: false,
isAiChatbotEnabledInPreview: false,
};
}
}

function checkDomainMatchesCustomers(domain: string, customers: readonly string[]): boolean {
if (customers == null) {
return false;
}
return customers.some((customer) => domain.toLowerCase().includes(customer.toLowerCase()));
}

Expand Down

0 comments on commit 9bc0ce0

Please sign in to comment.