mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Table component: Fix sub-table rows not displaying correctly (#89082)
* Fix expanded height issue
* Prettier
* 🙅♂️ to console.log
This commit is contained in:
parent
0bdd613f3b
commit
3776c44c33
@ -15,7 +15,7 @@ import { TableCellProps, CustomCellRendererProps, TableCellOptions } from './typ
|
|||||||
import { getCellColors, getCellOptions } from './utils';
|
import { getCellColors, getCellOptions } from './utils';
|
||||||
|
|
||||||
export const DefaultCell = (props: TableCellProps) => {
|
export const DefaultCell = (props: TableCellProps) => {
|
||||||
const { field, cell, tableStyles, row, cellProps, frame, rowStyled, textWrapped, height } = props;
|
const { field, cell, tableStyles, row, cellProps, frame, rowStyled, rowExpanded, textWrapped, height } = props;
|
||||||
|
|
||||||
const inspectEnabled = Boolean(field.config.custom?.inspect);
|
const inspectEnabled = Boolean(field.config.custom?.inspect);
|
||||||
const displayValue = field.display!(cell.value);
|
const displayValue = field.display!(cell.value);
|
||||||
@ -60,7 +60,8 @@ export const DefaultCell = (props: TableCellProps) => {
|
|||||||
isStringValue,
|
isStringValue,
|
||||||
textShouldWrap,
|
textShouldWrap,
|
||||||
textWrapped,
|
textWrapped,
|
||||||
rowStyled
|
rowStyled,
|
||||||
|
rowExpanded
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isStringValue) {
|
if (isStringValue) {
|
||||||
@ -122,7 +123,8 @@ function getCellStyle(
|
|||||||
isStringValue = false,
|
isStringValue = false,
|
||||||
shouldWrapText = false,
|
shouldWrapText = false,
|
||||||
textWrapped = false,
|
textWrapped = false,
|
||||||
rowStyled = false
|
rowStyled = false,
|
||||||
|
rowExpanded = false
|
||||||
) {
|
) {
|
||||||
// Setup color variables
|
// Setup color variables
|
||||||
let textColor: string | undefined = undefined;
|
let textColor: string | undefined = undefined;
|
||||||
@ -145,7 +147,8 @@ function getCellStyle(
|
|||||||
isStringValue,
|
isStringValue,
|
||||||
shouldWrapText,
|
shouldWrapText,
|
||||||
textWrapped,
|
textWrapped,
|
||||||
rowStyled
|
rowStyled,
|
||||||
|
rowExpanded
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +267,7 @@ export const RowsList = (props: RowsListProps) => {
|
|||||||
prepareRow(row);
|
prepareRow(row);
|
||||||
|
|
||||||
const expandedRowStyle = tableState.expanded[row.id] ? css({ '&:hover': { background: 'inherit' } }) : {};
|
const expandedRowStyle = tableState.expanded[row.id] ? css({ '&:hover': { background: 'inherit' } }) : {};
|
||||||
|
const rowExpanded = nestedDataField && tableState.expanded[row.id];
|
||||||
|
|
||||||
if (rowHighlightIndex !== undefined && row.index === rowHighlightIndex) {
|
if (rowHighlightIndex !== undefined && row.index === rowHighlightIndex) {
|
||||||
style = { ...style, backgroundColor: theme.components.table.rowHoverBackground };
|
style = { ...style, backgroundColor: theme.components.table.rowHoverBackground };
|
||||||
@ -304,7 +305,7 @@ export const RowsList = (props: RowsListProps) => {
|
|||||||
onMouseLeave={onRowLeave}
|
onMouseLeave={onRowLeave}
|
||||||
>
|
>
|
||||||
{/*add the nested data to the DOM first to prevent a 1px border CSS issue on the last cell of the row*/}
|
{/*add the nested data to the DOM first to prevent a 1px border CSS issue on the last cell of the row*/}
|
||||||
{nestedDataField && tableState.expanded[row.id] && (
|
{rowExpanded && (
|
||||||
<ExpandedRow
|
<ExpandedRow
|
||||||
nestedData={nestedDataField}
|
nestedData={nestedDataField}
|
||||||
tableStyles={tableStyles}
|
tableStyles={tableStyles}
|
||||||
@ -326,6 +327,7 @@ export const RowsList = (props: RowsListProps) => {
|
|||||||
timeRange={timeRange}
|
timeRange={timeRange}
|
||||||
frame={data}
|
frame={data}
|
||||||
rowStyled={rowBg !== undefined}
|
rowStyled={rowBg !== undefined}
|
||||||
|
rowExpanded={rowExpanded}
|
||||||
textWrapped={textWrapField !== undefined}
|
textWrapped={textWrapField !== undefined}
|
||||||
height={Number(style.height)}
|
height={Number(style.height)}
|
||||||
/>
|
/>
|
||||||
|
@ -16,6 +16,7 @@ export interface Props {
|
|||||||
userProps?: object;
|
userProps?: object;
|
||||||
frame: DataFrame;
|
frame: DataFrame;
|
||||||
rowStyled?: boolean;
|
rowStyled?: boolean;
|
||||||
|
rowExpanded?: boolean;
|
||||||
textWrapped?: boolean;
|
textWrapped?: boolean;
|
||||||
height?: number;
|
height?: number;
|
||||||
}
|
}
|
||||||
@ -28,6 +29,7 @@ export const TableCell = ({
|
|||||||
userProps,
|
userProps,
|
||||||
frame,
|
frame,
|
||||||
rowStyled,
|
rowStyled,
|
||||||
|
rowExpanded,
|
||||||
textWrapped,
|
textWrapped,
|
||||||
height,
|
height,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
@ -57,6 +59,7 @@ export const TableCell = ({
|
|||||||
userProps,
|
userProps,
|
||||||
frame,
|
frame,
|
||||||
rowStyled,
|
rowStyled,
|
||||||
|
rowExpanded,
|
||||||
textWrapped,
|
textWrapped,
|
||||||
height,
|
height,
|
||||||
})}
|
})}
|
||||||
|
@ -19,14 +19,15 @@ export function useTableStyles(theme: GrafanaTheme2, cellHeightOption: TableCell
|
|||||||
asCellText?: boolean,
|
asCellText?: boolean,
|
||||||
textShouldWrap?: boolean,
|
textShouldWrap?: boolean,
|
||||||
textWrapped?: boolean,
|
textWrapped?: boolean,
|
||||||
rowStyled?: boolean
|
rowStyled?: boolean,
|
||||||
|
rowExpanded?: boolean
|
||||||
) => {
|
) => {
|
||||||
return css({
|
return css({
|
||||||
label: overflowOnHover ? 'cellContainerOverflow' : 'cellContainerNoOverflow',
|
label: overflowOnHover ? 'cellContainerOverflow' : 'cellContainerNoOverflow',
|
||||||
padding: `${cellPadding}px`,
|
padding: `${cellPadding}px`,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
// Cell height need to account for row border
|
// Cell height need to account for row border
|
||||||
height: `${rowHeight - 1}px`,
|
height: rowExpanded ? 'auto !important' : `${rowHeight - 1}px`,
|
||||||
wordBreak: textWrapped ? 'break-all' : 'inherit',
|
wordBreak: textWrapped ? 'break-all' : 'inherit',
|
||||||
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
Loading…
Reference in New Issue
Block a user