Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiDataGrid] Add new cellContext prop/API #7374

Merged
merged 23 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fc625d0
Add rowCellContext POC
kqualters-elastic Nov 18, 2023
3248acc
Fix types in docs/tests
kqualters-elastic Nov 18, 2023
3261a14
Fix unneeded re-renders
kqualters-elastic Nov 21, 2023
b7eb3a7
Cleanup types
kqualters-elastic Nov 21, 2023
d15c935
Fix skeleton text performance
kqualters-elastic Nov 21, 2023
150662e
Delete React version specific snapshot test
kqualters-elastic Nov 21, 2023
2d17b85
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic Jan 18, 2024
b20463d
Merge upstream WIP
kqualters-elastic Feb 7, 2024
509412f
Merge remote-tracking branch 'upstream/main' into row-cell-context-pr…
kqualters-elastic Feb 7, 2024
9ed36d9
Fix upstream merge, tests, and types
kqualters-elastic Feb 7, 2024
46a5975
Merge remote-tracking branch 'upstream/main' into row-cell-context-pr…
kqualters-elastic Mar 3, 2024
03f545e
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic Mar 3, 2024
0ef0d42
Add display name
kqualters-elastic Mar 4, 2024
c83ce72
Merge branch 'row-cell-context-proposal' of github.com:kqualters-elas…
kqualters-elastic Mar 4, 2024
2a2b2d2
Remove non-datagrid related change
kqualters-elastic Mar 4, 2024
341595a
Added changelog
kqualters-elastic Mar 5, 2024
beda44c
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic Mar 5, 2024
57f9673
[PR feedback] Rename `renderCellContext` to `cellContext` and switch …
cee-chen Mar 6, 2024
c56a4a5
Write unit test for new API
cee-chen Mar 6, 2024
e8ce9c2
Update changelog
cee-chen Mar 6, 2024
5b7805e
Revert changes unrelated to `cellContext`
cee-chen Mar 7, 2024
ad95e85
Simplify and fix failing `RenderCellValue` types
cee-chen Mar 7, 2024
4cab7dc
Add docs example + copy
cee-chen Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"build-docs": "cross-env BABEL_MODULES=false cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 webpack --config=src-docs/webpack.config.js",
"build": "yarn extract-i18n-strings && node ./scripts/compile-clean.js && node ./scripts/compile-eui.js && yarn compile-scss",
"build-pack": "yarn build && npm pack",
"check-types": "yarn tsc --noEmit",
"compile-icons": "node ./scripts/compile-icons.js && prettier --write --loglevel=warn \"./src/components/icon/assets/**/*.tsx\"",
"compile-scss": "node ./scripts/compile-scss.js",
"extract-i18n-strings": "node ./scripts/babel/fetch-i18n-strings",
"lint": "yarn tsc --noEmit && yarn lint-es && yarn lint-css-in-js && yarn lint-sass",
"lint": "yarn check-types && yarn lint-es && yarn lint-css-in-js && yarn lint-sass",
"lint-fix": "yarn lint-es --fix && yarn lint-css-in-js --fix",
"lint-es": "eslint --cache \"{src,src-docs}/**/*.{ts,tsx,js}\" --max-warnings 0",
"lint-css-in-js": "yarn stylelint \"**/*.styles.ts\" \"./src/themes/**/*.ts\" \"./src/global_styling/**/*.ts\" --quiet-deprecation-warnings",
Expand Down
61 changes: 32 additions & 29 deletions src-docs/src/views/datagrid/advanced/custom_renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EuiDataGridPaginationProps,
EuiDataGridSorting,
EuiDataGridColumnSortingConfig,
RenderCellValue,
} from '../../../../../src';

const raw_data: Array<{ [key: string]: string }> = [];
Expand Down Expand Up @@ -67,6 +68,14 @@ const columns = [
},
];

