Skip to content

Commit b1740eb

Browse files
committed
make the last column right
1 parent 21f04a5 commit b1740eb

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

src/components/HTMLEngineProvider/HTMLRenderers/TableRenderer.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@ import TableChildrenRenderer, {getElementChildren} from './TableChildrenRenderer
1414
import TableColumnAlignmentContext from './TableColumnAlignmentContext';
1515
import TableContentWidthContext from './TableContentWidthContext';
1616

17-
/** Whether `node` has a descendant with the given tag name. */
18-
function hasDescendantTag(node: TNode, tagName: string): boolean {
19-
return node.children?.some((child) => child.tagName === tagName || hasDescendantTag(child, tagName)) ?? false;
20-
}
21-
2217
/**
23-
* Derives the horizontal alignment for each column from the table body. The Concierge HTML wraps amount values in
24-
* `<strong>` and carries no alignment attributes, so a column whose body cells are all amounts is right-aligned to
25-
* match how amounts are shown elsewhere in the app; every other column stays left-aligned.
18+
* Derives the horizontal alignment for each column from the table body. Concierge expense tables put the amount in
19+
* the last column and carry no alignment attributes, so the last column is right-aligned to match how amounts are
20+
* shown elsewhere in the app; every other column stays left-aligned.
2621
*/
2722
function getColumnAlignments(tableNode: TNode): CellHorizontalAlignment[] {
2823
const bodyRows = getElementChildren(tableNode)
@@ -33,11 +28,7 @@ function getColumnAlignments(tableNode: TNode): CellHorizontalAlignment[] {
3328
}
3429

3530
const columnCount = bodyRows.reduce((max, row) => Math.max(max, getElementChildren(row).length), 0);
36-
return Array.from({length: columnCount}, (_, columnIndex) => {
37-
const columnCells = bodyRows.map((row) => getElementChildren(row).at(columnIndex)).filter((cell): cell is TNode => !!cell);
38-
const isAmountColumn = columnCells.length > 0 && columnCells.every((cell) => hasDescendantTag(cell, 'strong'));
39-
return isAmountColumn ? 'right' : 'left';
40-
});
31+
return Array.from({length: columnCount}, (_, columnIndex) => (columnIndex === columnCount - 1 ? 'right' : 'left'));
4132
}
4233

4334
function TableRenderer({tnode}: CustomRendererProps<TBlock>) {

0 commit comments

Comments
 (0)