@xh/hoist 80.0.0-SNAPSHOT.1767974090726 → 80.0.0-SNAPSHOT.1767982629403

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/types/cmp/filter/FilterChooserFieldSpec.d.ts +1 -1
  3. package/build/types/cmp/filter/FilterChooserModel.d.ts +19 -10
  4. package/build/types/cmp/grid/filter/GridFilterFieldSpec.d.ts +4 -3
  5. package/build/types/cmp/grid/filter/GridFilterModel.d.ts +1 -1
  6. package/build/types/data/Store.d.ts +5 -6
  7. package/build/types/data/cube/View.d.ts +5 -3
  8. package/build/types/data/filter/BaseFilterFieldSpec.d.ts +3 -3
  9. package/build/types/data/filter/CompoundFilter.d.ts +1 -1
  10. package/build/types/data/filter/FieldFilter.d.ts +1 -1
  11. package/build/types/data/filter/Filter.d.ts +3 -3
  12. package/build/types/data/filter/FunctionFilter.d.ts +1 -1
  13. package/build/types/data/filter/Types.d.ts +39 -13
  14. package/build/types/desktop/cmp/grid/impl/filter/headerfilter/values/ValuesTabModel.d.ts +2 -2
  15. package/build/types/svc/InspectorService.d.ts +2 -2
  16. package/cmp/filter/FilterChooserFieldSpec.ts +5 -22
  17. package/cmp/filter/FilterChooserModel.ts +27 -12
  18. package/cmp/grid/filter/GridFilterFieldSpec.ts +52 -51
  19. package/cmp/grid/filter/GridFilterModel.ts +6 -7
  20. package/data/Store.ts +47 -13
  21. package/data/cube/View.ts +14 -3
  22. package/data/filter/BaseFilterFieldSpec.ts +3 -3
  23. package/data/filter/CompoundFilter.ts +3 -3
  24. package/data/filter/FieldFilter.ts +2 -2
  25. package/data/filter/Filter.ts +4 -4
  26. package/data/filter/FunctionFilter.ts +2 -2
  27. package/data/filter/Types.ts +53 -20
  28. package/desktop/cmp/grid/impl/filter/headerfilter/values/ValuesTabModel.ts +9 -9
  29. package/package.json +1 -1
  30. package/svc/InspectorService.ts +6 -5
  31. package/tsconfig.tsbuildinfo +1 -1
@@ -117,11 +117,11 @@ export class GridFilterModel extends HoistModel {
117
117
  return this.fieldSpecs.find(it => it.field === field);
118
118
  }
119
119
 
