From 05ccdac63ab6ef644e25f0de3af8efebd6df1882 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 20 Jan 2022 10:37:44 +0100 Subject: [PATCH] TablePanel: Makes footer not overlap table content (#44210) (#44247) (cherry picked from commit 9f0889c402def5d7fe82e7532c1e4d60a198f9fd) Co-authored-by: Dominik Prokop --- .../src/components/Table/FooterRow.tsx | 22 ++---------- .../grafana-ui/src/components/Table/Table.tsx | 36 +++++++++++++++++-- .../grafana-ui/src/components/Table/styles.ts | 4 +++ public/app/plugins/panel/table/TablePanel.tsx | 4 +-- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/packages/grafana-ui/src/components/Table/FooterRow.tsx b/packages/grafana-ui/src/components/Table/FooterRow.tsx index 3f77f923f47..5bdc13b8b61 100644 --- a/packages/grafana-ui/src/components/Table/FooterRow.tsx +++ b/packages/grafana-ui/src/components/Table/FooterRow.tsx @@ -9,30 +9,14 @@ import { EmptyCell, FooterCell } from './FooterCell'; export interface FooterRowProps { totalColumnsWidth: number; footerGroups: HeaderGroup[]; - footerValues?: FooterItem[]; + footerValues: FooterItem[]; + height: number; } export const FooterRow = (props: FooterRowProps) => { - const { totalColumnsWidth, footerGroups, footerValues } = props; + const { totalColumnsWidth, footerGroups, height } = props; const e2eSelectorsTable = selectors.components.Panels.Visualization.Table; const tableStyles = useStyles2(getTableStyles); - const EXTENDED_ROW_HEIGHT = 27; - - if (!footerValues) { - return null; - } - - let length = 0; - for (const fv of footerValues) { - if (Array.isArray(fv) && fv.length > length) { - length = fv.length; - } - } - - let height: number | undefined; - if (footerValues && length > 1) { - height = EXTENDED_ROW_HEIGHT * length; - } return ( = memo((props: Props) => { footerValues, showTypeIcons, } = props; + const tableStyles = useStyles2(getTableStyles); + const headerHeight = noHeader ? 0 : tableStyles.cellHeight; + + const footerHeight = useMemo(() => { + const EXTENDED_ROW_HEIGHT = 33; + let length = 0; + + if (!footerValues) { + return 0; + } + + for (const fv of footerValues) { + if (Array.isArray(fv) && fv.length > length) { + length = fv.length; + } + } + + if (length > 1) { + return EXTENDED_ROW_HEIGHT * length; + } + + return EXTENDED_ROW_HEIGHT; + }, [footerValues]); // React table data array. This data acts just like a dummy array to let react-table know how many rows exist // The cells use the field to look up values @@ -197,7 +220,7 @@ export const Table: FC = memo((props: Props) => { [onCellFilterAdded, prepareRow, rows, tableStyles] ); - const headerHeight = noHeader ? 0 : tableStyles.cellHeight; + const listHeight = height - (headerHeight + footerHeight); return (
@@ -206,7 +229,7 @@ export const Table: FC = memo((props: Props) => { {!noHeader && } {rows.length > 0 ? ( = memo((props: Props) => { No data
)} - + {footerValues && ( + + )} diff --git a/packages/grafana-ui/src/components/Table/styles.ts b/packages/grafana-ui/src/components/Table/styles.ts index 9182ec63bd1..2ac5c0c7ef5 100644 --- a/packages/grafana-ui/src/components/Table/styles.ts +++ b/packages/grafana-ui/src/components/Table/styles.ts @@ -131,6 +131,10 @@ export const getTableStyles = (theme: GrafanaTheme2) => { &:hover { background-color: ${rowHoverBg}; } + + &:last-child { + border-bottom: 0; + } `, imageCell: css` height: 100%; diff --git a/public/app/plugins/panel/table/TablePanel.tsx b/public/app/plugins/panel/table/TablePanel.tsx index 69326b3baef..cef9256800f 100644 --- a/public/app/plugins/panel/table/TablePanel.tsx +++ b/public/app/plugins/panel/table/TablePanel.tsx @@ -126,7 +126,7 @@ export class TablePanel extends Component { return (
- {this.renderTable(data.series[currentIndex], width, height - inputHeight - padding)} + {this.renderTable(data.series[currentIndex], width, height - inputHeight + padding)}