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: Update data model #181

Merged
merged 19 commits into from
Nov 6, 2023
Merged
8 changes: 4 additions & 4 deletions src/Components/EquipmentListView/EquipmentListReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function EquipmentListReview({
setActiveTagData(tagData)
}

const buildTagReview = (): Components.Schemas.CreateTagDataReviewDto => {
const newReview: Components.Schemas.CreateTagDataReviewDto = {
const buildTagReview = (): any => {
const newReview: any = {
tagNo: tagNoInReview ?? "",
status: "New",
}
Expand All @@ -73,7 +73,7 @@ function EquipmentListReview({
const buildPackageReview = (): Components.Schemas.CreateContainerReviewDto => {
const newReview: Components.Schemas.CreateContainerReviewDto = {
revisionContainerId: revisionInReview ?? "",
status: "New",
status: "NotReviewed",
}
return newReview
}
Expand Down Expand Up @@ -101,7 +101,7 @@ function EquipmentListReview({

const rejectPackage = async () => {
const review = buildPackageReview()
review.status = "Resubmit"
review.status = "NotReviewed"
const result = await (await GetRevisionReviewService()).createRevisionReview(review)
await updateTagData()
}
Expand Down
124 changes: 65 additions & 59 deletions src/Components/EquipmentListView/EquipmentListTable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React, { Dispatch, SetStateAction, useMemo } from "react"
import React, {
Dispatch, SetStateAction, useContext, useEffect, useMemo, useState,
} from "react"
import { AgGridReact } from "@ag-grid-community/react"
import useStyles from "@equinor/fusion-react-ag-grid-styles"
import { tokens } from "@equinor/eds-tokens"
import { Icon } from "@equinor/eds-core-react"
import { block, done, tag } from "@equinor/eds-icons"
import { Checkbox, Icon } from "@equinor/eds-core-react"
import {
block, tag,
} from "@equinor/eds-icons"
import styled from "styled-components"
import { ColDef, ICellRendererParams } from "@ag-grid-community/core"
import { Link, useLocation } from "react-router-dom"
import { TagData } from "../../Models/TagData"
import EquipmentListReviewRenderer from "./EquipmentListReviewRenderer"
import { ViewContext } from "../../Context/ViewContext"
import { GetTagReviewerService } from "../../api/TagReviewerService"

interface Props {
tags: TagData[]
Expand Down Expand Up @@ -42,6 +47,12 @@ function EquipmentListTable({
const location = useLocation()
const styles = useStyles()

const [tagReviewers, setTagReviewers] = useState<any[]>()

const {
currentUserId,
} = useContext(ViewContext)

const defaultColDef = useMemo<ColDef>(
() => ({
sortable: true,
Expand All @@ -52,6 +63,26 @@ function EquipmentListTable({
[],
)

useEffect(() => {
let isCancelled = false;
(async () => {
try {
if (currentUserId) {
const myReviewsFromServer = await (await GetTagReviewerService()).getTagReviewers(currentUserId)
setTagReviewers(myReviewsFromServer.data)
}
} catch {
if (!isCancelled) {
console.error("Error loading tags")
taustad marked this conversation as resolved.
Show resolved Hide resolved
}
}
})()

return () => {
isCancelled = true
}
}, [currentUserId])

const typeOfJIP33 = ({ data: { discipline } }: any) => {
if (discipline === "Mechanical") {
return "JIP33Mechanical"
Expand Down Expand Up @@ -88,32 +119,6 @@ function EquipmentListTable({
</Link>
)

const tagDataReviewStatusRenderer = (params: any) => {
const status = params.data.review?.status
switch (status) {
case "Reviewed":
return <Icon data={done} color="green" />
case "Resubmit":
return <Icon data={block} color="red" />
default:
return null
}
}

const revisionContainerReviewStatusRenderer = (
params: ICellRendererParams,
) => {
const status = params.data.revisionContainer?.revisionContainerReview?.status
switch (status) {
case "Reviewed":
return <Icon data={done} color="green" />
case "Resubmit":
return <Icon data={block} color="red" />
default:
return null
}
}

const reviewDeadlineRenderer = (params: ICellRendererParams) => {
if (
params.data.revisionContainer === null
Expand All @@ -139,6 +144,30 @@ function EquipmentListTable({
return deadline.toISOString().slice(0, 10)
}

const handleTagReviewerCheckboxClick = async (rowState: any) => {
const newState = rowState.state === "NotReviewed" ? "Reviewed" : "NotReviewed"
const dto: Components.Schemas.UpdateTagReviewerDto = {
state: newState,
}
const result = await (await GetTagReviewerService()).updateReviewer(rowState.containerReviewId, rowState.id, dto)

setTagReviewers(tagReviewers?.map((tr) => (tr.id === rowState.id ? { ...tr, state: newState } : tr)))
}

const reviewStatusRenderer = (params: ICellRendererParams) => {
if (!tagReviewers) { return null }

const rowState = tagReviewers.find((r) => r.tagNo === params.data.tagNo)

if (!rowState) { return null }

if (rowState.state === "NotReviewed") {
return (<Checkbox onClick={() => handleTagReviewerCheckboxClick(rowState)} />)
}

return (<Checkbox defaultChecked onClick={() => handleTagReviewerCheckboxClick(rowState)} />)
}

const columns = [
{
headerName: "Tag info",
Expand All @@ -148,6 +177,11 @@ function EquipmentListTable({
headerName: "Tag number",
cellRenderer: (params: any) => linkToDocument(params),
},
{
field: "reviewStatus",
headerName: "Review status",
cellRenderer: (params: any) => reviewStatusRenderer(params),
},
{ field: "version", headerName: "Version number" },
{
field: "revisionContainer.revisionNumber",
Expand Down Expand Up @@ -181,34 +215,6 @@ function EquipmentListTable({
{
headerName: "Review info",
children: [
{
field: "",
headerName: "Review",
cellRenderer: (params: any) => EquipmentListReviewRenderer(
params,
setReviewModalOpen,
setTagInReview,
setRevisionInReview,
),
},
{
field: "revisionContainer.revisionContainerReview.status",
headerName: "Revision container review status",
cellRenderer: (params: any) => revisionContainerReviewStatusRenderer(params),
},
{
field: "review.status",
headerName: "Review status",
cellRenderer: (params: any) => tagDataReviewStatusRenderer(params),
},
{
field: "review.approverId",
headerName: "Reviewers",
},
{
field: "review.commentResponsible",
headerName: "Comment responsible",
},
{
field: "reviewDeadline",
headerName: "Review deadline",
Expand All @@ -233,7 +239,7 @@ function EquipmentListTable({
rowSelection="multiple"
suppressMovableColumns
headerHeight={48}
rowHeight={35}
rowHeight={50}
enableRangeSelection
/>
</TableContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getPropertyName } from "../../../utils/helpers"
export const comparisonReviewColumnDefs = (): ColDef[] => [
{
headerName: "Assigned reviewers",
field: getPropertyName<Components.Schemas.ReviewerDto>("displayName"),
field: getPropertyName<Components.Schemas.TagReviewerDto>("displayName"),
hide: true,
},
]
26 changes: 12 additions & 14 deletions src/Components/TagComparisonTable/TagComparisonTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import TagPropertySideSheet from "../SideSheet/TagPropertySideSheet"
import TagSideSheet from "../SideSheet/TagSideSheet"
import { ViewContext } from "../../Context/ViewContext"
import { comparisonReviewColumnDefs } from "./ColumnDefs/ReviewColumnDefs"
import { GetTagDataReviewService } from "../../api/TagDataReviewService"
import { GetTagReviewerService } from "../../api/TagReviewerService"

const TableContainer = styled.div`
flex: 1 1 auto;
Expand Down Expand Up @@ -59,7 +59,7 @@ function TagComparisonTable({ tags }: Props) {
} = useContext(ViewContext)
const [FilterSidebarIsOpen, SetFilterSidebarIsOpen] = useState<boolean>(false)
const [showTagSideSheet, setShowTagSideSheet] = useState<boolean>(false)
const [tagReviews, setTagReviews] = useState<Components.Schemas.TagDataReviewDto[]>()
const [tagReviews, setTagReviews] = useState<any[]>()
taustad marked this conversation as resolved.
Show resolved Hide resolved

const toggleFilterSidebar = () => SetFilterSidebarIsOpen(!FilterSidebarIsOpen)
const defaultColDef = useMemo<ColDef>(
Expand All @@ -76,7 +76,7 @@ function TagComparisonTable({ tags }: Props) {
useEffect(() => {
(async () => {
try {
const result = await (await GetTagDataReviewService()).getTagDataReviews()
const result = await (await GetTagReviewerService()).getTagReviewers()
setTagReviews(result.data)
} catch (error) {
console.error(`Couldn't get tag reviews: ${error}`)
Expand All @@ -86,13 +86,11 @@ function TagComparisonTable({ tags }: Props) {

const getReviewerNamesFromReviews = (tag: InstrumentTagData) => {
const reviewers: string[] = []
tagReviews?.forEach((tagReview: Components.Schemas.TagDataReviewDto) => {
tagReviews?.forEach((tagReview: any) => {
taustad marked this conversation as resolved.
Show resolved Hide resolved
if (tag.tagNo !== tagReview.tagNo) { return }
tagReview?.reviewer?.forEach((tR: Components.Schemas.ReviewerDto) => {
if (tR.displayName) {
reviewers.push(tR?.displayName)
}
})
if (tagReview.displayName) {
reviewers.push(tagReview?.displayName)
}
})
return reviewers.toString()
}
Expand Down Expand Up @@ -199,11 +197,11 @@ function TagComparisonTable({ tags }: Props) {
const comparisonColumns = params.columnApi?.getColumns()
const renderedRowNodes = params.api?.getRenderedNodes()
comparisonColumns?.forEach((column: any) => {
const columnHasNoData = !renderedRowNodes?.some((rowNode: any) => {
const nodeValue = params.api?.getValue(column, rowNode)
return typeof nodeValue !== "undefined" && nodeValue !== null && nodeValue !== ""
})
params.columnApi.setColumnVisible(column, !columnHasNoData)
const columnHasNoData = !renderedRowNodes?.some((rowNode: any) => {
const nodeValue = params.api?.getValue(column, rowNode)
return typeof nodeValue !== "undefined" && nodeValue !== null && nodeValue !== ""
})
params.columnApi.setColumnVisible(column, !columnHasNoData)
})
}, [])

Expand Down
18 changes: 18 additions & 0 deletions src/Context/ViewContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ interface ViewContextProps {
setErrors: React.Dispatch<React.SetStateAction<ErrorType>>;
SideSheetScrollPos : number;
setSideSheetScrollPos : React.Dispatch<React.SetStateAction<number>>;
containerReviews: Components.Schemas.ContainerReviewDto[]
setContainerReviews: Dispatch<SetStateAction<Components.Schemas.ContainerReviewDto[]>>
currentUserId: string
setCurrentUserId: Dispatch<SetStateAction<string>>
}

export const ViewContext = createContext<ViewContextProps>({
Expand All @@ -61,6 +65,10 @@ export const ViewContext = createContext<ViewContextProps>({
setErrors: () => { },
SideSheetScrollPos: 0,
setSideSheetScrollPos: () => { },
containerReviews: [],
setContainerReviews: () => { },
currentUserId: "",
setCurrentUserId: () => "",
})

interface ViewContextProviderProps {
Expand All @@ -77,7 +85,9 @@ export const ViewContextProvider: React.FC<ViewContextProviderProps> = ({
const [SideSheetScrollPos, setSideSheetScrollPos] = useState<number>(() => parseInt(localStorage.getItem("SideSheetScrollPos") || "0", 10))
const [conversations, setConversations] = useState<Conversation[]>([])
const [activeConversation, setActiveConversation] = useState<Conversation>()
const [containerReviews, setContainerReviews] = useState<Components.Schemas.ContainerReviewDto[]>([])
const [errors, setErrors] = useState<{}>({})
const [currentUserId, setCurrentUserId] = useState<string>("")

useEffect(() => {
localStorage.setItem("isSideSheetOpen", JSON.stringify(sideSheetOpen))
Expand Down Expand Up @@ -119,6 +129,10 @@ export const ViewContextProvider: React.FC<ViewContextProviderProps> = ({
setErrors,
SideSheetScrollPos,
setSideSheetScrollPos,
containerReviews,
setContainerReviews,
currentUserId,
setCurrentUserId,
currentProperty,
setCurrentProperty,
}),
Expand All @@ -139,6 +153,10 @@ export const ViewContextProvider: React.FC<ViewContextProviderProps> = ({
setErrors,
SideSheetScrollPos,
setSideSheetScrollPos,
containerReviews,
setContainerReviews,
currentUserId,
setCurrentUserId,
currentProperty,
setCurrentProperty,
],
Expand Down
8 changes: 4 additions & 4 deletions src/Models/RevisionContainer.ts → src/Models/Container.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Contract } from "@equinor/fusion"
import { RevisionContainerReview } from "./RevisionContainerReview"
import { ContainerReview } from "./ContainerReview"
import { TagData } from "./TagData"
import { TagDataReview } from "./TagDataReview"

export class RevisionContainer implements Components.Schemas.RevisionContainerDto {
export class Container { // implements Components.Schemas.RevisionContainerDto {
taustad marked this conversation as resolved.
Show resolved Hide resolved
id?: string; // uuid
createdDate?: string; // date-time
modifiedDate?: string; // date-time
revisionContainerName?: string | null;
revisionNumber?: number; // int32
revisionContainerDate?: string; // date-time
tagData?: TagData[] | null;
revisionContainerReview?: RevisionContainerReview;
revisionContainerReview?: ContainerReview;
contractId?: string; // uuid
contract?: Contract;

constructor(init?: Partial<RevisionContainer>) {
constructor(init?: Partial<Container>) {
Object.assign(this, init)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Message } from "./Message"
import { RevisionContainer } from "./RevisionContainer"
import { Container } from "./Container"

export class RevisionContainerReview implements Components.Schemas.RevisionContainerReviewDto {
export class ContainerReview { // implements Components.Schemas.RevisionContainerReviewDto {
taustad marked this conversation as resolved.
Show resolved Hide resolved
id?: string; // uuid
createdDate?: string; // date-time
modifiedDate?: string; // date-time
Expand All @@ -11,10 +11,10 @@ export class RevisionContainerReview implements Components.Schemas.RevisionConta
approved?: boolean;
revisionContainerVersion?: number; // int32
revisionContainerId?: string; // uuid
revisionContainer?: RevisionContainer;
revisionContainer?: Container;
comments?: Message[] | null;

constructor(init?: Partial<RevisionContainerReview>) {
constructor(init?: Partial<ContainerReview>) {
Object.assign(this, init)
}
}
Loading