From d46c30507c87a09f6dc125de7581b9c207488ec8 Mon Sep 17 00:00:00 2001 From: Esteban Dalel R Date: Wed, 13 Dec 2023 12:49:35 -0300 Subject: [PATCH] Feature/granular settings (#402) --- app/(loggedIn)/settings/form.tsx | 206 +++++++++++++----------- app/api/actions/github/route.ts | 62 ++++--- components/Navbar.tsx | 16 +- utils/actions/getAllServices.ts | 69 ++++---- utils/actions/markdownHelpers/helper.ts | 12 +- utils/db/user/patchUserSettings.ts | 4 +- 6 files changed, 208 insertions(+), 161 deletions(-) diff --git a/app/(loggedIn)/settings/form.tsx b/app/(loggedIn)/settings/form.tsx index 2ea78d3af..29c468e8d 100644 --- a/app/(loggedIn)/settings/form.tsx +++ b/app/(loggedIn)/settings/form.tsx @@ -3,57 +3,42 @@ import { useEffect, useState } from "react"; import getUserSettings from "../../../utils/api/getUserSettings"; +let defaultState = { + AISummary: 1, + CodeComments: 1, + Badges: 1, + SearchAmount: 3, + ResponseTexts: 1, +}; export default function form({ userEmail }) { const [saveDisabled, setSaveDisabled] = useState(false); + const [formState, setFormState] = useState(defaultState); + + useEffect(() => { + setUserSettingsState(userEmail); + }, [userEmail]); const setUserSettingsState = async (userEmail) => { let settings = await getUserSettings(userEmail); setFormState(settings); }; - const services = [ - { - valueLabel: "JiraTickets", - label: "Jira Tickets", - }, - { - valueLabel: "SlackMessages", - label: "Slack Messages", - }, - { - valueLabel: "GitHubPRs", - label: "GitHub PRs", - }, - { - valueLabel: "NotionPages", - label: "Notion Pages", - }, - { - valueLabel: "LinearTickets", - label: "Linear Tickets", - }, - { - valueLabel: "ConfluenceDocs", - label: "Confluence Docs", - }, - { - valueLabel: "AsanaTasks", - label: "Asana Tasks", - }, - ]; - let defaultState = { - AISummary: 1, + const setDefault = () => { + setFormState(defaultState); }; - services.map((service) => (defaultState[service.valueLabel] = 3)); - const [formState, setFormState] = useState(defaultState); - const handleSubmit = async () => { + const handleSubmit = async (e) => { setSaveDisabled(true); + e.preventDefault(); + try { const response = await fetch("/api/user/updateSettings", { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ userSettings: formState, email: userEmail }), + body: JSON.stringify({ + userSettings: formState, + email: userEmail, + }), }).then((res) => setUserSettingsState(userEmail)); } catch (error) { console.error("An error occurred while saving the form", error); @@ -61,72 +46,105 @@ export default function form({ userEmail }) { setSaveDisabled(false); } }; - useEffect(() => { - setUserSettingsState(userEmail); - }, [userEmail]); - - function SettingsSelector({ label, valueLabel }) { - return ( -
- {" "} - {label}{" "} - {" "} -
- ); - } - return ( -
- {services.map((service) => ( - - ))} -
- AI Summary: + const handleChange = (e) => { + setFormState({ ...formState, [e.target.name]: e.target.value }); + }; + const ActivationDropdown = ({ name, ariaLabel, formStateName }) => ( +
+ +
+ ); + + return ( + +
+
+

Watermelon AI

+
+
+
+

PR Comment

+
+
+ + +
-
+ +
- {saveDisabled ? "Saving..." : "Save"} - + + +
); } diff --git a/app/api/actions/github/route.ts b/app/api/actions/github/route.ts index ccc2b1c94..834bf7526 100644 --- a/app/api/actions/github/route.ts +++ b/app/api/actions/github/route.ts @@ -26,8 +26,6 @@ import randomText from "../../../../utils/actions/markdownHelpers/randomText"; import createTeamAndMatchUser from "../../../../utils/db/teams/createTeamAndMatchUser"; import sendUninstall from "../../../../utils/sendgrid/sendUninstall"; - - const app = new App({ appId: process.env.GITHUB_APP_ID!, privateKey: process.env.GITHUB_PRIVATE_KEY!, @@ -70,7 +68,7 @@ export async function POST(request: Request) { if (pull_request.user.type === "Bot") { return new Response("We don't comment on bot PRs", { - status: 400 + status: 400, }); } @@ -313,6 +311,9 @@ export async function POST(request: Request) { watermelon_user, AISummary, user_email, + ResponseTexts, + CodeComments, + Badges, } = serviceAnswers; if (error) { return failedToFetchResponse({ @@ -381,42 +382,49 @@ export async function POST(request: Request) { textToWrite += generalMarkdownHelper({ value: github, userLogin, + ResponseTexts, systemName: "GitHub", systemResponseName: "GitHub PRs", }); textToWrite += generalMarkdownHelper({ value: jira, userLogin, + ResponseTexts, systemName: "Jira", systemResponseName: "Jira Tickets", }); textToWrite += generalMarkdownHelper({ value: confluence, userLogin, + ResponseTexts, systemName: "Confluence", systemResponseName: "Confluence Docs", }); textToWrite += generalMarkdownHelper({ value: slack, userLogin, + ResponseTexts, systemName: "Slack", systemResponseName: "Slack Threads", }); textToWrite += generalMarkdownHelper({ value: notion, userLogin, + ResponseTexts, systemName: "Notion", systemResponseName: "Notion Pages", }); textToWrite += generalMarkdownHelper({ value: linear, userLogin, + ResponseTexts, systemName: "Linear", systemResponseName: "Linear Tickets", }); textToWrite += generalMarkdownHelper({ value: asana, userLogin, + ResponseTexts, systemName: "Asana", systemResponseName: "Asana Tasks", }); @@ -428,27 +436,31 @@ export async function POST(request: Request) { textToWrite += randomText(); Promise.all([ // Detect console.logs and its equivalent in other languages - detectConsoleLogs({ - prTitle: title, - businessLogicSummary, - repo, - owner, - issue_number: number, - installationId, - reqUrl: request.url, - reqEmail: req.email, - }), + CodeComments + ? detectConsoleLogs({ + prTitle: title, + businessLogicSummary, + repo, + owner, + issue_number: number, + installationId, + reqUrl: request.url, + reqEmail: req.email, + }) + : null, // Make Watermelon Review the PR's business logic here by comparing the title with the AI-generated summary - labelPullRequest({ - prTitle: title, - businessLogicSummary, - repo, - owner, - issue_number: number, - installationId, - reqUrl: request.url, - reqEmail: req.email, - }), + Badges + ? labelPullRequest({ + prTitle: title, + businessLogicSummary, + repo, + owner, + issue_number: number, + installationId, + reqUrl: request.url, + reqEmail: req.email, + }) + : null, addActionLog({ randomWords, github, @@ -557,7 +569,9 @@ export async function POST(request: Request) { // Find our bot's comment let botComment = comments.data.find((comment) => { - return comment?.user?.login.includes("watermelon-copilot-for-code-review"); + return comment?.user?.login.includes( + "watermelon-copilot-for-code-review" + ); }); // Update the existing comment diff --git a/components/Navbar.tsx b/components/Navbar.tsx index f122cbc74..b8d80a74f 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -13,9 +13,19 @@ export default function Navbar({ children }: { children: React.ReactNode }) { { href: "/api/auth/signout", label: "Logout", onClick: signOut }, ]; return ( -
-