120
- toDisplayValue(value) {
120
+ toDisplayValue(value: any): any {
121
121
  return isNil(value) || value === '' ? GridFilterModel.BLANK_PLACEHOLDER : value;
122
122
  }
123
123
 
124
- fromDisplayValue(value) {
124
+ fromDisplayValue(value: any): any {
125
125
  return value === GridFilterModel.BLANK_PLACEHOLDER ? null : value;
126
126
  }
127
127
 
@@ -135,7 +135,7 @@ export class GridFilterModel extends HoistModel {
135
135
  this.dialogOpen = false;
136
136
  }
137
137
 
138
- setFilter(filter) {
138
+ setFilter(filter: Filter) {
139
139
  wait()
140
140
  .then(() => this.bind.setFilter(filter))
141
141
  .linkTo(this.gridModel.filterTask);
@@ -161,11 +161,10 @@ export class GridFilterModel extends HoistModel {
161
161
  });
162
162
  }
163
163
 
164
- private getOuterCompoundFilter(filter, field) {
165
- if (!filter?.isCompoundFilter) return null;
164
+ private getOuterCompoundFilter(filter: Filter, field: string) {
165
+ if (!CompoundFilter.isCompoundFilter(filter)) return null;
166
166
 
167
- // This is the outer compound filter if all its children
168
- // are FieldFilters on the matching field.
167
+ // This is the outer compound filter if all children are FieldFilters on the matching field.
169
168
  if (every(filter.filters, {field})) {
170
169
  return filter;
171
170
  }
package/data/Store.ts CHANGED
@@ -6,6 +6,18 @@
6
6
  */
7
7
 
8
8
  import {HoistBase, managed, PlainObject, Some, XH} from '@xh/hoist/core';
9
+ import {
10
+ Field,
11
+ FieldSpec,
12
+ Filter,
13
+ FilterBindTarget,
14
+ FilterLike,
15
+ FilterValueSource,
16
+ parseFilter,
17
+ StoreRecord,
18
+ StoreRecordId,
19
+ StoreRecordOrId
20
+ } from '@xh/hoist/data';
9
21
  import {action, computed, makeObservable, observable} from '@xh/hoist/mobx';
10
22
  import {logWithDebug, throwIf, warnIf} from '@xh/hoist/utils/js';
11
23
  import equal from 'fast-deep-equal';
@@ -13,6 +25,7 @@ import {
13
25
  castArray,
14
26
  defaultsDeep,
15
27
  differenceBy,
28
+ first,
16
29
  flatMapDeep,
17
30
  isArray,
18
31
  isEmpty,
@@ -20,21 +33,15 @@ import {
20
33
  isNil,
21
34
  isNull,
22
35
  isString,
23
- values,
36
+ partition,
24
37
  remove as lodashRemove,
25
- uniq,
26
- first,
27
38
  some,
28
- partition
39
+ uniq,
40
+ values
29
41
  } from 'lodash';
30
- import {Field, FieldSpec} from './Field';
31
- import {parseFilter} from './filter/Utils';
42
+ import {instanceManager} from '../core/impl/InstanceManager';
32
43
  import {RecordSet} from './impl/RecordSet';
33
44
  import {StoreErrorMap, StoreValidator} from './impl/StoreValidator';
34
- import {StoreRecord, StoreRecordId, StoreRecordOrId} from './StoreRecord';
35
- import {instanceManager} from '../core/impl/InstanceManager';
36
- import {Filter} from './filter/Filter';
37
- import {FilterLike} from './filter/Types';
38
45
 
39
46
  export interface StoreConfig {
40
47
  /** Field names, configs, or instances. */
@@ -181,11 +188,13 @@ export type StoreRecordIdSpec = string | ((data: PlainObject) => StoreRecordId);
181
188
  /**
182
189
  * A managed and observable set of local, in-memory Records.
183
190
  */
184
- export class Store extends HoistBase {
185
- get isStore() {
186
- return true;
191
+ export class Store extends HoistBase implements FilterBindTarget, FilterValueSource {
192
+ static isStore(obj: unknown): obj is Store {
193
+ return obj instanceof Store;
187
194
  }
188
195
 
196
+ readonly isFilterValueSource = true;
197
+
189
198
  fields: Field[] = null;
190
199
  idSpec: (data: PlainObject) => StoreRecordId;
191
200
  processRawData: (raw: any) => any;
@@ -811,6 +820,31 @@ export class Store extends HoistBase {
811
820
  return !this.getById(id, true) && !!this.getById(id, false);
812
821
  }
813
822
 
823
+ getValuesForFieldFilter(fieldName: string, filter?: Filter): any[] {
824
+ const field = this.getField(fieldName);
825
+ if (!field) return [];
826
+
827
+ let recs = this.allRecords;
828
+ if (filter) {
829
+ const testFn = filter.getTestFn(this);
830
+ recs = recs.filter(testFn);
831
+ }
832
+
833
+ const ret = new Set();
834
+ recs.forEach(rec => {
835
+ const val = rec.get(fieldName);
836
+ if (!isNil(val)) {
837
+ if (field.type === 'tags') {
838
+ val.forEach(it => ret.add(it));
839
+ } else {
840
+ ret.add(val);
841
+ }
842
+ }
843
+ });
844
+
845
+ return Array.from(ret);
846
+ }
847
+
814
848
  /**
815
849
  * Set whether the root should be loaded as summary data in loadData().
816
850
  */
package/data/cube/View.ts CHANGED
@@ -10,7 +10,9 @@ import {
10
10
  Cube,
11
11
  CubeField,
12
12
  Filter,
13
+ FilterBindTarget,
13
14
  FilterLike,
15
+ FilterValueSource,
14
16
  Query,
15
17
  QueryConfig,
16
18
  Store,
@@ -64,11 +66,13 @@ export interface DimensionValue {
64
66
  * Primary interface for consuming grouped and aggregated data from the cube.
65
67
  * Applications should create via the {@link Cube.createView} factory.
66
68
  */
67
- export class View extends HoistBase {
68
- get isView() {
69
- return true;
69
+ export class View extends HoistBase implements FilterBindTarget, FilterValueSource {
70
+ static isView(obj: unknown): obj is View {
71
+ return obj instanceof View;
70
72
  }
71
73
 
74
+ readonly isFilterValueSource = true;
75
+
72
76
  /** Query defining this View. Update via {@link updateQuery}. */
73
77
  @observable.ref
74
78
  query: Query = null;
@@ -222,6 +226,13 @@ export class View extends HoistBase {
222
226
  }
223
227
  }
224
228
 
229
+ //----------------------------
230
+ // FilterValueSource interface
231
+ //----------------------------
232
+ getValuesForFieldFilter(fieldName: string, filter?: Filter): any[] {
233
+ return this.cube.store.getValuesForFieldFilter(fieldName, filter);
234
+ }
235
+
225
236
  //------------------------
226
237
  // Implementation
227
238
  //------------------------
@@ -5,7 +5,7 @@
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
7
  import {HoistBase} from '@xh/hoist/core';
8
- import {Field, Store, FieldFilter, FieldType, genDisplayName, View} from '@xh/hoist/data';
8
+ import {Field, FieldFilter, FieldType, FilterValueSource, genDisplayName} from '@xh/hoist/data';
9
9
  import {compact, isArray, isEmpty} from 'lodash';
10
10
  import {FieldFilterOperator} from './Types';
11
11
 
@@ -19,7 +19,7 @@ export interface BaseFilterFieldSpecConfig {
19
19
  /** Operators available for filtering, will default to a supported set based on type.*/
20
20
  ops?: FieldFilterOperator[];
21
21
  /** Used to source matching data `Field` and extract values if configured. */
22
- source?: Store | View;
22
+ source?: FilterValueSource;
23
23
  /**
24
24
  * True to provide interfaces and auto-complete options
25
25
  * with enumerated matches for creating '=' or '!=' filters. Defaults to true for
@@ -47,7 +47,7 @@ export abstract class BaseFilterFieldSpec extends HoistBase {
47
47
  fieldType: FieldType;
48
48
  displayName: string;
49
49
  ops: FieldFilterOperator[];
50
- source: Store | View;
50
+ source: FilterValueSource;
51
51
  enableValues: boolean;
52
52
  forceSelection: boolean;
53
53
  values: any[];
@@ -17,8 +17,8 @@ import {CompoundFilterSpec, CompoundFilterOperator, FilterTestFn} from './Types'
17
17
  * Immutable.
18
18
  */
19
19
  export class CompoundFilter extends Filter {
20
- get isCompoundFilter() {
21
- return true;
20
+ static isCompoundFilter(obj: unknown): obj is CompoundFilter {
21
+ return obj instanceof CompoundFilter;
22
22
  }
23
23
 
24
24
  readonly filters: Filter[];
@@ -63,7 +63,7 @@ export class CompoundFilter extends Filter {
63
63
  other instanceof CompoundFilter &&
64
64
  other.op === this.op &&
65
65
  isEqualWith(other.filters, this.filters, (a, b) =>
66
- a.isFilter && b.isFilter ? a.equals(b) : undefined
66
+ Filter.isFilter(a) && Filter.isFilter(b) ? a.equals(b) : undefined
67
67
  )
68
68
  );
69
69
  }
@@ -36,8 +36,8 @@ import {FieldFilterOperator, FieldFilterSpec, FilterTestFn} from './Types';
36
36
  * Immutable.
37
37
  */
38
38
  export class FieldFilter extends Filter {
39
- get isFieldFilter() {
40
- return true;
39
+ static isFieldFilter(obj: unknown): obj is FieldFilter {
40
+ return obj instanceof FieldFilter;
41
41
  }
42
42
 
43
43
  readonly field: string;
@@ -5,8 +5,8 @@
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
7
 
8
- import {Store} from '../Store';
9
- import {FilterSpec, FilterTestFn} from './Types';
8
+ import {Store} from '@xh/hoist/data';
9
+ import type {FilterSpec, FilterTestFn} from './Types';
10
10
 
11
11
  /**
12
12
  * Base class for Hoist data package Filters.
@@ -20,8 +20,8 @@ import {FilterSpec, FilterTestFn} from './Types';
20
20
  * via an `AND` or `OR` operator.
21
21
  */
22
22
  export abstract class Filter {
23
- get isFilter() {
24
- return true;
23
+ static isFilter(obj: unknown): obj is Filter {
24
+ return obj instanceof Filter;
25
25
  }
26
26
 
27
27
  /**
@@ -19,8 +19,8 @@ import {FunctionFilterSpec, FilterTestFn} from './Types';
19
19
  * Immutable.
20
20
  */
21
21
  export class FunctionFilter extends Filter {
22
- get isFunctionFilter() {
23
- return true;
22
+ static isFunctionFilter(obj: unknown): obj is FunctionFilter {
23
+ return obj instanceof FunctionFilter;
24
24
  }
25
25
 
26
26
  readonly key: string;
@@ -5,17 +5,25 @@
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
7
 
8
- import {PlainObject} from '@xh/hoist/core';
9
- import {Filter} from './Filter';
10
- import {StoreRecord, Field, FieldType} from '../';
8
+ import type {PlainObject} from '@xh/hoist/core';
9
+ import type {Filter} from './Filter';
10
+ import type {StoreRecord, Field, FieldType} from '../';
11
11
 
12
- export type CompoundFilterOperator = 'AND' | 'OR' | 'and' | 'or';
13
- export interface CompoundFilterSpec {
14
- /** Collection of Filters or configs to create. */
15
- filters: FilterLike[];
12
+ export type FilterLike = Filter | FilterSpec | FilterTestFn | FilterLike[];
16
13
 
17
- /** logical operator 'AND' (default) or 'OR'. */
18
- op?: CompoundFilterOperator;
14
+ export type FilterSpec = FieldFilterSpec | FunctionFilterSpec | CompoundFilterSpec;
15
+
16
+ export interface FieldFilterSpec {
17
+ /** Name of Field to filter or Field instance. */
18
+ field: string | Field;
19
+
20
+ /** One of the supported operators to use for comparison. */
21
+ op: FieldFilterOperator;
22
+
23
+ value: any;
24
+
25
+ /** For internal serialization only. */
26
+ valueType?: FieldType;
19
27
  }
20
28
 
21
29
  export type FieldFilterOperator =
@@ -33,19 +41,17 @@ export type FieldFilterOperator =
33
41
  | 'not ends'
34
42
  | 'includes'
35
43
  | 'excludes';
36
- export interface FieldFilterSpec {
37
- /** Name of Field to filter or Field instance. */
38
- field: string | Field;
39
44
 
40
- /** One of the supported operators to use for comparison. */
41
- op: FieldFilterOperator;
42
-
43
- value: any;
45
+ export interface CompoundFilterSpec {
46
+ /** Collection of Filters or configs to create. */
47
+ filters: FilterLike[];
44
48
 
45
- /** For internal serialization only. */
46
- valueType?: FieldType;
49
+ /** logical operator 'AND' (default) or 'OR'. */
50
+ op?: CompoundFilterOperator;
47
51
  }
48
52
 
53
+ export type CompoundFilterOperator = 'AND' | 'OR' | 'and' | 'or';
54
+
49
55
  export interface FunctionFilterSpec {
50
56
  /** Key used to identify this FunctionFilter.*/
51
57
  key: string;
@@ -61,6 +67,33 @@ export interface FunctionFilterSpec {
61
67
  */
62
68
  export type FilterTestFn = (candidate: PlainObject | StoreRecord) => boolean;
63
69
 
64
- export type FilterSpec = FieldFilterSpec | FunctionFilterSpec | CompoundFilterSpec;
70
+ /**
71
+ * Target (typically a {@link Store} or Cube {@link View}) that can be used by filtering models
72
+ * such as {@link FilterChooserModel} and {@link GridFilterModel} to get and set filters.
73
+ */
74
+ export interface FilterBindTarget {
75
+ filter: Filter;
76
+ setFilter(filter: FilterLike): unknown;
77
+ }
65
78
 
66
- export type FilterLike = Filter | FilterSpec | FilterTestFn | FilterLike[];
79
+ /**
80
+ * Data provider (typically a {@link Store} or Cube {@link View}) that can be used by filtering
81
+ * models such as {@link FilterChooserModel} and {@link GridFilterModel} to source available
82
+ * values from within a dataset for display / suggestion to users.
83
+ */
84
+ export interface FilterValueSource {
85
+ /** Names of all fields available in the source. */
86
+ fieldNames: string[];
87
+ /** @returns the Field instance for the given field name. */
88
+ getField(fieldName: string): Field;
89
+ /** @returns unique values for the given field, applying the given filter if provided. */
90
+ getValuesForFieldFilter(fieldName: string, filter?: Filter): any[];
91
+ /** Observable timestamp for the source's data, to trigger consumers to re-query values. */
92
+ lastUpdated: number;
93
+ /** For the {@link isFilterValueSource} typeguard. */
94
+ isFilterValueSource: true;
95
+ }
96
+
97
+ export function isFilterValueSource(v: unknown): v is FilterValueSource {
98
+ return (v as any)?.isFilterValueSource === true;
99
+ }
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import {GridFilterModel, GridModel} from '@xh/hoist/cmp/grid';
8
8
  import {HoistModel, managed} from '@xh/hoist/core';
9
- import {FieldFilterSpec} from '@xh/hoist/data';
9
+ import type {FieldFilterOperator, FieldFilterSpec} from '@xh/hoist/data';
10
10
  import {checkbox} from '@xh/hoist/desktop/cmp/input';
11
11
  import {Icon} from '@xh/hoist/icon';
12
12
  import {action, bindable, computed, makeObservable, observable} from '@xh/hoist/mobx';
@@ -73,12 +73,12 @@ export class ValuesTabModel extends HoistModel {
73
73
  return this.fieldSpec.values;
74
74
  }
75
75
 
76
- get valueCount() {
77
- return this.fieldSpec.valueCount;
76
+ get allValuesCount() {
77
+ return this.fieldSpec.allValuesCount;
78
78
  }
79
79
 
80
80
  get hasHiddenValues() {
81
- return this.values.length < this.valueCount;
81
+ return this.values.length < this.allValuesCount;
82
82
  }
83
83
 
84
84
  get sortIcon() {
@@ -193,24 +193,24 @@ export class ValuesTabModel extends HoistModel {
193
193
  );
194
194
  }
195
195
 
196
- private getFilter() {
197
- const {gridFilterModel, pendingValues, values, valueCount, field} = this,
196
+ private getFilter(): FieldFilterSpec {
197
+ const {gridFilterModel, pendingValues, values, allValuesCount, field} = this,
198
198
  included = pendingValues.map(it => gridFilterModel.fromDisplayValue(it)),
199
199
  excluded = difference(values, pendingValues).map(it =>
200
200
  gridFilterModel.fromDisplayValue(it)
201
201
  );
202
202
 
203
- if (included.length === valueCount || excluded.length === valueCount) {
203
+ if (included.length === allValuesCount || excluded.length === allValuesCount) {
204
204
  return null;
205
205
  }
206
206
 
207
207
  const {fieldType} = this.headerFilterModel;
208
- let arr, op;
208
+ let arr: any[], op: FieldFilterOperator;
209
209
  if (fieldType === 'tags') {
210
210
  arr = included;
211
211
  op = 'includes';
212
212
  } else {
213
- const weight = valueCount <= 10 ? 2.5 : 1; // Prefer '=' for short lists
213
+ const weight = allValuesCount <= 10 ? 2.5 : 1; // Prefer '=' for short lists
214
214
  op = included.length > excluded.length * weight ? '!=' : '=';
215
215
  arr = op === '=' ? included : excluded;
216
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "80.0.0-SNAPSHOT.1767974090726",
3
+ "version": "80.0.0-SNAPSHOT.1767982629403",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",
@@ -5,6 +5,7 @@
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
7
  import {HoistService, managed, persist, XH} from '@xh/hoist/core';
8
+ import {Store} from '@xh/hoist/data';
8
9
  import {action, bindable, makeObservable, observable} from '@xh/hoist/mobx';
9
10
  import {wait} from '@xh/hoist/promise';
10
11
  import {Timer} from '@xh/hoist/utils/async';
@@ -59,8 +60,8 @@ export class InspectorService extends HoistService {
59
60
  @managed
60
61
  statsUpdateTimer: Timer;
61
62
 
62
- private _syncRun = 0;
63
- private _idToSyncRun = new Map();
63
+ private _syncRun: number = 0;
64
+ private _idToSyncRun = new Map<string, number>();
64
65
 
65
66
  constructor() {
66
67
  super();
@@ -196,7 +197,7 @@ export class InspectorService extends HoistService {
196
197
  created: inst._created,
197
198
  isHoistService: inst.isHoistService,
198
199
  isHoistModel: inst.isHoistModel,
199
- isStore: inst.isStore,
200
+ isStore: Store.isStore(inst),
200
201
  isLinked: inst.isLinked,
201
202
  isXhImpl: inst.xhImpl,
202
203
  hasLoadSupport: inst.loadSupport != null,
@@ -211,7 +212,7 @@ export class InspectorService extends HoistService {
211
212
  }
212
213
 
213
214
  @action
214
- setActiveInstances(ai) {
215
+ setActiveInstances(ai: InspectorInstanceData[]) {
215
216
  this.activeInstances = ai;
216
217
  }
217
218
 
@@ -229,7 +230,7 @@ export class InspectorService extends HoistService {
229
230
 
230
231
  interface InspectorInstanceData {
231
232
  className: string;
232
- created: Date;
233
+ created: number;
233
234
  isHoistModel: boolean;
234
235
  isHoistService: boolean;
235
236
  isStore: boolean;