Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use backend api in tag user #139

Merged
merged 8 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions src/Components/SideSheet/Comments/Components/CommentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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"
import { ViewContext } from "../../../../Context/ViewContext"
import ClusteredMessages from "./ClusteredMessages"
import TagDropDown from "./TagDropDown"
import { processMessageInput } from "../../../../utils/helpers"
import { GetProjectService } from "../../../../api/ProjectService"

const Controls = styled.div`
position: sticky;
Expand Down Expand Up @@ -47,6 +49,7 @@ const CommentView: React.FC<CommentViewProps> = ({
const [reRenderCounter, setReRenderCounter] = useState<number>(0)
const [searchTerm, setSearchTerm] = useState<string>("")
const [showTagDropDown, setShowTagDropDown] = useState<boolean>(false)
const [userTags, setUserTags] = useState<any[]>([])
const [charCount, setCharCount] = useState(0)

const {
Expand All @@ -57,36 +60,24 @@ const CommentView: React.FC<CommentViewProps> = ({
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 GetProjectService()).getUsers(fusionContextId.id, "", 1000, 0)
setUserTags(userTagsResult.data)
} catch (error) {
console.error("Error getting users for project: ", error)
}
}
})()
}, [])

useEffect(() => {
(async () => {
Expand Down Expand Up @@ -195,7 +186,7 @@ const CommentView: React.FC<CommentViewProps> = ({
SearchTerm={searchTerm}
setReRenderCounter={setReRenderCounter}
onTagSelected={handleTagSelected}
dummyData={dummyData}
dummyData={userTags}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const RenderComment: FC<RenderCommentProps> = ({
const [open, setOpen] = useState(false)

const {
activeTagData, conversations, activeConversation, setActiveConversation,
activeTagData, activeConversation, setActiveConversation,
} = useContext(ViewContext)

if (!activeConversation) { return (<>Error loading conversation</>) }
Expand Down
14 changes: 8 additions & 6 deletions src/Components/SideSheet/Comments/Components/TagDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ 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; mail: string }[]
setReRenderCounter: React.Dispatch<React.SetStateAction<number>>
}

const TagDropDown: FC<Props> = ({
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)
Expand All @@ -61,9 +63,9 @@ const TagDropDown: FC<Props> = ({

return (
<List>
{filteredNames.map(({ id, displayName }) => (
<li key={id}>
<ListItem onClick={() => handleTagClick(id, displayName)}>
{filteredNames.map(({ azureUniqueId, displayName }) => (
<li key={azureUniqueId}>
<ListItem onClick={() => handleTagClick(azureUniqueId, displayName)}>
{displayName}
</ListItem>
</li>
Expand Down
4 changes: 2 additions & 2 deletions src/api/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class BaseService {
path: string,
requestQuery?: AxiosRequestConfig,
): Promise<any> {
const { data } = await this.client.get(path, requestQuery)
const result = await this.client.get(path, requestQuery)

return data
return result
}

protected get<T = any>(path: string, options?: RequestOptions): Promise<T> {
Expand Down
10 changes: 10 additions & 0 deletions src/api/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/api/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const configuration = {
RevisionReviewService: {
BASE_URL: "",
},
UserTagService: {
BASE_URL: "",
},
}

export const buildConfig = (baseUrl: string) => {
Expand All @@ -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}/usertags`
}

export const config = Object.freeze(configuration)
Expand Down
25 changes: 25 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getPropertyName<T>(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 data-mention="(\d+)" contenteditable="false">([^<]+)<\/span>/g
const regex = /<span data-mention="(\w+-\w+-\w+-\w+-\w+)" contenteditable="false">([^<]+)<\/span>/g

let match
const mentions: number[] = []
Expand Down