From 1e3507fea030d9ac6110d648db78bea6f5f6429b Mon Sep 17 00:00:00 2001 From: EiffelFly <57251712+EiffelFly@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:27:20 +0800 Subject: [PATCH] fix: fix naming --- packages/sdk/src/catalog/CatalogClient.ts | 2 +- .../lib/react-query-service/catalog/index.ts | 2 +- .../catalog/useDeleteCatalogFile.tsx | 4 ++-- ...amespaceCatalogSingleSourceOfTruthFile.ts} | 19 +++++++++++-------- .../catalog/useListNamespaceCatalogs.ts | 4 ++-- .../catalog/useUpdateCatalogChunk.ts | 11 +++++++++-- .../catalog/useUpdateNamespaceCatalog.ts | 4 ++-- .../view/catalog/components/FileChunks.tsx | 17 +++++++++-------- .../catalog/components/FileDetailsOverlay.tsx | 17 +++++++++-------- 9 files changed, 46 insertions(+), 34 deletions(-) rename packages/toolkit/src/lib/react-query-service/catalog/{useGetCatalogSingleSourceOfTruthFile.ts => useGetNamespaceCatalogSingleSourceOfTruthFile.ts} (66%) diff --git a/packages/sdk/src/catalog/CatalogClient.ts b/packages/sdk/src/catalog/CatalogClient.ts index 640f66d8a..3fb875511 100644 --- a/packages/sdk/src/catalog/CatalogClient.ts +++ b/packages/sdk/src/catalog/CatalogClient.ts @@ -255,7 +255,7 @@ export class CatalogClient extends APIResource { } } - async getCatalogSingleSourceOfTruthFile({ + async getNamespaceCatalogSingleSourceOfTruthFile({ namespaceId, catalogId, fileUid, diff --git a/packages/toolkit/src/lib/react-query-service/catalog/index.ts b/packages/toolkit/src/lib/react-query-service/catalog/index.ts index 306d4d891..a57ce0181 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/index.ts +++ b/packages/toolkit/src/lib/react-query-service/catalog/index.ts @@ -6,6 +6,6 @@ export * from "./useCreateNamespaceCatalogFile"; export * from "./useProcessCatalogFiles"; export * from "./useListNamespaceCatalogFiles"; export * from "./useDeleteCatalogFile"; -export * from "./useGetCatalogSingleSourceOfTruthFile"; +export * from "./useGetNamespaceCatalogSingleSourceOfTruthFile"; export * from "./useUpdateCatalogChunk"; export * from "./useListNamespaceCatalogChunks"; diff --git a/packages/toolkit/src/lib/react-query-service/catalog/useDeleteCatalogFile.tsx b/packages/toolkit/src/lib/react-query-service/catalog/useDeleteCatalogFile.tsx index b1e59f186..34e753448 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/useDeleteCatalogFile.tsx +++ b/packages/toolkit/src/lib/react-query-service/catalog/useDeleteCatalogFile.tsx @@ -22,11 +22,11 @@ export function useDeleteCatalogFile() { accessToken: Nullable; }) => { if (!accessToken) { - throw new Error("accessToken not provided"); + throw new Error("accessToken is required"); } if (!fileUid) { - throw new Error("fileUid not provided"); + throw new Error("fileUid is required"); } const client = getInstillCatalogAPIClient({ accessToken }); diff --git a/packages/toolkit/src/lib/react-query-service/catalog/useGetCatalogSingleSourceOfTruthFile.ts b/packages/toolkit/src/lib/react-query-service/catalog/useGetNamespaceCatalogSingleSourceOfTruthFile.ts similarity index 66% rename from packages/toolkit/src/lib/react-query-service/catalog/useGetCatalogSingleSourceOfTruthFile.ts rename to packages/toolkit/src/lib/react-query-service/catalog/useGetNamespaceCatalogSingleSourceOfTruthFile.ts index a4d9950c9..5d8f2e778 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/useGetCatalogSingleSourceOfTruthFile.ts +++ b/packages/toolkit/src/lib/react-query-service/catalog/useGetNamespaceCatalogSingleSourceOfTruthFile.ts @@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query"; import { getInstillCatalogAPIClient } from "../../sdk-helper"; -export function useGetCatalogSingleSourceOfTruthFile({ +export function useGetNamespaceCatalogSingleSourceOfTruthFile({ fileUid, accessToken, enabled, @@ -22,27 +22,30 @@ export function useGetCatalogSingleSourceOfTruthFile({ queryKey: ["fileContent", fileUid], queryFn: async () => { if (!accessToken) { - throw new Error("accessToken not provided"); + throw new Error("accessToken is required"); } + if (!fileUid) { - throw new Error("fileUid not provided"); + throw new Error("fileUid is required"); } + if (!catalogId) { - throw new Error("catalogId not provided"); + throw new Error("catalogId is required"); } + if (!namespaceId) { - throw new Error("namespaceId not provided"); + throw new Error("namespaceId is required"); } const client = getInstillCatalogAPIClient({ accessToken }); - const fileContent = - await client.catalog.getCatalogSingleSourceOfTruthFile({ + const res = + await client.catalog.getNamespaceCatalogSingleSourceOfTruthFile({ namespaceId, catalogId, fileUid, }); - return Promise.resolve(fileContent.sourceFile); + return Promise.resolve(res.sourceFile); }, enabled: enabled && Boolean(accessToken) && Boolean(fileUid), }); diff --git a/packages/toolkit/src/lib/react-query-service/catalog/useListNamespaceCatalogs.ts b/packages/toolkit/src/lib/react-query-service/catalog/useListNamespaceCatalogs.ts index 0d7abe031..2d1652bfe 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/useListNamespaceCatalogs.ts +++ b/packages/toolkit/src/lib/react-query-service/catalog/useListNamespaceCatalogs.ts @@ -29,11 +29,11 @@ export function useListNamespaceCatalogs({ } const client = getInstillCatalogAPIClient({ accessToken }); - const catalogs = await client.catalog.listNamespaceCatalogs({ + const res = await client.catalog.listNamespaceCatalogs({ namespaceId, }); - return Promise.resolve(catalogs.catalogs); + return Promise.resolve(res.catalogs); }, enabled: enabled && Boolean(namespaceId) && Boolean(accessToken), }); diff --git a/packages/toolkit/src/lib/react-query-service/catalog/useUpdateCatalogChunk.ts b/packages/toolkit/src/lib/react-query-service/catalog/useUpdateCatalogChunk.ts index d805ee319..9b71db221 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/useUpdateCatalogChunk.ts +++ b/packages/toolkit/src/lib/react-query-service/catalog/useUpdateCatalogChunk.ts @@ -11,6 +11,8 @@ export function useUpdateCatalogChunk() { return useMutation({ mutationFn: async ({ + // Because the mutation reponse didn't have these information, but we need them to + // update the cache, so we need to pass them in as variables. namespaceId, catalogId, fileUid, @@ -38,12 +40,17 @@ export function useUpdateCatalogChunk() { } const client = getInstillCatalogAPIClient({ accessToken }); - await client.catalog.updateCatalogChunk({ + const res = await client.catalog.updateCatalogChunk({ chunkUid, retrievable, }); - return Promise.resolve({ namespaceId, catalogId, fileUid }); + return Promise.resolve({ + namespaceId, + catalogId, + fileUid, + response: res, + }); }, onSuccess: ({ namespaceId, catalogId, fileUid }) => { queryClient.invalidateQueries({ diff --git a/packages/toolkit/src/lib/react-query-service/catalog/useUpdateNamespaceCatalog.ts b/packages/toolkit/src/lib/react-query-service/catalog/useUpdateNamespaceCatalog.ts index 4222ae9d6..0dd816aee 100644 --- a/packages/toolkit/src/lib/react-query-service/catalog/useUpdateNamespaceCatalog.ts +++ b/packages/toolkit/src/lib/react-query-service/catalog/useUpdateNamespaceCatalog.ts @@ -22,11 +22,11 @@ export function useUpdateNamespaceCatalog() { } if (!payload.namespaceId) { - throw new Error("namespaceId not provided"); + throw new Error("namespaceId is required"); } if (!payload.catalogId) { - throw new Error("catalogId not provided"); + throw new Error("catalogId is required"); } const client = getInstillCatalogAPIClient({ accessToken }); diff --git a/packages/toolkit/src/view/catalog/components/FileChunks.tsx b/packages/toolkit/src/view/catalog/components/FileChunks.tsx index eb6320a99..ffe847467 100644 --- a/packages/toolkit/src/view/catalog/components/FileChunks.tsx +++ b/packages/toolkit/src/view/catalog/components/FileChunks.tsx @@ -5,7 +5,7 @@ import { Catalog, CatalogFile, Chunk } from "instill-sdk"; import { cn, Icons, Nullable } from "@instill-ai/design-system"; -import { useGetCatalogSingleSourceOfTruthFile } from "../../.."; +import { useGetNamespaceCatalogSingleSourceOfTruthFile } from "../../.."; import { useListNamespaceCatalogChunks } from "../../../lib"; import ChunkCard from "./ChunkCard"; @@ -40,13 +40,14 @@ const FileChunks = ({ chunkUids: null, }); - const catalogSingleSourceOfTruthFile = useGetCatalogSingleSourceOfTruthFile({ - fileUid: file.fileUid, - catalogId: catalog.catalogId, - accessToken: accessToken || null, - enabled: expanded, - namespaceId: catalog.ownerName, - }); + const catalogSingleSourceOfTruthFile = + useGetNamespaceCatalogSingleSourceOfTruthFile({ + fileUid: file.fileUid, + catalogId: catalog.catalogId, + accessToken: accessToken || null, + enabled: expanded, + namespaceId: catalog.ownerName, + }); const isProcessing = file.processStatus !== "FILE_PROCESS_STATUS_COMPLETED"; diff --git a/packages/toolkit/src/view/catalog/components/FileDetailsOverlay.tsx b/packages/toolkit/src/view/catalog/components/FileDetailsOverlay.tsx index 2a193c7d0..c398cba8d 100644 --- a/packages/toolkit/src/view/catalog/components/FileDetailsOverlay.tsx +++ b/packages/toolkit/src/view/catalog/components/FileDetailsOverlay.tsx @@ -8,7 +8,7 @@ import sanitizeHtml from "sanitize-html"; import { Dialog, ScrollArea, Skeleton } from "@instill-ai/design-system"; import { - useGetCatalogSingleSourceOfTruthFile, + useGetNamespaceCatalogSingleSourceOfTruthFile, useListNamespaceCatalogChunks, } from "../../../lib"; import { getFileIcon } from "./lib/helpers"; @@ -40,13 +40,14 @@ const FileDetailsOverlay = ({ highlightChunk = false, fileType, }: FileDetailsOverlayProps) => { - const catalogSingleSourceOfTruthFile = useGetCatalogSingleSourceOfTruthFile({ - fileUid, - catalogId, - accessToken, - enabled: isOpen, - namespaceId, - }); + const catalogSingleSourceOfTruthFile = + useGetNamespaceCatalogSingleSourceOfTruthFile({ + fileUid, + catalogId, + accessToken, + enabled: isOpen, + namespaceId, + }); const namespaceCatalogChunks = useListNamespaceCatalogChunks({ catalogId,