Skip to content
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 @@ -20,7 +20,7 @@

<div v-else-if="selectedTable && selectedTable.schema" class="content h-full">
<ff-data-table
:loading="isLoading"
:loading="isLoading" loading-type="skeleton"
:columns="columns" :rows="rows"
:pagination="pagination"
class="h-full"
Expand All @@ -30,6 +30,8 @@
/>
</div>

<ff-loading v-else-if="isLoading" message="Loading Table..." data-el="table-loading" />

<div v-else class="no-content w-full h-full flex justify-center items-center text-gray-400">
<p>There doesn't seem to be anything here!</p>
</div>
Expand Down Expand Up @@ -93,7 +95,11 @@ export default defineComponent({
},
watch: {
tableSelection (table) {
if (!table) return
if (!table) {
this.setTableLoadingState(false)
return
}
this.setTableLoadingState(true)
this.getTableSchema({
teamId: this.team.id,
databaseId: this.$route.params.id,
Expand All @@ -107,6 +113,10 @@ export default defineComponent({
schemaName: table.dbSchema
}))
.catch(e => e)
.finally(() => {
// a table picked in the meantime is still loading, so leave the state to it
if (this.tableSelection === table) this.setTableLoadingState(false)
})
}
},
beforeUnmount () {
Expand Down
61 changes: 61 additions & 0 deletions test/unit/frontend/pages/team/Tables/RowsList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,65 @@ describe('RowsList', () => {
expect(wrapper.find('thead .sortable').exists()).toBe(false)
})
})

describe('loading a table', () => {
const readings = { name: 'readings', dbSchema: 'public' }
const schema = [{ name: 'id', safeName: 'col', type: 'bigint' }]
// the store is a plain mock, so run the table selection watcher by hand
const selectTable = (wrapper, table) => wrapper.vm.$options.watch.tableSelection.call(wrapper.vm, table)

beforeEach(() => {
vi.clearAllMocks()
mocks.tablesStore.isLoading = false
mocks.tablesStore.tableSelection = readings
mocks.tablesStore.selectedTable = { schema, payload: { safe: [{ col: 1 }], total: 1 } }
})

test('shows a loading indicator while the columns of a table are not known yet', () => {
mocks.tablesStore.isLoading = true
mocks.tablesStore.selectedTable = { name: 'readings' }
const wrapper = mountRowsList()
expect(wrapper.find('[data-el="table-loading"]').exists()).toBe(true)
expect(wrapper.text()).not.toContain("There doesn't seem to be anything here!")
})

test('shows skeleton rows under the headers while the rows are loading', () => {
mocks.tablesStore.isLoading = true
const wrapper = mountRowsList()
expect(wrapper.find('thead').text()).toContain('id')
expect(wrapper.findAll('.ff-data-table--skeleton-row').length).toBeGreaterThan(0)
})

test('says there is nothing to show only once loading is done', () => {
mocks.tablesStore.selectedTable = { name: 'readings' }
const wrapper = mountRowsList()
expect(wrapper.find('[data-el="table-loading"]').exists()).toBe(false)
expect(wrapper.text()).toContain("There doesn't seem to be anything here!")
})

test('is loading from the moment a table is picked until its rows are in', async () => {
const wrapper = mountRowsList()
selectTable(wrapper, readings)
expect(mocks.tablesStore.setTableLoadingState.mock.calls).toEqual([[true]])
await flushPromises()
expect(mocks.tablesStore.getTableSchema).toHaveBeenCalledTimes(1)
expect(mocks.tablesStore.getTableData).toHaveBeenCalledTimes(1)
expect(mocks.tablesStore.setTableLoadingState.mock.calls).toEqual([[true], [false]])
})

test('stops loading when the table fails to load', async () => {
mocks.tablesStore.getTableSchema.mockRejectedValueOnce(new Error('nope'))
const wrapper = mountRowsList()
selectTable(wrapper, readings)
await flushPromises()
expect(mocks.tablesStore.setTableLoadingState.mock.calls).toEqual([[true], [false]])
})

test('stays loading when another table was picked before this one finished', async () => {
const wrapper = mountRowsList()
selectTable(wrapper, { name: 'orders', dbSchema: 'public' })
await flushPromises()
expect(mocks.tablesStore.setTableLoadingState.mock.calls).toEqual([[true]])
})
})
})
Loading