|
|
@@ -3,35 +3,27 @@ import React, { useCallback, useState } from 'react';
|
|
|
import { getIdStringForRef } from '@growi/core';
|
|
|
|
|
|
import { toastError, toastSuccess } from '~/client/util/toastr';
|
|
|
+import type { IThreadRelationHasId } from '~/features/openai/interfaces/thread-relation';
|
|
|
import { useCurrentUser } from '~/stores-universal/context';
|
|
|
|
|
|
import type { AiAssistantAccessScope } from '../../../../interfaces/ai-assistant';
|
|
|
import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interfaces/ai-assistant';
|
|
|
import { deleteAiAssistant } from '../../../services/ai-assistant';
|
|
|
import { useAiAssistantChatSidebar, useAiAssistantManagementModal } from '../../../stores/ai-assistant';
|
|
|
+import { useSWRxThreads } from '../../../stores/thread';
|
|
|
|
|
|
import styles from './AiAssistantTree.module.scss';
|
|
|
|
|
|
const moduleClass = styles['ai-assistant-tree-item'] ?? '';
|
|
|
|
|
|
-type Thread = {
|
|
|
- _id: string;
|
|
|
- name: string;
|
|
|
-}
|
|
|
-
|
|
|
-const dummyThreads: Thread[] = [
|
|
|
- { _id: '1', name: 'thread1' },
|
|
|
- { _id: '2', name: 'thread2' },
|
|
|
- { _id: '3', name: 'thread3' },
|
|
|
-];
|
|
|
-
|
|
|
+/*
|
|
|
+* For ThreadItem
|
|
|
+*/
|
|
|
type ThreadItemProps = {
|
|
|
- thread: Thread;
|
|
|
+ thread: IThreadRelationHasId
|
|
|
};
|
|
|
|
|
|
-const ThreadItem: React.FC<ThreadItemProps> = ({
|
|
|
- thread,
|
|
|
-}) => {
|
|
|
+const ThreadItem: React.FC<ThreadItemProps> = ({ thread }) => {
|
|
|
|
|
|
const deleteThreadHandler = useCallback(() => {
|
|
|
// TODO: https://redmine.weseek.co.jp/issues/161490
|
|
|
@@ -52,7 +44,7 @@ const ThreadItem: React.FC<ThreadItemProps> = ({
|
|
|
</div>
|
|
|
|
|
|
<div className="grw-ai-assistant-title-anchor ps-1">
|
|
|
- <p className="text-truncate m-auto">{thread.name}</p>
|
|
|
+ <p className="text-truncate m-auto">{thread.threadId}</p>
|
|
|
</div>
|
|
|
|
|
|
<div className="grw-ai-assistant-actions opacity-0 d-flex justify-content-center ">
|
|
|
@@ -69,6 +61,36 @@ const ThreadItem: React.FC<ThreadItemProps> = ({
|
|
|
};
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+* ThreadItems
|
|
|
+*/
|
|
|
+type ThreadItemsProps = {
|
|
|
+ aiAssistantId: string;
|
|
|
+};
|
|
|
+
|
|
|
+const ThreadItems: React.FC<ThreadItemsProps> = ({ aiAssistantId }) => {
|
|
|
+ const { data: threads } = useSWRxThreads(aiAssistantId);
|
|
|
+
|
|
|
+ if (threads == null || threads.length === 0) {
|
|
|
+ return <p className="text-secondary ms-5">スレッドが存在しません</p>;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div className="grw-ai-assistant-item-children">
|
|
|
+ {threads.map(thread => (
|
|
|
+ <ThreadItem
|
|
|
+ key={thread._id}
|
|
|
+ thread={thread}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+/*
|
|
|
+* AiAssistantItem
|
|
|
+*/
|
|
|
const getShareScopeIcon = (shareScope: AiAssistantShareScope, accessScope: AiAssistantAccessScope): string => {
|
|
|
const determinedSharedScope = shareScope === AiAssistantShareScope.SAME_AS_ACCESS_SCOPE ? accessScope : shareScope;
|
|
|
switch (determinedSharedScope) {
|
|
|
@@ -84,7 +106,6 @@ const getShareScopeIcon = (shareScope: AiAssistantShareScope, accessScope: AiAss
|
|
|
type AiAssistantItemProps = {
|
|
|
currentUserId?: string;
|
|
|
aiAssistant: AiAssistantHasId;
|
|
|
- threads: Thread[];
|
|
|
onEditClicked?: (aiAssistantData: AiAssistantHasId) => void;
|
|
|
onItemClicked?: (aiAssistantData: AiAssistantHasId) => void;
|
|
|
onDeleted?: () => void;
|
|
|
@@ -93,7 +114,6 @@ type AiAssistantItemProps = {
|
|
|
const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
|
currentUserId,
|
|
|
aiAssistant,
|
|
|
- threads,
|
|
|
onEditClicked,
|
|
|
onItemClicked,
|
|
|
onDeleted,
|
|
|
@@ -185,20 +205,17 @@ const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
|
)}
|
|
|
</li>
|
|
|
|
|
|
- {isThreadsOpened && threads.length > 0 && (
|
|
|
- <div className="grw-ai-assistant-item-children">
|
|
|
- {threads.map(thread => (
|
|
|
- <ThreadItem
|
|
|
- key={thread._id}
|
|
|
- thread={thread}
|
|
|
- />
|
|
|
- ))}
|
|
|
- </div>
|
|
|
- )}
|
|
|
+ { isThreadsOpened && (
|
|
|
+ <ThreadItems aiAssistantId={aiAssistant._id} />
|
|
|
+ ) }
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+/*
|
|
|
+* AiAssistantTree
|
|
|
+*/
|
|
|
type AiAssistantTreeProps = {
|
|
|
aiAssistants: AiAssistantHasId[];
|
|
|
onDeleted?: () => void;
|
|
|
@@ -216,7 +233,6 @@ export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants,
|
|
|
key={assistant._id}
|
|
|
currentUserId={currentUser?._id}
|
|
|
aiAssistant={assistant}
|
|
|
- threads={dummyThreads}
|
|
|
onEditClicked={openAiAssistantManagementModal}
|
|
|
onItemClicked={openAiAssistantChatSidebar}
|
|
|
onDeleted={onDeleted}
|