-
Notifications
You must be signed in to change notification settings - Fork 29
feat: move kb to config api and add cache layer #357
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
wavefront/client/src/pages/apps/[appId]/knowledge-bases/EditKnowledgeBaseDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import floConsoleService from '@app/api'; | ||
| import { KbData, UpdateKnowledgeBasePayload } from '@app/api/knowledge-base-service'; | ||
| import { Button } from '@app/components/ui/button'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@app/components/ui/dialog'; | ||
| import { | ||
| Form, | ||
| FormControl, | ||
| FormDescription, | ||
| FormField, | ||
| FormItem, | ||
| FormLabel, | ||
| FormMessage, | ||
| } from '@app/components/ui/form'; | ||
| import { Input } from '@app/components/ui/input'; | ||
| import { extractErrorMessage } from '@app/lib/utils'; | ||
| import { useNotifyStore } from '@app/store'; | ||
| import { zodResolver } from '@hookform/resolvers/zod'; | ||
| import React, { useEffect } from 'react'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import { z } from 'zod'; | ||
|
|
||
| const editKnowledgeBaseSchema = z.object({ | ||
| name: z.string().min(1, 'Knowledge base name is required'), | ||
| type: z.string().min(1, 'Type is required'), | ||
| description: z.string().optional(), | ||
| }); | ||
|
|
||
| type EditKnowledgeBaseInput = z.infer<typeof editKnowledgeBaseSchema>; | ||
|
|
||
| interface EditKnowledgeBaseDialogProps { | ||
| isOpen: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| knowledgeBase: KbData; | ||
| onSuccess?: () => void; | ||
| } | ||
|
|
||
| const EditKnowledgeBaseDialog: React.FC<EditKnowledgeBaseDialogProps> = ({ | ||
| isOpen, | ||
| onOpenChange, | ||
| knowledgeBase, | ||
| onSuccess, | ||
| }) => { | ||
| const { notifySuccess, notifyError } = useNotifyStore(); | ||
|
|
||
| const form = useForm<EditKnowledgeBaseInput>({ | ||
| resolver: zodResolver(editKnowledgeBaseSchema), | ||
| defaultValues: { | ||
| name: '', | ||
| type: '', | ||
| description: '', | ||
| }, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (knowledgeBase && isOpen) { | ||
| form.reset({ | ||
| name: knowledgeBase.name || '', | ||
| type: knowledgeBase.type || '', | ||
| description: knowledgeBase.description || '', | ||
| }); | ||
| } | ||
| }, [knowledgeBase, isOpen, form]); | ||
|
|
||
| const onSubmit = async (data: EditKnowledgeBaseInput) => { | ||
| try { | ||
| const payload: UpdateKnowledgeBasePayload = { | ||
| name: data.name.trim(), | ||
| description: data.description?.trim() || '', | ||
| type: data.type.trim(), | ||
| }; | ||
|
|
||
| await floConsoleService.knowledgeBaseService.updateKnowledgeBase(knowledgeBase.id, payload); | ||
|
|
||
| notifySuccess(`Knowledge Base '${payload.name}' updated successfully`); | ||
| onSuccess?.(); | ||
| onOpenChange(false); | ||
| } catch (error) { | ||
| console.error('Error updating knowledge base:', error); | ||
| const errorMessage = extractErrorMessage(error); | ||
| notifyError(errorMessage || 'Failed to update knowledge base'); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onOpenChange={onOpenChange}> | ||
| <DialogContent className="max-h-[90vh] max-w-4xl overflow-y-auto lg:max-w-4xl"> | ||
| <DialogHeader> | ||
| <DialogTitle>Edit Knowledge Base</DialogTitle> | ||
| <DialogDescription>Update the details for this knowledge base</DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6"> | ||
| <div className="grid grid-cols-2 gap-6"> | ||
| <FormField | ||
| control={form.control} | ||
| name="name" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel> | ||
| Knowledge Base Name<span className="text-red-500">*</span> | ||
| </FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="e.g., Customer Support FAQ" {...field} /> | ||
| </FormControl> | ||
| <FormDescription>A unique name for your knowledge base</FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="type" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel> | ||
| Type<span className="text-red-500">*</span> | ||
| </FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="e.g., General" {...field} /> | ||
| </FormControl> | ||
| <FormDescription>The type of your knowledge base</FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </div> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="description" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Description</FormLabel> | ||
| <FormControl> | ||
| <textarea | ||
| rows={3} | ||
| placeholder="A brief description of the knowledge base's purpose" | ||
| className="border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex min-h-[80px] w-full rounded-md border px-3 py-2 text-sm focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50" | ||
| {...field} | ||
| /> | ||
| </FormControl> | ||
| <FormDescription>Provide a description for your knowledge base</FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <DialogFooter> | ||
| <Button type="button" variant="outline" onClick={() => onOpenChange(false)}> | ||
| Cancel | ||
| </Button> | ||
| <Button type="submit" loading={form.formState.isSubmitting}> | ||
| Save Changes | ||
| </Button> | ||
| </DialogFooter> | ||
| </form> | ||
| </Form> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default EditKnowledgeBaseDialog; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: rootflo/wavefront
Length of output: 18177
🤖 get_repo_knowledge executed:
get_repo_knowledge rootflo/wavefront /tmp/coderabbit-repo-knowledge/rootflo-wavefront-652b9598Length of output: 1382
Show the edit control on keyboard focus.
The button uses
opacity-0and only becomes visible withgroup-hover:opacity-100. Addfocus-visible:opacity-100so keyboard users can see the focused edit control.🤖 Prompt for AI Agents