|
@@ -1,5 +1,9 @@
|
|
|
import React, { useCallback, useState } from 'react';
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
+import { getIdStringForRef } from '@growi/core';
|
|
|
|
|
+
|
|
|
|
|
+import { useCurrentUser } from '~/stores-universal/context';
|
|
|
|
|
+
|
|
|
import type { AiAssistantAccessScope } from '../../../../interfaces/ai-assistant';
|
|
import type { AiAssistantAccessScope } from '../../../../interfaces/ai-assistant';
|
|
|
import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interfaces/ai-assistant';
|
|
import { AiAssistantShareScope, type AiAssistantHasId } from '../../../../interfaces/ai-assistant';
|
|
|
|
|
|
|
@@ -39,11 +43,13 @@ const getShareScopeIcon = (shareScope: AiAssistantShareScope, accessScope: AiAss
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
type AiAssistantItemProps = {
|
|
type AiAssistantItemProps = {
|
|
|
|
|
+ currentUserId?: string;
|
|
|
aiAssistant: AiAssistantHasId;
|
|
aiAssistant: AiAssistantHasId;
|
|
|
threads: { id: string; name: string }[]; // dummy data
|
|
threads: { id: string; name: string }[]; // dummy data
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
|
|
|
+ currentUserId,
|
|
|
aiAssistant,
|
|
aiAssistant,
|
|
|
threads,
|
|
threads,
|
|
|
}) => {
|
|
}) => {
|
|
@@ -53,6 +59,8 @@ const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
|
setIsExpanded(toggle => !toggle);
|
|
setIsExpanded(toggle => !toggle);
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
+ const isOperable = currentUserId != null && getIdStringForRef(aiAssistant.owner) === currentUserId;
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="grw-ai-assistant-item-container">
|
|
<div className="grw-ai-assistant-item-container">
|
|
|
<li
|
|
<li
|
|
@@ -77,20 +85,22 @@ const AiAssistantItem: React.FC<AiAssistantItemProps> = ({
|
|
|
<p className="text-truncate m-auto">{aiAssistant.name}</p>
|
|
<p className="text-truncate m-auto">{aiAssistant.name}</p>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <div className="grw-ai-assistant-actions opacity-0 d-flex justify-content-center ">
|
|
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- className="btn btn-link text-secondary p-0 ms-2"
|
|
|
|
|
- >
|
|
|
|
|
- <span className="material-symbols-outlined fs-5">edit</span>
|
|
|
|
|
- </button>
|
|
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- className="btn btn-link text-secondary p-0"
|
|
|
|
|
- >
|
|
|
|
|
- <span className="material-symbols-outlined fs-5">delete</span>
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ { isOperable && (
|
|
|
|
|
+ <div className="grw-ai-assistant-actions opacity-0 d-flex justify-content-center ">
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ className="btn btn-link text-secondary p-0 ms-2"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span className="material-symbols-outlined fs-5">edit</span>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ className="btn btn-link text-secondary p-0"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span className="material-symbols-outlined fs-5">delete</span>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
</li>
|
|
</li>
|
|
|
|
|
|
|
|
{isExpanded && threads.length > 0 && (
|
|
{isExpanded && threads.length > 0 && (
|
|
@@ -119,11 +129,13 @@ type AiAssistantTreeProps = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants }) => {
|
|
export const AiAssistantTree: React.FC<AiAssistantTreeProps> = ({ aiAssistants }) => {
|
|
|
|
|
+ const { data: currentUser } = useCurrentUser();
|
|
|
return (
|
|
return (
|
|
|
<ul className="list-group">
|
|
<ul className="list-group">
|
|
|
{aiAssistants.map(assistant => (
|
|
{aiAssistants.map(assistant => (
|
|
|
<AiAssistantItem
|
|
<AiAssistantItem
|
|
|
key={assistant._id}
|
|
key={assistant._id}
|
|
|
|
|
+ currentUserId={currentUser?._id}
|
|
|
aiAssistant={assistant}
|
|
aiAssistant={assistant}
|
|
|
threads={dummyThreads}
|
|
threads={dummyThreads}
|
|
|
/>
|
|
/>
|