SurfSense/surfsense_web/hooks/use-connectors-sync.ts
Anish Sarkar a8c1fb660d feat(rename): complete searchSpace to workspace transition across frontend and backend
- Introduced a comprehensive specification for renaming `searchSpace` to `workspace` in `surfsense_web` and `surfsense_desktop`, ensuring all TypeScript identifiers, React props, and local data structures are updated.
- Implemented migration shims for persisted local state to prevent data loss during the transition.
- Updated observability metrics and IPC channels to reflect the new naming convention.
- Removed legacy `active-search-space` module and replaced it with `active-workspace` to maintain consistency.
- Ensured no behavioral changes or data loss for users during the renaming process.
2026-07-06 15:12:40 +05:30

42 lines
1.6 KiB
TypeScript

"use client";
import { useQuery } from "@rocicorp/zero/react";
import { useMemo } from "react";
import type { SearchSourceConnector } from "@/contracts/types/connector.types";
import { queries } from "@/zero/queries";
/**
* Syncs connectors for a workspace via Zero.
* Returns connectors, loading state, error, and a refresh function.
*/
export function useConnectorsSync(workspaceId: number | string | null) {
const spaceId = workspaceId ? Number(workspaceId) : -1;
const [data, result] = useQuery(queries.connectors.bySpace({ workspaceId: spaceId }));
const connectors: SearchSourceConnector[] = useMemo(() => {
if (!workspaceId || !data) return [];
return data.map((c) => ({
id: c.id,
name: c.name,
connector_type: c.connectorType as SearchSourceConnector["connector_type"],
is_indexable: c.isIndexable,
is_active: true,
last_indexed_at: c.lastIndexedAt ? new Date(c.lastIndexedAt).toISOString() : null,
config: (c.config as Record<string, unknown>) ?? {},
periodic_indexing_enabled: c.periodicIndexingEnabled,
indexing_frequency_minutes: c.indexingFrequencyMinutes ?? null,
next_scheduled_at: c.nextScheduledAt ? new Date(c.nextScheduledAt).toISOString() : null,
workspace_id: c.workspaceId,
user_id: c.userId,
created_at: c.createdAt ? new Date(c.createdAt).toISOString() : new Date().toISOString(),
}));
}, [workspaceId, data]);
const loading = !workspaceId ? false : result.type !== "complete";
const error = !workspaceId ? null : null;
const refreshConnectors = async () => {};
return { connectors, loading, error, refreshConnectors };
}