|
23 | 23 | */ |
24 | 24 |
|
25 | 25 | import { Page, Editor, Component } from 'grapesjs' |
26 | | -import { DataSourceId, IDataSource, Expression, StateId, StoredToken, Token, Field, Context, TypeId } from './types' |
| 26 | +import { DataSourceId, IDataSource, Expression, StateId, StoredToken, Token, Field, Context, TypeId, Filter } from './types' |
27 | 27 |
|
28 | 28 | // Internal imports |
29 | 29 | import { getPageQuery as getPageQueryInternal, buildPageQueries as buildPageQueriesInternal } from './model/queryBuilder' |
@@ -224,6 +224,25 @@ export function getExpressionResultType(expression: Expression, component: Compo |
224 | 224 | return getExpressionResultTypeInternal(expression, component, dataTree) |
225 | 225 | } |
226 | 226 |
|
| 227 | +export function addFilters(filters: Filter | Filter[]) { |
| 228 | + const dataTree = getDataTreeInternal() |
| 229 | + dataTree.filters = dataTree.filters.concat(filters) |
| 230 | +} |
| 231 | + |
| 232 | +/** |
| 233 | + * Remove filters from the data tree. |
| 234 | + * Accepts a single Filter or an array of Filters. |
| 235 | + * Removes by reference. |
| 236 | + */ |
| 237 | +export function removeFilters(filters: Filter | Filter[]) { |
| 238 | + const dataTree = getDataTreeInternal() |
| 239 | + if (Array.isArray(filters)) { |
| 240 | + dataTree.filters = dataTree.filters.filter(f => !filters.includes(f)) |
| 241 | + } else { |
| 242 | + dataTree.filters = dataTree.filters.filter(f => f !== filters) |
| 243 | + } |
| 244 | +} |
| 245 | + |
227 | 246 | // =============================== |
228 | 247 | // STATE MANAGEMENT |
229 | 248 | // =============================== |
|
0 commit comments