useS3VectorsWrapperInstance.tsx43 lines · main
| 1 | import { useMemo } from 'react' |
| 2 | |
| 3 | import { getVectorBucketFDWName } from './VectorBuckets.utils' |
| 4 | import { |
| 5 | WRAPPER_HANDLERS, |
| 6 | WRAPPERS, |
| 7 | } from '@/components/interfaces/Integrations/Wrappers/Wrappers.constants' |
| 8 | import { wrapperMetaComparator } from '@/components/interfaces/Integrations/Wrappers/Wrappers.utils' |
| 9 | import { useFDWsQuery } from '@/data/fdw/fdws-query' |
| 10 | import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' |
| 11 | |
| 12 | export const useS3VectorsWrapperInstance = ({ bucketId }: { bucketId?: string }) => { |
| 13 | const { data: project, isPending: isLoadingProject } = useSelectedProjectQuery() |
| 14 | |
| 15 | const { data, isPending: isLoadingFDWs } = useFDWsQuery( |
| 16 | { |
| 17 | projectRef: project?.ref, |
| 18 | connectionString: project?.connectionString, |
| 19 | }, |
| 20 | { |
| 21 | enabled: !!bucketId, |
| 22 | } |
| 23 | ) |
| 24 | |
| 25 | const s3VectorsWrapper = useMemo(() => { |
| 26 | return data |
| 27 | ?.filter((wrapper) => |
| 28 | wrapperMetaComparator( |
| 29 | { handlerName: WRAPPER_HANDLERS.S3_VECTORS, server: { options: [] } }, |
| 30 | wrapper |
| 31 | ) |
| 32 | ) |
| 33 | .find((w) => w.name === getVectorBucketFDWName(bucketId ?? '')) |
| 34 | }, [data, bucketId]) |
| 35 | |
| 36 | const s3VectorsWrapperMeta = WRAPPERS.find((w) => w.handlerName === WRAPPER_HANDLERS.S3_VECTORS) |
| 37 | |
| 38 | return { |
| 39 | data: s3VectorsWrapper, |
| 40 | meta: s3VectorsWrapperMeta!, |
| 41 | isLoading: isLoadingProject || isLoadingFDWs, |
| 42 | } |
| 43 | } |