Skip to content

Commit 2ab0b98

Browse files
committed
limit to one search context in demo
1 parent f720ec9 commit 2ab0b98

2 files changed

Lines changed: 93 additions & 73 deletions

File tree

packages/web/src/app/[domain]/components/homepage/askSourcebotDemoCards.tsx

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export const AskSourcebotDemoCards = ({
3333

3434
const getContextIcon = (context: DemoSearchContext, size: number = 20) => {
3535
const sizeClass = size === 12 ? "h-3 w-3" : "h-5 w-5";
36-
36+
3737
if (context.type === "set") {
3838
return <LibraryBigIcon className={cn(sizeClass, "text-muted-foreground")} />;
3939
}
40-
40+
4141
if (context.codeHostType) {
4242
const codeHostIcon = getCodeHostIcon(context.codeHostType);
4343
if (codeHostIcon) {
@@ -52,7 +52,7 @@ export const AskSourcebotDemoCards = ({
5252
);
5353
}
5454
}
55-
55+
5656
return <Code className={cn(sizeClass, "text-muted-foreground")} />;
5757
}
5858

@@ -63,40 +63,48 @@ export const AskSourcebotDemoCards = ({
6363
return;
6464
}
6565

66-
if (context.type === "set") {
67-
const searchContext = searchContexts.find((item) => item.name === context.value);
68-
if (!searchContext) {
69-
console.error(`Search context ${context.value} not found on handleContextClick`);
70-
return;
71-
}
72-
73-
const isSelected = selectedItems.some(
74-
(selected) => selected.type === 'context' && selected.value === context.value
75-
);
76-
const newSelectedItems = isSelected
77-
? selectedItems.filter(
78-
(selected) => !(selected.type === 'context' && selected.value === context.value)
79-
)
80-
: [...selectedItems, { type: 'context', value: context.value, name: context.displayName, repoCount: searchContext.repoNames.length } as SearchContextItem];
81-
82-
setSelectedItems(newSelectedItems);
83-
} else {
84-
const repo = repos.find((repo) => repo.repoName === context.value);
85-
if (!repo) {
86-
console.error(`Repo ${context.value} not found on handleContextClick`);
87-
return;
88-
}
66+
const isDemoMode = process.env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo";
67+
const isSelected = selectedItems.some((item) => item.value === context.value);
68+
if (isSelected) {
69+
setSelectedItems(selectedItems.filter((item) => item.value !== context.value));
70+
return;
71+
}
72+
73+
const getNewSelectedItem = (): ContextItem | null => {
74+
if (context.type === "set") {
75+
const searchContext = searchContexts.find((item) => item.name === context.value);
76+
if (!searchContext) {
77+
console.error(`Search context ${context.value} not found on handleContextClick`);
78+
return null;
79+
}
8980

90-
const isSelected = selectedItems.some(
91-
(selected) => selected.type === 'repo' && selected.value === context.value
92-
);
93-
const newSelectedItems = isSelected
94-
? selectedItems.filter(
95-
(selected) => !(selected.type === 'repo' && selected.value === context.value)
96-
)
97-
: [...selectedItems, { type: 'repo', value: context.value, name: context.displayName, codeHostType: repo.codeHostType } as RepoContextItem];
81+
return {
82+
type: 'context',
83+
value: context.value,
84+
name: context.displayName,
85+
repoCount: searchContext.repoNames.length
86+
} as SearchContextItem;
87+
} else {
88+
const repo = repos.find((repo) => repo.repoName === context.value);
89+
if (!repo) {
90+
console.error(`Repo ${context.value} not found on handleContextClick`);
91+
return null;
92+
}
9893

99-
setSelectedItems(newSelectedItems);
94+
return {
95+
type: 'repo',
96+
value: context.value,
97+
name: context.displayName,
98+
codeHostType: repo.codeHostType
99+
} as RepoContextItem;
100+
}
101+
}
102+
103+
const newSelectedItem = getNewSelectedItem();
104+
if (newSelectedItem) {
105+
setSelectedItems(isDemoMode ? [newSelectedItem] : [...selectedItems, newSelectedItem]);
106+
} else {
107+
console.error(`No new selected item found on handleContextClick`);
100108
}
101109
}
102110

@@ -107,7 +115,7 @@ export const AskSourcebotDemoCards = ({
107115
<div className="text-center mb-8">
108116
<div className="flex items-center justify-center gap-2 mb-2">
109117
<Layers className="h-5 w-5 text-muted-foreground" />
110-
<h3 className="text-lg font-semibold">Search Context</h3>
118+
<h3 className="text-lg font-semibold">Search Contexts</h3>
111119
</div>
112120
<p className="text-sm text-muted-foreground">Select the context you want to ask questions about</p>
113121
</div>
@@ -177,33 +185,34 @@ export const AskSourcebotDemoCards = ({
177185
{demoExamples.searchExamples.map((example) => {
178186
const searchContexts = demoExamples.searchContexts.filter((context) => example.searchContext.includes(context.id))
179187
return (
180-
<Card
181-
key={example.url}
182-
className="cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
183-
onClick={() => handleExampleClick(example)}
184-
>
185-
<CardContent className="p-4">
186-
<div className="space-y-3">
187-
<div className="flex items-center justify-between">
188-
{searchContexts.map((context) => (
189-
<Badge key={context.value} variant="secondary" className="text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1">
190-
{getContextIcon(context, 12)}
191-
{context.displayName}
192-
</Badge>
193-
))}
194-
</div>
195-
<div className="space-y-1">
196-
<h4 className="font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2">
197-
{example.title}
198-
</h4>
199-
<p className="text-xs text-muted-foreground line-clamp-3 leading-relaxed">
200-
{example.description}
201-
</p>
188+
<Card
189+
key={example.url}
190+
className="cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
191+
onClick={() => handleExampleClick(example)}
192+
>
193+
<CardContent className="p-4">
194+
<div className="space-y-3">
195+
<div className="flex items-center justify-between">
196+
{searchContexts.map((context) => (
197+
<Badge key={context.value} variant="secondary" className="text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1">
198+
{getContextIcon(context, 12)}
199+
{context.displayName}
200+
</Badge>
201+
))}
202+
</div>
203+
<div className="space-y-1">
204+
<h4 className="font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2">
205+
{example.title}
206+
</h4>
207+
<p className="text-xs text-muted-foreground line-clamp-3 leading-relaxed">
208+
{example.description}
209+
</p>
210+
</div>
202211
</div>
203-
</div>
204-
</CardContent>
205-
</Card>
206-
)})}
212+
</CardContent>
213+
</Card>
214+
)
215+
})}
207216
</div>
208217
</div>
209218
</div>

packages/web/src/features/chat/components/chatBox/contextSelector.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,23 @@ export const ContextSelector = React.forwardRef<
9696
const isSelected = selectedItems.some(
9797
(selected) => selected.type === item.type && selected.value === item.value
9898
);
99-
100-
const newSelectedItems = isSelected
101-
? selectedItems.filter(
99+
100+
const isDemoMode = process.env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo";
101+
102+
let newSelectedItems: ContextItem[];
103+
if (isSelected) {
104+
newSelectedItems = selectedItems.filter(
102105
(selected) => !(selected.type === item.type && selected.value === item.value)
103-
)
104-
: [...selectedItems, item];
106+
);
107+
} else {
108+
// Limit selected context to 1 in demo mode
109+
if (isDemoMode) {
110+
newSelectedItems = [item];
111+
} else {
112+
newSelectedItems = [...selectedItems, item];
113+
}
114+
}
115+
105116
onSelectedItemsChange(newSelectedItems);
106117
};
107118

@@ -120,14 +131,14 @@ export const ContextSelector = React.forwardRef<
120131
name: context.name,
121132
repoCount: context.repoNames.length
122133
}));
123-
134+
124135
const repoItems: ContextItem[] = repos.map(repo => ({
125136
type: 'repo' as const,
126137
value: repo.repoName,
127138
name: repo.repoDisplayName || repo.repoName.split('/').pop() || repo.repoName,
128139
codeHostType: repo.codeHostType,
129140
}));
130-
141+
131142
return [...contextItems, ...repoItems];
132143
}, [repos, searchContexts]);
133144

@@ -225,8 +236,8 @@ export const ContextSelector = React.forwardRef<
225236
(() => {
226237
const codeHostIcon = item.codeHostType ? getCodeHostIcon(item.codeHostType) : null;
227238
return codeHostIcon ? (
228-
<Image
229-
src={codeHostIcon.src}
239+
<Image
240+
src={codeHostIcon.src}
230241
alt={`${item.codeHostType} icon`}
231242
width={16}
232243
height={16}
@@ -243,8 +254,8 @@ export const ContextSelector = React.forwardRef<
243254
{item.name}
244255
</span>
245256
{item.type === 'context' && (
246-
<Badge
247-
variant="default"
257+
<Badge
258+
variant="default"
248259
className="text-[10px] px-1.5 py-0 h-4 bg-primary text-primary-foreground"
249260
>
250261
{item.repoCount} repo{item.repoCount === 1 ? '' : 's'}

0 commit comments

Comments
 (0)