@adminforth/quick-filters 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -53,18 +53,19 @@ export default class extends AdminForthPlugin {
53
53
  }
54
54
  });
55
55
  const normalizeFilterValue = (filters) => {
56
- var _a, _b;
56
+ var _a, _b, _c, _d;
57
57
  const filtersToReturn = [];
58
- for (const filter of filters) {
59
- if (filter.field.startsWith('_universal_search_')) {
58
+ const normalizedFilters = Array.isArray(filters) ? filters : [];
59
+ for (const filter of normalizedFilters) {
60
+ if ((_a = filter.field) === null || _a === void 0 ? void 0 : _a.startsWith('_universal_search_')) {
60
61
  const searchTerm = filter.value;
61
62
  if (!searchTerm)
62
63
  continue;
63
64
  const searchFieldName = filter.field.replace('_universal_search_', '');
64
- const filterFromSearch = ((_b = (_a = this.options.filters.find(f => f.name === searchFieldName)) === null || _a === void 0 ? void 0 : _a.searchInput) === null || _b === void 0 ? void 0 : _b.call(_a, searchTerm)) || { field: searchFieldName, operator: AdminForthFilterOperators.EQ, value: searchTerm };
65
+ const filterFromSearch = ((_c = (_b = this.options.filters.find(f => f.name === searchFieldName)) === null || _b === void 0 ? void 0 : _b.searchInput) === null || _c === void 0 ? void 0 : _c.call(_b, searchTerm)) || { field: searchFieldName, operator: AdminForthFilterOperators.EQ, value: searchTerm };
65
66
  filtersToReturn.push(filterFromSearch);
66
67
  }
67
- else if (filter.field.startsWith('_qf_')) {
68
+ else if ((_d = filter.field) === null || _d === void 0 ? void 0 : _d.startsWith('_qf_')) {
68
69
  const quickFilter = this.options.filters.find(f => `_qf_${f.name}` === filter.field);
69
70
  if (quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.enum) {
70
71
  const enumOption = quickFilter.enum.find(e => e.label === filter.value);
package/index.ts CHANGED
@@ -51,14 +51,15 @@ export default class extends AdminForthPlugin {
51
51
 
52
52
  const normalizeFilterValue = (filters: any[]) => {
53
53
  const filtersToReturn = [];
54
- for (const filter of filters) {
55
- if (filter.field.startsWith('_universal_search_')) {
54
+ const normalizedFilters = Array.isArray(filters) ? filters : [];
55
+ for (const filter of normalizedFilters) {
56
+ if (filter.field?.startsWith('_universal_search_')) {
56
57
  const searchTerm = filter.value as string;
57
58
  if (!searchTerm) continue;
58
59
  const searchFieldName = filter.field.replace('_universal_search_', '');
59
60
  const filterFromSearch = this.options.filters.find(f => f.name === searchFieldName)?.searchInput?.(searchTerm) || { field: searchFieldName, operator: AdminForthFilterOperators.EQ, value: searchTerm };
60
61
  filtersToReturn.push(filterFromSearch);
61
- } else if (filter.field.startsWith('_qf_')) {
62
+ } else if (filter.field?.startsWith('_qf_')) {
62
63
  const quickFilter = this.options.filters.find(f => `_qf_${f.name}` === filter.field);
63
64
  if (quickFilter?.enum) {
64
65
  const enumOption = quickFilter.enum.find(e => e.label === filter.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/quick-filters",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "typescript": "^5.7.3"
22
22
  },
23
23
  "peerDependencies": {
24
- "adminforth": "^2.24.0"
24
+ "adminforth": "^2.30.0"
25
25
  },
26
26
  "release": {
27
27
  "plugins": [
package/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Filters, type IAdminForthSingleFilter, type IAdminForthAndOrFilter } from "adminforth"
1
+ import { Filters, type IAdminForthSingleFilter, type IAdminForthAndOrFilter, type PluginsCommonOptions } from "adminforth"
2
2
  interface IFilter {
3
3
  name: string;
4
4
  icon?: string;
@@ -9,6 +9,6 @@ interface IFilter {
9
9
  }[];
10
10
  searchInput?: (searchVal: string) => IAdminForthSingleFilter | IAdminForthAndOrFilter | Promise<IAdminForthSingleFilter | IAdminForthAndOrFilter>;
11
11
  }
12
- export interface PluginOptions {
12
+ export interface PluginOptions extends PluginsCommonOptions {
13
13
  filters: IFilter[]
14
14
  }