Skip to content

Commit

Permalink
Merge pull request #128 from Vizzuality/SKY30-191-m-16-blue-shading-r…
Browse files Browse the repository at this point in the history
…epresenting-progress-in-the-table-is-not-working

[SKY30-191] Remove blue bar colors from table rows
  • Loading branch information
andresgnlez authored Jan 15, 2024
2 parents 7464c5c + c2e754f commit 555f123
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions frontend/src/containers/map/content/details/table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLayoutEffect, useRef, useState } from 'react';
import { useRef } from 'react';

import {
flexRender,
Expand All @@ -14,16 +14,6 @@ const MapTable = ({ columns, data }) => {
const tableRef = useRef<HTMLTableElement>();
const firstColumnRef = useRef<HTMLTableCellElement>(null);

const [tableDimensions, setTableDimensions] = useState<{
firstColumnWidth: HTMLTableCellElement['offsetWidth'];
tableWidth: HTMLTableElement['offsetWidth'];
availableBarWidth: number;
}>({
firstColumnWidth: 0,
tableWidth: 0,
availableBarWidth: 0,
});

const table = useReactTable<typeof data>({
data,
columns,
Expand All @@ -36,18 +26,6 @@ const MapTable = ({ columns, data }) => {
const firstColumn = columns[0];
const lastColumn = columns[columns.length - 1];

useLayoutEffect(() => {
const tableWidth = tableRef.current?.offsetWidth;
const firstColumnWidth = firstColumnRef.current?.offsetWidth;
const availableBarWidth = tableWidth - firstColumnWidth;

setTableDimensions({
firstColumnWidth,
tableWidth,
availableBarWidth,
});
}, [data]);

return (
<table ref={tableRef} className="whitespace-nowrap font-mono text-xs">
<thead className="text-left">
Expand Down Expand Up @@ -78,19 +56,8 @@ const MapTable = ({ columns, data }) => {
<tbody>
{hasData &&
table.getRowModel().rows.map((row) => {
const coverage = row.original?.coverage || null; // %;
const offset = tableDimensions.firstColumnWidth;
const barWidth = (coverage * tableDimensions.availableBarWidth) / 100;

return (
<tr
key={row.id}
className="border-b border-t border-black"
style={{
backgroundImage: `linear-gradient(to right, rgb(72, 121, 255) ${barWidth}px, transparent ${barWidth}px)`,
backgroundPositionX: `${offset}px`,
}}
>
<tr key={row.id} className="border-b border-t border-black">
{row.getVisibleCells().map((cell) => {
const { column } = cell;
const isFirstColumn = column.id === firstColumn.accessorKey;
Expand Down

0 comments on commit 555f123

Please sign in to comment.