From 64f4497c76f768a4bcb1e314b789c57086508d18 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Sep 2024 11:02:00 +0200 Subject: [PATCH] Prevent flashed while sorting --- .../grid/stores/datasources/viewV2.js | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js index 425519d97e..360d7a0e1c 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.js @@ -120,25 +120,29 @@ export const initialise = context => { // When sorting changes, ensure view definition is kept up to date unsubscribers.push( 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 (get(config).canSaveSchema) { - // Ensure we're updating the correct view - const $view = get(definition) - if ($view?.id !== $datasource.id) { - return - } - if ( - $sort?.column !== $view.sort?.field || - $sort?.order !== $view.sort?.order - ) { - await datasource.actions.saveDefinition({ - ...$view, - sort: { - field: $sort.column, - order: $sort.order || "ascending", - }, - }) - } + await datasource.actions.saveDefinition({ + ...$view, + sort: { + field: $sort.column, + order: $sort.order || "ascending", + }, + }) } // Also update the fetch to ensure the new sort is respected.