From 53c74c75095cda40591644e0b94f1d95e5536c19 Mon Sep 17 00:00:00 2001 From: MikaelNordberg Date: Thu, 19 Dec 2024 16:41:17 +0100 Subject: [PATCH] Fix for sonarcube issues --- .../src/app/context/TableDataProvider.tsx | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/packages/pxweb2/src/app/context/TableDataProvider.tsx b/packages/pxweb2/src/app/context/TableDataProvider.tsx index 5947e026..475372e2 100644 --- a/packages/pxweb2/src/app/context/TableDataProvider.tsx +++ b/packages/pxweb2/src/app/context/TableDataProvider.tsx @@ -765,45 +765,48 @@ const TableDataProvider: React.FC = ({ children }) => { * Pivots the table clockwise. */ function pivotCW(): void { - if (data?.heading !== undefined) { - const tmpTable = structuredClone(data); + if (data?.heading === undefined) { + return; + } - if (tmpTable !== undefined) { - let stub: string[]; - let heading: string[]; + const tmpTable = structuredClone(data); + if (tmpTable === undefined) { + return; + } - if (isMobileMode) { - stub = structuredClone(stubMobile); - heading = structuredClone(headingMobile); - } else { - stub = structuredClone(stubDesktop); - heading = structuredClone(headingDesktop); - } + let stub: string[]; + let heading: string[]; - if (stub.length === 0 && heading.length === 0) { - return; - } + if (isMobileMode) { + stub = structuredClone(stubMobile); + heading = structuredClone(headingMobile); + } else { + stub = structuredClone(stubDesktop); + heading = structuredClone(headingDesktop); + } - if (stub.length > 0 && heading.length > 0) { - stub.push(heading.pop() as string); - heading.unshift(stub.shift() as string); - } else if (stub.length === 0) { - heading.unshift(heading.pop() as string); - } else if (heading.length === 0) { - stub.unshift(stub.pop() as string); - } + if (stub.length === 0 && heading.length === 0) { + return; + } - pivotTable(tmpTable, stub, heading); - setData(tmpTable); + if (stub.length > 0 && heading.length > 0) { + stub.push(heading.pop() as string); + heading.unshift(stub.shift() as string); + } else if (stub.length === 0) { + heading.unshift(heading.pop() as string); + } else if (heading.length === 0) { + stub.unshift(stub.pop() as string); + } - if (isMobileMode) { - setStubMobile(stub); - setHeadingMobile(heading); - } else { - setStubDesktop(stub); - setHeadingDesktop(heading); - } - } + pivotTable(tmpTable, stub, heading); + setData(tmpTable); + + if (isMobileMode) { + setStubMobile(stub); + setHeadingMobile(heading); + } else { + setStubDesktop(stub); + setHeadingDesktop(heading); } }