Skip to content

Commit

Permalink
[Discover] Fine tune row controls positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Sep 9, 2023
1 parent 0aaf693 commit a93943c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 37 deletions.
27 changes: 22 additions & 5 deletions packages/kbn-unified-data-table/src/components/data_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@
border-bottom: $euiBorderThin;
}

.euiDataGridRowCell.euiDataGridRowCell--controlColumn[data-gridcell-column-id='openDetails'],
.euiDataGridRowCell.euiDataGridRowCell--controlColumn[data-gridcell-column-id='select'] {
padding: $euiSizeS+2 0 0 $euiSizeXS;
}

.euiDataGridRowCell.euiDataGridRowCell--controlColumn[data-gridcell-column-id='openDetails'] {
padding: $euiSizeXS+1 0 0 0;
padding-left: 0;
padding-right: 0;
}

.euiDataGrid--rowHoverHighlight .euiDataGridRow:hover,
Expand Down Expand Up @@ -109,6 +107,25 @@
@include euiTextTruncate;
}

.unifiedDataTable__rowControl {
// fine-tuning the vertical alignment with the text for any row height setting
margin-top: -3px;
.euiDataGridRowCell__truncate & { // "Single line" row height setting
margin-top: 0;
}
}

.unifiedDataTable__descriptionList {
// force the content truncation when "Single line" row height setting is active
.euiDataGridRowCell__truncate & {
-webkit-line-clamp: 1;
display: -webkit-box;
-webkit-box-orient: vertical;
height: 100%;
overflow: hidden;
}
}

.unifiedDataTable__descriptionListTitle {
margin-inline: 0 0;
padding-inline: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ import {
EuiCopy,
EuiDataGridCellValueElementProps,
EuiPopover,
EuiFlexGroup,
EuiFlexItem,
useEuiTheme,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiDarkVars as themeDark, euiLightVars as themeLight } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import { UnifiedDataTableContext } from '../table_context';

export const SelectButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueElementProps) => {
const { euiTheme } = useEuiTheme();
const { selectedDocs, expanded, rows, isDarkMode, setSelectedDocs } =
useContext(UnifiedDataTableContext);
const doc = useMemo(() => rows[rowIndex], [rows, rowIndex]);
Expand All @@ -46,20 +51,33 @@ export const SelectButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
}, [expanded, doc, setCellProps, isDarkMode]);

return (
<EuiCheckbox
id={doc.id}
aria-label={toggleDocumentSelectionLabel}
checked={checked}
data-test-subj={`dscGridSelectDoc-${doc.id}`}
onChange={() => {
if (checked) {
const newSelection = selectedDocs.filter((docId) => docId !== doc.id);
setSelectedDocs(newSelection);
} else {
setSelectedDocs([...selectedDocs, doc.id]);
}
}}
/>
<EuiFlexGroup
responsive={false}
direction="column"
justifyContent="center"
className="unifiedDataTable__rowControl"
css={css`
padding-block: ${euiTheme.size.xs}; // to have the same height as "openDetails" control
padding-left: ${euiTheme.size.xs}; // space between controls
`}
>
<EuiFlexItem grow={false}>
<EuiCheckbox
id={doc.id}
aria-label={toggleDocumentSelectionLabel}
checked={checked}
data-test-subj={`dscGridSelectDoc-${doc.id}`}
onChange={() => {
if (checked) {
const newSelection = selectedDocs.filter((docId) => docId !== doc.id);
setSelectedDocs(newSelection);
} else {
setSelectedDocs([...selectedDocs, doc.id]);
}
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ export const ExpandButton = ({ rowIndex, setCellProps }: EuiDataGridCellValueEle
}

return (
<EuiToolTip content={buttonLabel} delay="long" ref={toolTipRef}>
<EuiButtonIcon
id={rowIndex === 0 ? tourStep : undefined}
size="xs"
iconSize="s"
aria-label={buttonLabel}
data-test-subj={testSubj}
onClick={() => {
const nextHit = isCurrentRowExpanded ? undefined : current;
toolTipRef.current?.hideToolTip();
setPressed(Boolean(nextHit));
setExpanded?.(nextHit);
}}
color={isCurrentRowExpanded ? 'primary' : 'text'}
iconType={isCurrentRowExpanded ? 'minimize' : 'expand'}
isSelected={isCurrentRowExpanded}
/>
</EuiToolTip>
<div className="unifiedDataTable__rowControl">
<EuiToolTip content={buttonLabel} delay="long" ref={toolTipRef}>
<EuiButtonIcon
id={rowIndex === 0 ? tourStep : undefined}
size="xs"
iconSize="s"
aria-label={buttonLabel}
data-test-subj={testSubj}
onClick={() => {
const nextHit = isCurrentRowExpanded ? undefined : current;
toolTipRef.current?.hideToolTip();
setPressed(Boolean(nextHit));
setExpanded?.(nextHit);
}}
color={isCurrentRowExpanded ? 'primary' : 'text'}
iconType={isCurrentRowExpanded ? 'minimize' : 'expand'}
isSelected={isCurrentRowExpanded}
/>
</EuiToolTip>
</div>
);
};

0 comments on commit a93943c

Please sign in to comment.