Merge branch 'type-portal-backups-store' of github.com:Budibase/budibase into type-portal-email-store
This commit is contained in:
commit
2345efe0c4
|
@ -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", () => {
|
||||||
|
|
|
@ -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({})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue