Skip to content

Commit

Permalink
update google sites + formik (#2834)
Browse files Browse the repository at this point in the history
* update google sites + formik

* nit

* k
  • Loading branch information
pablonyx authored Oct 19, 2024
1 parent 8f9d433 commit 2fb1d06
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export default function AddConnector({
advancedConfiguration.pruneFreq,
advancedConfiguration.indexingStart,
values.access_type == "public",
groups,
name
);
if (response) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useField } from "formik";
import { FileUpload } from "@/components/admin/connectors/FileUpload";
import CredentialSubText from "@/components/credentials/CredentialFields";

Expand All @@ -6,18 +7,16 @@ interface FileInputProps {
label: string;
optional?: boolean;
description?: string;
selectedFiles: File[];
setSelectedFiles: (files: File[]) => void;
}

export default function FileInput({
name,
label,
optional = false,
description,
selectedFiles,
setSelectedFiles,
}: FileInputProps) {
const [field, meta, helpers] = useField(name);

return (
<>
<label
Expand All @@ -29,9 +28,14 @@ export default function FileInput({
</label>
{description && <CredentialSubText>{description}</CredentialSubText>}
<FileUpload
selectedFiles={selectedFiles}
setSelectedFiles={setSelectedFiles}
selectedFiles={field.value ? [field.value] : []}
setSelectedFiles={(files: File[]) => {
helpers.setValue(files[0] || null);
}}
/>
{meta.touched && meta.error && (
<div className="text-red-500 text-sm mt-1">{meta.error}</div>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const DynamicConnectionForm: FC<DynamicConnectionFormProps> = ({
label={field.label}
optional={field.optional}
description={field.description}
selectedFiles={selectedFiles}
setSelectedFiles={setSelectedFiles}
/>
) : field.type === "list" ? (
<ListInput field={field} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const submitGoogleSite = async (
pruneFreq: number,
indexingStart: Date,
is_public: boolean,
groups: number[],
name?: string
) => {
const uploadCreateAndTriggerConnector = async () => {
Expand Down Expand Up @@ -56,7 +57,13 @@ export const submitGoogleSite = async (
return false;
}

const credentialResponse = await linkCredential(connector.id, 0, base_url);
const credentialResponse = await linkCredential(
connector.id,
0,
base_url,
undefined,
groups
);
if (!credentialResponse.ok) {
const credentialResponseJson = await credentialResponse.json();
setPopup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const DocumentSetCreationForm = ({
placeholder="Describe what the document set represents"
autoCompleteDisabled={true}
/>

{isPaidEnterpriseFeaturesEnabled && (
<IsPublicGroupSelector
formikProps={props}
Expand Down
123 changes: 67 additions & 56 deletions web/src/app/admin/embeddings/pages/EmbeddingFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { usePopup } from "@/components/admin/connectors/Popup";
import { HealthCheckBanner } from "@/components/health/healthcheck";

import { EmbeddingModelSelection } from "../EmbeddingModelSelectionForm";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { Button, Card, Text } from "@tremor/react";
import { ArrowLeft, ArrowRight, WarningCircle } from "@phosphor-icons/react";
import {
Expand Down Expand Up @@ -152,6 +152,68 @@ export default function EmbeddingForm() {
}
}, [currentEmbeddingModel]);

const handleReindex = async () => {
const update = await updateSearch();
if (update) {
await onConfirm();
}
};

const needsReIndex =
currentEmbeddingModel != selectedProvider ||
searchSettings?.multipass_indexing !=
advancedEmbeddingDetails.multipass_indexing;

const ReIndexingButton = useMemo(() => {
const ReIndexingButtonComponent = ({
needsReIndex,
}: {
needsReIndex: boolean;
}) => {
return needsReIndex ? (
<div className="flex mx-auto gap-x-1 ml-auto items-center">
<button
className="enabled:cursor-pointer disabled:bg-accent/50 disabled:cursor-not-allowed bg-accent flex gap-x-1 items-center text-white py-2.5 px-3.5 text-sm font-regular rounded-sm"
onClick={handleReindex}
>
Re-index
</button>
<div className="relative group">
<WarningCircle
className="text-text-800 cursor-help"
size={20}
weight="fill"
/>
<div className="absolute z-10 invisible group-hover:visible bg-background-800 text-text-200 text-sm rounded-md shadow-md p-2 right-0 mt-1 w-64">
<p className="font-semibold mb-2">Needs re-indexing due to:</p>
<ul className="list-disc pl-5">
{currentEmbeddingModel != selectedProvider && (
<li>Changed embedding provider</li>
)}
{searchSettings?.multipass_indexing !=
advancedEmbeddingDetails.multipass_indexing && (
<li>Multipass indexing modification</li>
)}
</ul>
</div>
</div>
</div>
) : (
<button
className="enabled:cursor-pointer ml-auto disabled:bg-accent/50 disabled:cursor-not-allowed bg-accent flex mx-auto gap-x-1 items-center text-white py-2.5 px-3.5 text-sm font-regular rounded-sm"
onClick={async () => {
updateSearch();
navigateToEmbeddingPage("search settings");
}}
>
Update Search
</button>
);
};
ReIndexingButtonComponent.displayName = "ReIndexingButton";
return ReIndexingButtonComponent;
}, [needsReIndex]);

if (!selectedProvider) {
return <ThreeDotsLoader />;
}
Expand Down Expand Up @@ -196,12 +258,13 @@ export default function EmbeddingForm() {

// We use a spread operation to merge properties from multiple objects into a single object.
// Advanced embedding details may update default values.
// Do NOT modify the order unless you are positive the new hierarchy is correct.
if (selectedProvider.provider_type != null) {
// This is a cloud model
newModel = {
...selectedProvider,
...rerankingDetails,
...advancedEmbeddingDetails,
...selectedProvider,
provider_type:
(selectedProvider.provider_type
?.toLowerCase()
Expand All @@ -213,10 +276,10 @@ export default function EmbeddingForm() {
...selectedProvider,
...rerankingDetails,
...advancedEmbeddingDetails,
...selectedProvider,
provider_type: null,
};
}

newModel.index_name = null;

const response = await fetch(
Expand All @@ -239,58 +302,6 @@ export default function EmbeddingForm() {
}
};

const needsReIndex =
currentEmbeddingModel != selectedProvider ||
searchSettings?.multipass_indexing !=
advancedEmbeddingDetails.multipass_indexing;

const ReIndexingButton = ({ needsReIndex }: { needsReIndex: boolean }) => {
return needsReIndex ? (
<div className="flex mx-auto gap-x-1 ml-auto items-center">
<button
className="enabled:cursor-pointer disabled:bg-accent/50 disabled:cursor-not-allowed bg-accent flex gap-x-1 items-center text-white py-2.5 px-3.5 text-sm font-regular rounded-sm"
onClick={async () => {
const update = await updateSearch();
if (update) {
await onConfirm();
}
}}
>
Re-index
</button>
<div className="relative group">
<WarningCircle
className="text-text-800 cursor-help"
size={20}
weight="fill"
/>
<div className="absolute z-10 invisible group-hover:visible bg-background-800 text-text-200 text-sm rounded-md shadow-md p-2 right-0 mt-1 w-64">
<p className="font-semibold mb-2">Needs re-indexing due to:</p>
<ul className="list-disc pl-5">
{currentEmbeddingModel != selectedProvider && (
<li>Changed embedding provider</li>
)}
{searchSettings?.multipass_indexing !=
advancedEmbeddingDetails.multipass_indexing && (
<li>Multipass indexing modification</li>
)}
</ul>
</div>
</div>
</div>
) : (
<button
className="enabled:cursor-pointer ml-auto disabled:bg-accent/50 disabled:cursor-not-allowed bg-accent flex mx-auto gap-x-1 items-center text-white py-2.5 px-3.5 text-sm font-regular rounded-sm"
onClick={async () => {
updateSearch();
navigateToEmbeddingPage("search settings");
}}
>
Update Search
</button>
);
};

return (
<div className="mx-auto mb-8 w-full">
{popup}
Expand Down Expand Up @@ -391,7 +402,7 @@ export default function EmbeddingForm() {
/>
</Card>

<div className={` mt-4 w-full grid grid-cols-3`}>
<div className={`mt-4 w-full grid grid-cols-3`}>
<button
className="border-border-dark mr-auto border flex gap-x-1 items-center text-text p-2.5 text-sm font-regular rounded-sm "
onClick={() => prevFormStep()}
Expand Down

0 comments on commit 2fb1d06

Please sign in to comment.