fix TableListView empty view trapping users with no action to create new item (#109345)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nathan Reese 2021-08-23 08:25:08 -06:00 committed by GitHub
parent c736d99c87
commit 3669aad41f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 0 deletions

View file

@ -42,6 +42,52 @@ exports[`TableListView render default empty prompt 1`] = `
</KibanaPageTemplate>
`;
exports[`TableListView render default empty prompt with create action when createItem supplied 1`] = `
<KibanaPageTemplate
data-test-subj="testLandingPage"
isEmptyState={true}
pageBodyProps={
Object {
"aria-labelledby": undefined,
}
}
>
<EuiEmptyPrompt
actions={
<EuiButton
data-test-subj="newItemButton"
fill={true}
iconType="plusInCircleFilled"
onClick={[Function]}
>
<FormattedMessage
defaultMessage="Create {entityName}"
id="kibana-react.tableListView.listing.createNewItemButtonLabel"
values={
Object {
"entityName": "test",
}
}
/>
</EuiButton>
}
title={
<h1>
<FormattedMessage
defaultMessage="No {entityNamePlural} available."
id="kibana-react.tableListView.listing.noAvailableItemsMessage"
values={
Object {
"entityNamePlural": "tests",
}
}
/>
</h1>
}
/>
</KibanaPageTemplate>
`;
exports[`TableListView render list view 1`] = `
<KibanaPageTemplate
data-test-subj="testLandingPage"

View file

@ -39,6 +39,19 @@ describe('TableListView', () => {
expect(component).toMatchSnapshot();
});
// avoid trapping users in empty prompt that can not create new items
test('render default empty prompt with create action when createItem supplied', async () => {
const component = shallowWithIntl(<TableListView {...requiredProps} createItem={() => {}} />);
// Using setState to check the final render while sidestepping the debounced promise management
component.setState({
hasInitialFetchReturned: true,
isFetchingItems: false,
});
expect(component).toMatchSnapshot();
});
test('render custom empty prompt', () => {
const component = shallowWithIntl(
<TableListView {...requiredProps} emptyPrompt={<EuiEmptyPrompt />} />

View file

@ -362,6 +362,7 @@ class TableListView extends React.Component<TableListViewProps, TableListViewSta
}
</h1>
}
actions={this.renderCreateButton()}
/>
);
}