From f6db307ebcff019c6b819919a01009494bbcac2d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 14:33:58 +0100 Subject: [PATCH] Use existing types --- .../src/components/grid/stores/filter.ts | 27 ++++++++++--------- packages/types/src/ui/stores/grid/filters.ts | 16 ++--------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/filter.ts b/packages/frontend-core/src/components/grid/stores/filter.ts index 3df28d22e1..36f6cd9483 100644 --- a/packages/frontend-core/src/components/grid/stores/filter.ts +++ b/packages/frontend-core/src/components/grid/stores/filter.ts @@ -1,21 +1,23 @@ import { get, derived, Writable, Readable } from "svelte/store" import { + ArrayOperator, + BasicOperator, FieldType, UIColumn, - UIFilter, - UIInlineFilter, + UILegacyFilter, UILogicalOperator, + UISearchFilter, } from "@budibase/types" import { Store as StoreContext } from "." import { memo } from "../../../utils/memo" export interface FilterStore { - filter: Writable - inlineFilters: Writable + filter: Writable + inlineFilters: Writable } export interface FilterDerivedStore { - allFilters: Readable + allFilters: Readable } export type Store = FilterStore & FilterDerivedStore @@ -42,7 +44,7 @@ export const deriveStores = (context: StoreContext): FilterDerivedStore => { if (!$inlineFilters?.length) { return $filter } - let allFilters = { + const allFilters: UISearchFilter = { logicalOperator: UILogicalOperator.ALL, groups: [ { @@ -51,12 +53,13 @@ export const deriveStores = (context: StoreContext): FilterDerivedStore => { }, ], } + // Just use inline if no filter if (!$filter?.groups?.length) { return allFilters } // Join them together if both - allFilters.groups = [...allFilters.groups, ...$filter.groups] + allFilters.groups = [...allFilters.groups!, ...$filter.groups] return allFilters } ) @@ -72,10 +75,10 @@ export const createActions = (context: StoreContext) => { const addInlineFilter = (column: UIColumn, value: string) => { const filterId = `inline-${column.name}` const type = column.schema.type - const inlineFilter: UIInlineFilter = { + const inlineFilter: UILegacyFilter = { field: column.name, id: filterId, - operator: "string", + operator: BasicOperator.STRING, valueType: "value", type, value, @@ -84,11 +87,11 @@ export const createActions = (context: StoreContext) => { // Add overrides specific so the certain column type if (type === FieldType.NUMBER) { inlineFilter.value = parseFloat(value) - inlineFilter.operator = "equal" + inlineFilter.operator = BasicOperator.EQUAL } else if (type === FieldType.BIGINT) { - inlineFilter.operator = "equal" + inlineFilter.operator = BasicOperator.EQUAL } else if (type === FieldType.ARRAY) { - inlineFilter.operator = "contains" + inlineFilter.operator = ArrayOperator.CONTAINS } inlineFilters.update($inlineFilters => { diff --git a/packages/types/src/ui/stores/grid/filters.ts b/packages/types/src/ui/stores/grid/filters.ts index cde922adc9..d75f32370c 100644 --- a/packages/types/src/ui/stores/grid/filters.ts +++ b/packages/types/src/ui/stores/grid/filters.ts @@ -1,17 +1,5 @@ -import { FieldType, UILogicalOperator } from "@budibase/types" +import { LegacyFilter } from "@budibase/types" -export interface UIFilter { - groups: { - logicalOperator: UILogicalOperator - filters: UIInlineFilter[] - }[] -} - -export interface UIInlineFilter { - field: string - type: FieldType - value: number | string - operator: string +export type UILegacyFilter = LegacyFilter & { id: string - valueType: string }