This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch feat/1.3.1/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/1.3.1/ui by this push:
     new dfeca6e5 fix: support search admin uses #795
dfeca6e5 is described below

commit dfeca6e549c69ff78d5d6a6cb1b87f0a47fc27a7
Author: shuai <[email protected]>
AuthorDate: Thu Apr 25 18:12:58 2024 +0800

    fix: support search admin uses #795
---
 ui/src/components/Comment/components/Form/index.tsx  |  3 +++
 ui/src/components/Comment/components/Reply/index.tsx |  2 ++
 ui/src/components/Mentions/index.tsx                 | 19 ++++++++++++++++++-
 ui/src/services/client/user.ts                       |  7 +++++++
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/ui/src/components/Comment/components/Form/index.tsx 
b/ui/src/components/Comment/components/Form/index.tsx
index 05ae5b2d..82d547f8 100644
--- a/ui/src/components/Comment/components/Form/index.tsx
+++ b/ui/src/components/Comment/components/Form/index.tsx
@@ -65,6 +65,9 @@ const Index = ({
       }
     });
   };
+
+  console.log('userName:', pageUsers.getUsers());
+
   return (
     <div
       className={classNames(
diff --git a/ui/src/components/Comment/components/Reply/index.tsx 
b/ui/src/components/Comment/components/Reply/index.tsx
index 2bd722f2..9d236f11 100644
--- a/ui/src/components/Comment/components/Reply/index.tsx
+++ b/ui/src/components/Comment/components/Reply/index.tsx
@@ -50,6 +50,8 @@ const Index = ({ userName, onSendReply, onCancel, mode }) => {
     });
   };
 
+  console.log('userName:', pageUsers.getUsers());
+
   return (
     <div className="mb-2">
       <div className="small mb-2">
diff --git a/ui/src/components/Mentions/index.tsx 
b/ui/src/components/Mentions/index.tsx
index 9b61f0bf..63d0f702 100644
--- a/ui/src/components/Mentions/index.tsx
+++ b/ui/src/components/Mentions/index.tsx
@@ -20,6 +20,7 @@
 import React, { useEffect, useRef, useState, FC } from 'react';
 import { Dropdown } from 'react-bootstrap';
 
+import { useSearchUserStaff } from '@/services';
 import * as Types from '@/common/interface';
 
 interface IProps {
@@ -37,6 +38,19 @@ const Mentions: FC<IProps> = ({ children, pageUsers, 
onSelected }) => {
   const [users, setUsers] = useState<Types.PageUser[]>([]);
   const [cursor, setCursor] = useState(0);
   const [isRequested, setRequestedState] = useState(false);
+  const { data: staffUserList = [] } = useSearchUserStaff(val);
+  const mapStaffUsers =
+    staffUserList
+      ?.map((item) => ({
+        displayName: item.display_name,
+        userName: item.username,
+      }))
+      ?.filter(
+        (item) =>
+          users.findIndex((user) => user.userName === item.userName) < 0,
+      ) || [];
+
+  console.log('staffUserList:', staffUserList);
 
   const searchUser = () => {
     const element = dropdownRef.current?.children[0];
@@ -57,6 +71,9 @@ const Mentions: FC<IProps> = ({ children, pageUsers, 
onSelected }) => {
     if (str.substring(str.lastIndexOf(' '), selectionStart).indexOf('@') < 0) {
       return;
     }
+
+    console.log('str111111:', str);
+    console.log('str2222:', str.substring(1));
     setValue(str.substring(1));
 
     if (!str.substring(1)) {
@@ -103,7 +120,7 @@ const Mentions: FC<IProps> = ({ children, pageUsers, 
onSelected }) => {
     setValue('');
   };
   const filterData = val
-    ? users.filter(
+    ? [...users, ...mapStaffUsers].filter(
         (item) =>
           item.displayName?.indexOf(val) === 0 ||
           item.userName?.indexOf(val) === 0,
diff --git a/ui/src/services/client/user.ts b/ui/src/services/client/user.ts
index 66282b57..62ce0c76 100644
--- a/ui/src/services/client/user.ts
+++ b/ui/src/services/client/user.ts
@@ -96,3 +96,10 @@ export const useUserPermission = (
     >
   >([apiUrl, { params: { action } }], request.instance.get);
 };
+
+export const useSearchUserStaff = (name: string) => {
+  const apiUrl = name
+    ? `/answer/api/v1/user/staff?username=${name}&page_size=10`
+    : null;
+  return useSWR<Type.User[]>(apiUrl, request.instance.get);
+};

Reply via email to