feat: Update SearxNG connector form validation, enhance connector connect view with additional properties, and refine type handling in connector dialog for improved schema compliance.

This commit is contained in:
Anish Sarkar 2025-12-31 16:33:15 +05:30
parent 21146485e6
commit 4d6186a43a
5 changed files with 17 additions and 8 deletions

View file

@ -27,7 +27,8 @@ const searxngFormSchema = z.object({
message: "Connector name must be at least 3 characters.",
}),
host: z
.string({ required_error: "Host is required." })
.string()
.min(1, { message: "Host is required." })
.url({ message: "Enter a valid SearxNG host URL (e.g. https://searxng.example.org)." }),
api_key: z.string().optional(),
engines: z.string().optional(),
@ -37,7 +38,7 @@ const searxngFormSchema = z.object({
.string()
.regex(/^[0-2]?$/, { message: "SafeSearch must be 0, 1, or 2." })
.optional(),
verify_ssl: z.boolean().default(true),
verify_ssl: z.boolean(),
});
type SearxngFormValues = z.infer<typeof searxngFormSchema>;

View file

@ -17,8 +17,12 @@ interface ConnectorConnectViewProps {
is_indexable: boolean;
last_indexed_at: null;
periodic_indexing_enabled: boolean;
indexing_frequency_minutes: null;
indexing_frequency_minutes: number | null;
next_scheduled_at: null;
startDate?: Date;
endDate?: Date;
periodicEnabled?: boolean;
frequencyMinutes?: string;
}) => Promise<void>;
onBack: () => void;
isSubmitting: boolean;

View file

@ -40,7 +40,7 @@ export type IndexingConfigState = z.infer<typeof indexingConfigStateSchema>;
* Schema for frequency minutes (must be one of the allowed values)
*/
export const frequencyMinutesSchema = z.enum(["15", "60", "360", "720", "1440", "10080"], {
errorMap: () => ({ message: "Invalid frequency value" }),
message: "Invalid frequency value",
});
export type FrequencyMinutes = z.infer<typeof frequencyMinutesSchema>;

View file

@ -232,7 +232,7 @@ export const useConnectorDialog = () => {
// Handle OAuth connection
const handleConnectOAuth = useCallback(
async (connector: (typeof OAUTH_CONNECTORS)[0]) => {
async (connector: (typeof OAUTH_CONNECTORS)[number]) => {
if (!searchSpaceId || !connector.authEndpoint) return;
// Set connecting state immediately to disable button and show spinner
@ -368,9 +368,13 @@ export const useConnectorDialog = () => {
// Extract UI-only fields before sending to backend
const { startDate, endDate, periodicEnabled, frequencyMinutes, ...connectorData } = formData;
// Create connector
// Create connector - ensure types match the schema
const newConnector = await createConnector({
data: connectorData,
data: {
...connectorData,
connector_type: connectorData.connector_type as EnumConnectorName,
next_scheduled_at: connectorData.next_scheduled_at as string | null,
},
queryParams: {
search_space_id: searchSpaceId,
},

View file

@ -12,7 +12,7 @@ interface AllConnectorsTabProps {
connectedTypes: Set<string>;
connectingId: string | null;
allConnectors: SearchSourceConnector[] | undefined;
onConnectOAuth: (connector: (typeof OAUTH_CONNECTORS)[0]) => void;
onConnectOAuth: (connector: (typeof OAUTH_CONNECTORS)[number]) => void;
onConnectNonOAuth?: (connectorType: string) => void;
onCreateWebcrawler?: () => void;
onManage?: (connector: SearchSourceConnector) => void;