From c8be1265574744dfb2d57ce02157af0896256ac2 Mon Sep 17 00:00:00 2001 From: mheggelund Date: Wed, 30 Oct 2024 13:53:44 +0100 Subject: [PATCH] chore: Explore expand rows --- .../VariogramResultTable.tsx | 316 +++++++++++++----- 1 file changed, 229 insertions(+), 87 deletions(-) diff --git a/src/features/Results/CaseResult/CaseResultView/VariogramCaseResult/VariogramResultTable/VariogramResultTable.tsx b/src/features/Results/CaseResult/CaseResultView/VariogramCaseResult/VariogramResultTable/VariogramResultTable.tsx index 5eae068..40ac058 100644 --- a/src/features/Results/CaseResult/CaseResultView/VariogramCaseResult/VariogramResultTable/VariogramResultTable.tsx +++ b/src/features/Results/CaseResult/CaseResultView/VariogramCaseResult/VariogramResultTable/VariogramResultTable.tsx @@ -1,12 +1,15 @@ /* eslint-disable max-lines-per-function */ import { Typography } from '@equinor/eds-core-react'; -import { EdsDataGrid } from '@equinor/eds-data-grid-react'; +import { + ColumnDef, + EdsDataGrid, + ExpandedState, +} from '@equinor/eds-data-grid-react'; import { useState } from 'react'; import { GetVariogramResultsDto } from '../../../../../../api/generated'; import { useFetchCases } from '../../../../../../hooks/useFetchCases'; import { ImageResult } from '../ImageResult/ImageResult'; import * as Styled from './VariogramResultTable.styled'; - interface ResultObjectType { variogramResultId: string; computeCaseId: string; @@ -20,6 +23,39 @@ interface ResultObjectType { const NumberOfDecimals = 3; +// const expandCell = ({ row, getValue }: { row: any; getValue: any }) => { +// console.log(row.getCanExpand()); + +// return row.getCanExpand() ? ( +// <>EXPAND +// ) : ( +// // <> +// //
+// // {row.getCanExpand() && ( +// // +// // )} +// // {' HALLO '} +// // {getValue()} +// //
+// // +// 'NOT POSSIBLE' +// ); +// }; + export const VariogramResultTable = ({ resultList, }: { @@ -27,7 +63,7 @@ export const VariogramResultTable = ({ }) => { const [open, setOpen] = useState(false); const [imageId, setImageId] = useState(''); - + const [expansionState, setExpansionState] = useState({}); const caseList = useFetchCases(); const roundResultString = (value: number) => { @@ -36,38 +72,6 @@ export const VariogramResultTable = ({ } else return value; }; - const resultElementsList: ResultObjectType[] = resultList.map((e) => { - const method = caseList.data?.data.filter( - (c) => c.computeCaseId === e.computeCaseId, - )[0]?.computeMethod?.name; - let parameter = ''; - if (method === 'Indicator') { - parameter = e.indicator ? e.indicator : ''; - } else if (method === 'Net-To-Gross') { - parameter = e.customIndicator ? e.customIndicator : ''; - } else if (method === 'ContiniousParameter') { - parameter = e.attribute ? e.attribute : ''; - } - - const modelArea = caseList.data?.data.filter( - (c) => c.computeCaseId === e.computeCaseId, - )[0]?.modelArea; - - const element: ResultObjectType = { - variogramResultId: e.variogramResultId, - computeCaseId: e.computeCaseId, - method: method ? method : '', - parameter: parameter, - archelFilter: e.archelFilter ? e.archelFilter : '', - modelArea: modelArea ? modelArea.name : '', - variogramModel: e.family ? e.family : '', - quality: roundResultString(e.quality) - ? roundResultString(e.quality) - : e.quality, - }; - return element; - }); - const handleImageDialog = (id: string, variogramResultId: string) => { const computeCaseResults = resultList.filter((e) => e.computeCaseId === id); const resultFile = computeCaseResults @@ -81,68 +85,206 @@ export const VariogramResultTable = ({ setOpen(!open); }; + const columns: ColumnDef[] = [ + { + id: 'expand', + header: () => null, + // cell: () => expandCell, + cell: ({ row }) => { + return row.getCanExpand() ? ( + + ) : ( + '🔵' + ); + }, + enableColumnFilter: false, + enableSorting: false, + }, + { + accessorKey: 'method', + header: () => Compute method, + cell: ({ row, getValue }) => ( +
+ {getValue()} +
+ ), + id: 'method', + }, + { + accessorKey: 'parameter', + header: () => Parameter, + id: 'parameter', + }, + { + accessorKey: 'archelFilter', + header: () => Archel Filter, + id: 'archelFilter', + }, + { + accessorKey: 'modelArea', + header: () => Model Area, + id: 'modelArea', + }, + { + accessorKey: 'variogramModel', + header: () => Variogram model, + id: 'variogramModel', + cell: ({ row }) => ( +
+ + handleImageDialog( + row.original.computeCaseId, + row.original.variogramResultId, + ) + } + link + > + {row.original.variogramModel} + +
+ ), + }, + { + accessorKey: 'quality', + header: () => Quality factor, + id: 'quality', + enableColumnFilter: false, + cell: ({ row }) => ( + {row.original.quality} + ), + }, + ]; + + const getSubRows = (row: ResultObjectType) => { + console.log(row); + + const subRowArray: ResultObjectType[] = []; + if (row === undefined) return subRowArray; + + resultList + .filter((c) => c.computeCaseId === row.computeCaseId) + .map((e) => { + const method = caseList.data?.data.filter( + (c) => c.computeCaseId === e.computeCaseId, + )[0]?.computeMethod?.name; + + let parameter = ''; + if (method === 'Indicator') { + parameter = e.indicator ? e.indicator : ''; + } else if (method === 'Net-To-Gross') { + parameter = e.customIndicator ? e.customIndicator : ''; + } else if (method === 'ContiniousParameter') { + parameter = e.attribute ? e.attribute : ''; + } + + const modelArea = caseList.data?.data.filter( + (c) => c.computeCaseId === e.computeCaseId, + )[0]?.modelArea; + + const element: ResultObjectType = { + variogramResultId: e.variogramResultId, + computeCaseId: e.computeCaseId, + method: method ? method : '', + parameter: parameter, + archelFilter: e.archelFilter ? e.archelFilter : '', + modelArea: modelArea ? modelArea.name : '', + variogramModel: e.family ? e.family : '', + quality: roundResultString(e.quality) + ? roundResultString(e.quality) + : e.quality, + }; + + subRowArray.push(element); + }); + + console.log(subRowArray); + + return subRowArray; + }; + + const getRows = () => { + const rowArray: ResultObjectType[] = []; + + resultList.map((e) => { + const res = rowArray.some( + (element) => element.computeCaseId === e.computeCaseId, + ); + // console.log(res); + + if (res) return; + + const method = caseList.data?.data.filter( + (c) => c.computeCaseId === e.computeCaseId, + )[0]?.computeMethod?.name; + let parameter = ''; + if (method === 'Indicator') { + parameter = e.indicator ? e.indicator : ''; + } else if (method === 'Net-To-Gross') { + parameter = e.customIndicator ? e.customIndicator : ''; + } else if (method === 'ContiniousParameter') { + parameter = e.attribute ? e.attribute : ''; + } + + const modelArea = caseList.data?.data.filter( + (c) => c.computeCaseId === e.computeCaseId, + )[0]?.modelArea; + + const element: ResultObjectType = { + variogramResultId: e.variogramResultId, + computeCaseId: e.computeCaseId, + method: method ? method : '', + parameter: parameter, + archelFilter: e.archelFilter ? e.archelFilter : '', + modelArea: modelArea ? modelArea.name : '', + variogramModel: e.family ? e.family : '', + quality: roundResultString(e.quality) + ? roundResultString(e.quality) + : e.quality, + }; + rowArray.push(element); + }); + console.log(rowArray); + + return rowArray; + }; + return ( <> { + // console.log('test'); + // const res = getSubRows(row); + // console.log(res); + // }} + getSubRows={(row) => getSubRows(row)} enableSorting enableColumnFiltering enablePagination emptyMessage="No results to show" columnResizeMode="onChange" - rows={resultElementsList} pageSize={20} - columns={[ - { - accessorKey: 'method', - header: () => Compute method, - id: 'method', - }, - { - accessorKey: 'parameter', - header: () => Parameter, - id: 'parameter', - }, - { - accessorKey: 'archelFilter', - header: () => Archel Filter, - id: 'archelFilter', - }, - { - accessorKey: 'modelArea', - header: () => Model Area, - id: 'modelArea', - }, - { - accessorKey: 'variogramModel', - header: () => Variogram model, - id: 'variogramModel', - cell: ({ row }) => ( -
- - handleImageDialog( - row.original.computeCaseId, - row.original.variogramResultId, - ) - } - link - > - {row.original.variogramModel} - -
- ), - }, - { - accessorKey: 'quality', - header: () => Quality factor, - id: 'quality', - enableColumnFilter: false, - cell: ({ row }) => ( - {row.original.quality} - ), - }, - ]} + // enableVirtual />