mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
limit to one search context in demo
This commit is contained in:
parent
f720ec945d
commit
2ab0b988e4
2 changed files with 93 additions and 73 deletions
|
|
@ -63,40 +63,48 @@ export const AskSourcebotDemoCards = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.type === "set") {
|
const isDemoMode = process.env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo";
|
||||||
const searchContext = searchContexts.find((item) => item.name === context.value);
|
const isSelected = selectedItems.some((item) => item.value === context.value);
|
||||||
if (!searchContext) {
|
if (isSelected) {
|
||||||
console.error(`Search context ${context.value} not found on handleContextClick`);
|
setSelectedItems(selectedItems.filter((item) => item.value !== context.value));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getNewSelectedItem = (): ContextItem | null => {
|
||||||
|
if (context.type === "set") {
|
||||||
|
const searchContext = searchContexts.find((item) => item.name === context.value);
|
||||||
|
if (!searchContext) {
|
||||||
|
console.error(`Search context ${context.value} not found on handleContextClick`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'context',
|
||||||
|
value: context.value,
|
||||||
|
name: context.displayName,
|
||||||
|
repoCount: searchContext.repoNames.length
|
||||||
|
} as SearchContextItem;
|
||||||
|
} else {
|
||||||
|
const repo = repos.find((repo) => repo.repoName === context.value);
|
||||||
|
if (!repo) {
|
||||||
|
console.error(`Repo ${context.value} not found on handleContextClick`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'repo',
|
||||||
|
value: context.value,
|
||||||
|
name: context.displayName,
|
||||||
|
codeHostType: repo.codeHostType
|
||||||
|
} as RepoContextItem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const isSelected = selectedItems.some(
|
const newSelectedItem = getNewSelectedItem();
|
||||||
(selected) => selected.type === 'context' && selected.value === context.value
|
if (newSelectedItem) {
|
||||||
);
|
setSelectedItems(isDemoMode ? [newSelectedItem] : [...selectedItems, newSelectedItem]);
|
||||||
const newSelectedItems = isSelected
|
|
||||||
? selectedItems.filter(
|
|
||||||
(selected) => !(selected.type === 'context' && selected.value === context.value)
|
|
||||||
)
|
|
||||||
: [...selectedItems, { type: 'context', value: context.value, name: context.displayName, repoCount: searchContext.repoNames.length } as SearchContextItem];
|
|
||||||
|
|
||||||
setSelectedItems(newSelectedItems);
|
|
||||||
} else {
|
} else {
|
||||||
const repo = repos.find((repo) => repo.repoName === context.value);
|
console.error(`No new selected item found on handleContextClick`);
|
||||||
if (!repo) {
|
|
||||||
console.error(`Repo ${context.value} not found on handleContextClick`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isSelected = selectedItems.some(
|
|
||||||
(selected) => selected.type === 'repo' && selected.value === context.value
|
|
||||||
);
|
|
||||||
const newSelectedItems = isSelected
|
|
||||||
? selectedItems.filter(
|
|
||||||
(selected) => !(selected.type === 'repo' && selected.value === context.value)
|
|
||||||
)
|
|
||||||
: [...selectedItems, { type: 'repo', value: context.value, name: context.displayName, codeHostType: repo.codeHostType } as RepoContextItem];
|
|
||||||
|
|
||||||
setSelectedItems(newSelectedItems);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +115,7 @@ export const AskSourcebotDemoCards = ({
|
||||||
<div className="text-center mb-8">
|
<div className="text-center mb-8">
|
||||||
<div className="flex items-center justify-center gap-2 mb-2">
|
<div className="flex items-center justify-center gap-2 mb-2">
|
||||||
<Layers className="h-5 w-5 text-muted-foreground" />
|
<Layers className="h-5 w-5 text-muted-foreground" />
|
||||||
<h3 className="text-lg font-semibold">Search Context</h3>
|
<h3 className="text-lg font-semibold">Search Contexts</h3>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-muted-foreground">Select the context you want to ask questions about</p>
|
<p className="text-sm text-muted-foreground">Select the context you want to ask questions about</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -177,33 +185,34 @@ export const AskSourcebotDemoCards = ({
|
||||||
{demoExamples.searchExamples.map((example) => {
|
{demoExamples.searchExamples.map((example) => {
|
||||||
const searchContexts = demoExamples.searchContexts.filter((context) => example.searchContext.includes(context.id))
|
const searchContexts = demoExamples.searchContexts.filter((context) => example.searchContext.includes(context.id))
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={example.url}
|
key={example.url}
|
||||||
className="cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
|
className="cursor-pointer transition-all duration-200 hover:shadow-md hover:scale-105 hover:border-primary/50 group w-full max-w-[350px]"
|
||||||
onClick={() => handleExampleClick(example)}
|
onClick={() => handleExampleClick(example)}
|
||||||
>
|
>
|
||||||
<CardContent className="p-4">
|
<CardContent className="p-4">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
{searchContexts.map((context) => (
|
{searchContexts.map((context) => (
|
||||||
<Badge key={context.value} variant="secondary" className="text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1">
|
<Badge key={context.value} variant="secondary" className="text-[10px] px-1.5 py-0.5 h-4 flex items-center gap-1">
|
||||||
{getContextIcon(context, 12)}
|
{getContextIcon(context, 12)}
|
||||||
{context.displayName}
|
{context.displayName}
|
||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<h4 className="font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2">
|
||||||
|
{example.title}
|
||||||
|
</h4>
|
||||||
|
<p className="text-xs text-muted-foreground line-clamp-3 leading-relaxed">
|
||||||
|
{example.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1">
|
</CardContent>
|
||||||
<h4 className="font-semibold text-sm group-hover:text-primary transition-colors line-clamp-2">
|
</Card>
|
||||||
{example.title}
|
)
|
||||||
</h4>
|
})}
|
||||||
<p className="text-xs text-muted-foreground line-clamp-3 leading-relaxed">
|
|
||||||
{example.description}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)})}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,22 @@ export const ContextSelector = React.forwardRef<
|
||||||
(selected) => selected.type === item.type && selected.value === item.value
|
(selected) => selected.type === item.type && selected.value === item.value
|
||||||
);
|
);
|
||||||
|
|
||||||
const newSelectedItems = isSelected
|
const isDemoMode = process.env.NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT === "demo";
|
||||||
? selectedItems.filter(
|
|
||||||
|
let newSelectedItems: ContextItem[];
|
||||||
|
if (isSelected) {
|
||||||
|
newSelectedItems = selectedItems.filter(
|
||||||
(selected) => !(selected.type === item.type && selected.value === item.value)
|
(selected) => !(selected.type === item.type && selected.value === item.value)
|
||||||
)
|
);
|
||||||
: [...selectedItems, item];
|
} else {
|
||||||
|
// Limit selected context to 1 in demo mode
|
||||||
|
if (isDemoMode) {
|
||||||
|
newSelectedItems = [item];
|
||||||
|
} else {
|
||||||
|
newSelectedItems = [...selectedItems, item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onSelectedItemsChange(newSelectedItems);
|
onSelectedItemsChange(newSelectedItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue