Skip to content

Commit

Permalink
Merge pull request #886 from navikt/bugfix/tabelll-rendres-feil
Browse files Browse the repository at this point in the history
Bugfix/tabelll rendres feil
  • Loading branch information
tordbjorn77 authored Jul 19, 2024
2 parents 069bc30 + 9e28b6b commit 994a19c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
2 changes: 0 additions & 2 deletions src/components/guielements/Cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export function Cell(props) {

function getDetailView() {
let detail = generateTables(subitem['popoverContent'])
// console.log("detail" ,renderToString(detail))
// let text = '<div>'+'{{$detail}}'+'</div>'
document.getElementById("datailView").innerHTML = renderToString(detail)
// detailView.style.
return <div open={open} onClose={() => setOpen(false)}>
Expand Down
79 changes: 47 additions & 32 deletions src/components/guielements/Table.jsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
import React, { useState } from "react";
import { Heading, Table } from '@navikt/ds-react';
import React, {useState} from "react";
import {Heading, Table} from '@navikt/ds-react';
import './CSS/EnTable.css'
import { Cell } from "./Cell";
import {Cell} from "./Cell";

export function EnTable(props) {
let [table] = useState(props.table)

function horizontalHeader(item, index) {
if (item[index] == null)
return (null)
else if (item[index].hasOwnProperty('header'))
return <Table.HeaderCell key={index} scope="col">{item[index]['data']}</Table.HeaderCell>
if (item[index] == null) {
return null;
} else if (Object.hasOwn(item[index], 'header') && item[index]['header'] === true) {
return <Table.HeaderCell key={index} scope="col">{item[index]['data']}</Table.HeaderCell>;
}
}

function showRow(item) {
let row = []
function verticalHeader(item, index) {
if (item == null) {
return null;
} else if (Object.hasOwn(item, 'header') && item['header'] === true) {
return <Table.HeaderCell key={index} scope="row">{item['data']}</Table.HeaderCell>;
}
}

function showRow(item, isVertical = false, index) {
let row = [];
if (Array.isArray(item)) {
item.map((subitem, j) => {
row.push(<Cell element={subitem} j={j}></Cell>)
})
row.push(<Cell key={`cell-${index}-${j}`} index={index} element={subitem} j={j}
isVertical={isVertical}/>);
});
}
return row
return row;
}

const Checkname = ({ name }) => {
const Checkname = ({name}) => {
if (name != null && name.includes('Ingen')) {
return (null);
return null;
} else
return <div className="w-full flex flex-col gap-4" >
return <div className="w-full flex flex-col gap-4">
<Table size="small">
<Table.Header>
<Table.Row>
{table['cells'].map((item, index) => (
horizontalHeader(item, index)
{table['orientation'] === 'HORIZONTAL' && table['cells'][0].map((item, index) => (
horizontalHeader(table['cells'][0], index)
))}
</Table.Row>
</Table.Header>
<Table.Body>
{table['cells'].map((item, index) => (
<Table.Row key={index}>
{table['orientation'] === 'HORIZONTAL' && table['cells'].slice(1).map((item, index) => (
<Table.Row key={`horizontal-row-${index}`}>
{showRow(item, index)}
</Table.Row>
))
}
))}
{table['orientation'] === 'VERTICAL' && table['cells'].map((item, index) => (
<Table.Row key={`vertical-row-${index}`}>
{verticalHeader(item[0])}
{showRow(item.slice(1), true)}
</Table.Row>
))}
</Table.Body>
</Table>
</div>
Expand All @@ -52,19 +67,19 @@ export function EnTable(props) {
<div>
<Heading size="xsmall" level="6"> &ensp;
</Heading>
<Heading spacing className={"tableHeading"}
style={{
borderBottom: table.hasOwnProperty('name') ? "2px solid grey" : "",
borderTop: table.hasOwnProperty('name') ? "2px solid grey" : "",
backgroundColor: table.hasOwnProperty('name') ? "#f1f1f1" : "",
display: 'flex',
flexDirection: 'column',
alignItems: 'center'
}}
level="6"> &ensp; {table.hasOwnProperty('name') ? table['name'] : ''}</Heading>
<Heading spacing className={"tableHeading"} size={"medium"}
style={{
borderBottom: Object.hasOwn(table, 'name') ? "2px solid grey" : "",
borderTop: Object.hasOwn(table, 'name') ? "2px solid grey" : "",
backgroundColor: Object.hasOwn(table, 'name') ? "#f1f1f1" : "",
display: 'flex',
flexDirection: 'column',
alignItems: 'center'
}}
level="6"> &ensp; {Object.hasOwn(table, 'name') ? table['name'] : ''}</Heading>
<Checkname name={table['name']} className={"tableBody"}>

</Checkname>
</div>
)
}
}
2 changes: 1 addition & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
align-items: center;
}

@media only screen and (max-width: 768px) {
@media (max-width: 820px) {
.detailcontainer {
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr;
Expand Down

0 comments on commit 994a19c

Please sign in to comment.