diff --git a/backend/api/Services/CaseService.cs b/backend/api/Services/CaseService.cs index 35435a57f..b855bb626 100644 --- a/backend/api/Services/CaseService.cs +++ b/backend/api/Services/CaseService.cs @@ -76,6 +76,7 @@ public ProjectDto NewCreateCase(CaseDto caseDto) { ProjectId = createdCase.Entity.ProjectId, Name = "Topside", + Source = Source.ConceptApp, }; var topside = _topsideService.NewCreateTopside(topsideDto, createdCase.Entity.Id); caseItem.TopsideLink = topside.Id; @@ -84,6 +85,7 @@ public ProjectDto NewCreateCase(CaseDto caseDto) { ProjectId = createdCase.Entity.ProjectId, Name = "Surf", + Source = Source.ConceptApp, }; var surf = _surfService.NewCreateSurf(surfDto, createdCase.Entity.Id); caseItem.SurfLink = surf.Id; @@ -92,6 +94,7 @@ public ProjectDto NewCreateCase(CaseDto caseDto) { ProjectId = createdCase.Entity.ProjectId, Name = "Substructure", + Source = Source.ConceptApp, }; var substructure = _substructureService.NewCreateSubstructure(substructureDto, createdCase.Entity.Id); caseItem.SubstructureLink = substructure.Id; @@ -100,6 +103,7 @@ public ProjectDto NewCreateCase(CaseDto caseDto) { ProjectId = createdCase.Entity.ProjectId, Name = "Transport", + Source = Source.ConceptApp, }; var transport = _transportService.NewCreateTransport(transportDto, createdCase.Entity.Id); caseItem.TransportLink = transport.Id; diff --git a/backend/api/Services/ProspExcelImportService.cs b/backend/api/Services/ProspExcelImportService.cs index 5d7aab234..d96838a85 100644 --- a/backend/api/Services/ProspExcelImportService.cs +++ b/backend/api/Services/ProspExcelImportService.cs @@ -508,6 +508,7 @@ private void ClearImportedSurf(Case caseItem) Id = surfLink, CostProfile = null, ProjectId = caseItem.ProjectId, + Source = Source.ConceptApp, }; var dto = SurfDtoAdapter.Convert(surf); @@ -526,6 +527,7 @@ private void ClearImportedTopside(Case caseItem) Id = topsideLink, CostProfile = null, ProjectId = caseItem.ProjectId, + Source = Source.ConceptApp, }; var dto = TopsideDtoAdapter.Convert(topside); @@ -544,6 +546,7 @@ private void ClearImportedSubstructure(Case caseItem) Id = substructureLink, CostProfile = null, ProjectId = caseItem.ProjectId, + Source = Source.ConceptApp, }; var dto = SubstructureDtoAdapter.Convert(substructure); @@ -562,6 +565,7 @@ private void ClearImportedTransport(Case caseItem) Id = transportLink, CostProfile = null, ProjectId = caseItem.ProjectId, + Source = Source.ConceptApp, }; var dto = TransportDtoAdapter.Convert(transport); diff --git a/frontend/src/Components/EditTechnicalInput/ImportStatusEnum.ts b/frontend/src/Components/EditTechnicalInput/ImportStatusEnum.ts index 51203e46e..cf8e10b97 100644 --- a/frontend/src/Components/EditTechnicalInput/ImportStatusEnum.ts +++ b/frontend/src/Components/EditTechnicalInput/ImportStatusEnum.ts @@ -1,5 +1,4 @@ export enum ImportStatusEnum { - PROSP, Selected, NotSelected } diff --git a/frontend/src/Components/EditTechnicalInput/PROSPCaseList.tsx b/frontend/src/Components/EditTechnicalInput/PROSPCaseList.tsx index 1f96fa713..acd54efb1 100644 --- a/frontend/src/Components/EditTechnicalInput/PROSPCaseList.tsx +++ b/frontend/src/Components/EditTechnicalInput/PROSPCaseList.tsx @@ -25,7 +25,6 @@ interface Props { driveItems: DriveItem[] | undefined check: boolean } - interface RowData { id: string, name: string, @@ -38,9 +37,12 @@ interface RowData { sharepointFileUrl?: string | null driveItem: [DriveItem[] | undefined, string | undefined | null] fileLink?: string | null - caseSelected: boolean, + surfStateChanged: boolean, + substructureStateChanged: boolean, + topsideStateChanged: boolean, + transportStateChanged: boolean + sharePointFileChanged: boolean, } - function PROSPCaseList({ setProject, project, @@ -49,9 +51,7 @@ function PROSPCaseList({ }: Props) { const gridRef = useRef(null) const [rowData, setRowData] = useState() - const [isApplying, setIsApplying] = useState() - const casesToRowData = () => { if (project.cases) { const tableCases: RowData[] = [] @@ -68,14 +68,17 @@ function PROSPCaseList({ sharepointFileUrl: c.sharepointFileUrl, fileLink: c.sharepointFileUrl, driveItem: [driveItems, c.sharepointFileId], - caseSelected: false, + surfStateChanged: false, + substructureStateChanged: false, + topsideStateChanged: false, + transportStateChanged: false, + sharePointFileChanged: false, } tableCases.push(tableCase) }) setRowData(tableCases) } } - useEffect(() => { casesToRowData() }, [project, driveItems]) @@ -86,44 +89,81 @@ function PROSPCaseList({ resizable: true, }), []) + const rowIsChanged = (p: any) => (p.data.surfStateChanged + || p.data.substructureStateChanged + || p.data.topsideStateChanged + || p.data.transportStateChanged + || p.data.sharePointFileChanged) + const caseAutoSelect = (nodeId: string) => { const rowNode = gridRef.current?.getRowNode(nodeId) - rowNode.setDataValue("caseSelected", true) - } - const changeStatus = (p: any, value: ImportStatusEnum) => { - caseAutoSelect(p.node?.data.id) - p.setValue(value) - } + if (rowIsChanged(rowNode)) { + rowNode.selected = true + rowNode.setSelected(true) + rowNode.selectable = true + } else { + rowNode.selected = false + rowNode.setSelected(false) + rowNode.selectable = false + } - const handleCheckboxChange = (p: any, value: boolean) => { - p.setValue(value) + gridRef.current.redrawRows() } - const caseSelectedRenderer = (p: any) => { - if (p.value) { - return handleCheckboxChange(p, false)} /> + const handleAdvancedSettingsChange = (p: any, value: ImportStatusEnum) => { + if (project.cases && project.cases !== null && project.cases !== undefined) { + const caseItem = project.cases.find((el: any) => p.data.id && p.data.id === el.id) + const rowNode = gridRef.current?.getRowNode(p.node?.data.id) + if (caseItem) { + switch (p.column.colId) { + case "surfState": + rowNode.data.surfStateChanged = (SharePointImport.surfStatus(caseItem, project) !== value) + break + case "substructureState": + rowNode.data.substructureStateChanged = ( + SharePointImport.substructureStatus(caseItem, project) !== value) + break + case "topsideState": + rowNode.data.topsideStateChanged = (SharePointImport.topsideStatus(caseItem, project) !== value) + break + case "transportState": + rowNode.data.transportStateChanged = (SharePointImport.transportStatus(caseItem, project) !== value) + break + default: + break + } + } } - return handleCheckboxChange(p, true)} /> + p.setValue(value) + caseAutoSelect(p.node?.data.id) } - const checkBoxStatus = ( + const advancedSettingsRenderer = ( p: any, ) => { - if (p.value === ImportStatusEnum.PROSP) { - // Imported assets should have checked checkboxes and remaining assets should remain unchecked. - return changeStatus(p, ImportStatusEnum.NotSelected)} /> - } - if (p.value === ImportStatusEnum.Selected && p.node.data.sharePointFileName !== "") { - return changeStatus(p, ImportStatusEnum.NotSelected)} /> - } - if (p.value === ImportStatusEnum.Selected && p.node.data.sharePointFileName === "") { - return changeStatus(p, ImportStatusEnum.NotSelected)} /> + if (p.value === ImportStatusEnum.Selected) { + return ( + handleAdvancedSettingsChange(p, ImportStatusEnum.NotSelected)} + /> + ) } if (p.value === ImportStatusEnum.NotSelected) { - return changeStatus(p, ImportStatusEnum.Selected)} /> + return ( + handleAdvancedSettingsChange(p, ImportStatusEnum.Selected)} + /> + ) } - return changeStatus(p, ImportStatusEnum.Selected)} /> + return ( + handleAdvancedSettingsChange(p, ImportStatusEnum.Selected)} + /> + ) } const sharePointFileDropdownOptions = (items: DriveItem[]) => { @@ -137,10 +177,10 @@ function PROSPCaseList({ const getRowId = useMemo(() => (params: GetRowIdParams) => params.data.id, []) const getFileLink = (p: any, selectedFileId: any) => { - const driveItemsList = p.data.driveItem[0] + const driveItemChosen = p.data?.driveItem[0] let link = null - if (selectedFileId && Array.isArray(driveItemsList)) { - const item = driveItemsList.find((el: any) => selectedFileId && selectedFileId === el.id) + if (selectedFileId && driveItemChosen !== null && driveItemChosen !== undefined) { + const item = driveItemChosen.find((el: any) => selectedFileId && selectedFileId === el.id) if (item) { link = item.sharepointFileUrl } @@ -171,11 +211,18 @@ function PROSPCaseList({ const handleFileChange = (event: ChangeEvent, p: any) => { const value = { ...p.value } value[1] = event.currentTarget.selectedOptions[0].value - caseAutoSelect(p.node?.data.id) updateFileLink(p.node?.data.id, value[1]) + const rowNode = gridRef.current?.getRowNode(p.node?.data.id) + if (value[1] === rowNode.data.sharePointFileId) { + rowNode.data.sharePointFileChanged = false + } else { + rowNode.data.sharePointFileChanged = true + } p.setValue(value) + caseAutoSelect(p.node?.data.id) } - const fileIdDropDown = (p: any) => { + + const fileSelectorRenderer = (p: any) => { const fileId = p.value[1] const items: DriveItem[] = p.value[0] return ( @@ -208,20 +255,18 @@ function PROSPCaseList({ return null } - type SortOrder = "desc" | "asc" | null - const order: SortOrder = "asc" - const [columnDefs, setColumnDefs] = useState([ { - field: "caseSelected", headerName: "", cellRenderer: caseSelectedRenderer, flex: 1, - }, - { - field: "name", flex: 3, + field: "name", + flex: 3, + headerCheckboxSelection: true, + checkboxSelection: true, + showDisabledCheckboxes: true, }, { field: "driveItem", headerName: "SharePoint file", - cellRenderer: fileIdDropDown, + cellRenderer: fileSelectorRenderer, sortable: false, flex: 5, }, @@ -232,16 +277,32 @@ function PROSPCaseList({ width: 60, }, { - field: "surfState", headerName: "Surf", flex: 1, cellRenderer: checkBoxStatus, hide: check, + field: "surfState", + headerName: "Surf", + flex: 1, + cellRenderer: advancedSettingsRenderer, + hide: check, }, { - field: "substructureState", headerName: "Substructure", flex: 1, cellRenderer: checkBoxStatus, hide: check, + field: "substructureState", + headerName: "Substructure", + flex: 1, + cellRenderer: advancedSettingsRenderer, + hide: check, }, { - field: "topsideState", headerName: "Topside", flex: 1, cellRenderer: checkBoxStatus, hide: check, + field: "topsideState", + headerName: "Topside", + flex: 1, + cellRenderer: advancedSettingsRenderer, + hide: check, }, { - field: "transportState", headerName: "Transport", flex: 1, cellRenderer: checkBoxStatus, hide: check, + field: "transportState", + headerName: "Transport", + flex: 1, + cellRenderer: advancedSettingsRenderer, + hide: check, }, ]) @@ -272,22 +333,19 @@ function PROSPCaseList({ gridRef.current.forEachNode((node: RowNode) => { const dto: any = {} dto.sharePointFileId = node.data?.driveItem[1] - dto.sharePointFileName = node.data?.driveItem[0]?.find( (di) => di.id === dto.sharePointFileId, )?.name - dto.sharepointFileUrl = node.data?.driveItem[0]?.find( (di) => di.id === dto.sharePointFileId, )?.sharepointFileUrl - dto.sharePointSiteUrl = p.sharepointSiteUrl dto.id = node.data?.id dto.surf = node.data?.surfState === ImportStatusEnum.Selected dto.substructure = node.data?.substructureState === ImportStatusEnum.Selected dto.topside = node.data?.topsideState === ImportStatusEnum.Selected dto.transport = node.data?.transportState === ImportStatusEnum.Selected - if (node.data?.caseSelected) { + if (node.isSelected()) { dtos.push(dto) } }) @@ -317,6 +375,9 @@ function PROSPCaseList({ rowData={rowData} columnDefs={columnDefs} defaultColDef={defaultColDef} + rowSelection="multiple" + isRowSelectable={rowIsChanged} + suppressRowClickSelection animateRows domLayout="autoHeight" onGridReady={onGridReady} @@ -337,7 +398,6 @@ function PROSPCaseList({ )} - ) } diff --git a/frontend/src/Components/EditTechnicalInput/SharePointImport.ts b/frontend/src/Components/EditTechnicalInput/SharePointImport.ts index b15184070..a092ee323 100644 --- a/frontend/src/Components/EditTechnicalInput/SharePointImport.ts +++ b/frontend/src/Components/EditTechnicalInput/SharePointImport.ts @@ -33,7 +33,8 @@ export default class SharePointImport implements Components.Schemas.SharePointIm const surfId = caseItem.surfLink const surf = project.surfs.find((s) => s.id === surfId) if (!surf) { return ImportStatusEnum.NotSelected } - if (SharePointImport.mapSource(surf.source) === "ConceptApp") { return ImportStatusEnum.NotSelected } + if (SharePointImport.mapSource(surf.source) === "ConceptApp" + && caseItem.sharepointFileName !== "") { return ImportStatusEnum.NotSelected } return ImportStatusEnum.Selected } @@ -42,7 +43,8 @@ export default class SharePointImport implements Components.Schemas.SharePointIm const substructureId = caseItem.substructureLink const substructure = project.substructures.find((s) => s.id === substructureId) if (!substructure) { return ImportStatusEnum.NotSelected } - if (SharePointImport.mapSource(substructure.source) === "ConceptApp") { return ImportStatusEnum.NotSelected } + if (SharePointImport.mapSource(substructure.source) === "ConceptApp" + && caseItem.sharepointFileName !== "") { return ImportStatusEnum.NotSelected } return ImportStatusEnum.Selected } @@ -51,7 +53,8 @@ export default class SharePointImport implements Components.Schemas.SharePointIm const topsideId = caseItem.topsideLink const topside = project.topsides.find((s) => s.id === topsideId) if (!topside) { return ImportStatusEnum.NotSelected } - if (SharePointImport.mapSource(topside.source) === "ConceptApp") { return ImportStatusEnum.NotSelected } + if (SharePointImport.mapSource(topside.source) === "ConceptApp" + && caseItem.sharepointFileName !== "") { return ImportStatusEnum.NotSelected } return ImportStatusEnum.Selected } @@ -60,7 +63,8 @@ export default class SharePointImport implements Components.Schemas.SharePointIm const transportId = caseItem.transportLink const transport = project.transports.find((s) => s.id === transportId) if (!transport) { return ImportStatusEnum.NotSelected } - if (SharePointImport.mapSource(transport.source) === "ConceptApp") { return ImportStatusEnum.NotSelected } + if (SharePointImport.mapSource(transport.source) === "ConceptApp" + && caseItem.sharepointFileName !== "") { return ImportStatusEnum.NotSelected } return ImportStatusEnum.Selected }