Merge pull request #10848 from Budibase/fix/grid-data-type-swap

Reset rows and tick before updating schema when swapping table ID in grids
This commit is contained in:
Andrew Kingston 2023-06-22 08:18:24 +01:00 committed by GitHub
commit f5d8851dec
1 changed files with 11 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { writable, derived, get } from "svelte/store"
import { fetchData } from "../../../fetch/fetchData"
import { notifications } from "@budibase/bbui"
import { NewRowID, RowPageSize } from "../lib/constants"
import { tick } from "svelte"
const initialSortState = {
column: null,
@ -124,13 +125,22 @@ export const deriveStores = context => {
})
// Subscribe to changes of this fetch model
unsubscribe = newFetch.subscribe($fetch => {
unsubscribe = newFetch.subscribe(async $fetch => {
if ($fetch.loaded && !$fetch.loading) {
hasNextPage.set($fetch.hasNextPage)
const $instanceLoaded = get(instanceLoaded)
const resetRows = $fetch.resetKey !== lastResetKey
const previousResetKey = lastResetKey
lastResetKey = $fetch.resetKey
// If resetting rows due to a table change, wipe data and wait for
// derived stores to compute. This prevents stale data being passed
// to cells when we save the new schema.
if (!$instanceLoaded && previousResetKey) {
rows.set([])
await tick()
}
// Reset state properties when dataset changes
if (!$instanceLoaded || resetRows) {
table.set($fetch.definition)