Skip to content

Commit

Permalink
fix: fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly committed Nov 1, 2024
1 parent 52225b4 commit 1e3507f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/catalog/CatalogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class CatalogClient extends APIResource {
}
}

async getCatalogSingleSourceOfTruthFile({
async getNamespaceCatalogSingleSourceOfTruthFile({
namespaceId,
catalogId,
fileUid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export function useDeleteCatalogFile() {
accessToken: Nullable<string>;
}) => {
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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query";

import { getInstillCatalogAPIClient } from "../../sdk-helper";

export function useGetCatalogSingleSourceOfTruthFile({
export function useGetNamespaceCatalogSingleSourceOfTruthFile({
fileUid,
accessToken,
enabled,
Expand All @@ -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),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
17 changes: 9 additions & 8 deletions packages/toolkit/src/view/catalog/components/FileChunks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1e3507f

Please sign in to comment.