Add Loopio Connector (#850)

Looks good! I couldn't verify that it end-to-end because Loopio still hasn't granted me API access but the code looks good. Thanks a bunch for the contribution!

Would you be open to also writing the docs page for the setup? It's just adding an md file with some images or gifs:
https://github.com/danswer-ai/danswer-docs

I can provide a template branch if that would make it easier, just let me know 🙏
This commit is contained in:
Sam Jakos
2024-01-06 01:32:10 -06:00
committed by GitHub
parent 30983657ec
commit 885e698d5d
9 changed files with 504 additions and 0 deletions

BIN
web/public/Loopio.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

View File

@@ -0,0 +1,252 @@
"use client";
import * as Yup from "yup";
import { LoopioIcon, TrashIcon } from "@/components/icons/icons";
import { TextFormField } from "@/components/admin/connectors/Field";
import { HealthCheckBanner } from "@/components/health/healthcheck";
import { CredentialForm } from "@/components/admin/connectors/CredentialForm";
import {
Credential,
ConnectorIndexingStatus,
LoopioConfig,
LoopioCredentialJson,
} from "@/lib/types";
import useSWR, { useSWRConfig } from "swr";
import { fetcher } from "@/lib/fetcher";
import { LoadingAnimation } from "@/components/Loading";
import { adminDeleteCredential, linkCredential } from "@/lib/credential";
import { ConnectorForm } from "@/components/admin/connectors/ConnectorForm";
import { ConnectorsTable } from "@/components/admin/connectors/table/ConnectorsTable";
import { usePopup } from "@/components/admin/connectors/Popup";
import { usePublicCredentials } from "@/lib/hooks";
const Main = () => {
const { popup, setPopup } = usePopup();
const { mutate } = useSWRConfig();
const {
data: connectorIndexingStatuses,
isLoading: isConnectorIndexingStatusesLoading,
error: isConnectorIndexingStatusesError,
} = useSWR<ConnectorIndexingStatus<any, any>[]>(
"/api/manage/admin/connector/indexing-status",
fetcher
);
const {
data: credentialsData,
isLoading: isCredentialsLoading,
isValidating: isCredentialsValidating,
error: isCredentialsError,
refreshCredentials,
} = usePublicCredentials();
if (
isConnectorIndexingStatusesLoading ||
isCredentialsLoading ||
isCredentialsValidating
) {
return <LoadingAnimation text="Loading" />;
}
if (isConnectorIndexingStatusesError || !connectorIndexingStatuses) {
return <div>Failed to load connectors</div>;
}
if (isCredentialsError || !credentialsData) {
return <div>Failed to load credentials</div>;
}
const loopioConnectorIndexingStatuses: ConnectorIndexingStatus<
LoopioConfig,
LoopioCredentialJson
>[] = connectorIndexingStatuses.filter(
(connectorIndexingStatus) =>
connectorIndexingStatus.connector.source === "loopio"
);
const loopioCredential: Credential<LoopioCredentialJson> | undefined =
credentialsData.find(
(credential) => credential.credential_json?.loopio_client_id
);
return (
<>
{popup}
<p className="text-sm">
This connector allows you to sync your Loopio Library Entries into
Danswer
</p>
<h2 className="font-bold mb-2 mt-6 ml-auto mr-auto">
Step 1: Provide your API Access info
</h2>
{loopioCredential ? (
<>
<div className="flex mb-1 text-sm">
<p className="my-auto">Existing App Key Secret: </p>
<p className="ml-1 italic my-auto max-w-md truncate">
{loopioCredential.credential_json?.loopio_client_token}
</p>
<button
className="ml-1 hover:bg-gray-700 rounded-full p-1"
onClick={async () => {
if (loopioConnectorIndexingStatuses.length > 0) {
setPopup({
type: "error",
message:
"Must delete all connectors before deleting credentials",
});
return;
}
await adminDeleteCredential(loopioCredential.id);
refreshCredentials();
}}
>
<TrashIcon />
</button>
</div>
</>
) : (
<>
<div className="border-solid border-gray-600 border rounded-md p-6 mt-2">
<CredentialForm<LoopioCredentialJson>
formBody={
<>
<TextFormField
name="loopio_subdomain"
label="Account Subdomain:"
/>
<TextFormField name="loopio_client_id" label="App Key ID:" />
<TextFormField
name="loopio_client_token"
label="App Key Secret:"
type="password"
/>
</>
}
validationSchema={Yup.object().shape({
loopio_subdomain: Yup.string().required(
"Please enter your Loopio Account subdomain"
),
loopio_client_id: Yup.string().required(
"Please enter your Loopio App Key ID"
),
loopio_client_token: Yup.string().required(
"Please enter your Loopio App Key Secret"
),
})}
initialValues={{
loopio_subdomain: "",
loopio_client_id: "",
loopio_client_token: "",
}}
onSubmit={(isSuccess) => {
if (isSuccess) {
refreshCredentials();
}
}}
/>
</div>
</>
)}
<h2 className="font-bold mt-6 ml-auto mr-auto">
Step 2: Which Stack do you want to make searchable?
</h2>
<p className="text-sm mb-2">
Leave this blank if you want to index all stacks.
</p>
{loopioConnectorIndexingStatuses.length > 0 && (
<>
<p className="text-sm mb-2">
We pull the latest library entries every <b>24</b> hours.
</p>
<div className="mb-2">
<ConnectorsTable<LoopioConfig, LoopioCredentialJson>
connectorIndexingStatuses={loopioConnectorIndexingStatuses}
liveCredential={loopioCredential}
getCredential={(credential) =>
credential.credential_json.loopio_client_id
}
specialColumns={[
{
header: "Stack",
key: "loopio_stack_name",
getValue: (ccPairStatus) =>
ccPairStatus.connector.connector_specific_config
.loopio_stack_name || "All stacks",
},
]}
includeName={true}
onUpdate={() =>
mutate("/api/manage/admin/connector/indexing-status")
}
onCredentialLink={async (connectorId) => {
if (loopioCredential) {
await linkCredential(connectorId, loopioCredential.id);
mutate("/api/manage/admin/connector/indexing-status");
}
}}
/>
</div>
</>
)}
{loopioCredential ? (
<>
<div className="border-solid border-gray-600 border rounded-md p-6 mt-4">
<h2 className="font-bold mb-3">Create a new Loopio Connector</h2>
<ConnectorForm<LoopioConfig>
nameBuilder={(values) =>
values?.loopio_stack_name
? `LoopioConnector-${values.loopio_stack_name}-Stack`
: `LoopioConnector-AllStacks`
}
source="loopio"
inputType="poll"
formBody={
<>
<TextFormField
name="loopio_stack_name"
label="[Optional] Loopio Stack name:"
subtext=" Must be exact match to the name in Library Management, leave this blank if you want to index all Stacks"
/>
</>
}
validationSchema={Yup.object().shape({
loopio_stack_name: Yup.string(),
})}
initialValues={{
loopio_stack_name: "",
}}
refreshFreq={60 * 60 * 24} // 24 hours
credentialId={loopioCredential.id}
/>
</div>
</>
) : (
<p className="text-sm">
Please provide your API Access Info in Step 1 first! Once done with
that, you can start indexing your Loopio library.
</p>
)}
</>
);
};
export default function Page() {
return (
<div className="mx-auto container">
<div className="mb-4">
<HealthCheckBanner />
</div>
<div className="border-solid border-gray-600 border-b mb-4 pb-2 flex">
<LoopioIcon size={32} />
<h1 className="text-3xl font-bold pl-2">Loopio</h1>
</div>
<Main />
</div>
);
}

View File

@@ -302,6 +302,20 @@ export const ConnectorIcon = ({
// COMPANY LOGOS
//
export const LoopioIcon = ({
size = 16,
className = defaultTailwindCSS,
}: IconProps) => {
return (
<div
style={{ width: `${size}px`, height: `${size}px` }}
className={`w-[${size}px] h-[${size}px] dark:invert ` + className}
>
<Image src="/Loopio.png" alt="Logo" width="96" height="96" />
</div>
);
};
export const SlackIcon = ({
size = 16,
className = defaultTailwindCSS,

View File

@@ -12,6 +12,7 @@ import {
HubSpotIcon,
JiraIcon,
LinearIcon,
LoopioIcon,
NotionIcon,
ProductboardIcon,
RequestTrackerIcon,
@@ -134,6 +135,11 @@ const SOURCE_METADATA_MAP: SourceMap = {
displayName: "Request Tracker",
category: SourceCategory.AppConnection,
},
loopio: {
icon: LoopioIcon,
displayName: "Loopio",
category: SourceCategory.AppConnection,
},
};
function fillSourceMetadata(

View File

@@ -29,6 +29,7 @@ export type ValidSources =
| "requesttracker"
| "file"
| "google_sites"
| "loopio"
| "zendesk";
export type ValidInputTypes = "load_state" | "poll" | "event";
@@ -109,6 +110,10 @@ export interface GongConfig {
workspaces?: string[];
}
export interface LoopioConfig {
loopio_stack_name?: string;
}
export interface FileConfig {
file_locations: string[];
}
@@ -239,6 +244,12 @@ export interface GongCredentialJson {
gong_access_key_secret: string;
}
export interface LoopioCredentialJson {
loopio_subdomain: string;
loopio_client_id: string;
loopio_client_token: string;
}
export interface LinearCredentialJson {
linear_api_key: string;
}