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

[EuiInMemoryTable] Added ability to insert component between the searchbar and the table #4103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `childrenBetween` prop to `EuiInMemoryTable` to add content between search bar and table ([#4103](https://github.com/elastic/eui/pull/4103))
- Added `max-width: 100%` to `EuiKeyPadMenu` to allow it to shrink when its container is smaller than its fixed width ([ #4092](https://github.com/elastic/eui/pull/4092))
- Changed `EuiIcon` test mock to render as `span` instead of `div` ([#4099](https://github.com/elastic/eui/pull/4099))
- Added `scripts/docker-puppeteer` as the new home for test-related Docker images ([#4062](https://github.com/elastic/eui/pull/4062))
Expand Down
18 changes: 18 additions & 0 deletions src-docs/src/views/tables/in_memory/in_memory_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
EuiSwitch,
EuiFlexGroup,
EuiFlexItem,
EuiText,
EuiCode,
} from '../../../../../src/components';

/*
Expand Down Expand Up @@ -38,6 +40,7 @@ const store = createDataStore();
export const Table = () => {
const [incremental, setIncremental] = useState(false);
const [filters, setFilters] = useState(false);
const [contentBetween, setContentBetween] = useState(false);

const columns = [
{
Expand Down Expand Up @@ -132,6 +135,13 @@ export const Table = () => {
onChange={() => setFilters(!filters)}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiSwitch
label="Content between"
checked={contentBetween}
onChange={() => setContentBetween(!contentBetween)}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
<EuiInMemoryTable
Expand All @@ -140,6 +150,14 @@ export const Table = () => {
search={search}
pagination={true}
sorting={true}
childrenBetween={
contentBetween && (
<EuiText>
You can inject custom content between the search bar and the table
using <EuiCode>childrenBetween</EuiCode>.
</EuiText>
)
}
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2148,3 +2148,66 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea
/>
</div>
`;

exports[`EuiInMemoryTable with search and component between search and table 1`] = `
<div>
<EuiSearchBar
onChange={[Function]}
/>
<EuiSpacer
size="l"
/>
<div>
Children Between
</div>
<EuiSpacer
size="l"
/>
<EuiBasicTable
aria-label="aria-label"
className="testClass1 testClass2"
columns={
Array [
Object {
"description": "description",
"field": "name",
"name": "Name",
"sortable": true,
},
Object {
"actions": Array [
Object {
"description": "edit",
"name": "Edit",
"onClick": [Function],
},
],
"name": "Actions",
},
]
}
data-test-subj="test subject string"
itemId="id"
items={
Array [
Object {
"id": "1",
"name": "name1",
},
Object {
"id": "2",
"name": "name2",
},
Object {
"id": "3",
"name": "name3",
},
]
}
noItemsMessage="No items found"
onChange={[Function]}
responsive={true}
tableLayout="fixed"
/>
</div>
`;
35 changes: 35 additions & 0 deletions src/components/basic_table/in_memory_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,41 @@ describe('EuiInMemoryTable', () => {
expect(component).toMatchSnapshot();
});

test('with search and component between search and table', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
items: [
{ id: '1', name: 'name1' },
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' },
],
itemId: 'id',
columns: [
{
field: 'name',
name: 'Name',
description: 'description',
sortable: true,
},
{
name: 'Actions',
actions: [
{
name: 'Edit',
description: 'edit',
onClick: () => undefined,
},
],
},
],
search: true,
childrenBetween: <div>Children Between</div>,
};
const component = shallow(<EuiInMemoryTable {...props} />);

expect(component).toMatchSnapshot();
});

test('with pagination, selection, sorting and configured search', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
Expand Down
7 changes: 7 additions & 0 deletions src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ type InMemoryTableProps<T> = Omit<
isClauseMatcher?: (...args: any) => boolean;
explain?: boolean;
};
/**
* Insert content between the search bar and table components.
*/
childrenBetween?: ReactNode;
};

type InMemoryTablePropsWithPagination<T> = Omit<
Expand Down Expand Up @@ -604,6 +608,7 @@ export class EuiInMemoryTable<T> extends Component<
onTableChange,
executeQueryOptions,
allowNeutralSort,
childrenBetween,
...rest
} = this.props;

Expand Down Expand Up @@ -678,6 +683,8 @@ export class EuiInMemoryTable<T> extends Component<
return (
<div>
{searchBar}
{childrenBetween != null ? <EuiSpacer size="l" /> : null}
{childrenBetween}
<EuiSpacer size="l" />
{table}
</div>
Expand Down