Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"commitizen": "^4.3.1",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"cypress": "^13.15.2",
"cypress": "^13.17.0",
"cypress-fail-fast": "^7.1.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^9.22.0",
Expand Down
49 changes: 24 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/components/KTableData/KTableData.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ describe('KTableData', () => {
cy.get('.skeleton-table-wrapper').should('be.visible')
cy.get('.k-empty-state').should('not.exist')
})

it('does not display a loading state when `loading` is false, regardless of fetcher state', () => {
const slowFetcher = () => {
return new Promise((resolve) => setTimeout(resolve, 2500))
}

cy.mount(KTableData, {
props: {
fetcher: slowFetcher,
headers: options.headers,
cacheIdentifier: 'loading-test',
loading: false,
paginationAttributes: {
pageSizes: [10, 20, 30, 40],
},
},
})

cy.get('.skeleton-table-wrapper').should('not.exist')
})
})

describe('default', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/KTableData/KTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:hide-pagination="hidePagination || !showPagination"
:hide-pagination-when-optional="false"
:hide-toolbar="hideToolbar"
:loading="loading || fetcherIsLoading"
:loading="loading ?? fetcherIsLoading"
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/Kong/konnect-ui-apps/blob/37492e0dcbc48d8376d4cc06b1fdc0132203f0ea/apps/gateway-manager/src/pages/GatewayLogsPage.vue#L74

It appears that it’s common practice across our tables in Konnect to initialize a ref<boolean> that defaults to false for many of our KTableData instances.

Wouldn’t this usage pattern prevent the table’s built-in loading state from showing when it actually does need to initially fetch the data when a component mounts?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the linked implementation, each time fetcher is called, it triggers clearLoadingAndError, which sets isLoading to true. The logic seems a bit convoluted, but I assume the behavior remains consistent. We can confirm this by testing it in a preview PR.

Actually, I believe we’re misusing fetcherCacheKey to trigger revalidation like this. Instead, we should directly include the fetcher parameters in the cache key.

For the current change, if users explicitly set the loading prop to false, we should consider respecting that.

Copy link
Member Author

Choose a reason for hiding this comment

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

The behavior of the loading prop isn’t the core of the problem we’re facing. The key issue is that we haven’t exposed a “revalidate only” interface on the Table. The auto-incrementing cache key actually implies loading new data that hasn’t been loaded before, which, technically, is not accurate. Another viable solution is to defineExpose the revalidate method from <KTableData>, and also, for the scenario we’re currently encountering (polling), expose the refreshInterval configuration of SWRV as a prop. This way, we can trigger polling revalidation in a more declarative manner. WDYT?

:max-height="maxHeight"
:nested="nested"
:pagination-attributes="tablePaginationAttributes"
Expand Down Expand Up @@ -190,7 +190,7 @@ const props = withDefaults(defineProps<TableDataProps>(), {
rowBulkActionEnabled: () => true,
rowKey: '',
cellAttrs: () => ({}),
loading: false,
loading: undefined,
emptyStateTitle: 'No Data',
emptyStateMessage: 'There is no data to display.',
emptyStateActionMessage: '',
Expand Down