Skip to content

Commit

Permalink
Revert "feat: remove private prompts on related brain delete (#842)"
Browse files Browse the repository at this point in the history
This reverts commit 4c15fe2.
  • Loading branch information
StanGirard authored Aug 7, 2023
1 parent 4c15fe2 commit 166646c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 189 deletions.
12 changes: 0 additions & 12 deletions backend/core/routes/subscription_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from fastapi import APIRouter, Depends, HTTPException
from models.brains import Brain
from models.brains_subscription_invitations import BrainSubscription
from models.prompt import PromptStatusEnum
from models.users import User
from pydantic import BaseModel
from repository.brain.create_brain_user import create_brain_user
from repository.brain.get_brain_by_id import get_brain_by_id
from repository.brain.get_brain_details import get_brain_details
from repository.brain.get_brain_for_user import get_brain_for_user
from repository.brain.update_user_rights import update_brain_user_rights
Expand All @@ -19,8 +17,6 @@
from repository.brain_subscription.subscription_invitation_service import (
SubscriptionInvitationService,
)
from repository.prompt.delete_prompt_py_id import delete_prompt_by_id
from repository.prompt.get_prompt_by_id import get_prompt_by_id
from repository.user.get_user_email_by_user_id import get_user_email_by_user_id
from repository.user.get_user_id_by_user_email import get_user_id_by_user_email

Expand Down Expand Up @@ -147,14 +143,6 @@ async def remove_user_subscription(
]

if len(brain_other_owners) == 0:
# Delete its prompt if it's private
deleting_brain = get_brain_by_id(brain_id)
if deleting_brain and deleting_brain.prompt_id:
deleting_brain_prompt = get_prompt_by_id(deleting_brain.prompt_id)
if deleting_brain_prompt is not None and (
deleting_brain_prompt.status == PromptStatusEnum.private
):
delete_prompt_by_id(deleting_brain.prompt_id)
brain.delete_brain(current_user.id)
else:
brain.delete_user_from_brain(current_user.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TextArea } from "@/lib/components/ui/TextArea";
import { models, paidModels } from "@/lib/context/BrainConfigProvider/types";
import { defineMaxTokens } from "@/lib/helpers/defineMexTokens";

import { PublicPrompts } from "./components/PublicPrompts/PublicPrompts";
import { PublicPrompts } from "./components/PublicPrompts";
import { useSettingsTab } from "./hooks/useSettingsTab";

type SettingsTabProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as Accordion from "@radix-ui/react-accordion";
import { ChangeEvent, useEffect, useState } from "react";

import { usePromptApi } from "@/lib/api/prompt/usePromptApi";
import { Prompt } from "@/lib/types/Prompt";

type PublicPromptsProps = {
onSelect: ({ title, content }: { title: string; content: string }) => void;
};

export const PublicPrompts = ({
onSelect,
}: PublicPromptsProps): JSX.Element => {
const [publicPrompts, setPublicPrompts] = useState<Prompt[]>([]);

const { getPublicPrompts } = usePromptApi();

const fetchPublicPrompts = async () => {
setPublicPrompts(await getPublicPrompts());
};

const handleChange = (event: ChangeEvent<HTMLSelectElement>) => {
const selectedPrompt = publicPrompts.find(
(prompt) => prompt.id === event.target.value
);
if (selectedPrompt) {
onSelect({
title: selectedPrompt.title,
content: selectedPrompt.content,
});
}
};

useEffect(() => {
void fetchPublicPrompts();
}, []);

return (
<Accordion.Root className="AccordionRoot" type="single" collapsible>
<Accordion.Item className="AccordionItem" value="item-1">
<Accordion.Trigger>Pick in public prompts</Accordion.Trigger>
<Accordion.Content>
<select
onChange={handleChange}
className="px-5 w-full py-2 dark:bg-gray-700 bg-gray-200 rounded-md"
>
{publicPrompts.map((prompt) => (
<option value={prompt.id} key={prompt.id}>
{prompt.title}
</option>
))}
</select>
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 166646c

Please sign in to comment.