-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: separate forms like/dislike + api config route #506
base: package/ragbits-api
Are you sure you want to change the base?
Conversation
Code Coverage Summary
Diff against main
Results for commit: 539483f Minimum allowed coverage is ♻️ This comment has been updated with latest results |
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.
Overall looks good, some minor changes from my side.
One thing that should be added to the backlog is creating a store/context with the config so that is accessible everywhere and fetched before app loads.
Regarding the enums, you can use them or create union type e.g. type FormType = ...
and object that reassembles the enum (if you don't want to use them)
if (config) { | ||
if ( | ||
config.hasOwnProperty("like_form") || | ||
config.hasOwnProperty("dislike_form") | ||
) { | ||
pluginManager.activate(FeedbackFormPluginName); | ||
} | ||
} |
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.
nit: I am not a fan of that much nesting. We can change it to use be something like this:
if (!config || (!config.hasOwnProperty("likeForm) && !config.hasOwnProperty("dislike_form")) {
return
}
We can even extract the second part to named variable, like hasFeedbackForms
to give it more meaning
@@ -17,6 +19,8 @@ | |||
|
|||
logger = logging.getLogger(__name__) | |||
|
|||
STARTED_FROM_DIR = Path(os.getcwd()).resolve() |
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.
nit: Maybe let's change the name of this variable to WORKING_DIRECTORY
. We can also consider removing it, as it's only used in one place and can be inlined in line 57 (that way maybe we would only call resolve
once, but I am not sure if it's needed at all)
like_form?: FormSchema | null; | ||
dislike_form?: FormSchema | null; |
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.
Maybe let's use an enum for the names, something like:
enum FormType {
LIKE "like_form"
DISLIKE: "dislike_form"
}
The goal is to use it to define type describing this state and chosen form in the lines 31-33 and hide the snake cased string literals.
const [feedbackName, setFeedbackName] = useState< | ||
"like_form" | "dislike_form" | ||
>(); |
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.
^ Same as above, let's hide the snake cased string literals
setIsLoading(true); | ||
|
||
const [data] = await axiosWrapper<Record<string, unknown>>({ | ||
url: "http://127.0.0.1:8000/api/config", |
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.
Let's use buildApiUrl
method with absolute path -> buildApiUrl('/api/config')
(might require rebasing)
const handleFetchConfig = async () => { | ||
setIsLoading(true); | ||
|
||
const [data] = await axiosWrapper<Record<string, unknown>>({ |
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.
We know the type of the config returned from the server, let's type it in the types/api.ts
and use the type here.
|
||
export type ChatMessageProps = { | ||
classNames?: string[]; | ||
chatMessage: ChatMessage; | ||
onOpenFeedbackForm?: () => void; | ||
onOpenFeedbackForm?: (name: "like_form" | "dislike_form") => void; |
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.
Mentioned above, let's also use enum
here
No description provided.