-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
64 deletions.
There are no files selected for viewing
16 changes: 7 additions & 9 deletions
16
packages/toolkit/src/lib/react-query-service/knowledge/useListKnowledgeBaseFiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { Nullable } from "@instill-ai/toolkit"; | ||
|
||
import { createInstillAxiosClient } from "../../vdp-sdk/helper"; | ||
import { File } from "../../vdp-sdk/knowledge/types"; | ||
|
||
export function useListKnowledgeBaseFiles({ | ||
ownerId, | ||
namespaceId, | ||
knowledgeBaseId, | ||
accessToken, | ||
enabled, | ||
}: { | ||
ownerId: Nullable<string>; | ||
namespaceId: Nullable<string> | undefined; | ||
knowledgeBaseId: Nullable<string>; | ||
accessToken: Nullable<string>; | ||
enabled: boolean; | ||
}) { | ||
return useQuery<File[]>({ | ||
queryKey: ["knowledgeBaseFiles", ownerId, knowledgeBaseId], | ||
queryKey: ["knowledgeBaseFiles", namespaceId, knowledgeBaseId], | ||
queryFn: async () => { | ||
if (!accessToken) { | ||
throw new Error("accessToken not provided"); | ||
} | ||
if (!ownerId) { | ||
throw new Error("ownerId not provided"); | ||
if (!namespaceId) { | ||
throw new Error("namespaceId not provided"); | ||
} | ||
if (!knowledgeBaseId) { | ||
throw new Error("knowledgeBaseId not provided"); | ||
} | ||
const client = createInstillAxiosClient(accessToken, true); | ||
const response = await client.get<{ files: File[] }>( | ||
`/namespaces/${ownerId}/knowledge-bases/${knowledgeBaseId}/files`, | ||
`/namespaces/${namespaceId}/knowledge-bases/${knowledgeBaseId}/files`, | ||
); | ||
return response.data.files; | ||
}, | ||
enabled, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface KnowledgeBase { | ||
export type KnowledgeBase = { | ||
usage: number; | ||
kbId: string; | ||
name: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/toolkit/src/view/knowledge/components/Notifications/DuplicateFileNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as React from "react"; | ||
|
||
import { Button, Icons } from "@instill-ai/design-system"; | ||
|
||
type DuplicateFileNotificationProps = { | ||
deletedFileName: string; | ||
undoDelete: () => void; | ||
setShowDeleteMessage: React.Dispatch<React.SetStateAction<boolean>>; | ||
}; | ||
|
||
const DuplicateFileNotification = ({ | ||
deletedFileName, | ||
setShowDeleteMessage, | ||
}: DuplicateFileNotificationProps) => { | ||
|
||
return ( | ||
<div className="fixed bottom-4 right-8 flex h-[136px] w-[400px] rounded-sm border border-semantic-bg-line bg-semantic-bg-primary p-4 shadow"> | ||
<Icons.AlertTriangle className="mr-4 h-6 w-6 stroke-semantic-warning-on-bg" /> | ||
<div className="mr-4 shrink grow basis-0 flex-col items-start justify-start space-y-4"> | ||
<div className="flex flex-col items-start justify-start gap-1 self-stretch"> | ||
<div className="self-stretch product-body-text-2-semibold truncate"> | ||
{deletedFileName} Already Uploaded or Exists in Knowledge Base | ||
</div> | ||
<div className="self-stretch text-semantic-fg-secondary product-body-text-3-regular"> | ||
Current knowledge base does not support uploading the same file twice. Please consider deleting the old file with the same name or renaming your new file before attempting to upload again. | ||
</div> | ||
</div> | ||
</div> | ||
<Button | ||
className="absolute right-2 top-2" | ||
variant="tertiaryGrey" | ||
size="sm" | ||
onClick={() => setShowDeleteMessage(false)} | ||
> | ||
<Icons.X className="h-6 w-6 stroke-semantic-fg-secondary" /> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DuplicateFileNotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters