@kronor/dtv 13.0.1 → 13.0.3

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.
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { DataTable } from 'primereact/datatable';
3
- import { type ColumnDefinition } from '../framework/column-definition';
3
+ import type { ColumnDefinition } from '../framework/column-definition';
4
4
  import { NoRowsComponent, RowExpansionDefinition, type SimplifiedRow } from '../framework/view';
5
5
  import { FilterState } from '../framework/state';
6
6
  import { type FlattenedDataRow } from '../framework/data';
@@ -0,0 +1,11 @@
1
+ export declare const COUNTRY_CODES: {
2
+ label: string;
3
+ value: string;
4
+ }[];
5
+ export declare const DEFAULT_CODE: string;
6
+ export declare function splitCountryCode(value: string): {
7
+ code: string | null;
8
+ number: string;
9
+ };
10
+ export declare function isQueryablePhoneNumber(value: string): boolean;
11
+ export declare function phoneFilterValue(code: string, number: string): string;
@@ -16,9 +16,16 @@
16
16
  * view authors have a single import site.
17
17
  */
18
18
  import type { ReactNode } from "react";
19
- import { type FieldQuery, type DataFromFieldQueriesForRowSafe, type FieldQueryForRowSafe, type TableColumnDefinition, type VirtualColumnDefinition, type CellRenderer, type CellRendererProps, type OrderableFieldPath, type TableColumnDefinitionFooter } from "../framework/column-definition";
19
+ import { type FieldQuery, type DataFromFieldQueriesForRowSafe, type FieldQueryForRowSafe, type TableColumnDefinition, type VirtualColumnDefinition, type CellRenderer, type CellRendererProps, type TableColumnDefinitionFooter } from "../framework/column-definition";
20
+ import * as Orderable from "../framework/orderable";
20
21
  import type { ColumnFieldValue, FieldColumnData, FieldColumnOrderBy, FieldColumnSelect, ValidateColumnFieldType } from "./columnTyping";
21
22
  export { valueQuery, objectQuery, arrayQuery, rowType } from "@kronor/hasura-graphql";
23
+ /**
24
+ * `orderBy: Orderable.notOrderable` declares a column that cannot be sorted. Without it, a
25
+ * column whose data is a single scalar field is sorted by that field — also when sorting by
26
+ * it is useless, as for a JSON field.
27
+ */
28
+ export * as Orderable from "../framework/orderable";
22
29
  /**
23
30
  * Creates a renderable table column definition for a view over `Row`.
24
31
  * Convenience wrapper around the underlying TableColumnDefinition type.
@@ -29,7 +36,7 @@ export declare function column<Row, const FieldQueries extends readonly FieldQue
29
36
  name: string;
30
37
  data: FieldQueries & readonly FieldQueryForRowSafe<Row>[];
31
38
  footer?: TableColumnDefinitionFooter;
32
- orderBy?: OrderableFieldPath<FieldQueries>;
39
+ orderBy?: Orderable.OrderableFieldPath<FieldQueries> | Orderable.NotOrderable;
33
40
  cellRenderer: CellRenderer<DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
34
41
  }): TableColumnDefinition<FieldQueries, DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
35
42
  /** The props a `fieldColumn` renderer gets: the usual ones, plus the field's value. */
@@ -64,7 +71,8 @@ type FieldCellRenderer<Value> = (props: FieldCellRendererProps<Value>) => ReactN
64
71
  * selected inside the field follows from that type: nothing for a scalar,
65
72
  * `select: { object: [...] }` for an object, `select: { list: [...] }` for a
66
73
  * list, each checked against it. `orderBy` names the field itself for a
67
- * scalar, or a scalar inside it for an object.
74
+ * scalar, or a scalar inside it for an object; `Orderable.notOrderable` keeps a scalar
75
+ * field's column from being sorted by it.
68
76
  *
69
77
  * The column puts the field on the row DTV hands out (`SimplifiedRow`) with the type
70
78
  * its renderer takes.
@@ -77,7 +85,7 @@ export declare function fieldColumn<Row, const Field extends string, Value = Col
77
85
  id?: string;
78
86
  name: string;
79
87
  footer?: TableColumnDefinitionFooter;
80
- orderBy?: NoInfer<FieldColumnOrderBy<Field, Value>>;
88
+ orderBy?: NoInfer<FieldColumnOrderBy<Field, Value>> | Orderable.NotOrderable;
81
89
  cellRenderer: FieldCellRenderer<Value>;
82
90
  } & NoInfer<FieldColumnSelect<Value>>): TableColumnDefinition<readonly FieldQuery[], FieldColumnData<Row, Field, NoInfer<Value>>>;
83
91
  /**
@@ -70,6 +70,32 @@ export type UndecodedFilterFormStateFor<F> = F extends {
70
70
  child: UndecodedFilterFormStateFor<Child>;
71
71
  } : never;
72
72
  type StateOf<P extends ViewProjection, Id extends keyof P['filters']> = UndecodedFilterFormStateFor<P['filters'][Id]>;
73
+ type OneValueControl = {
74
+ type: 'dropdown';
75
+ } | {
76
+ type: 'autocomplete';
77
+ multiple: false;
78
+ };
79
+ type ListControl = {
80
+ type: 'multiselect';
81
+ } | {
82
+ type: 'autocomplete';
83
+ multiple: true;
84
+ };
85
+ /** The comparison of a filter taking one value, and of the same filter taking a list of them. */
86
+ type ListComparison<One, List> = Same<One, List> extends true ? true : [One, List] extends ['equals', 'in'] | ['notEquals', 'notIn'] ? true : false;
87
+ /** Whether the filter `F` became `T` by taking a list of the values it took one of, on the same field. */
88
+ export type WrapsInList<F, T> = F extends {
89
+ kind: 'leaf';
90
+ cmp: infer FromCmp;
91
+ field: infer FromField;
92
+ control: OneValueControl;
93
+ } ? T extends {
94
+ kind: 'leaf';
95
+ cmp: infer ToCmp;
96
+ field: infer ToField;
97
+ control: ListControl;
98
+ } ? Same<FromField, ToField> extends true ? ListComparison<FromCmp, ToCmp> : false : false : false;
73
99
  /** A value a filter's items offer, when the snapshot has them; any value otherwise. */
