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

[8.9] [Content management] fix table list flashes table interface when empty (#160650) #160893

Merged
merged 1 commit into from
Jun 29, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import React, { ReactNode, useState } from 'react';
import React, { ReactNode, useCallback, useState } from 'react';
import {
TableListViewTable,
type TableListViewTableProps,
Expand Down Expand Up @@ -81,6 +81,12 @@ export const TableListView = <T extends UserContentCommonSchema>({
const [hasInitialFetchReturned, setHasInitialFetchReturned] = useState(false);
const [pageDataTestSubject, setPageDataTestSubject] = useState<string>();

const onFetchSuccess = useCallback(() => {
if (!hasInitialFetchReturned) {
setHasInitialFetchReturned(true);
}
}, [hasInitialFetchReturned]);

return (
<PageTemplate panelled data-test-subj={pageDataTestSubject}>
<KibanaPageTemplate.Header
Expand Down Expand Up @@ -115,11 +121,7 @@ export const TableListView = <T extends UserContentCommonSchema>({
contentEditor={contentEditor}
titleColumnName={titleColumnName}
withoutPageTemplateWrapper={withoutPageTemplateWrapper}
onFetchSuccess={() => {
if (!hasInitialFetchReturned) {
setHasInitialFetchReturned(true);
}
}}
onFetchSuccess={onFetchSuccess}
setPageDataTestSubject={setPageDataTestSubject}
/>
</KibanaPageTemplate.Section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,10 +1197,23 @@ describe('TableList', () => {
}
);

it('refreshes the list when the bouncer changes', async () => {
it('refreshes the list when "refreshListBouncer" changes', async () => {
let testBed: TestBed;

const findItems = jest.fn().mockResolvedValue({ total: 0, hits: [] });
const originalHits: UserContentCommonSchema[] = [
{
id: `item`,
type: 'dashboard',
updatedAt: 'original timestamp',
attributes: {
title: `Original title`,
},
references: [],
},
];
const findItems = jest
.fn()
.mockResolvedValue({ total: originalHits.length, hits: originalHits });

await act(async () => {
testBed = setup({ findItems });
Expand All @@ -1215,7 +1228,7 @@ describe('TableList', () => {
{
id: `item`,
type: 'dashboard',
updatedAt: 'some date',
updatedAt: 'updated timestamp',
attributes: {
title: `Updated title`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
} = state;

const hasQuery = searchQuery.text !== '';
const hasNoItems = !isFetchingItems && items.length === 0 && !hasQuery;
const hasNoItems = hasInitialFetchReturned && items.length === 0 && !hasQuery;
const showFetchError = Boolean(fetchError);
const showLimitError = !showFetchError && totalItems > listingLimit;

Expand Down Expand Up @@ -411,10 +411,6 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
}
}, [searchQueryParser, searchQuery.text, findItems, onFetchSuccess]);

useEffect(() => {
fetchItems();
}, [fetchItems, refreshListBouncer]);

const updateQuery = useCallback(
(query: Query) => {
if (urlStateEnabled) {
Expand Down Expand Up @@ -800,7 +796,17 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
// ------------
// Effects
// ------------
useDebounce(fetchItems, 300, [fetchItems]);
useDebounce(
() => {
// Do not call fetchItems on dependency changes when initial fetch does not load any items
// to avoid flashing between empty table and no items view
if (!hasNoItems) {
fetchItems();
}
},
300,
[fetchItems, refreshListBouncer]
);

useEffect(() => {
if (!urlStateEnabled) {
Expand Down
2 changes: 1 addition & 1 deletion test/accessibility/apps/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await listingTable.clickDeleteSelected();
await a11y.testAppSnapshot();
await PageObjects.common.clickConfirmOnModal();
await listingTable.searchForItemWithName('');
await listingTable.isShowingEmptyPromptCreateNewButton();
});
});
}
4 changes: 4 additions & 0 deletions test/functional/services/listing_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ export class ListingTableService extends FtrService {
await this.testSubjects.click('newItemButton');
}

public async isShowingEmptyPromptCreateNewButton(): Promise<void> {
await this.testSubjects.existOrFail('newItemButton');
}

public async onListingPage(appName: AppName) {
return await this.testSubjects.exists(`${appName}LandingPage`, {
timeout: 5000,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/dashboard/group2/sync_colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

return colorMapping;
}
// Failing: See https://github.com/elastic/kibana/issues/148557
describe.skip('sync colors', function () {

describe('sync colors', function () {
before(async function () {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/logstash_functional');
await kibanaServer.importExport.load(
Expand Down