Skip to content

Commit

Permalink
Merge branch 'master' into flexing/header_links
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos authored Sep 17, 2020
2 parents c4f6e58 + 8dcdabd commit 1553d33
Show file tree
Hide file tree
Showing 25 changed files with 588 additions and 56 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added footer row to `EuiDataGrid` via the `renderFooterCellValue` prop ([#3770](https://github.com/elastic/eui/pull/3770))
- Added `gutterSize`, `popoverBreakpoints`, `popoverButtonProps`, and `popoverProps` props to `EuiHeaderLinks` ([#4046](https://github.com/elastic/eui/pull/4046))
- Added `'all'` and `'none'` options to the `sizes` prop of `EuiHideFor` and `EuiShowFor` ([#4046](https://github.com/elastic/eui/pull/4046))


## [`29.0.0`](https://github.com/elastic/eui/tree/v29.0.0)

- Added `.browserslistrc` for global browser support reference ([#4022](https://github.com/elastic/eui/pull/4022))
Expand Down Expand Up @@ -47,6 +47,7 @@

**Bug fixes**

- Fixed `EuiFieldSearch`'s clear button covering the `value` of the input ([#3936](https://github.com/elastic/eui/pull/3936))
- Fixed bug in `EuiComboBox` where the input was dropping to the next line when a `EuiBadge` had a very long text ([#3968](https://github.com/elastic/eui/pull/3968))
- Fixed type mismatch between `EuiSelectable` options extended via `EuiSelectableOption` and internal option types ([#3983](https://github.com/elastic/eui/pull/3983))
- Fixed `EuiButton` CSS for RTL languages by using `margin-inline-[pos]` instead of `margin-[pos]` ([#3974](https://github.com/elastic/eui/pull/3974))
Expand Down Expand Up @@ -91,7 +92,6 @@

**Bug fixes**

- Fixed `EuiFieldSearch`'s clear button covering the `value` of the input ([#3936](https://github.com/elastic/eui/pull/3936))
- Fixed bug in `EuiCodeBlock` content overlapping with control buttons when `whiteSpace` was set to `"pre"` ([#3853](https://github.com/elastic/eui/pull/3853))
- Fixed `EuiFocusTrap` not applying provided `style` prop ([#3916](https://github.com/elastic/eui/pull/3916))
- Fixed bug in `EuiDataGrid` when a new pagination object would cause every cell to render ([#3919](https://github.com/elastic/eui/pull/3919))
Expand Down
10 changes: 5 additions & 5 deletions docs/bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/bundle.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src-docs/src/components/codesandbox/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { EuiSpacer } from '../../../../src/components';
* 6. We pass the files and dependencies as params to CS through a POST call.
* */

const displayTogglesRawCode = require('!!raw-loader!../../views/form_controls/display_toggles');
const displayTogglesRawCode = require('!!raw-loader!../../views/form_controls/display_toggles')
.default;

/* 1 */
export const CodeSandboxLink = ({ children, content }) => {
Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { DataGridSchemaExample } from './views/datagrid/datagrid_schema_example'
import { DataGridFocusExample } from './views/datagrid/datagrid_focus_example';
import { DataGridStylingExample } from './views/datagrid/datagrid_styling_example';
import { DataGridControlColumnsExample } from './views/datagrid/datagrid_controlcolumns_example';
import { DataGridFooterRowExample } from './views/datagrid/datagrid_footer_row_example';

import { DatePickerExample } from './views/date_picker/date_picker_example';

Expand Down Expand Up @@ -371,6 +372,7 @@ const navigation = [
DataGridFocusExample,
DataGridStylingExample,
DataGridControlColumnsExample,
DataGridFooterRowExample,
TableExample,
TableInMemoryExample,
].map(example => createExample(example)),
Expand Down
6 changes: 3 additions & 3 deletions src-docs/src/views/code/code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';

import { EuiCodeBlock, EuiSpacer } from '../../../../src/components';

const htmlCode = require('!!raw-loader!./code_examples/example.html');
const htmlCode = require('!!raw-loader!./code_examples/example.html').default;

const jsCode = require('!!raw-loader!./code_examples/example.js');
const jsCode = require('!!raw-loader!./code_examples/example.js').default;

const sqlCode = require('!!raw-loader!./code_examples/example.sql');
const sqlCode = require('!!raw-loader!./code_examples/example.sql').default;

export default () => (
<div>
Expand Down
4 changes: 3 additions & 1 deletion src-docs/src/views/code/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { PropTypes } from 'react-view';
import { EuiCodeBlock, EuiCode } from '../../../../src/components/';
import { propUtilityForPlayground } from '../../services/playground';

const codeDemo = `\n{\`${require('!!raw-loader!./code_examples/example.html')}\`}\n`;
const codeDemo = `\n{\`${
require('!!raw-loader!./code_examples/example.html').default
}\`}\n`;

export const codeBlockConfig = () => {
const docgenInfo = Array.isArray(EuiCodeBlock.__docgenInfo)
Expand Down
71 changes: 71 additions & 0 deletions src-docs/src/views/datagrid/datagrid_footer_row_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React, { Fragment } from 'react';

import { renderToHtml } from '../../services';

import { GuideSectionTypes } from '../../components';
import { EuiDataGrid, EuiCodeBlock, EuiCode } from '../../../../src/components';

import DataGridFooterRow from './footer_row';
const dataGridControlColumnsSource = require('!!raw-loader!./footer_row');
const dataGridControlColumnsHtml = renderToHtml(DataGridFooterRow);

import { EuiDataGridControlColumn } from '!!prop-loader!../../../../src/components/datagrid/data_grid_types';
import { EuiDataGridCellValueElementProps } from '!!prop-loader!../../../../src/components/datagrid/data_grid_cell';

const gridSnippet = `const footerCellValues = {
// desired data
};
<EuiDataGrid
{...usualProps}
renderFooterCellValue={({ columnId }) =>
footerCellValues[columnId] || null
}
/>
`;

export const DataGridFooterRowExample = {
title: 'Data grid footer row',
sections: [
{
source: [
{
type: GuideSectionTypes.JS,
code: dataGridControlColumnsSource,
},
{
type: GuideSectionTypes.HTML,
code: dataGridControlColumnsHtml,
},
],
text: (
<Fragment>
<p>
A footer row can be used to include value aggregations to the grid.
Values could be based on the dataset, such as sum/average/min/max of
numeric values in a column, or any other necessary data.
</p>
<p>
The footer row is defined by passing{' '}
<EuiCode>renderFooterCellValue</EuiCode> function prop into
EuiDataGrid. <EuiCode>renderFooterCellValue</EuiCode> acts like a
React component, receiving{' '}
<EuiCode>EuiDataGridCellValueElementProps</EuiCode> and returning a
React node.
</p>
<EuiCodeBlock language="javascript" paddingSize="s" isCopyable>
{gridSnippet}
</EuiCodeBlock>
</Fragment>
),
components: { DataGridFooterRow },

props: {
EuiDataGrid,
EuiDataGridControlColumn,
EuiDataGridCellValueElementProps,
},
demo: <DataGridFooterRow />,
},
],
};
1 change: 1 addition & 0 deletions src-docs/src/views/datagrid/datagrid_styling_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const gridSnippet = `<EuiDataGrid
// If showStyleSelector={true} from toolbarVisibility, these last two will be superceded by what the user decides.
fontSize: 'm',
cellPadding: 'm',
footer: 'overline'
}}
/>
`;
Expand Down
143 changes: 143 additions & 0 deletions src-docs/src/views/datagrid/footer_row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { fake } from 'faker';

import {
EuiDataGrid,
EuiSwitch,
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components/';

const raw_data = [];

for (let i = 1; i < 20; i++) {
raw_data.push({
name: fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}'),
date: fake('{{date.past}}'),
amount: fake('${{commerce.price}}'),
phone: fake('{{phone.phoneNumber}}'),
version: fake('{{system.semver}}'),
});
}

const columns = [
{
id: 'name',
displayAsText: 'Name',
defaultSortDirection: 'asc',
},
{
id: 'date',
defaultSortDirection: 'desc',
},
{
id: 'amount',
},
{
id: 'phone',
isSortable: false,
},
{
id: 'version',
defaultSortDirection: 'desc',
},
];

const footerCellValues = {
amount: `Total: $${raw_data.reduce(
(acc, { amount }) => acc + Number(amount.split('$')[1]),
0
)}`,
version: `Latest: ${
raw_data.map(({ version }) => version).sort()[raw_data.length - 1]
}`,
};

export default () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const onChangeItemsPerPage = useCallback(
pageSize =>
setPagination(pagination => ({ ...pagination, pageSize, pageIndex: 0 })),
[setPagination]
);
const onChangePage = useCallback(
pageIndex => setPagination(pagination => ({ ...pagination, pageIndex })),
[setPagination]
);

// Column visibility
const [visibleColumns, setVisibleColumns] = useState(() =>
columns.map(({ id }) => id)
); // initialize to the full set of columns

const renderCellValue = useMemo(() => {
return ({ rowIndex, columnId, setCellProps }) => {
useEffect(() => {
if (columnId === 'amount') {
if (raw_data.hasOwnProperty(rowIndex)) {
const numeric = parseFloat(
raw_data[rowIndex][columnId].match(/\d+\.\d+/)[0],
10
);
setCellProps({
style: {
backgroundColor: `rgba(0, 255, 0, ${numeric * 0.0002})`,
},
});
}
}
}, [rowIndex, columnId, setCellProps]);

return raw_data.hasOwnProperty(rowIndex)
? raw_data[rowIndex][columnId]
: null;
};
}, []);

const renderFooterCellValue = useCallback(
({ columnId }) => footerCellValues[columnId] || null,
[]
);

// Footer row
const [showFooterRow, setShowFooterRow] = useState(true);

return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiSwitch
label="Show footer row"
checked={showFooterRow}
onChange={e => setShowFooterRow(e.target.checked)}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiDataGrid
aria-label="Data grid footer row demo"
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
rowCount={raw_data.length}
renderCellValue={renderCellValue}
renderFooterCellValue={
showFooterRow ? renderFooterCellValue : undefined
}
pagination={{
...pagination,
pageSizeOptions: [10, 15, 20],
onChangeItemsPerPage: onChangeItemsPerPage,
onChangePage: onChangePage,
}}
onColumnResize={eventData => {
console.log(eventData);
}}
gridStyle={{
border: 'horizontal',
rowHover: 'highlight',
header: 'underline',
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
);
};
Loading

0 comments on commit 1553d33

Please sign in to comment.