Skip to content
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

fix: update public brain subscription logic #1727

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ApiBrainDefinitionSecret } from "@/lib/api/brain/types";
type SecretsDefinitionFieldsProps = {
secrets?: ApiBrainDefinitionSecret[];
register: UseFormRegister<{
secrets: Record<string, string>;
secrets?: Record<string, string>;
}>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const usePublicBrainItem = ({ brain }: UseSubscribeToBrainProps) => {
const { publish } = useToast();
const { allBrains, fetchAllBrains } = useBrainContext();
const { register, watch } = useForm<{
secrets: Record<string, string>;
secrets?: Record<string, string>;
}>({});
const secrets = watch("secrets");
const secrets = watch("secrets") ?? {};

const searchParams = useSearchParams();
const urlBrainId = searchParams?.get("brainId");
Expand Down Expand Up @@ -80,11 +80,11 @@ export const usePublicBrainItem = ({ brain }: UseSubscribeToBrainProps) => {
};
const handleBrainSubscription = () => {
const brainHasSecretsLength = brain.brain_definition?.secrets?.length ?? 0;
const filledSecretsLength = Object.keys(secrets).filter(
(key) => secrets[key].length > 0
).length;

if (brain.brain_type === "api") {
const filledSecretsLength = Object.keys(secrets).filter(
(key) => secrets[key].length > 0
).length;
if (
brainHasSecretsLength > 0 &&
filledSecretsLength !== brainHasSecretsLength
Expand Down
Loading