diff --git a/src/Components/SideSheet/Comments/CommentSideSheet.tsx b/src/Components/SideSheet/Comments/CommentSideSheet.tsx index 98e81a30..bb2dcf50 100644 --- a/src/Components/SideSheet/Comments/CommentSideSheet.tsx +++ b/src/Components/SideSheet/Comments/CommentSideSheet.tsx @@ -4,6 +4,7 @@ import React, { import styled from "styled-components" import { Button, Icon, Tooltip } from "@equinor/eds-core-react" import { search, filter_alt } from "@equinor/eds-icons" +import { useCurrentContext } from "@equinor/fusion-framework-react-app/context" import CommentView from "./Components/CommentView" import LocalNavigation from "../Components/LocalNavigation" import TabsTitle from "../Components/TabsTitle" @@ -74,6 +75,8 @@ const CommentSideSheet: FC = ({ } }, [activeTab]) + const currentContext = useCurrentContext() + const getPropertyValue = (property: string, obj: any): any => { if (obj == null) { return null } if (Object.prototype.hasOwnProperty.call(obj, property)) { @@ -137,8 +140,12 @@ const CommentSideSheet: FC = ({ useEffect(() => { (async () => { try { - if (!activeTagData?.review || !activeTagData?.review.id) { return } - const newConversations = await (await GetConversationService()).getConversationsForTagReview(activeTagData.review.id) + if (!activeTagData?.tagNo || !currentContext.currentContext?.externalId) { return } + const newConversations = await (await GetConversationService()).getConversationsForTag( + currentContext.currentContext?.externalId, + activeTagData.tagNo, + true, + ) setConversations(newConversations) } catch (error) { console.error("Error getting messages for conversation: ", error) diff --git a/src/Components/SideSheet/Comments/Components/CommentView.tsx b/src/Components/SideSheet/Comments/Components/CommentView.tsx index ebc4a235..9c8c510b 100644 --- a/src/Components/SideSheet/Comments/Components/CommentView.tsx +++ b/src/Components/SideSheet/Comments/Components/CommentView.tsx @@ -4,7 +4,7 @@ import React, { useState, } from "react" import styled from "styled-components" -import { useCurrentContext } from "@equinor/fusion" +import { useCurrentContext } from "@equinor/fusion-framework-react-app/context" import { GetConversationService } from "../../../../api/ConversationService" import { Message } from "../../../../Models/Message" import InputController from "./InputController" @@ -13,6 +13,7 @@ import ClusteredMessages from "./ClusteredMessages" import TagDropDown from "./TagDropDown" import { processMessageInput } from "../../../../utils/helpers" import { GetProjectService } from "../../../../api/ProjectService" +import { GetMessageService } from "../../../../api/MessageService" const Controls = styled.div` position: sticky; @@ -60,7 +61,7 @@ const CommentView: React.FC = ({ setActiveConversation, } = useContext(ViewContext) - const fusionContextId = useCurrentContext() + const currentContext = useCurrentContext() const getConversationForProperty = (property: string) => ( conversations.find((conversation) => conversation.property?.toUpperCase() === property.toUpperCase()) @@ -68,9 +69,9 @@ const CommentView: React.FC = ({ useEffect(() => { (async () => { - if (fusionContextId) { + if (currentContext && currentContext.currentContext?.id) { try { - const userTagsResult = await (await GetProjectService()).getUsers(fusionContextId.id, "", 1000, 0) + const userTagsResult = await (await GetProjectService()).getUsers(currentContext.currentContext.id, "", 1000, 0) setUserTags(userTagsResult.data) } catch (error) { console.error("Error getting users for project: ", error) @@ -85,8 +86,7 @@ const CommentView: React.FC = ({ const currentConversationId = getConversationForProperty(currentProperty)?.id if (currentConversationId) { - const currentConversation = await (await GetConversationService()).getMessagesForConversation( - activeTagData?.review?.id ?? "", + const currentConversation = await (await GetMessageService()).getMessagesForConversation( currentConversationId, ) setActiveConversation(currentConversation) @@ -122,9 +122,14 @@ const CommentView: React.FC = ({ conversationLevel: "Tag", conversationStatus: "Open", } + if (!currentContext.currentContext?.externalId || !activeTagData?.tagNo) { return } try { const service = await GetConversationService() - const savedConversation = await service.createConversation(activeTagData?.review?.id ?? "", createCommentDto) + const savedConversation = await service.createConversation( + currentContext.currentContext?.externalId, + activeTagData?.tagNo, + createCommentDto, + ) setActiveConversation(savedConversation) const newConversations = [...conversations, savedConversation] setConversations(newConversations) @@ -135,13 +140,12 @@ const CommentView: React.FC = ({ } const addMessage = async () => { - const message = { ...newMessage } const { processedString, mentions } = processMessageInput(newMessage?.text ?? "") + const message: Components.Schemas.MessageDto = { ...newMessage, text: processedString } console.log("mentions: ", mentions) // to be used for tagging users in the future - message.text = processedString try { - const service = await GetConversationService() - const savedMessage = await service.addMessage(activeTagData?.review?.id ?? "", activeConversation?.id ?? "", message) + const service = await GetMessageService() + const savedMessage = await service.addMessage(activeConversation?.id ?? "", message) const updatedMessages = [...activeConversation?.messages ?? [], savedMessage] diff --git a/src/Components/SideSheet/Comments/Components/RenderComment.tsx b/src/Components/SideSheet/Comments/Components/RenderComment.tsx index 9f9f7e17..aa6b57cc 100644 --- a/src/Components/SideSheet/Comments/Components/RenderComment.tsx +++ b/src/Components/SideSheet/Comments/Components/RenderComment.tsx @@ -9,10 +9,10 @@ import { delete_to_trash, edit, } from "@equinor/eds-icons" import { Message } from "../../../../Models/Message" -import { GetConversationService } from "../../../../api/ConversationService" import { Conversation } from "../../../../Models/Conversation" import { ViewContext } from "../../../../Context/ViewContext" import { unescapeHtmlEntities } from "../../../../utils/helpers" +import { GetMessageService } from "../../../../api/MessageService" const Container = styled.div` max-width: 500px; @@ -55,18 +55,19 @@ interface RenderCommentProps { const updateComment = async ( reviewId: string, activeConversationId: string, - comment: Message, + message: Message, newCommentText: string, activeConversation: Conversation, setActiveConversation: Dispatch>, ) => { - if (newCommentText && comment.id) { + if (newCommentText && message.id) { try { - const newComment = { ...comment } - newComment.text = newCommentText - const commentService = await GetConversationService() - const updatedComment = await commentService.updateMessage(reviewId, activeConversationId, comment.id, newComment) - const updatedMessages = activeConversation.messages?.map((m) => (m.id !== comment.id ? m : updatedComment)) + const newMessage: Components.Schemas.MessageDto = { + text: newCommentText, + } + const commentService = await GetMessageService() + const updatedComment = await commentService.updateMessage(activeConversationId, message.id, newMessage) + const updatedMessages = activeConversation.messages?.map((m) => (m.id !== message.id ? m : updatedComment)) const updatedConversation = { ...activeConversation } updatedConversation.messages = updatedMessages setActiveConversation(updatedConversation) @@ -85,8 +86,8 @@ const deleteComment = async ( ) => { if (message.id && activeConversation && activeConversation.messages) { try { - const service = await GetConversationService() - const response = await service.deleteMessage(reviewId, activeConversationId, message.id) + const service = await GetMessageService() + const response = await service.deleteMessage(activeConversationId, message.id) if (response === 204) { const deletedMessage = { ...activeConversation.messages?.find((m) => m.id === message.id) } deletedMessage.softDeleted = true diff --git a/src/Views/JIP33InstrumentTabView.tsx b/src/Views/JIP33InstrumentTabView.tsx index 793d7c72..e0031840 100644 --- a/src/Views/JIP33InstrumentTabView.tsx +++ b/src/Views/JIP33InstrumentTabView.tsx @@ -7,6 +7,7 @@ import React, { } from "react" import { useParams } from "react-router-dom" import { comment_chat, open_side_sheet } from "@equinor/eds-icons" +import { useCurrentContext } from "@equinor/fusion-framework-react-app/context" import { generateGeneralRowData } from "../Components/JIP33Table/RowData/Instrument/GeneralRowData" import { generateInstallationConditionsRowData } from "../Components/JIP33Table/RowData/Instrument/InstallationConditionsRowData" import { generateOperatingConditionsRowData } from "../Components/JIP33Table/RowData/Instrument/OperatingConditionsRowData" @@ -88,6 +89,8 @@ function JIP33InstrumentTabView({ }) { const [activeTab, setActiveTab] = useState(0) const [sheetWidth, setSheetWidth] = useState(0) + const currentContext = useCurrentContext() + const { activeTagData, setActiveTagData, activeSheetTab, setActiveSheetTab, setConversations, } = useContext(ViewContext) @@ -105,9 +108,10 @@ function JIP33InstrumentTabView({ }) { }, [setOpen]) const getConversationsForTagReview = async (id: string) => { - const newConversations: Conversation[] = await ( + if (!currentContext.currentContext?.externalId || !activeTagData?.tagNo) { return } + const newConversations = await ( await GetConversationService() - ).getConversationsForTagReview(id) + ).getConversationsForTag(currentContext.currentContext.externalId, activeTagData.tagNo, true) setConversations(newConversations) } diff --git a/src/api/ConversationService.ts b/src/api/ConversationService.ts index f627c0f2..5f101724 100644 --- a/src/api/ConversationService.ts +++ b/src/api/ConversationService.ts @@ -1,46 +1,21 @@ -import { Message } from "../Models/Message" import { BaseService } from "./BaseService" import { config, GetToken, LoginAccessTokenKey } from "./config" class ConversationService extends BaseService { - async getMessage(id: string) { - const result: any = await this.get(`project/${id}`) - return result.value - } - - async getMessagesForConversation(reviewId: string, conversationId: string) { - const result: any = await this.get(`${reviewId}/conversations/${conversationId}`) + async getConversationsForTag(projectId: string, tagNo: string, includeLatestMessage: boolean = false) { + const result: Components.Schemas.GetConversationDto[] = await this.get( + `${projectId}/tags/${tagNo}/conversations?includeLatestMessage=${includeLatestMessage}`, + ) return result } - async getConversationsForTagReview(reviewId: string) { - const result: any = await this.get(`${reviewId}/conversations`) - return result - } - - async addMessage(reviewId: string, conversationId: string, message: Message) { - const result: any = await this.post(`${reviewId}/conversations/${conversationId}/messages`, { - body: message, - }) - return result - } - - async createConversation(reviewId: string, message: Components.Schemas.ConversationDto) { - const result: any = await this.post(`${reviewId}/conversations`, { - body: message, - }) - return result - } - - async deleteMessage(reviewId: string, conversationId: string, commentId: string) { - const result: any = await this.delete(`${reviewId}/conversations/${conversationId}/messages/${commentId}`) - return result.status - } - - async updateMessage(reviewId: string, conversationId: string, commentId: string, message: Message) { - const result: any = await this.put(`${reviewId}/conversations/${conversationId}/messages/${commentId}`, { - body: message, - }) + async createConversation(projectId: string, tagNo: string, message: Components.Schemas.ConversationDto) { + const result: Components.Schemas.ConversationDto = await this.post( + `${projectId}/tags/${tagNo}/conversations`, + { + body: message, + }, + ) return result } } diff --git a/src/api/MessageService.ts b/src/api/MessageService.ts new file mode 100644 index 00000000..7705da4b --- /dev/null +++ b/src/api/MessageService.ts @@ -0,0 +1,40 @@ +import { BaseService } from "./BaseService" +import { config, GetToken, LoginAccessTokenKey } from "./config" + +class MessageService extends BaseService { + async getMessage(id: string) { + const result: any = await this.get(`project/${id}`) + return result.value + } + + async getMessagesForConversation(conversationId: string) { + const result: any = await this.get(`${conversationId}`) + return result + } + + async addMessage(conversationId: string, message: Components.Schemas.MessageDto) { + const result: any = await this.post(`${conversationId}/messages`, { + body: message, + }) + return result + } + + async deleteMessage(conversationId: string, messageId: string) { + const result: any = await this.delete(`${conversationId}/messages/${messageId}`) + return result.status + } + + async updateMessage(conversationId: string, messageId: string, message: Components.Schemas.MessageDto) { + const result: any = await this.put(`${conversationId}/messages/${messageId}`, { + body: message, + }) + return result + } +} + +export async function GetMessageService() { + return new MessageService({ + ...config.MessageService, + accessToken: await GetToken(LoginAccessTokenKey)!, + }) +} diff --git a/src/api/config.tsx b/src/api/config.tsx index eebf0a7f..7c3b4cc0 100644 --- a/src/api/config.tsx +++ b/src/api/config.tsx @@ -17,6 +17,9 @@ const configuration = { ConversationService: { BASE_URL: "", }, + MessageService: { + BASE_URL: "", + }, TagDataReviewService: { BASE_URL: "", }, @@ -32,7 +35,8 @@ export const buildConfig = (baseUrl: string) => { configuration.ProjectService.BASE_URL = `${baseUrl}/projects` configuration.TagDataService.BASE_URL = `${baseUrl}/tagdata` configuration.ContractService.BASE_URL = `${baseUrl}/contracts` - configuration.ConversationService.BASE_URL = `${baseUrl}/tag/reviews` + configuration.ConversationService.BASE_URL = `${baseUrl}/projects` + configuration.MessageService.BASE_URL = `${baseUrl}/conversations` configuration.TagDataReviewService.BASE_URL = `${baseUrl}/tagdatareviews` configuration.RevisionReviewService.BASE_URL = `${baseUrl}/revisionreviews` configuration.UserTagService.BASE_URL = `${baseUrl}/usertags` diff --git a/src/types.d.ts b/src/types.d.ts index 5d3ec09f..308ae4f9 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -15,7 +15,7 @@ declare namespace Components { conversationLevel?: ConversationLevelDto; conversationStatus?: ConversationStatusDto; } - export type ConversationLevelDto = "Tag" | "PurchaserRequirement" | "SupplierOfferedValue"; + export type ConversationLevelDto = "Tag" | "Property"; export type ConversationStatusDto = "Open" | "To_be_implemented" | "Closed" | "Implemented"; export interface CreateContainerReviewDto { revisionContainerId?: string; // uuid @@ -1641,10 +1641,8 @@ declare namespace Paths { namespace AddMessage { namespace Parameters { export type ConversationId = string; // uuid - export type ReviewId = string; // uuid } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; conversationId: Parameters.ConversationId /* uuid */; } export type RequestBody = Components.Schemas.MessageDto; @@ -1654,10 +1652,12 @@ declare namespace Paths { } namespace CreateConversation { namespace Parameters { - export type ReviewId = string; // uuid + export type ProjectId = string; // uuid + export type TagNo = string; } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; + projectId: Parameters.ProjectId /* uuid */; + tagNo: Parameters.TagNo; } export type RequestBody = Components.Schemas.ConversationDto; namespace Responses { @@ -1692,10 +1692,8 @@ declare namespace Paths { namespace Parameters { export type ConversationId = string; // uuid export type MessageId = string; // uuid - export type ReviewId = string; // uuid } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; conversationId: Parameters.ConversationId /* uuid */; messageId: Parameters.MessageId /* uuid */; } @@ -1728,10 +1726,12 @@ declare namespace Paths { namespace GetConversation { namespace Parameters { export type ConversationId = string; // uuid - export type ReviewId = string; // uuid + export type ProjectId = string; // uuid + export type TagNo = string; } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; + projectId: Parameters.ProjectId /* uuid */; + tagNo: Parameters.TagNo; conversationId: Parameters.ConversationId /* uuid */; } namespace Responses { @@ -1741,10 +1741,12 @@ declare namespace Paths { namespace GetConversations { namespace Parameters { export type IncludeLatestMessage = boolean; - export type ReviewId = string; // uuid + export type ProjectId = string; // uuid + export type TagNo = string; } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; + projectId: Parameters.ProjectId /* uuid */; + tagNo: Parameters.TagNo; } export interface QueryParameters { includeLatestMessage?: Parameters.IncludeLatestMessage; @@ -1777,10 +1779,8 @@ declare namespace Paths { namespace Parameters { export type ConversationId = string; // uuid export type MessageId = string; // uuid - export type ReviewId = string; // uuid } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; conversationId: Parameters.ConversationId /* uuid */; messageId: Parameters.MessageId /* uuid */; } @@ -1791,10 +1791,8 @@ declare namespace Paths { namespace GetMessages { namespace Parameters { export type ConversationId = string; // uuid - export type ReviewId = string; // uuid } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; conversationId: Parameters.ConversationId /* uuid */; } namespace Responses { @@ -1884,10 +1882,8 @@ declare namespace Paths { namespace Parameters { export type ConversationId = string; // uuid export type MessageId = string; // uuid - export type ReviewId = string; // uuid } export interface PathParameters { - reviewId: Parameters.ReviewId /* uuid */; conversationId: Parameters.ConversationId /* uuid */; messageId: Parameters.MessageId /* uuid */; }