Prevent flashed while sorting

This commit is contained in:
Adria Navarro 2024-09-27 11:02:00 +02:00
parent 3e294c3cb9
commit 64f4497c76
1 changed files with 21 additions and 17 deletions

View File

@ -120,25 +120,29 @@ export const initialise = context => {
// When sorting changes, ensure view definition is kept up to date // When sorting changes, ensure view definition is kept up to date
unsubscribers.push( unsubscribers.push(
sort.subscribe(async $sort => { sort.subscribe(async $sort => {
// Ensure we're updating the correct view
const $view = get(definition)
if ($view?.id !== $datasource.id) {
return
}
// Skip if nothing actually changed
if (
$sort?.column === $view.sort?.field &&
$sort?.order === $view.sort?.order
) {
return
}
// If we can mutate schema then update the view definition // If we can mutate schema then update the view definition
if (get(config).canSaveSchema) { if (get(config).canSaveSchema) {
// Ensure we're updating the correct view await datasource.actions.saveDefinition({
const $view = get(definition) ...$view,
if ($view?.id !== $datasource.id) { sort: {
return field: $sort.column,
} order: $sort.order || "ascending",
if ( },
$sort?.column !== $view.sort?.field || })
$sort?.order !== $view.sort?.order
) {
await datasource.actions.saveDefinition({
...$view,
sort: {
field: $sort.column,
order: $sort.order || "ascending",
},
})
}
} }
// Also update the fetch to ensure the new sort is respected. // Also update the fetch to ensure the new sort is respected.