From c0e1fd8562cc8f67fda6ea459b02f2a3b15c3501 Mon Sep 17 00:00:00 2001 From: Philippe Rolet Date: Mon, 18 Mar 2024 17:00:56 +0100 Subject: [PATCH] [Poke] Check notion url from notion page in Poke (#4303) * ux * api call --- connectors/src/api/admin.ts | 6 +- .../poke/[wId]/data_sources/[name]/index.tsx | 130 +++++++++++++++++- 2 files changed, 131 insertions(+), 5 deletions(-) diff --git a/connectors/src/api/admin.ts b/connectors/src/api/admin.ts index 25078e93edf8..60432cbe4624 100644 --- a/connectors/src/api/admin.ts +++ b/connectors/src/api/admin.ts @@ -13,8 +13,8 @@ import { apiError, withLogging } from "@connectors/logger/withlogging"; const whitelistedCommands = [ { - majorCommand: "connectors", - command: "resume", + majorCommand: "notion", + command: "check-url", }, ]; @@ -49,7 +49,7 @@ const _adminAPIHandler = async ( return apiError(req, res, { api_error: { type: "invalid_request_error", - message: `Command not whitelisted: ${JSON.stringify(adminCommand)}`, + message: `Command not whitelisted: ${adminCommand.majorCommand} ${adminCommand.command}`, }, status_code: 400, }); diff --git a/front/pages/poke/[wId]/data_sources/[name]/index.tsx b/front/pages/poke/[wId]/data_sources/[name]/index.tsx index 2919e7581a23..31cfe442cab9 100644 --- a/front/pages/poke/[wId]/data_sources/[name]/index.tsx +++ b/front/pages/poke/[wId]/data_sources/[name]/index.tsx @@ -5,10 +5,15 @@ import { EyeIcon, Icon, InformationCircleIcon, + Input, Page, SliderToggle, } from "@dust-tt/sparkle"; -import type { CoreAPIDataSource, DataSourceType } from "@dust-tt/types"; +import type { + CoreAPIDataSource, + DataSourceType, + NotionCheckUrlResponseType, +} from "@dust-tt/types"; import type { WorkspaceType } from "@dust-tt/types"; import type { ConnectorType } from "@dust-tt/types"; import { ConnectorsAPI } from "@dust-tt/types"; @@ -26,7 +31,11 @@ import { useSubmitFunction } from "@app/lib/client/utils"; import { getDisplayNameForDocument } from "@app/lib/data_sources"; import { withSuperUserAuthRequirements } from "@app/lib/iam/session"; import { useDocuments } from "@app/lib/swr"; -import { formatTimestampToFriendlyDate, timeAgoFrom } from "@app/lib/utils"; +import { + classNames, + formatTimestampToFriendlyDate, + timeAgoFrom, +} from "@app/lib/utils"; import logger from "@app/logger/logger"; const { TEMPORAL_CONNECTORS_NAMESPACE = "" } = process.env; @@ -282,6 +291,8 @@ const DataSourcePage = ({ } }; + const [notionUrlToCheck, setNotionUrlToCheck] = useState(""); + return (
@@ -351,6 +362,13 @@ const DataSourcePage = ({ />
)} + {dataSource.connectorProvider === "notion" && ( + + )} {dataSource.connectorProvider === "google_drive" && (
PDF syncing enabled?
@@ -513,4 +531,112 @@ const DataSourcePage = ({ ); }; +async function handleCheckNotionUrl( + url: string, + wId: string +): Promise { + const res = await fetch(`/api/poke/admin`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + majorCommand: "notion", + command: "check-url", + args: { + url, + wId, + }, + }), + }); + + if (!res.ok) { + const err = await res.json(); + alert( + `Failed to check Notion URL: ${ + err.error?.connectors_error?.message + }\n\n${JSON.stringify(err)}` + ); + return null; + } + return res.json(); +} + +function NotionUrlChecker({ + notionUrlToCheck, + setNotionUrlToCheck, + owner, +}: { + notionUrlToCheck: string; + setNotionUrlToCheck: (value: string) => void; + owner: WorkspaceType; +}) { + const [urlDetails, setUrlDetails] = + useState(null); + return ( +
+
+
Check Notion URL
+
+ +
+
+
+

+ Check if we have access to the Notion URL, if it's a page or a DB, and + provide a few details. +

+ {urlDetails && ( +
+ + {(() => { + if (urlDetails.page) { + return "Page found"; + } + if (urlDetails.db) { + return "Database found"; + } + return "Not found"; + })()} + + {(urlDetails.page || urlDetails.db) && ( +
+ Details:{" "} + + {urlDetails.page ? ( + + ) : ( + + )} + +
+ )} +
+ )} +
+
+ ); +} + export default DataSourcePage;