From 56fe3ce6feeeb4c0ebcf6dacad8340931195f3df Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 13:40:52 +0100 Subject: [PATCH] Type sort store --- .../components/grid/stores/datasources/viewV2.ts | 2 +- .../src/components/grid/stores/index.ts | 4 ++-- .../src/components/grid/stores/sort.ts | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index 71c22e6866..6a788d3ec6 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -173,7 +173,7 @@ export const initialise = (context: StoreContext) => { await datasource.actions.saveDefinition({ ...$view, sort: { - field: $sort.column, + field: $sort.column!, order: $sort.order || SortOrder.ASCENDING, }, }) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index d55002186f..8a4d40976d 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -95,7 +95,6 @@ export type Store = BaseStore & Clipboard.Store & Scroll.Store & { // TODO while typing the rest of stores - sort: Writable subscribe: any dispatch: (event: string, data: any) => any width: Writable @@ -108,7 +107,8 @@ export type Store = BaseStore & Conditions.Store & Cache.Store & Viewport.Store & - Notifications.Store + Notifications.Store & + Sort.Store export const attachStores = (context: Store): Store => { // Atomic store creation diff --git a/packages/frontend-core/src/components/grid/stores/sort.ts b/packages/frontend-core/src/components/grid/stores/sort.ts index 474de59e7b..ab58d7dabe 100644 --- a/packages/frontend-core/src/components/grid/stores/sort.ts +++ b/packages/frontend-core/src/components/grid/stores/sort.ts @@ -1,9 +1,18 @@ -import { derived, get } from "svelte/store" +import { derived, get, Writable } from "svelte/store" import { memo } from "../../../utils" import { SortOrder } from "@budibase/types" import { Store as StoreContext } from "." -export const createStores = (context: StoreContext) => { +interface SortStore { + sort: Writable<{ + column: string | null | undefined + order: SortOrder + }> +} + +export type Store = SortStore + +export const createStores = (context: StoreContext): SortStore => { const { props } = context const $props = get(props)