const checkboxRowCellRender: RenderCellValue = ({ rowIndex }) => (
<EuiCheckbox
id={`select-row-${rowIndex}`}
aria-label="Select row"
onChange={() => {}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the anonymous function get re-created on re-renders? Technically this array should be stable since it's outside the render, but not sure if it's worth passing const noOp = () => {} to this and the headerCellRender below?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore, I see this is docs

/>
);

const leadingControlColumns: EuiDataGridProps['leadingControlColumns'] = [
{
id: 'selection',
Expand All @@ -78,13 +87,7 @@ const leadingControlColumns: EuiDataGridProps['leadingControlColumns'] = [
onChange={() => {}}
/>
),
rowCellRender: ({ rowIndex }) => (
<EuiCheckbox
id={`select-row-${rowIndex}`}
aria-label="Select row"
onChange={() => {}}
/>
),
rowCellRender: checkboxRowCellRender,
},
];

Expand All @@ -103,6 +106,22 @@ const trailingControlColumns: EuiDataGridProps['trailingControlColumns'] = [
},
];

const RowCellRender: RenderCellValue = ({ setCellProps, rowIndex }) => {
setCellProps({ style: { width: '100%', height: 'auto' } });

const firstName = raw_data[rowIndex].name.split(', ')[1];
const isGood = faker.datatype.boolean();
return (
<>
{firstName}&apos;s account has {isGood ? 'no' : ''} outstanding fees.{' '}
<EuiIcon
type={isGood ? 'checkInCircleFilled' : 'error'}
color={isGood ? 'success' : 'danger'}
/>
</>
);
};

// The custom row details is actually a trailing control column cell with
// a hidden header. This is important for accessibility and markup reasons
// @see https://fuschia-stretch.glitch.me/ for more
Expand All @@ -120,21 +139,7 @@ const rowDetails: EuiDataGridProps['trailingControlColumns'] = [

// When rendering this custom cell, we'll want to override
// the automatic width/heights calculated by EuiDataGrid
rowCellRender: ({ setCellProps, rowIndex }) => {
setCellProps({ style: { width: '100%', height: 'auto' } });

const firstName = raw_data[rowIndex].name.split(', ')[1];
const isGood = faker.datatype.boolean();
return (
<>
{firstName}&apos;s account has {isGood ? 'no' : ''} outstanding fees.{' '}
<EuiIcon
type={isGood ? 'checkInCircleFilled' : 'error'}
color={isGood ? 'success' : 'danger'}
/>
</>
);
},
rowCellRender: RowCellRender,
},
];

