Merge branch 'type-portal-backups-store' of github.com:Budibase/budibase into type-portal-email-store

This commit is contained in:
Andrew Kingston 2025-01-02 12:12:14 +00:00
commit 2345efe0c4
No known key found for this signature in database
3 changed files with 33 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import { it, expect, describe, beforeEach, vi } from "vitest" import { it, expect, describe, beforeEach, vi } from "vitest"
import { createBackupsStore } from "./backups" import { BackupStore } from "./backups"
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { API } from "@/api" import { API } from "@/api"
@ -33,7 +33,7 @@ describe("backups store", () => {
ctx.writableReturn = { update: vi.fn(), subscribe: vi.fn() } ctx.writableReturn = { update: vi.fn(), subscribe: vi.fn() }
writable.mockReturnValue(ctx.writableReturn) writable.mockReturnValue(ctx.writableReturn)
ctx.returnedStore = createBackupsStore() ctx.returnedStore = new BackupStore()
}) })
it("inits the writable store with the default config", () => { it("inits the writable store with the default config", () => {

View File

@ -6,7 +6,7 @@ interface BackupState {
selectedBackup?: string selectedBackup?: string
} }
class BackupStore extends BudiStore<BackupState> { export class BackupStore extends BudiStore<BackupState> {
constructor() { constructor() {
super({}) super({})
} }

View File

@ -151,6 +151,35 @@ export const initialise = (context: StoreContext) => {
}) })
) )
function sortHasChanged(
newSort: {
column: string | null | undefined
order: SortOrder
},
existingSort?: {
field: string
order?: SortOrder
}
) {
const newColumn = newSort.column ?? null
const existingColumn = existingSort?.field ?? null
if (newColumn !== existingColumn) {
return true
}
if (!newColumn) {
return false
}
const newOrder = newSort.order ?? null
const existingOrder = existingSort?.order ?? null
if (newOrder !== existingOrder) {
return true
}
return false
}
// 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 => {
@ -161,10 +190,7 @@ export const initialise = (context: StoreContext) => {
} }
// Skip if nothing actually changed // Skip if nothing actually changed
if ( if (!sortHasChanged($sort, $view.sort)) {
$sort?.column === $view.sort?.field &&
$sort?.order === $view.sort?.order
) {
return return
} }