From 50b1f50abd2ca701833075e403478509ae4e0777 Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Tue, 19 Sep 2023 12:17:32 +0200 Subject: [PATCH 1/6] feat: use backend api in tag --- .../Comments/Components/CommentView.tsx | 45 ++++++++----------- .../Comments/Components/TagDropDown.tsx | 8 ++-- src/api/BaseService.ts | 4 +- src/api/UserTagService.ts | 22 +++++++++ src/api/config.tsx | 4 ++ src/types.d.ts | 25 +++++++++++ 6 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 src/api/UserTagService.ts diff --git a/src/Components/SideSheet/Comments/Components/CommentView.tsx b/src/Components/SideSheet/Comments/Components/CommentView.tsx index 6090e5d1..de6fb1aa 100644 --- a/src/Components/SideSheet/Comments/Components/CommentView.tsx +++ b/src/Components/SideSheet/Comments/Components/CommentView.tsx @@ -4,6 +4,7 @@ import React, { useState, } from "react" import styled from "styled-components" +import { useCurrentContext } from "@equinor/fusion" import { GetConversationService } from "../../../../api/ConversationService" import { Message } from "../../../../Models/Message" import InputController from "./InputController" @@ -11,6 +12,7 @@ import { ViewContext } from "../../../../Context/ViewContext" import ClusteredMessages from "./ClusteredMessages" import TagDropDown from "./TagDropDown" import { processMessageInput } from "../../../../utils/helpers" +import { GetUserTagService } from "../../../../api/UserTagService" const Controls = styled.div` position: sticky; @@ -47,6 +49,7 @@ const CommentView: React.FC = ({ const [reRenderCounter, setReRenderCounter] = useState(0) const [searchTerm, setSearchTerm] = useState("") const [showTagDropDown, setShowTagDropDown] = useState(false) + const [userTags, setUserTags] = useState([]) const { activeTagData, conversations, @@ -55,36 +58,24 @@ const CommentView: React.FC = ({ setActiveConversation, } = useContext(ViewContext) + const fusionContextId = useCurrentContext() + const getConversationForProperty = (property: string) => ( conversations.find((conversation) => conversation.property?.toUpperCase() === property.toUpperCase()) ) - const dummyData = [ - { - id: "1", - displayName: "Henrik Hansen", - accountType: "Consultant", - status: "Active", - }, - { - id: "2", - displayName: "Peter Jensen", - accountType: "Consultant", - status: "Active", - }, - { - id: "3", - displayName: "Jesper Gudbransen", - accountType: "Consultant", - status: "inactive", - }, - { - id: "4", - displayName: "Mikkel Eriksen", - accountType: "Consultant", - status: "inactive", - }, - ] + useEffect(() => { + (async () => { + if (fusionContextId) { + try { + const userTagsResult = await (await GetUserTagService()).getUsers(fusionContextId.id, "", 1000, 0) + setUserTags(userTagsResult.data) + } catch (error) { + console.error("Error users for project: ", error) + } + } + })() + }, []) useEffect(() => { (async () => { @@ -188,7 +179,7 @@ const CommentView: React.FC = ({ SearchTerm={searchTerm} setReRenderCounter={setReRenderCounter} onTagSelected={handleTagSelected} - dummyData={dummyData} + dummyData={userTags} /> )} diff --git a/src/Components/SideSheet/Comments/Components/TagDropDown.tsx b/src/Components/SideSheet/Comments/Components/TagDropDown.tsx index 85431e88..0fbf4009 100644 --- a/src/Components/SideSheet/Comments/Components/TagDropDown.tsx +++ b/src/Components/SideSheet/Comments/Components/TagDropDown.tsx @@ -45,7 +45,7 @@ const ListItem = styled.button` interface Props { SearchTerm?: string onTagSelected: (displayName: string, userId: string) => void - dummyData: { id: string; displayName: string; accountType: string; status: string }[] + dummyData: { azureUniqueId: string; displayName: string; accountType: string; status: string }[] setReRenderCounter: React.Dispatch> } @@ -61,9 +61,9 @@ const TagDropDown: FC = ({ return ( - {filteredNames.map(({ id, displayName }) => ( -
  • - handleTagClick(id, displayName)}> + {filteredNames.map(({ azureUniqueId, displayName }) => ( +
  • + handleTagClick(azureUniqueId, displayName)}> {displayName}
  • diff --git a/src/api/BaseService.ts b/src/api/BaseService.ts index f6d5b6e1..91253366 100644 --- a/src/api/BaseService.ts +++ b/src/api/BaseService.ts @@ -77,9 +77,9 @@ export class BaseService { path: string, requestQuery?: AxiosRequestConfig, ): Promise { - const { data } = await this.client.get(path, requestQuery) + const result = await this.client.get(path, requestQuery) - return data + return result } protected get(path: string, options?: RequestOptions): Promise { diff --git a/src/api/UserTagService.ts b/src/api/UserTagService.ts new file mode 100644 index 00000000..4aede11b --- /dev/null +++ b/src/api/UserTagService.ts @@ -0,0 +1,22 @@ +import { BaseService } from "./BaseService" + +import { config, GetToken, LoginAccessTokenKey } from "./config" + +class UserTagService extends BaseService { + async getUsers(fusionContextId: string, search: string, top: number, skip: number) { + const result: any = await this.getWithParams( + `${fusionContextId}`, + { + params: { search, top, skip }, + }, + ) + return result + } +} + +export async function GetUserTagService() { + return new UserTagService({ + ...config.UserTagService, + accessToken: await GetToken(LoginAccessTokenKey)!, + }) +} diff --git a/src/api/config.tsx b/src/api/config.tsx index 1f67583a..3a6c81be 100644 --- a/src/api/config.tsx +++ b/src/api/config.tsx @@ -23,6 +23,9 @@ const configuration = { RevisionReviewService: { BASE_URL: "", }, + UserTagService: { + BASE_URL: "", + }, } export const buildConfig = (baseUrl: string) => { @@ -32,6 +35,7 @@ export const buildConfig = (baseUrl: string) => { configuration.ConversationService.BASE_URL = `${baseUrl}/tag/reviews` configuration.TagDataReviewService.BASE_URL = `${baseUrl}/tagdatareviews` configuration.RevisionReviewService.BASE_URL = `${baseUrl}/revisionreviews` + configuration.UserTagService.BASE_URL = `${baseUrl}/usertag` } export const config = Object.freeze(configuration) diff --git a/src/types.d.ts b/src/types.d.ts index 5a44f33d..2e526927 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1606,6 +1606,12 @@ declare namespace Components { userId?: string; // uuid displayName?: string | null; } + export interface UserTagDto { + azureUniqueId?: string | null; + displayName?: string | null; + mail?: string | null; + accountType?: string | null; + } } } declare namespace Paths { @@ -1901,6 +1907,25 @@ declare namespace Paths { export type $200 = Components.Schemas.ITagDataDto[]; } } + namespace GetUsersForProject { + namespace Parameters { + export type FusionContextId = string; + export type Search = string; + export type Skip = number; // int32 + export type Top = number; // int32 + } + export interface PathParameters { + fusionContextId: Parameters.FusionContextId; + } + export interface QueryParameters { + search?: Parameters.Search; + top?: Parameters.Top /* int32 */; + skip?: Parameters.Skip /* int32 */; + } + namespace Responses { + export type $200 = Components.Schemas.UserTagDto[]; + } + } namespace UpdateMessage { namespace Parameters { export type ConversationId = string; // uuid From ee14ffc70af12eba48be34f9e1535bc676f168ec Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Tue, 19 Sep 2023 12:50:34 +0200 Subject: [PATCH 2/6] add mail to filter --- .../SideSheet/Comments/Components/TagDropDown.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Components/SideSheet/Comments/Components/TagDropDown.tsx b/src/Components/SideSheet/Comments/Components/TagDropDown.tsx index 0fbf4009..1e2cc7f1 100644 --- a/src/Components/SideSheet/Comments/Components/TagDropDown.tsx +++ b/src/Components/SideSheet/Comments/Components/TagDropDown.tsx @@ -45,14 +45,16 @@ const ListItem = styled.button` interface Props { SearchTerm?: string onTagSelected: (displayName: string, userId: string) => void - dummyData: { azureUniqueId: string; displayName: string; accountType: string; status: string }[] + dummyData: { azureUniqueId: string; displayName: string; accountType: string; status: string; mail: string }[] setReRenderCounter: React.Dispatch> } const TagDropDown: FC = ({ - SearchTerm, onTagSelected, dummyData, setReRenderCounter, + SearchTerm, onTagSelected, dummyData, setReRenderCounter, }) => { - const filteredNames = dummyData.filter(({ displayName }) => !SearchTerm || displayName.toLowerCase().includes(SearchTerm.toLowerCase())) + const filteredNames = dummyData.filter(({ displayName, mail }) => !SearchTerm + || displayName.toLowerCase().includes(SearchTerm.toLowerCase()) + || mail.toLowerCase().includes(SearchTerm.toLowerCase())) const handleTagClick = (userId: string, displayName: string) => { setReRenderCounter((prev) => prev + 1) From b592fef377b183e4dd240c53520a406fe893fc8f Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Tue, 19 Sep 2023 13:00:01 +0200 Subject: [PATCH 3/6] update endpoint --- src/api/config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/config.tsx b/src/api/config.tsx index 3a6c81be..eebf0a7f 100644 --- a/src/api/config.tsx +++ b/src/api/config.tsx @@ -35,7 +35,7 @@ export const buildConfig = (baseUrl: string) => { configuration.ConversationService.BASE_URL = `${baseUrl}/tag/reviews` configuration.TagDataReviewService.BASE_URL = `${baseUrl}/tagdatareviews` configuration.RevisionReviewService.BASE_URL = `${baseUrl}/revisionreviews` - configuration.UserTagService.BASE_URL = `${baseUrl}/usertag` + configuration.UserTagService.BASE_URL = `${baseUrl}/usertags` } export const config = Object.freeze(configuration) From 9714e2ee08df41a9b69e5027a79a3ade2ca5aeb9 Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Tue, 19 Sep 2023 13:00:29 +0200 Subject: [PATCH 4/6] . --- src/Components/SideSheet/Comments/Components/CommentView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/SideSheet/Comments/Components/CommentView.tsx b/src/Components/SideSheet/Comments/Components/CommentView.tsx index de6fb1aa..0fedf60c 100644 --- a/src/Components/SideSheet/Comments/Components/CommentView.tsx +++ b/src/Components/SideSheet/Comments/Components/CommentView.tsx @@ -71,7 +71,7 @@ const CommentView: React.FC = ({ const userTagsResult = await (await GetUserTagService()).getUsers(fusionContextId.id, "", 1000, 0) setUserTags(userTagsResult.data) } catch (error) { - console.error("Error users for project: ", error) + console.error("Error getting users for project: ", error) } } })() From e90993ffc57efbdcc265fbd219ba4fb3dad819db Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Thu, 21 Sep 2023 09:06:38 +0200 Subject: [PATCH 5/6] fix regex for mentions --- src/Components/SideSheet/Comments/Components/RenderComment.tsx | 2 +- src/utils/helpers.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/SideSheet/Comments/Components/RenderComment.tsx b/src/Components/SideSheet/Comments/Components/RenderComment.tsx index 060b1c73..9f9f7e17 100644 --- a/src/Components/SideSheet/Comments/Components/RenderComment.tsx +++ b/src/Components/SideSheet/Comments/Components/RenderComment.tsx @@ -114,7 +114,7 @@ const RenderComment: FC = ({ const [open, setOpen] = useState(false) const { - activeTagData, conversations, activeConversation, setActiveConversation, + activeTagData, activeConversation, setActiveConversation, } = useContext(ViewContext) if (!activeConversation) { return (<>Error loading conversation) } diff --git a/src/utils/helpers.tsx b/src/utils/helpers.tsx index f08a380f..8716b1e8 100644 --- a/src/utils/helpers.tsx +++ b/src/utils/helpers.tsx @@ -66,7 +66,7 @@ export function getPropertyName(property: keyof T): keyof T { * @returns {number[]} mentions - An array of mention IDs. */ export function processMessageInput(input: string): { processedString: string, mentions: number[] } { - const regex = /([^<]+)<\/span>/g + const regex = /([^<]+)<\/span>/g let match const mentions: number[] = [] From 64a650b166058b0923df5bb34f9969c9e37a35f6 Mon Sep 17 00:00:00 2001 From: Tord Austad Date: Thu, 21 Sep 2023 12:50:50 +0200 Subject: [PATCH 6/6] move endpoint for user lookup --- .../Comments/Components/CommentView.tsx | 4 ++-- src/api/ProjectService.ts | 10 +++++++++ src/api/UserTagService.ts | 22 ------------------- 3 files changed, 12 insertions(+), 24 deletions(-) delete mode 100644 src/api/UserTagService.ts diff --git a/src/Components/SideSheet/Comments/Components/CommentView.tsx b/src/Components/SideSheet/Comments/Components/CommentView.tsx index 0ea3b849..8948c14b 100644 --- a/src/Components/SideSheet/Comments/Components/CommentView.tsx +++ b/src/Components/SideSheet/Comments/Components/CommentView.tsx @@ -12,7 +12,7 @@ import { ViewContext } from "../../../../Context/ViewContext" import ClusteredMessages from "./ClusteredMessages" import TagDropDown from "./TagDropDown" import { processMessageInput } from "../../../../utils/helpers" -import { GetUserTagService } from "../../../../api/UserTagService" +import { GetProjectService } from "../../../../api/ProjectService" const Controls = styled.div` position: sticky; @@ -70,7 +70,7 @@ const CommentView: React.FC = ({ (async () => { if (fusionContextId) { try { - const userTagsResult = await (await GetUserTagService()).getUsers(fusionContextId.id, "", 1000, 0) + const userTagsResult = await (await GetProjectService()).getUsers(fusionContextId.id, "", 1000, 0) setUserTags(userTagsResult.data) } catch (error) { console.error("Error getting users for project: ", error) diff --git a/src/api/ProjectService.ts b/src/api/ProjectService.ts index b9524ea2..a4c11880 100644 --- a/src/api/ProjectService.ts +++ b/src/api/ProjectService.ts @@ -7,6 +7,16 @@ class ProjectService extends BaseService { const result: any = await this.get(`${id}`) return result.value } + + async getUsers(fusionContextId: string, search: string, top: number, skip: number) { + const result: any = await this.getWithParams( + `${fusionContextId}/users`, + { + params: { search, top, skip }, + }, + ) + return result + } } export async function GetProjectService() { diff --git a/src/api/UserTagService.ts b/src/api/UserTagService.ts deleted file mode 100644 index 4aede11b..00000000 --- a/src/api/UserTagService.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { BaseService } from "./BaseService" - -import { config, GetToken, LoginAccessTokenKey } from "./config" - -class UserTagService extends BaseService { - async getUsers(fusionContextId: string, search: string, top: number, skip: number) { - const result: any = await this.getWithParams( - `${fusionContextId}`, - { - params: { search, top, skip }, - }, - ) - return result - } -} - -export async function GetUserTagService() { - return new UserTagService({ - ...config.UserTagService, - accessToken: await GetToken(LoginAccessTokenKey)!, - }) -}