Expand All @@ -144,10 +149,10 @@ const footerCellValues: { [key: string]: string } = {
.toLocaleString('en-US', { style: 'currency', currency: 'USD' })}`,
};

const RenderFooterCellValue: EuiDataGridProps['renderFooterCellValue'] = ({
columnId,
setCellProps,
}) => {
const renderCellValue: RenderCellValue = ({ rowIndex, columnId }) =>
raw_data[rowIndex][columnId];

const RenderFooterCellValue: RenderCellValue = ({ columnId, setCellProps }) => {
const value = footerCellValues[columnId];

useEffect(() => {
Expand Down Expand Up @@ -298,9 +303,7 @@ export default () => {
onChangeItemsPerPage: onChangePageSize,
}}
rowCount={raw_data.length}
renderCellValue={({ rowIndex, columnId }) =>
raw_data[rowIndex][columnId]
}
renderCellValue={renderCellValue}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾

renderFooterCellValue={RenderFooterCellValue}
renderCustomGridBody={RenderCustomGridBody}
height={autoHeight ? undefined : 400}
Expand Down
8 changes: 5 additions & 3 deletions src-docs/src/views/datagrid/advanced/ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EuiDataGridColumnSortingConfig,
EuiDataGridPaginationProps,
EuiDataGridSorting,
RenderCellValue,
} from '../../../../../src';

const raw_data: Array<{ [key: string]: string }> = [];
Expand All @@ -33,6 +34,9 @@ for (let i = 1; i < 100; i++) {
});
}

const renderCellValue: RenderCellValue = ({ rowIndex, columnId }) =>
raw_data[rowIndex][columnId];

export default () => {
const dataGridRef = useRef<EuiDataGridRefProps | null>(null);

Expand Down Expand Up @@ -219,9 +223,7 @@ export default () => {
sorting={{ columns: sortingColumns, onSort }}
inMemory={{ level: 'sorting' }}
rowCount={raw_data.length}
renderCellValue={({ rowIndex, columnId }) =>
raw_data[rowIndex][columnId]
}
renderCellValue={renderCellValue}
pagination={{
...pagination,
onChangePage: onChangePage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EuiDataGrid,
EuiDataGridColumnCellAction,
EuiDataGridColumn,
RenderCellValue as RenderCellValueType,
} from '../../../../../src';

const cellActions: EuiDataGridColumnCellAction[] = [
Expand Down Expand Up @@ -50,6 +51,22 @@ for (let i = 1; i < 5; i++) {
});
}

const RenderCellValue: RenderCellValueType = ({
rowIndex,
columnId,
setCellProps,
}) => {
const value = data[rowIndex][columnId];

useEffect(() => {
if (columnId === 'boolean' && value === 'false') {
setCellProps({ isExpandable: false });
}
}, [columnId, value, setCellProps]);

return value;
};

export default () => {
const [visibleColumns, setVisibleColumns] = useState(
columns.map(({ id }) => id)
Expand All @@ -61,17 +78,7 @@ export default () => {
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={data.length}
renderCellValue={({ rowIndex, columnId, setCellProps }) => {
const value = data[rowIndex][columnId];

useEffect(() => {
if (columnId === 'boolean' && value === 'false') {
setCellProps({ isExpandable: false });
}
}, [columnId, value, setCellProps]);

return value;
}}
renderCellValue={RenderCellValue}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EuiCopy,
EuiText,
EuiImage,
RenderCellValue as RenderCellValueType,
} from '../../../../../src';

const cellActions: EuiDataGridColumnCellAction[] = [
Expand Down Expand Up @@ -163,6 +164,9 @@ const RenderCellPopover = (props: EuiDataGridCellPopoverElementProps) => {
);
};

const renderCellValue: RenderCellValueType = ({ rowIndex, columnId }) =>
data[rowIndex][columnId];

export default () => {
const [visibleColumns, setVisibleColumns] = useState(
columns.map(({ id }) => id)
Expand All @@ -174,7 +178,7 @@ export default () => {
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={data.length}
renderCellValue={({ rowIndex, columnId }) => data[rowIndex][columnId]}
renderCellValue={renderCellValue}
renderCellPopover={RenderCellPopover}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EuiDataGrid,
EuiDataGridColumnCellAction,
EuiDataGridColumn,
RenderCellValue as RenderCellValueType,
} from '../../../../../src/components';

const cellActions1: EuiDataGridColumnCellAction[] = [
Expand Down Expand Up @@ -79,6 +80,9 @@ for (let i = 1; i < 5; i++) {
});
}

const renderCellValue: RenderCellValueType = ({ rowIndex, columnId }) =>
data[rowIndex][columnId];

export default () => {
const [visibleColumns, setVisibleColumns] = useState(
columns.map(({ id }) => id)
Expand All @@ -90,7 +94,7 @@ export default () => {
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={data.length}
renderCellValue={({ rowIndex, columnId }) => data[rowIndex][columnId]}
renderCellValue={renderCellValue}
/>
);
};
4 changes: 2 additions & 2 deletions src-docs/src/views/datagrid/styling/row_height_auto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import githubData from '../_row_auto_height_data.json';

import {
EuiDataGrid,
EuiDataGridProps,
RenderCellValue as RenderCellValueType,
EuiLink,
EuiAvatar,
EuiBadge,
Expand Down Expand Up @@ -68,7 +68,7 @@ const columns = [
// instead of loading up front, generate entries on the fly
const raw_data: DataShape[] = githubData;

const RenderCellValue: EuiDataGridProps['renderCellValue'] = ({
const RenderCellValue: RenderCellValueType = ({
rowIndex,
columnId,
isDetails,
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/datagrid/styling/row_height_fixed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import githubData from '../_row_auto_height_data.json';

import {
EuiDataGrid,
EuiDataGridProps,
RenderCellValue as RenderCellValueType,
EuiLink,
EuiAvatar,
EuiBadge,
Expand Down Expand Up @@ -68,7 +68,7 @@ const columns = [
// instead of loading up front, generate entries on the fly
const raw_data: DataShape[] = githubData;

const RenderCellValue: EuiDataGridProps['renderCellValue'] = ({
const RenderCellValue: RenderCellValueType = ({
rowIndex,
columnId,
isDetails,
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/datagrid/styling/row_line_height.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EuiDataGrid,
EuiDataGridColumnSortingConfig,
EuiDataGridPaginationProps,
EuiDataGridProps,
RenderCellValue as RenderCellValueType,
EuiDataGridSorting,
formatDate,
} from '../../../../../src';
Expand Down Expand Up @@ -62,7 +62,7 @@ const columns = [
// instead of loading up front, generate entries on the fly
const raw_data: DataShape[] = githubData;

const RenderCellValue: EuiDataGridProps['renderCellValue'] = ({
const RenderCellValue: RenderCellValueType = ({
rowIndex,
columnId,
isDetails,
Expand Down
6 changes: 5 additions & 1 deletion src-docs/src/views/datagrid/toolbar/additional_controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiContextMenuPanel,
EuiPopover,
EuiDataGridPaginationProps,
RenderCellValue,
} from '../../../../../src';

const columns = [
Expand Down Expand Up @@ -50,6 +51,9 @@ for (let i = 1; i < 20; i++) {
});
}

const renderCellValue: RenderCellValue = ({ rowIndex, columnId }) =>
data[rowIndex][columnId];

export default () => {
const [pagination, setPagination] = useState({ pageIndex: 0 });
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
Expand Down Expand Up @@ -127,7 +131,7 @@ export default () => {
border: 'horizontal',
header: 'underline',
}}
renderCellValue={({ rowIndex, columnId }) => data[rowIndex][columnId]}
renderCellValue={renderCellValue}
pagination={{
...pagination,
onChangeItemsPerPage: setPageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
euiScreenReaderOnly,
RenderCellValue,
} from '../../../../../src';

const raw_data: Array<{ [key: string]: string }> = [];
Expand Down Expand Up @@ -82,6 +83,9 @@ const renderCustomToolbar: EuiDataGridToolbarProps['renderCustomToolbar'] = ({
);
};

const renderCellValue: RenderCellValue = ({ rowIndex, columnId }) =>
raw_data[rowIndex][columnId];

// Some additional custom settings to show in the Display popover
const AdditionalDisplaySettings = () => {
const [exampleSettingValue, setExampleSettingValue] = useState<number>(10);
Expand Down Expand Up @@ -126,7 +130,7 @@ export default () => {
columnVisibility={{ visibleColumns, setVisibleColumns }}
sorting={{ columns: sortingColumns, onSort }}
rowCount={raw_data.length}
renderCellValue={({ rowIndex, columnId }) => raw_data[rowIndex][columnId]}
renderCellValue={renderCellValue}
gridStyle={{ border: 'none', header: 'underline' }}
renderCustomToolbar={renderCustomToolbar}
toolbarVisibility={{
Expand Down
8 changes: 4 additions & 4 deletions src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
style="height: 202px; width: 200px;"
style="width: 200px; height: 202px;"
>
<div
class="euiDataGridHeader"
Expand Down Expand Up @@ -1014,7 +1014,7 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
style="height: 202px; width: 300px;"
style="width: 300px; height: 202px;"
>
<div
class="euiDataGridHeader"
Expand Down Expand Up @@ -1632,7 +1632,7 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
style="height: 202px; width: 200px;"
style="width: 200px; height: 202px;"
>
<div
class="euiDataGridHeader"
Expand Down Expand Up @@ -2058,7 +2058,7 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
style="position: relative; height: 9007199254740991px; width: 9007199254740991px; overflow: auto; will-change: transform; direction: ltr;"
>
<div
style="height: 202px; width: 200px;"
style="width: 200px; height: 202px;"
>
<div
class="euiDataGridHeader"
Expand Down
Loading
Loading