fix: address assistant review findings
This commit is contained in:
1 parent
87f264a286
commit
b988e431e8
8 files changed
+71
-180
No files matched your search
@@ -8,16 +8,9 @@ describe("assistant widget definition", () => {
|
||||
expect(supportsAdvancedFocus(definition)).toBe(false);
|
||||
});
|
||||
|
||||
it("follows the current conversation by default", () => {
|
||||
it("does not persist private conversation data in board options", () => {
|
||||
const options = definition.createOptions();
|
||||
|
||||
expect(options.conversationMode.defaultValue).toBe("current");
|
||||
expect(options.conversation.shouldHide?.({ conversationMode: "current", conversation: null }, [])).toBe(true);
|
||||
});
|
||||
|
||||
it("reveals the conversation selector only when a conversation is pinned", () => {
|
||||
const options = definition.createOptions();
|
||||
|
||||
expect(options.conversation.shouldHide?.({ conversationMode: "pinned", conversation: null }, [])).toBe(false);
|
||||
expect(options).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -1,50 +1,12 @@
|
||||
import { IconRobot } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("assistant", {
|
||||
icon: IconRobot,
|
||||
createOptions() {
|
||||
return optionsBuilder.from(
|
||||
(factory) => ({
|
||||
conversationMode: factory.select({
|
||||
options: (["current", "pinned"] as const).map((value) => ({
|
||||
value,
|
||||
label: (t) => t(`widget.assistant.option.conversationMode.option.${value}`),
|
||||
})),
|
||||
defaultValue: "current",
|
||||
withDescription: true,
|
||||
}),
|
||||
conversation: factory.dynamicSelect({
|
||||
withDescription: true,
|
||||
useOptions(query) {
|
||||
const { data: threads = [], isPending, isError } = clientApi.assistant.listThreads.useQuery();
|
||||
const normalizedQuery = query.trim().toLocaleLowerCase();
|
||||
return {
|
||||
isPending,
|
||||
isError,
|
||||
options: threads
|
||||
.filter((thread) => {
|
||||
if (normalizedQuery.length === 0) return true;
|
||||
return (thread.title ?? "").toLocaleLowerCase().includes(normalizedQuery);
|
||||
})
|
||||
.map((thread) => ({
|
||||
value: thread.id,
|
||||
label: thread.title?.trim() || thread.id,
|
||||
})),
|
||||
};
|
||||
},
|
||||
}),
|
||||
}),
|
||||
{
|
||||
conversation: {
|
||||
shouldHide: (options) => options.conversationMode !== "pinned",
|
||||
},
|
||||
},
|
||||
);
|
||||
return optionsBuilder.from(() => ({}));
|
||||
},
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user