74
100
  export type ItemValueOf<P extends ViewProjection, Id extends string> = P extends {
75
101
  items: infer Items;
@@ -101,6 +127,12 @@ export interface MigrationBuilder<From extends ViewProjection, To extends ViewPr
101
127
  mapOperators<Id extends FilterIdOf<From> & FilterIdOf<To>>(id: Id, map: {
102
128
  [O in Exclude<OperatorsOf<From['filters'][Id]>, OperatorsOf<To['filters'][Id]>>]: OperatorsOf<To['filters'][Id]> | null;
103
129
  }): MigrationOp;
130
+ /**
131
+ * The filter takes several values where it took one, on the same field: a dropdown became
132
+ * a multiselect, or an autocomplete `multiple` (comparing with `in` where it compared with
133
+ * `equals`). A value stored for it becomes a list of that value.
134
+ */
135
+ wrapInList<Id extends FilterIdOf<From> & FilterIdOf<To>>(id: Id & Check<WrapsInList<From['filters'][Id], To['filters'][Id]>, `wrapInList: "${Id}" did not go from one value to a list of them on the same field; use custom() or reset()`>): MigrationOp;
104
136
  /** Turn what is stored for `from` into a state of `to`, or `RESET`. */
105
137
  custom<A extends FilterIdOf<From>, B extends FilterIdOf<To>>(from: A, to: B, migrate: (state: StateOf<From, A>) => StateOf<To, B> | typeof RESET): MigrationOp;
106
138
  renameColumn<A extends ColumnIdOf<From>, B extends ColumnIdOf<To>>(from: A, to: B): MigrationOp;
@@ -9,10 +9,11 @@ import type { ColumnProps } from "primereact/column";
9
9
  import type { FilterState } from "./state";
10
10
  import type { FilterFormState } from "./filter-form-state";
11
11
  import type { FilterId } from "./filters";
12
+ import type * as Orderable from "./orderable";
12
13
  import type { FieldQuery } from "@kronor/hasura-graphql";
13
- import type { DataFromFieldQueriesSafe, OrderableFieldPath } from "@kronor/hasura-graphql";
14
- export type { OrderByConfig, FieldAlias, ValueQuery, ObjectQuery, ArrayQuery, Query, FieldQuery, OrderableFieldPath, DataFromQuery, DataFromFieldQuery, DataFromSelectionSet, DataFromFieldQueries, DataFromFieldQueriesSafe, DataFromQueryForRow, DataFromFieldQueryForRow, DataFromSelectionSetForRow, DataFromFieldQueriesForRow, DataFromFieldQueriesForRowSafe, ValueQueryForRow, ObjectQueryForRow, ArrayQueryForRow, QueryForRow, QueryForRowSafe, FieldAliasForRow, FieldQueryForRow, FieldQueryForRowSafe, ValidateFieldQueriesForRow, } from "@kronor/hasura-graphql";
15
- export { fieldAlias, getOrderableFieldPaths, orderByIsSelectedField } from "@kronor/hasura-graphql";
14
+ import type { DataFromFieldQueriesSafe } from "@kronor/hasura-graphql";
15
+ export type { OrderByConfig, FieldAlias, ValueQuery, ObjectQuery, ArrayQuery, Query, FieldQuery, DataFromQuery, DataFromFieldQuery, DataFromSelectionSet, DataFromFieldQueries, DataFromFieldQueriesSafe, DataFromQueryForRow, DataFromFieldQueryForRow, DataFromSelectionSetForRow, DataFromFieldQueriesForRow, DataFromFieldQueriesForRowSafe, ValueQueryForRow, ObjectQueryForRow, ArrayQueryForRow, QueryForRow, QueryForRowSafe, FieldAliasForRow, FieldQueryForRow, FieldQueryForRowSafe, ValidateFieldQueriesForRow, } from "@kronor/hasura-graphql";
16
+ export { fieldAlias } from "@kronor/hasura-graphql";
16
17
  export type CellRendererProps<Data extends object = Record<string, unknown>> = {
17
18
  data: Data;
18
19
  setFilterState: (updater: (currentState: FilterState) => FilterState) => void;
@@ -49,7 +50,7 @@ export type TableColumnDefinition<FieldQueries extends readonly FieldQuery[] = r
49
50
  data: FieldQueries;
50
51
  name: string;
51
52
  footer?: TableColumnDefinitionFooter;
52
- orderBy?: OrderableFieldPath<FieldQueries>;
53
+ orderBy?: Orderable.OrderableFieldPath<FieldQueries> | Orderable.NotOrderable;
53
54
  cellRenderer: CellRenderer<CellData>;
54
55
  };
55
56
  export type VirtualColumnDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[], Data extends object = DataFromFieldQueriesSafe<FieldQueries>> = {
@@ -63,4 +64,3 @@ export type VirtualColumnDefinition<FieldQueries extends readonly FieldQuery[] =
63
64
  rowData?: Data;
64
65
  };
65
66
  export type ColumnDefinition = TableColumnDefinition | VirtualColumnDefinition;
66
- export declare function getColumnOrderBy(column: TableColumnDefinition): string | undefined;
@@ -33,5 +33,11 @@ export declare const filterTransforms: {
33
33
  };
34
34
  };
35
35
  hasuraCustomOperator: import("../filters").ConditionOnlyTransform;
36
+ phoneNumber: {
37
+ toQuery: (input: unknown) => {
38
+ field?: import("../filters").FilterField;
39
+ value: FilterValue.FilterValue;
40
+ };
41
+ };
36
42
  };
37
43
  export declare const nativeRuntime: NativeRuntime;
