Skip to content

Commit 2ffa2c1

Browse files
committed
Small improvements
1 parent 93555b7 commit 2ffa2c1

File tree

9 files changed

+109
-31
lines changed

9 files changed

+109
-31
lines changed

web/src/app/admin/add-connector/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
TooltipTrigger,
1616
} from "@/components/ui/tooltip";
1717
import { useFederatedConnectors } from "@/lib/hooks";
18-
import { FederatedConnectorInfo, ValidSources } from "@/lib/types";
18+
import {
19+
FederatedConnectorInfo,
20+
federatedSourceToRegularSource,
21+
ValidSources,
22+
} from "@/lib/types";
1923
import useSWR from "swr";
2024
import { errorHandlingFetcher } from "@/lib/fetcher";
2125
import { buildSimilarCredentialInfoURL } from "@/app/admin/connector/[ccPairId]/lib";
@@ -40,7 +44,8 @@ function SourceTile({
4044

4145
return federatedConnectors.find(
4246
(connector) =>
43-
connector.source === `federated_${sourceMetadata.internalName}`
47+
federatedSourceToRegularSource(connector.source) ===
48+
sourceMetadata.internalName
4449
);
4550
}, [sourceMetadata, federatedConnectors]);
4651

web/src/app/admin/connectors/[connector]/AddConnectorPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ export default function AddConnector({
511511
includeDivider={false}
512512
icon={<SourceIcon iconSize={32} sourceType={connector} />}
513513
title={displayName}
514+
farRightElement={undefined}
514515
/>
515516

516517
{formStep == 0 && (

web/src/app/admin/connectors/[connector]/ConnectorWrapper.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ import { HeaderTitle } from "@/components/header/HeaderTitle";
88
import { Button } from "@/components/ui/button";
99
import { isValidSource, getSourceMetadata } from "@/lib/sources";
1010
import { FederatedConnectorForm } from "@/components/admin/federated/FederatedConnectorForm";
11+
import { useSearchParams } from "next/navigation";
12+
import useSWR from "swr";
13+
import { errorHandlingFetcher } from "@/lib/fetcher";
14+
import { buildSimilarCredentialInfoURL } from "@/app/admin/connector/[ccPairId]/lib";
15+
import { Credential } from "@/lib/connectors/credentials";
1116

1217
export default function ConnectorWrapper({
1318
connector,
1419
}: {
1520
connector: ConfigurableSources;
1621
}) {
22+
const searchParams = useSearchParams();
23+
const mode = searchParams?.get("mode"); // 'federated' or 'regular'
24+
25+
// Fetch existing credentials for this connector type
26+
const { data: existingCredentials } = useSWR<Credential<any>[]>(
27+
buildSimilarCredentialInfoURL(connector),
28+
errorHandlingFetcher
29+
);
30+
1731
// Check if the connector is valid
1832
if (!isValidSource(connector)) {
1933
return (
@@ -39,12 +53,34 @@ export default function ConnectorWrapper({
3953
);
4054
}
4155

42-
// Check if the connector is federated
4356
const sourceMetadata = getSourceMetadata(connector);
44-
const isFederated = sourceMetadata.federated;
57+
const supportsFederated = sourceMetadata.federated === true;
58+
const hasExistingCredentials =
59+
existingCredentials && existingCredentials.length > 0;
60+
61+
// Determine which form to show based on:
62+
// 1. URL parameter mode (takes priority)
63+
// 2. If no mode specified and existing credentials exist, show regular form
64+
// 3. If no mode specified and no credentials, show federated form for federated-supported sources
65+
let showFederatedForm = false;
66+
67+
if (mode === "federated") {
68+
showFederatedForm = supportsFederated;
69+
} else if (mode === "regular") {
70+
showFederatedForm = false;
71+
} else {
72+
// No mode specified - use default logic
73+
if (hasExistingCredentials) {
74+
// Default to regular form if existing credentials exist
75+
showFederatedForm = false;
76+
} else {
77+
// Default to federated for federated-supported sources with no existing credentials
78+
showFederatedForm = supportsFederated;
79+
}
80+
}
4581

46-
// For federated connectors, use the specialized form without FormProvider
47-
if (isFederated) {
82+
// For federated form, use the specialized form without FormProvider
83+
if (showFederatedForm) {
4884
return (
4985
<div className="flex justify-center w-full h-full">
5086
<div className="mt-12 w-full max-w-4xl mx-auto">

web/src/app/admin/indexing/status/CCPairIndexingStatusTable.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ValidSources,
1919
ValidStatuses,
2020
FederatedConnectorInfo,
21+
federatedSourceToRegularSource,
2122
} from "@/lib/types";
2223
import { useRouter } from "next/navigation";
2324
import {
@@ -245,7 +246,7 @@ border border-border dark:border-neutral-700
245246
{federatedConnector.name}
246247
</p>
247248
</TableCell>
248-
<TableCell>n/a</TableCell>
249+
<TableCell>N/A</TableCell>
249250
<TableCell>
250251
<Badge variant="success">Indexed</Badge>
251252
</TableCell>
@@ -256,7 +257,7 @@ border border-border dark:border-neutral-700
256257
</Badge>
257258
</TableCell>
258259
)}
259-
<TableCell>n/a</TableCell>
260+
<TableCell>N/A</TableCell>
260261
<TableCell>
261262
<TooltipProvider>
262263
<Tooltip>
@@ -357,7 +358,7 @@ export function CCPairIndexingStatusTable({
357358
sorted.forEach((source) => {
358359
const statuses = grouped[source];
359360
const federatedForSource = federatedConnectors.filter(
360-
(fc) => fc.source.replace(/^federated_/, "") === source
361+
(fc) => federatedSourceToRegularSource(fc.source) === source
361362
);
362363

363364
summaries[source] = {
@@ -446,7 +447,9 @@ export function CCPairIndexingStatusTable({
446447
const allSourcesWithFederated = useMemo(() => {
447448
const federatedSources = Array.from(
448449
new Set(
449-
federatedConnectors.map((fc) => fc.source.replace(/^federated_/, ""))
450+
federatedConnectors.map((fc) =>
451+
federatedSourceToRegularSource(fc.source)
452+
)
450453
)
451454
) as ValidSources[];
452455

@@ -696,7 +699,7 @@ export function CCPairIndexingStatusTable({
696699
);
697700

698701
const federatedForSource = federatedConnectors.filter(
699-
(fc) => fc.source.replace(/^federated_/, "") === source
702+
(fc) => federatedSourceToRegularSource(fc.source) === source
700703
);
701704

702705
const hasFederatedMatches = federatedForSource.some((fc) =>

web/src/app/chat/ChatPage.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,17 @@ export function ChatPage({
484484
return getSourceMetadata(connector.source as ValidSources);
485485
}) || [];
486486

487-
return [...regularSources, ...federatedSources];
487+
// Combine sources and deduplicate based on internalName
488+
const allSources = [...regularSources, ...federatedSources];
489+
const deduplicatedSources = allSources.reduce((acc, source) => {
490+
const existing = acc.find((s) => s.internalName === source.internalName);
491+
if (!existing) {
492+
acc.push(source);
493+
}
494+
return acc;
495+
}, [] as SourceMetadata[]);
496+
497+
return deduplicatedSources;
488498
}, [availableSources, federatedConnectorsData]);
489499

490500
const stopGenerating = () => {

web/src/app/chat/modal/UserSettingsModal.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ export function UserSettingsModal({
296296
showPasswordSection || hasConnectors ? "max-w-3xl" : "max-w-xl"
297297
}`}
298298
>
299-
<div className="p-2">
299+
<div className="p-2 max-h-[80vh] flex flex-col">
300300
<h2 className="text-xl font-bold mb-4">User Settings</h2>
301301
<Separator className="mb-6" />
302-
<div className="flex">
302+
<div className="flex flex-1 min-h-0">
303303
{(showPasswordSection || hasConnectors) && (
304-
<div className="w-1/4 pr-4">
304+
<div className="w-1/4 pr-4 flex-shrink-0">
305305
<nav>
306306
<ul className="space-y-2">
307307
<li>
@@ -350,8 +350,10 @@ export function UserSettingsModal({
350350
)}
351351
<div
352352
className={`${
353-
showPasswordSection || hasConnectors ? "w-3/4 pl-4" : "w-full"
354-
}`}
353+
showPasswordSection || hasConnectors
354+
? "w-3/4 pl-4 pr-3"
355+
: "w-full pr-3"
356+
} overflow-y-scroll default-scrollbar`}
355357
>
356358
{activeSection === "settings" && (
357359
<div className="space-y-6">

web/src/components/FederatedConnectorSelector.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React, { useState, useRef, useEffect } from "react";
2-
import { FederatedConnectorInfo, FederatedConnectorConfig } from "@/lib/types";
2+
import {
3+
FederatedConnectorInfo,
4+
FederatedConnectorConfig,
5+
federatedSourceToRegularSource,
6+
ValidSources,
7+
} from "@/lib/types";
38
import { SourceIcon } from "@/components/SourceIcon";
49
import { X, Search, Settings } from "lucide-react";
510
import { Label } from "@/components/ui/label";
@@ -28,7 +33,7 @@ interface FederatedConnectorSelectorProps {
2833
interface EntityConfigDialogProps {
2934
connectorId: number;
3035
connectorName: string;
31-
connectorSource: string;
36+
connectorSource: ValidSources | null;
3237
currentEntities: Record<string, any>;
3338
onSave: (entities: Record<string, any>) => void;
3439
onClose: () => void;
@@ -92,13 +97,17 @@ const EntityConfigDialog = ({
9297
}));
9398
};
9499

100+
if (!connectorSource) {
101+
return null;
102+
}
103+
95104
return (
96105
<Dialog open={isOpen} onOpenChange={onClose}>
97106
<DialogContent className="max-w-md">
98107
<DialogHeader>
99108
<DialogTitle className="flex items-center gap-2">
100109
<SourceIcon
101-
sourceType={connectorSource.replace(/^federated_/, "") as any}
110+
sourceType={federatedSourceToRegularSource(connectorSource)}
102111
iconSize={20}
103112
/>
104113
Configure {connectorName}
@@ -219,13 +228,13 @@ export const FederatedConnectorSelector = ({
219228
isOpen: boolean;
220229
connectorId: number | null;
221230
connectorName: string;
222-
connectorSource: string;
231+
connectorSource: ValidSources | null;
223232
currentEntities: Record<string, any>;
224233
}>({
225234
isOpen: false,
226235
connectorId: null,
227236
connectorName: "",
228-
connectorSource: "",
237+
connectorSource: null,
229238
currentEntities: {},
230239
});
231240
const dropdownRef = useRef<HTMLDivElement>(null);
@@ -410,9 +419,9 @@ export const FederatedConnectorSelector = ({
410419
<div className="flex items-center truncate mr-2">
411420
<div className="mr-2">
412421
<SourceIcon
413-
sourceType={
414-
connector.source.replace(/^federated_/, "") as any
415-
}
422+
sourceType={federatedSourceToRegularSource(
423+
connector.source
424+
)}
416425
iconSize={16}
417426
/>
418427
</div>
@@ -444,9 +453,9 @@ export const FederatedConnectorSelector = ({
444453
<div className="flex items-center overflow-hidden">
445454
<div className="mr-1 flex-shrink-0">
446455
<SourceIcon
447-
sourceType={
448-
connector.source.replace(/^federated_/, "") as any
449-
}
456+
sourceType={federatedSourceToRegularSource(
457+
connector.source
458+
)}
450459
iconSize={14}
451460
/>
452461
</div>

web/src/components/admin/federated/FederatedConnectorForm.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
TooltipProvider,
3434
TooltipTrigger,
3535
} from "@/components/ui/tooltip";
36+
import { Badge } from "@/components/ui/badge";
3637

3738
export interface FederatedConnectorFormProps {
3839
connector: ConfigurableSources;
@@ -467,9 +468,11 @@ export function FederatedConnectorForm({
467468
<div className="ml-2 overflow-hidden text-ellipsis whitespace-nowrap flex-1 mr-4">
468469
<div className="text-2xl font-bold text-text-default flex items-center gap-2">
469470
<span>
470-
{isEditMode ? "Edit" : "Setup"} {sourceMetadata.displayName}{" "}
471-
(Federated)
471+
{isEditMode ? "Edit" : "Setup"} {sourceMetadata.displayName}
472472
</span>
473+
<Badge variant="outline" className="text-xs">
474+
Federated
475+
</Badge>
473476
<TooltipProvider>
474477
<Tooltip>
475478
<TooltipTrigger asChild>

web/src/lib/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export interface ConnectorIndexingStatus<
177177

178178
export interface FederatedConnectorInfo {
179179
id: number;
180-
source: string;
180+
source: ValidSources;
181181
name: string;
182182
status: string;
183183
last_success: string | null;
@@ -434,6 +434,15 @@ export enum ValidSources {
434434
FederatedSlack = "federated_slack",
435435
}
436436

437+
export const federatedSourceToRegularSource = (
438+
maybeFederatedSource: ValidSources
439+
): ValidSources => {
440+
if (maybeFederatedSource === ValidSources.FederatedSlack) {
441+
return ValidSources.Slack;
442+
}
443+
return maybeFederatedSource;
444+
};
445+
437446
export const validAutoSyncSources = [
438447
ValidSources.Confluence,
439448
ValidSources.GoogleDrive,

0 commit comments

Comments
 (0)