Skip to content

Commit

Permalink
[TIP] Fixing row height on indicators data grid (#144290)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeOberti authored Nov 8, 2022
1 parent 80bda1a commit 0719411
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React, { useContext, VFC } from 'react';
import { EuiFlexGroup } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { InvestigateInTimelineButtonIcon } from '../../../../timeline';
import { Indicator } from '../../../../../../common/types/indicator';
import { OpenIndicatorFlyoutButton } from './open_flyout_button';
Expand All @@ -24,13 +24,17 @@ export const ActionsRowCell: VFC<{ indicator: Indicator }> = ({ indicator }) =>
const { setExpanded, expanded } = indicatorTableContext;

return (
<EuiFlexGroup justifyContent="center">
<OpenIndicatorFlyoutButton
indicator={indicator}
onOpen={setExpanded}
isOpen={Boolean(expanded && expanded._id === indicator._id)}
/>
<InvestigateInTimelineButtonIcon data={indicator} data-test-subj={INVESTIGATE_TEST_ID} />
<EuiFlexGroup justifyContent="center" gutterSize="none">
<EuiFlexItem grow={false}>
<OpenIndicatorFlyoutButton
indicator={indicator}
onOpen={setExpanded}
isOpen={Boolean(expanded && expanded._id === indicator._id)}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<InvestigateInTimelineButtonIcon data={indicator} data-test-subj={INVESTIGATE_TEST_ID} />
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { EuiDataGridCellValueElementProps } from '@elastic/eui';
import React, { useContext, useEffect } from 'react';
import { euiDarkVars as themeDark, euiLightVars as themeLight } from '@kbn/ui-theme';
import { useStyles } from './styles';
import { useKibana } from '../../../../../hooks';
import { Indicator } from '../../../../../../common/types/indicator';
import { IndicatorFieldValue } from '../../field_value';
Expand All @@ -16,6 +17,8 @@ import { ActionsRowCell } from '.';

export const cellRendererFactory = (from: number) => {
return ({ rowIndex, columnId, setCellProps }: EuiDataGridCellValueElementProps) => {
const styles = useStyles();

const indicatorsTableContext = useContext(IndicatorsTableContext);

if (!indicatorsTableContext) {
Expand Down Expand Up @@ -48,10 +51,13 @@ export const cellRendererFactory = (from: number) => {
return null;
}

if (columnId === 'Actions') {
return <ActionsRowCell indicator={indicator} />;
}
const renderContent =
columnId === 'Actions' ? (
<ActionsRowCell indicator={indicator} />
) : (
<IndicatorFieldValue indicator={indicator} field={columnId} />
);

return <IndicatorFieldValue indicator={indicator} field={columnId} />;
return <div css={styles.tableCell}>{renderContent}</div>;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ export const useStyles = () => {
'word-break': 'break-word',
};

const tableCell: CSSObject = {
overflow: 'hidden',
'text-overflow': 'ellipsis',
'overflow-wrap': 'initial',
'word-wrap': 'initial',
'word-break': 'initial',
};

return {
popoverMaxWidth,
tableCell,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
} from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n-react';
import { EuiDataGridColumn } from '@elastic/eui/src/components/datagrid/data_grid_types';
import {
EuiDataGridColumn,
EuiDataGridRowHeightsOptions,
} from '@elastic/eui/src/components/datagrid/data_grid_types';
import { CellActions, cellPopoverRendererFactory, cellRendererFactory } from './components';
import { BrowserFields, SecuritySolutionDataViewBase } from '../../../../types';
import { Indicator, RawIndicatorFieldId } from '../../../../../common/types/indicator';
Expand Down Expand Up @@ -161,6 +164,10 @@ export const IndicatorsTable: VFC<IndicatorsTableProps> = ({
);
}

const rowHeightsOptions: EuiDataGridRowHeightsOptions = {
lineHeight: '30px',
};

if (!indicatorCount) {
return <EmptyState />;
}
Expand Down Expand Up @@ -194,6 +201,7 @@ export const IndicatorsTable: VFC<IndicatorsTableProps> = ({
sorting={sorting}
columnVisibility={columnVisibility}
columns={mappedColumns}
rowHeightsOptions={rowHeightsOptions}
/>
</>
);
Expand Down

0 comments on commit 0719411

Please sign in to comment.