@@ -0,0 +1,10 @@
1
+ import type { TableColumnDefinition } from "./column-definition";
2
+ export type { OrderableFieldPath } from "@kronor/hasura-graphql";
3
+ export { getOrderableFieldPaths, orderByIsSelectedField } from "@kronor/hasura-graphql";
4
+ export declare const notOrderable: {
5
+ readonly type: "notOrderable";
6
+ };
7
+ export type NotOrderable = typeof notOrderable;
8
+ export declare function isNotOrderable(orderBy: unknown): orderBy is NotOrderable;
9
+ /** The field a column orders by when its header is sorted, or undefined when it cannot be sorted. */
10
+ export declare function getColumnOrderBy(column: TableColumnDefinition): string | undefined;
@@ -28,6 +28,11 @@ export type MigrationOp = {
28
28
  readonly kind: 'mapOperators';
29
29
  readonly filterId: FilterId;
30
30
  readonly map: Readonly<Record<string, string | null>>;
31
+ }
32
+ /** The filter takes several values where it took one: a value stored for it becomes a list of that value. */
33
+ | {
34
+ readonly kind: 'wrapInList';
35
+ readonly filterId: FilterId;
31
36
  } | {
32
37
  readonly kind: 'custom';
33
38
  readonly from: FilterId;
@@ -1,4 +1,5 @@
1
1
  import { type FieldQuery, type FieldAlias } from './column-definition';
2
+ import * as Orderable from './orderable';
2
3
  import type { FilterControl, FilterExpr, FilterFieldGroup, FilterGroups } from './filters';
3
4
  import { View } from './view';
4
5
  import type { Runtime } from './runtime';
@@ -181,7 +182,7 @@ export type TableColumnDefinitionJson = {
181
182
  data: FieldQueryJson[];
182
183
  name: string;
183
184
  footer?: RuntimeReference;
184
- orderBy?: string;
185
+ orderBy?: string | Orderable.NotOrderable;
185
186
  cellRenderer: RuntimeReference;
186
187
  };
187
188
  export type VirtualColumnDefinitionJson = {
@@ -19,6 +19,7 @@ export type { FilterState } from '../framework/state';
19
19
  export type { CustomOperatorOption, FilterSchema, FilterField, FilterValueFormatter, FilterValueFormatContext, QueryTransformContext, SuggestionFetcher, TransformConditionResult } from '../framework/filters';
20
20
  export { TransformResult } from '../framework/filters';
21
21
  export * as FilterValue from '../framework/filterValue';
22
+ export * as Orderable from '../framework/orderable';
22
23
  export { FilterExpr } from '../dsl/filterExpr';
23
24
  export { FilterControl } from '../dsl/filterControl';
24
25
  export { CellRenderer } from '../dsl/cellRenderer';
@@ -48,6 +48,7 @@ Add additional docs here for transforms, custom filters, etc. as needed.
48
48
  - A table column with exactly one simple `valueQuery` automatically orders by that field.
49
49
  - For rendered or composite columns, set `orderBy` on the table column JSON to one of the scalar GraphQL fields selected by `data` to enable sorting.
50
50
  - `orderBy` may be a dot-separated path for nested order fields, such as `customer.profile.status`.
51
+ - A column that must not be sorted, although its data is a single `valueQuery`, sets `orderBy` to `{ "type": "notOrderable" }` (`orderBy: DTV.Orderable.notOrderable` in the DSL). A JSON field is the usual case: GraphQL can order by it, but the order means nothing, and a keyset-paginated export cannot page through it.
51
52
  - Users can order by one sortable header at a time. Clicking a sorted header a third time removes the header ordering.
52
53
  - A view's `staticOrdering` always applies: the sorted header leads and static entries trail it as tie-breakers, so an unsorted table orders by `staticOrdering` alone. An entry for the field the user sorted by is dropped, since their direction supersedes it. A unique `paginationKey` ordering closes the list.
53
54
 
@@ -94,6 +94,8 @@ accountColumn(InvoicesRowType, 'memo', 'Memo');
94
94
  (`orderBy: 'memo'`), or a scalar inside it for an object
95
95
  (`orderBy: 'arAccount.accountNr'`); a list cannot be ordered by. The path has
96
96
  to be one the selection includes, which is checked when the column is built.
97
+ `orderBy: Orderable.notOrderable` keeps a scalar field's column from being sorted by it,
98
+ as `column` does for a single `valueQuery`.
97
99
  - **Forwarding.** The field has to be a literal path, or a field branded as
98
100
  above. A plain `string`, or a helper's own `Field` that nothing has checked, is
99
101
  rejected, since nothing could check it. A helper that takes the field from its
@@ -126,7 +126,8 @@ writes `m.todo(…)` with the candidates in comments. **A `todo` does not type-c
126
126
  | Filter removed and exactly one added with the same definition, matching no other | `m.renameFilter(old, new)` |
127
127
  | Filters removed and added with the same definition, but not one to one | `m.todo` for each removed one (rename or drop) |
128
128
  | Filter removed and one added that its stored state fits, after a change | `m.todo` (`custom` rename, or drop) |
129
- | Filter gained/lost parts, or its control changed type | `m.reset(id)` |
129
+ | Filter takes a list of the values it took one of, on the same field (dropdown to multiselect, autocomplete to `multiple`; `equals` to `in`) | `m.wrapInList(id)` |
130
+ | Filter gained/lost parts, or its control changed type otherwise | `m.reset(id)` |
130
131
  | Filter's comparison or field changed | `m.todo` (keep or reset) |
131
132
  | Custom operators added / removed | `m.mapOperators(id, {})` / `m.todo` (map them) |
132
133
  | Column removed, none added / some added | `m.dropColumn(id)` / `m.todo` (rename or drop) |
@@ -142,6 +143,7 @@ writes `m.todo(…)` with the candidates in comments. **A `todo` does not type-c
142
143
  | `m.drop(id)` | The filter was removed. |
143
144
  | `m.mapValues(id, value => …)` | Stored values change, e.g. renamed enum values. Lists are mapped element by element; return `DROP` to remove one. Users are told about removed values. Where the snapshots have the filter's items, `value` is one of the older items (other stored values are left as they are) and the result has to be one of the newer ones (checked by the types, and by running it). |
144
145
  | `m.mapOperators(id, { old: 'new' \| null })` | Custom operators were removed (checked: every removed one is mapped). `null` clears what used it; users are told. |
146
+ | `m.wrapInList(id)` | The filter takes several values where it took one, on the same field (checked: a dropdown or single autocomplete became a multiselect or `multiple` one, comparing with `in` where it compared with `equals`). A stored value becomes a list of that value. |
145
147
  | `m.custom(from, to, state => … \| RESET)` | Anything else; `state` is typed by both snapshots. |
146
148
  | `m.renameColumn(from, to)`, `m.dropColumn(id)`, `m.resetSort(id)` | Columns. A stored sort by what a dropped column, or one given `resetSort`, sorted by is reset. |
147
149
 
@@ -181,6 +183,11 @@ are named in a notice.
181
183
  error is logged and the stored state of the changed filters is reset rather than misread. Columns
182
184
  are not compared at runtime (an instance may show a column only with some arguments); `check` does.
183
185
  - Shared links carry the view and revision they were made for, and are migrated too.
186
+ - A stored value that does not fit its filter's control after migrating — a list for a dropdown, a
187
+ record for a number — resets that filter rather than breaking the filter form. Users are told
188
+ where it was persisted or in a saved filter. One value where the control takes several (a multiselect, an autocomplete with `multiple`)
189
+ is read as a list of it, as `m.wrapInList` does. That covers data no migration reaches: data
190
+ written before a view's first snapshot, and links built by hand, which are read as revision 1.
184
191
 
185
192
  ## Known limits
186
193
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronor/dtv",
3
- "version": "13.0.1",
3
+ "version": "13.0.3",
4
4
  "description": "Schema-driven, declarative table views with advanced filtering, data fetching and AI-assisted filter generation.",
5
5
  "repository": {
6
6
  "type": "git",