From 3e58f9f8ab9f4cba032e6d1aa5aca5bd423dbdcb Mon Sep 17 00:00:00 2001 From: hagen-danswer Date: Fri, 22 Nov 2024 14:39:55 -0800 Subject: [PATCH] fixed ugly stuff --- .../6d562f86c78b_remove_default_bot.py | 4 + .../app/admin/bots/SlackBotCreationForm.tsx | 27 +++-- web/src/app/admin/bots/SlackBotTokensForm.tsx | 92 ---------------- web/src/app/admin/bots/SlackBotUpdateForm.tsx | 17 +-- web/src/app/admin/bots/SlackTokensForm.tsx | 103 +++++++++++------- .../SlackChannelConfigCreationForm.tsx | 10 +- .../app/admin/connector/[ccPairId]/page.tsx | 19 ++-- .../components/EditableStringFieldDisplay.tsx | 9 +- 8 files changed, 117 insertions(+), 164 deletions(-) delete mode 100644 web/src/app/admin/bots/SlackBotTokensForm.tsx diff --git a/backend/alembic/versions/6d562f86c78b_remove_default_bot.py b/backend/alembic/versions/6d562f86c78b_remove_default_bot.py index 5f7b643deb8..3e7097b87bc 100644 --- a/backend/alembic/versions/6d562f86c78b_remove_default_bot.py +++ b/backend/alembic/versions/6d562f86c78b_remove_default_bot.py @@ -23,6 +23,10 @@ def upgrade() -> None: WHERE name = 'Default Bot' AND bot_token = '' AND app_token = '' + AND NOT EXISTS ( + SELECT 1 FROM slack_channel_config + WHERE slack_channel_config.slack_bot_id = slack_bot.id + ) """ ) ) diff --git a/web/src/app/admin/bots/SlackBotCreationForm.tsx b/web/src/app/admin/bots/SlackBotCreationForm.tsx index bedca762380..8a113af05f4 100644 --- a/web/src/app/admin/bots/SlackBotCreationForm.tsx +++ b/web/src/app/admin/bots/SlackBotCreationForm.tsx @@ -1,9 +1,12 @@ "use client"; +import CardSection from "@/components/admin/CardSection"; import { usePopup } from "@/components/admin/connectors/Popup"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { SlackTokensForm } from "./SlackTokensForm"; +import { SourceIcon } from "@/components/SourceIcon"; +import { AdminPageTitle } from "@/components/admin/Title"; export const NewSlackBotForm = ({}: {}) => { const [formValues] = useState({ @@ -17,15 +20,21 @@ export const NewSlackBotForm = ({}: {}) => { return (
- {popup} -
- -
+ } + title="New Slack Bot" + /> + + {popup} +
+ +
+
); }; diff --git a/web/src/app/admin/bots/SlackBotTokensForm.tsx b/web/src/app/admin/bots/SlackBotTokensForm.tsx deleted file mode 100644 index 03c88975603..00000000000 --- a/web/src/app/admin/bots/SlackBotTokensForm.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { Form, Formik } from "formik"; -import * as Yup from "yup"; -import { PopupSpec } from "@/components/admin/connectors/Popup"; -import { SlackBot } from "@/lib/types"; -import { TextFormField } from "@/components/admin/connectors/Field"; -import CardSection from "@/components/admin/CardSection"; -import { Button } from "@/components/ui/button"; -import { updateSlackBot, SlackBotCreationRequest } from "./new/lib"; - -interface SlackBotTokensFormProps { - onClose: () => void; - setPopup: (popupSpec: PopupSpec | null) => void; - existingSlackApp?: SlackBot; - onTokensSet?: (tokens: { bot_token: string; app_token: string }) => void; - embedded?: boolean; - noForm?: boolean; -} - -export const SlackBotTokensForm = ({ - onClose, - setPopup, - existingSlackApp, - onTokensSet, - embedded = true, - noForm = true, -}: SlackBotTokensFormProps) => { - const Wrapper = embedded ? "div" : CardSection; - - const FormWrapper = noForm ? "div" : Form; - - return ( - - { - if (embedded && onTokensSet) { - onTokensSet(values); - return; - } - - formikHelpers.setSubmitting(true); - const response = await updateSlackBot( - existingSlackApp?.id || 0, - values as SlackBotCreationRequest - ); - formikHelpers.setSubmitting(false); - if (response.ok) { - setPopup({ - message: "Successfully set Slack tokens!", - type: "success", - }); - onClose(); - } else { - const errorMsg = await response.text(); - setPopup({ - message: `Error setting Slack tokens - ${errorMsg}`, - type: "error", - }); - } - }} - > - {({ isSubmitting }) => ( - - - - {!embedded && ( -
- -
- )} -
- )} -
-
- ); -}; diff --git a/web/src/app/admin/bots/SlackBotUpdateForm.tsx b/web/src/app/admin/bots/SlackBotUpdateForm.tsx index 3f43842816f..9eec40eeb95 100644 --- a/web/src/app/admin/bots/SlackBotUpdateForm.tsx +++ b/web/src/app/admin/bots/SlackBotUpdateForm.tsx @@ -78,14 +78,16 @@ export const ExistingSlackBotForm = ({
- + +
+
+ handleUpdateField("name", value)} + scale={2.1} + />
- handleUpdateField("name", value)} - scale={2.5} - />
@@ -124,6 +126,7 @@ export const ExistingSlackBotForm = ({ refreshSlackBot={refreshSlackBot} setPopup={setPopup} router={router} + onValuesChange={(values) => setFormValues(values)} />
diff --git a/web/src/app/admin/bots/SlackTokensForm.tsx b/web/src/app/admin/bots/SlackTokensForm.tsx index e0685dee914..3449e4f1178 100644 --- a/web/src/app/admin/bots/SlackTokensForm.tsx +++ b/web/src/app/admin/bots/SlackTokensForm.tsx @@ -5,7 +5,8 @@ import { Form, Formik } from "formik"; import * as Yup from "yup"; import { createSlackBot, updateSlackBot } from "./new/lib"; import { Button } from "@/components/ui/button"; -import { SourceIcon } from "@/components/SourceIcon"; +import { Separator } from "@/components/ui/separator"; +import { useEffect } from "react"; export const SlackTokensForm = ({ isUpdate, @@ -14,6 +15,7 @@ export const SlackTokensForm = ({ refreshSlackBot, setPopup, router, + onValuesChange, }: { isUpdate: boolean; initialValues: any; @@ -21,6 +23,7 @@ export const SlackTokensForm = ({ refreshSlackBot?: () => void; setPopup: (popup: { message: string; type: "error" | "success" }) => void; router: any; + onValuesChange?: (values: any) => void; }) => ( - {({ isSubmitting, setFieldValue, values }) => ( -
- {!isUpdate && ( -
-
- + {({ isSubmitting, setFieldValue, values }) => { + useEffect(() => { + onValuesChange?.(values); + }, [values, onValuesChange]); + + return ( + + {!isUpdate && ( +
+
- -
- )} + )} - {!isUpdate && ( -
- Please enter your Slack Bot Token and Slack App Token to give - Danswerbot access to your Slack! + {!isUpdate && ( +
+ + Please refer to our{" "} + + guide + {" "} + if you are not sure how to get these tokens! +
+ )} + + +
+
- )} - - -
- -
- - )} + + ); + }} ); diff --git a/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx b/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx index ce54b2dd839..9a8caad2ad5 100644 --- a/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx +++ b/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx @@ -261,10 +261,12 @@ export const SlackChannelConfigCreationForm = ({
- +
+ +
{showAdvancedOptions && (
diff --git a/web/src/app/admin/connector/[ccPairId]/page.tsx b/web/src/app/admin/connector/[ccPairId]/page.tsx index c3b2cf84342..1d435f4df33 100644 --- a/web/src/app/admin/connector/[ccPairId]/page.tsx +++ b/web/src/app/admin/connector/[ccPairId]/page.tsx @@ -119,16 +119,19 @@ function Main({ ccPairId }: { ccPairId: number }) { router.push("/admin/indexing/status")} /> -
-
- +
+
+
- +
+ +
{ccPair.is_editable_for_current_user && (
diff --git a/web/src/components/EditableStringFieldDisplay.tsx b/web/src/components/EditableStringFieldDisplay.tsx index d9a42f5cd6d..c8e68852815 100644 --- a/web/src/components/EditableStringFieldDisplay.tsx +++ b/web/src/components/EditableStringFieldDisplay.tsx @@ -83,6 +83,7 @@ export function EditableStringFieldDisplay({ onKeyDown={handleKeyDown} className={cn( textClassName, + "text-3xl font-bold text-text-800", "user-text", isEditing ? "block" : "hidden" )} @@ -91,7 +92,11 @@ export function EditableStringFieldDisplay({ {!isEditing && ( isEditable && setIsEditing(true)} - className={cn(textClassName, "cursor-pointer user-text")} + className={cn( + textClassName, + "text-3xl font-bold text-text-800", + "cursor-pointer user-text" + )} style={{ fontSize: `${scale}rem` }} > {value} @@ -125,7 +130,7 @@ export function EditableStringFieldDisplay({ style={{ fontSize: `${scale}rem` }} > {isEditable && ( - + )} )}