Skip to content

Commit

Permalink
Prosp checkbox fixes (#947)
Browse files Browse the repository at this point in the history
Prosp checkboxes fix.
Have case autoselect set based on changes in table. Fixed advanced settings asset checkboxes to work as intended.
  • Loading branch information
DanielBohme authored Feb 13, 2023
1 parent d0646fc commit da1d520
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 58 deletions.
4 changes: 4 additions & 0 deletions backend/api/Services/CaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions backend/api/Services/ProspExcelImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ private void ClearImportedSurf(Case caseItem)
Id = surfLink,
CostProfile = null,
ProjectId = caseItem.ProjectId,
Source = Source.ConceptApp,
};

var dto = SurfDtoAdapter.Convert(surf);
Expand All @@ -526,6 +527,7 @@ private void ClearImportedTopside(Case caseItem)
Id = topsideLink,
CostProfile = null,
ProjectId = caseItem.ProjectId,
Source = Source.ConceptApp,
};

var dto = TopsideDtoAdapter.Convert(topside);
Expand All @@ -544,6 +546,7 @@ private void ClearImportedSubstructure(Case caseItem)
Id = substructureLink,
CostProfile = null,
ProjectId = caseItem.ProjectId,
Source = Source.ConceptApp,
};

var dto = SubstructureDtoAdapter.Convert(substructure);
Expand All @@ -562,6 +565,7 @@ private void ClearImportedTransport(Case caseItem)
Id = transportLink,
CostProfile = null,
ProjectId = caseItem.ProjectId,
Source = Source.ConceptApp,
};

var dto = TransportDtoAdapter.Convert(transport);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum ImportStatusEnum {
PROSP,
Selected,
NotSelected
}
166 changes: 113 additions & 53 deletions frontend/src/Components/EditTechnicalInput/PROSPCaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface Props {
driveItems: DriveItem[] | undefined
check: boolean
}

interface RowData {
id: string,
name: string,
Expand All @@ -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,
Expand All @@ -49,9 +51,7 @@ function PROSPCaseList({
}: Props) {
const gridRef = useRef<any>(null)
const [rowData, setRowData] = useState<RowData[]>()

const [isApplying, setIsApplying] = useState<boolean>()

const casesToRowData = () => {
if (project.cases) {
const tableCases: RowData[] = []
Expand All @@ -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])
Expand All @@ -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 <Checkbox checked onChange={() => 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 <Checkbox onChange={() => 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 <Checkbox checked onChange={() => changeStatus(p, ImportStatusEnum.NotSelected)} />
}
if (p.value === ImportStatusEnum.Selected && p.node.data.sharePointFileName !== "") {
return <Checkbox checked onChange={() => changeStatus(p, ImportStatusEnum.NotSelected)} />
}
if (p.value === ImportStatusEnum.Selected && p.node.data.sharePointFileName === "") {
return <Checkbox checked onChange={() => changeStatus(p, ImportStatusEnum.NotSelected)} />
if (p.value === ImportStatusEnum.Selected) {
return (
<Checkbox
checked
onChange={() => handleAdvancedSettingsChange(p, ImportStatusEnum.NotSelected)}
/>
)
}
if (p.value === ImportStatusEnum.NotSelected) {
return <Checkbox checked={false} onChange={() => changeStatus(p, ImportStatusEnum.Selected)} />
return (
<Checkbox
checked={false}
onChange={() => handleAdvancedSettingsChange(p, ImportStatusEnum.Selected)}
/>
)
}
return <Checkbox checked onChange={() => changeStatus(p, ImportStatusEnum.Selected)} />
return (
<Checkbox
checked
onChange={() => handleAdvancedSettingsChange(p, ImportStatusEnum.Selected)}
/>
)
}

const sharePointFileDropdownOptions = (items: DriveItem[]) => {
Expand All @@ -137,10 +177,10 @@ function PROSPCaseList({
const getRowId = useMemo<GetRowIdFunc>(() => (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
}
Expand Down Expand Up @@ -171,11 +211,18 @@ function PROSPCaseList({
const handleFileChange = (event: ChangeEvent<HTMLSelectElement>, 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 (
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
])

Expand Down Expand Up @@ -272,22 +333,19 @@ function PROSPCaseList({
gridRef.current.forEachNode((node: RowNode<RowData>) => {
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)
}
})
Expand Down Expand Up @@ -317,6 +375,9 @@ function PROSPCaseList({
rowData={rowData}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
rowSelection="multiple"
isRowSelectable={rowIsChanged}
suppressRowClickSelection
animateRows
domLayout="autoHeight"
onGridReady={onGridReady}
Expand All @@ -337,7 +398,6 @@ function PROSPCaseList({
</Button>
)}
</ApplyButtonWrapper>

</>
)
}
Expand Down
Loading

0 comments on commit da1d520

Please sign in to comment.