@gridsay/mui-x-data-grid 0.1.0 → 1.1.0

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/README.md CHANGED
@@ -8,8 +8,37 @@ current view with each question, and checks every answer before the grid applies
8
8
  npm install @gridsay/mui-x-data-grid
9
9
  ```
10
10
 
11
- Peer dependency: `@mui/x-data-grid-premium` 9.18 or a later 9.x release (`^9.18.0`); other major
12
- versions are not tested. Data Grid Premium is a commercial MUI package: you need your own MUI X licence, and the grid shows MUI's watermark without one.
11
+ MUI X Data Grid Premium is MUI's commercial product, not part of Gridsay's service. This helper is
12
+ compatible with it: peer dependency `@mui/x-data-grid-premium` 9.18 or a later 9.x release
13
+ (`^9.18.0`), tested with 9.18.0; other major versions are not tested. In a project on another
14
+ version, such as 9.17 or a future 10.x, npm 7 and later stop the install with an `ERESOLVE` error, and so does pnpm with strict peer dependencies on; otherwise pnpm and yarn warn. Earlier versions, 9.17 included, are not supported. You need your own MUI X Premium licence; without one, MUI shows its
15
+ watermark.
16
+
17
+ ## What leaves the browser
18
+
19
+ With every question, the resolver posts to your `url`:
20
+
21
+ - the question and the conversation id;
22
+ - the column context the grid builds: each column's field, description, type and filter
23
+ operators, and the columns the grid derives for pivoting. Pivoting on a column turns that column's values into column names (pivot on an id column, and the ids become column names), and the grid puts these names in its context even with data sampling off; the helper's own description leaves them out. Of any option list in this context, the helper sends only the first 500 options, and of each only its value and label, when its value is text, a number or a boolean; an option with any other value is left out and still counts toward the 500. Example values go only if you turn on
24
+ the grid's `allowAiAssistantDataSampling` (the grid then picks values from random rows) or write
25
+ `examples` on a column;
26
+ - with `apiRef`, the grid as it is now: the features you switched off (filtering, sorting,
27
+ grouping, aggregation, pivoting, selection, and charts when no chart is active); per column,
28
+ the limits you set (`filterable`, `sortable`, `groupable`, `pivotable` or `aggregable` set to `false`, and the names in `availableAggregationFunctions` as you wrote them); for `singleSelect` and `multiSelect` columns
29
+ only, the value and label of each of the first 500 options, the same whether data sampling is
30
+ on or off; and the filters (with the values typed or picked in them, when they are text, numbers, booleans or dates), sorting, grouping,
31
+ aggregation and pivot. With showing and hiding columns switched on (see
32
+ [below](#showing-and-hiding-columns)), also, of the columns a question can show or hide, those
33
+ set to `hideable: false` and those hidden now;
34
+ - `additionalContext`, `privateMode` and `referenceId`, when you set them;
35
+ - in the headers: always `content-type: application/json` (your own `headers` can replace it),
36
+ then your own `headers`, `x-api-key` when you set `publishableKey`, and
37
+ `Authorization: Bearer …` with the end user's token when you set `getToken`.
38
+ The helper calls `fetch` with its default credentials mode, so the browser adds your cookies
39
+ only when `url` is on the page's own origin.
40
+
41
+ The helper sends no rows, row ids or selection of its own.
13
42
 
14
43
  ## Usage
15
44
 
@@ -44,30 +73,34 @@ from the browser, pass that URL with a `publishableKey` and `getToken`; see
44
73
  | Option | Meaning |
45
74
  |---|---|
46
75
  | `url` | Required. Where the prompt is posted: your own route, or the Gridsay gateway. |
47
- | `apiRef` | The grid's `apiRef`. With it, the helper describes the grid to the server and adapts answers to it. Without it, you still get answer checking and readable errors. |
76
+ | `apiRef` | The grid's `apiRef`. With it, the helper describes the grid to the server and adapts answers to it. Without it, you still get answer checking and readable errors, but the helper cannot see the grid: an answer that leaves pivot mode can be overwritten (see [Versioning](#versioning)). With controlled state, such as `filterModel`, update it from the grid's change callbacks, or the panel reports answers the grid does not show. |
48
77
  | `headers` | An object, or a function returning one (it may be async), added to each request. |
49
78
  | `publishableKey` | A publishable key, sent as `x-api-key`. For calling the gateway from the browser. |
50
79
  | `getToken` | Returns your end user's token, called for every request and sent as `Authorization: Bearer …`. If it throws or returns nothing (`null`, `undefined` or `''`, at once or from a promise), the prompt fails with "Sign in to use the assistant." (`unauthenticated_user`) and nothing is sent. |
51
80
  | `additionalContext`, `privateMode`, `referenceId` | Sent in the request's `options`, as the stock resolver sends them. |
81
+ | `features` | Abilities that are off unless you switch them on. `{ columnVisibility: true }` lets questions show and hide columns; see [Showing and hiding columns](#showing-and-hiding-columns). |
52
82
 
53
83
  ## Errors
54
84
 
55
85
  The resolver rejects with a `GridsayError`; the grid shows its `message` to your user as it is.
56
86
  To log why, wrap the resolver and read the error's `code`, `status`, `retryAfter` and `detail`.
57
87
  `code` is the gateway's (such as `quota_exceeded` or `rate_limited`) or one of the helper's own,
58
- below. Compare codes, never messages: the messages may change.
88
+ below. Compare codes, never messages: the messages may be reworded in a minor release. A code
89
+ the helper does not know, such as one the gateway adds later, arrives as it is, with the
90
+ gateway's `status` and sentence.
59
91
 
60
92
  The helper's own failures, each code exported as `<NAME>_CODE` beside its sentence:
61
93
 
62
94
  | `code` | Sentence | When |
63
95
  |---|---|---|
64
96
  | `unauthenticated_user` | `UNAUTHENTICATED_USER`: "Sign in to use the assistant." (or your route's own sentence) | `getToken` threw or returned nothing (nothing was sent), or the response was a 401 whose body names no other code. The same code the gateway sends. |
65
- | `unexpected_error` | `INVALID_ANSWER`: "The assistant couldn't complete your request. Try again." | Your `headers` function threw. The user sees this sentence, never the text of what it threw; the original is in `cause`. |
97
+ | `unexpected_error` | `INVALID_ANSWER`: "The assistant couldn't complete your request. Try again." | Your `headers` function threw, or something failed unexpectedly while the helper prepared the request or the answer; the original is in `cause`. The user sees this sentence, never the text of what was thrown. |
66
98
  | `connection_failed` | `CONNECTION_FAILED`: "The connection was interrupted. Try again." | The request got no answer, or the answer was cut off. |
67
99
  | `not_json` | `NOT_JSON`: "The assistant couldn't respond. Try again." | The response was not JSON (a 401 is `unauthenticated_user` instead). `status` 404 usually means `url` is wrong. |
68
100
  | `invalid_answer` | `INVALID_ANSWER` | The response was not an answer the helper can read, or an error without a sentence of its own. |
101
+ | `cannot_apply` | `INVALID_ANSWER` | An answer that shows or hides columns could not be applied: a column it changes was removed or locked while the question was out, the grid was in pivot mode by the time it came, or the grid did not take the change (what it threw is in `cause`). The grid gets nothing else of that answer. After a throw the helper tries once to put the columns back; if that fails too, the columns can stay as the answer set them, in part or in whole. |
69
102
 
70
- An error from the gateway keeps the gateway's own code, `status`, `retryAfter` and `detail`.
103
+ An error from the gateway keeps the gateway's own code, `status`, `retryAfter` and `detail`; a 401 that names no code keeps its sentence, `status` and `detail` but not `retryAfter`.
71
104
 
72
105
  ## What changes compared with the stock resolver
73
106
 
@@ -79,38 +112,235 @@ An error from the gateway keeps the gateway's own code, `status`, `retryAfter` a
79
112
  - **Answers are checked before the grid touches them.** A malformed answer leaves the grid as it
80
113
  was. End users see short messages instead of browser errors
81
114
  (see Errors). Messages from the server are shown as they are.
82
- - **Top N works.** Asking for more rows than exist, or for rows spread over several pages, selects
83
- the rows that exist. With a data source, selection waits for the new rows.
115
+ - **Top N selects rows that exist.** Asking for more rows than exist, or for rows spread over
116
+ several pages, selects the rows that exist. With a data source, selection waits for the grid to
117
+ announce the new rows, and selects nothing if it does not within 15 seconds.
84
118
  - **Sorting a grouped column reorders the groups.** The sort is moved to the grouping column the
85
119
  grid generates (single or multiple grouping-column mode); other sorts are kept.
86
120
  - **Leaving pivot mode** no longer brings back the grouping and aggregation from before the pivot.
87
121
  - **A chart follow-up** keeps the aggregation it asked for.
88
- - **One prompt at a time.** A prompt sent while another is running waits for it, so a follow-up
89
- always builds on the previous answer.
122
+ - **Questions can show and hide columns,** once you switch it on. See
123
+ [Showing and hiding columns](#showing-and-hiding-columns).
124
+ - **One prompt at a time.** A prompt sent while another is running on the same grid waits for it,
125
+ for a bounded time, then is sent anyway; with `apiRef`, every resolver created for the same grid shares that line. If that time passes, both prompts are in flight and each answer is applied when it is ready,
126
+ so the two can interleave. A failed prompt does not block the next one. The request itself has no
127
+ time limit, as with MUI's own resolver; the helper's wait for a data source's rows ends after 15
128
+ seconds. Each request carries exactly the conversation id the grid gave the prompt, as with MUI's
129
+ own resolver: a prompt typed before the first answer of a new conversation starts its own
130
+ conversation. When an app keeps `aiAssistantConversations` in its own state and a second resolver
131
+ asks while an answer is being read, the grid writes that state from stale props: with MUI's own
132
+ resolver and with this helper alike, the overlapping prompt is lost from the conversation; the
133
+ difference is that with this helper the first prompt ends as successful instead of staying at
134
+ "Processing…".
135
+
136
+ ## Showing and hiding columns
137
+
138
+ Off unless you switch it on:
139
+
140
+ ```ts
141
+ createPromptResolver({ url: '/api/ai-assistant', apiRef, features: { columnVisibility: true } });
142
+ ```
143
+
144
+ A question can then show and hide columns: "hide the email column", "show the region column
145
+ again", "only show name and amount", "show all columns". The helper offers it on a question when
146
+ all of these hold; otherwise, and whenever it is switched off, it sends what 1.0.0 sends, and a
147
+ question cannot show or hide columns:
148
+
149
+ - you pass `apiRef`, the grid is in the document, and its settings and current view could be read;
150
+ - the grid is not in pivot mode;
151
+ - the column panel is on (`disableColumnSelector` is not set);
152
+ - the grid has its column visibility model, as a plain object of booleans, and
153
+ `setColumnVisibilityModel`, as 9.18.0 does;
154
+ - at most 500 of the grid's columns are hidden, its own (such as the checkbox column) included;
155
+ - at least one column a question can change can be hidden.
156
+
157
+ **Which columns a question can change.** The columns in the context the grid builds for the
158
+ question that are still in the grid when the question is asked, other than columns listed only as
159
+ derived from another for pivoting, the grid's own columns (checkbox, grouping, row reordering,
160
+ detail panel, tree data, formula row number), `actions` columns, and columns whose field is over
161
+ 255 characters, contains the pivot separator `>->`, or is `__proto__`. Set `hideable: false` on a column, as you do to take it out of the column menu
162
+ and panel, and the helper never shows or hides it: "show all columns" leaves it hidden if it is.
163
+ Every other column can be shown, including columns your app starts hidden, such as through
164
+ `initialState`, and every column can be hidden. The lock holds for the helper's own changes: with
165
+ MUI's `useKeepGroupedColumnsHidden`, the grid itself shows a grouped column when an answer removes
166
+ its grouping, locked or not.
167
+
168
+ **How the change is made.** The helper changes the column visibility model itself, with one
169
+ `setColumnVisibilityModel` call, before it hands the rest of the answer to the grid. It changes only
170
+ what the answer changed compared with what the question sent, so a column you show or hide by hand
171
+ while the question is out stays as you left it. Just before it writes, it reads your columns again
172
+ and checks each column it would change: if one has been removed or locked while the question was
173
+ out, it changes nothing and the question fails with `cannot_apply`. An answer that names a column
174
+ the question did not offer, or that shows or hides columns and pivots too, is refused with
175
+ `invalid_answer`. If the grid is in pivot mode by the time the answer comes, the question fails with
176
+ `cannot_apply`. If the grid throws on the change, the helper tries once to put the columns back and
177
+ the question fails with `cannot_apply`, so the grid gets nothing else of the answer; if putting them
178
+ back fails too, the columns can stay as the answer set them, in part or in whole.
179
+
180
+ ## When something goes wrong after the answer arrives
90
181
 
91
- ## Limits
182
+ - **The grid refuses part of an answer.** The grid applies an answer itself, after the resolver
183
+ returns it, one part after another (in 9.18: filters, pivot, grouping, aggregation, sorting,
184
+ chart, selection). It has no rollback: if it throws partway, the parts before stay, and the
185
+ panel shows the grid's own error text, not one of this helper's sentences. The helper's own
186
+ steps come around that: it leaves pivot mode before returning an answer without a pivot, and
187
+ selects the top rows a moment after, so pivot mode can already be off, and the top rows can
188
+ still be selected, when the grid refuses the rest. Nothing undoes an answer; ask again or change
189
+ the grid by hand.
190
+ - **The delayed top-rows selection fails.** It runs after the panel has shown the answer as
191
+ applied, so its error cannot be shown there; the rows are simply not selected.
192
+ - **The grid is unmounted while a question is out.** If the grid unmounts or is replaced while a
193
+ question is in flight, the answer is handled by MUI exactly as with MUI's own resolver; the
194
+ helper's own steps are applied only to a grid that is still in the document. With React 19.3.1, a
195
+ reply that arrives while the grid is hidden under `<Activity>` gets the same handling as from
196
+ MUI's own resolver, and the helper's own steps (leaving pivot mode, rewriting a sort on a grouped
197
+ column, the safe top-rows selection, waiting for a data source's rows, repairing a chart's
198
+ aggregation) are skipped. The helper describes the grid after your `headers` and `getToken` have
199
+ resolved, checking that it is in the document before each read and once more after the last, with
200
+ nothing awaited between that check and the request; a grid that leaves the document after that
201
+ moment, while the request is out, is described as it was then.
202
+ - **Part of the grid fails: an untested grid version, or a callback of yours.** Every call into the
203
+ grid goes through one guarded path: reading its private API, its root props
204
+ (`disableColumnFilter`, `disableColumnSorting`, `disableRowGrouping`, `disableAggregation`,
205
+ `disablePivoting`, `rowSelection`, `rowGroupingColumnMode`, `dataSource`,
206
+ `disableColumnSelector`) and its state (filters, sorting, row grouping, aggregation, pivot mode
207
+ and model, the active chart, whether rows are loading, the column visibility model), your column
208
+ definitions and functions (`valueOptions`, `getOptionValue`, `getOptionLabel`, and what they
209
+ return), and each of the helper's own steps on it (subscribing to its events, leaving pivot mode,
210
+ keeping a chart's aggregation, selecting the top rows, showing and hiding columns). The one
211
+ thing the helper does on a grid that has left the document is remove its own listeners. A part
212
+ that is missing, in another shape, or throws is a failure. An error thrown by the grid or by your
213
+ own callbacks (such as `onPivotActiveChange`) during these steps is reported in the console and
214
+ the step is skipped: the question goes ahead with what could be read, and the steps that depend on
215
+ a failed one are skipped too. Without the root props, or when pivot mode cannot be read or left,
216
+ the helper skips moving a grouped column's sort to the grouping column, selecting the top rows
217
+ (the grid is not asked to either: its own selection throws when asked for more rows than its
218
+ filters leave) and keeping a chart's aggregation; it never selects rows of a page whose loading it
219
+ could not see end. Every wait on the grid has a bound and always ends. The grid's current view is
220
+ sent whole or not at all, so the server keeps the conversation's last answer rather than being
221
+ told a part is empty. Showing and hiding columns is not skipped once offered: when the change an
222
+ answer makes cannot be read or made, that question fails with `cannot_apply`.
223
+ - **The console warning.** Each part of the grid that fails is reported once per resolver, when
224
+ the question that met it has settled, however it ended. The first question to meet a failure
225
+ prints the full warning, naming every part it could not read or change, followed by each error
226
+ it caught, so you see your own stack. A part that first fails on a later question prints one
227
+ short line (the package, the part, "skipped", and the error). A part already reported is never
228
+ reported again, so the output is bounded by the number of parts the helper touches, however many questions are asked. One exception: an `apiRef` whose `current` throws when read is reported at once, before the question settles, in a full warning of its own.
229
+ - **Reading your column definitions.** The helper reads your column definitions once, before the
230
+ request (with showing and hiding columns on, once more before it shows or hides any), as MUI
231
+ reads them: `valueOptions` called with `{ field }`, then `getOptionValue` and
232
+ `getOptionLabel` once per option, each as a method of its column. If reading them throws, or the
233
+ grid has left the page by the end of that read, the question is sent without a description and
234
+ settles as MUI's resolver would; what was thrown is reported in the console. Nothing read from the
235
+ grid refuses a question. With showing and hiding columns on, this holds for what is read before
236
+ the request: a `hideable` (or `type`) that throws then is reported, the description is kept, and
237
+ the question cannot show or hide columns; a column that cannot be read again when the answer
238
+ arrives makes that answer fail with `cannot_apply`. Column definitions whose getters or functions throw only sometimes,
239
+ return different values on each call, or change the grid while being read are outside what the
240
+ helper supports. A change that makes nothing fail, such as a prop that keeps its name but changes
241
+ its meaning, is not noticed.
242
+
243
+ ## Known limits
92
244
 
93
245
  - Grid-wide switches (`disable…`, `rowSelection`, `rowGroupingColumnMode`, `dataSource`) are not
94
246
  in the grid's public API. The helper reads them from the grid's internal props, tested with
95
- `@mui/x-data-grid-premium` 9.18. If a later version moves them, the helper treats every feature
96
- as switched on.
247
+ `@mui/x-data-grid-premium` 9.18.0. If a later version moves them, the helper warns once and
248
+ skips its own steps that depend on them rather than guess (see above). An optional prop such as
249
+ `dataSource` cannot be told apart from one that moved.
97
250
  - With a data source, top N selects at most the rows of the loaded page.
98
251
  - In single grouping-column mode, all group levels share one sort direction: the first grouped
99
252
  column in the sort decides it.
100
253
  - While leaving pivot mode, the grid shows its pre-pivot state for a moment before the answer
101
254
  lands.
102
- - The snapshot leaves out quick-filter text, filter values that are not text, numbers, booleans
103
- or dates, aggregation functions other than `avg`, `sum`, `min`, `max` and `size`, and
104
- singleSelect options computed from a row.
255
+ - The snapshot leaves out quick-filter text, filter values that are not text, numbers, booleans or
256
+ dates, aggregation functions other than `avg`, `sum`, `min`, `max` and `size`, options past the
257
+ 500th, and options that `valueOptions` gives only for a row (it is called with `{ field }` only,
258
+ as by MUI's own assistant).
105
259
  - The assistant cannot create, remove or change the type of a chart; it only fills the active one.
260
+ - **Selecting the top rows** differs from MUI's own resolver: the helper selects the first rows that
261
+ pass the filters and are not group rows, even inside a collapsed group, where MUI's selects the
262
+ first visible rows, a group row included. The answer it returns, and the grid stores in the
263
+ conversation, has `select: -1` in place of the number asked for.
264
+ - A chart's aggregation that you change by hand within half a second of an answer that set it is
265
+ put back to the answer's.
266
+ - **Showing and hiding columns.** The change stays if the grid then refuses another part of the
267
+ same answer: the helper makes it before the grid applies the rest, and nothing undoes it. With a
268
+ controlled `columnVisibilityModel`, update it from `onColumnVisibilityModelChange`, or the grid
269
+ keeps your columns while the panel reports the answer applied. The assistant panel has no entry
270
+ for showing or hiding columns: in 9.18.0 it lists the other parts of the answer whenever they are
271
+ not empty, such as a sort the grid already had.
272
+ - The description can be incomplete in three cases: an active filter whose operator needs no value
273
+ and is past the column's 64th operator is left out; an option whose label is over 255 characters
274
+ is left out and still counts toward the 500; an aggregation function name over 64 characters is
275
+ left out and still counts toward the 32.
276
+ - The per-grid ordering holds when each grid has its own resolver and passes `apiRef`. Without
277
+ `apiRef`, one resolver shared by two grids makes each wait for the other, and two resolvers on
278
+ one grid do not wait for each other.
279
+ - A column whose field contains `>->` is treated as a pivot column and left out of the helper's
280
+ description: its limits, and its filters, sorting, grouping, aggregation and pivot entries.
281
+ - With no `additionalContext`, the request's `options` is `{}`, where MUI's own resolver sends
282
+ `additionalContext: ''`.
106
283
  - Requests use the browser's default credentials mode (cookies only for the same origin). Put a
107
284
  cross-origin route's credentials in `headers` or `getToken`.
108
285
 
109
- ## Status
286
+ ## Exports
287
+
288
+ Everything the package exports, and nothing else, is covered by the versioning rule below.
289
+
290
+ | Export | What it is |
291
+ |---|---|
292
+ | `createPromptResolver(options)` | Returns the grid's `onPrompt`. |
293
+ | `PromptResolver` (type) | The type of what `createPromptResolver` returns: `(prompt, context, conversationId?) => Promise<PromptData>`. |
294
+ | `PromptResolverOptions` (type) | The options in the table above. |
295
+ | `GridsayError` | The class every rejection is an instance of (see Errors). |
296
+ | `CONNECTION_FAILED`, `INVALID_ANSWER`, `NOT_JSON`, `UNAUTHENTICATED_USER` | The sentences (typed as `string`). |
297
+ | `CANNOT_APPLY_CODE`, `CONNECTION_FAILED_CODE`, `INVALID_ANSWER_CODE`, `NOT_JSON_CODE`, `UNAUTHENTICATED_USER_CODE`, `UNEXPECTED_ERROR_CODE` | The codes. |
298
+
299
+ Entry points: `@gridsay/mui-x-data-grid` (ESM, with its type declarations) and
300
+ `@gridsay/mui-x-data-grid/package.json` (the package's manifest, for tools that read it).
301
+
302
+ ## Versioning
303
+
304
+ `@gridsay/mui-x-data-grid` follows semver from its first major release. It pins `@gridsay/core`
305
+ exactly. An app that imports `GridsayError` from `@gridsay/core` keeps that package at the version
306
+ this one pins (0.2.0 for 1.1.0), or imports it from `@gridsay/mui-x-data-grid`.
307
+
308
+ - **Codes are the contract; sentences are not.** Match on `error.code`. The sentences
309
+ (`error.message`, and the exported `INVALID_ANSWER`, `CONNECTION_FAILED` and the others) are for
310
+ people and may be reworded in a minor.
311
+ - **A major** for anything that breaks what this package exports, whether the change is here or in
312
+ `@gridsay/core`: a removed or changed export, type, option or error code, or a new required
313
+ method or prop on what it accepts from the grid (`apiRef`).
314
+ - **A minor** for what only adds: a new optional field on `GridsayError` or on an answer, a new
315
+ option, a new error code.
316
+
317
+ **What this package promises.** It is tested with `@mui/x-data-grid-premium` 9.18.0. With that
318
+ version, `apiRef` passed, callbacks of yours that do not throw, and any controlled state (such as
319
+ `filterModel`) updated from the grid's change callbacks, an answer the panel shows as applied is what the grid shows, except a chart when no chart is active: the panel lists "Charts" among the applied changes, as with MUI's own resolver, while the grid has no chart to fill. Without `apiRef` the helper cannot see the grid: an answer that leaves pivot
320
+ mode can be overwritten when the grid restores what it showed before the pivot. With controlled
321
+ state your callbacks do not update, the grid keeps your state while the panel reports the answer
322
+ applied. An error thrown by the grid or by your own callbacks during the helper's own steps (reading
323
+ the grid, leaving pivot mode, selecting the top rows, keeping a chart's aggregation) is reported in the console and that step is skipped; when it is thrown while reading your column definitions, the question goes out without a description of the grid. While the grid
324
+ applies the answer itself, an error from your callbacks (such as `onSortModelChange`) is the grid's:
325
+ it stops the answer there, the panel shows its text, and the helper does not see it. On other grid
326
+ versions the behaviour is best effort and failures are reported the same way; a change that makes
327
+ nothing fail is not noticed.
328
+
329
+ Its own types (`PromptResolver`, what `apiRef` accepts) are declared in this package and do not
330
+ change with the grid; they accept what 9.18.0's types do, with `strict` and with
331
+ `exactOptionalPropertyTypes`.
332
+
333
+ To check this package's types against a release of the grid by hand, build it and run
334
+ `node packages/mui-x-data-grid/compat/check.mjs 9.18.0` (or `9` for the newest 9.x). It is not in
335
+ CI, because it installs MUI X Data Grid Premium, a commercial package.
336
+
337
+ `pnpm --filter @gridsay/mui-x-data-grid compare` runs each life-cycle scenario (unmount, a
338
+ replacement, a re-key, a ref swap, two resolvers, strict mode, `<Activity>`, a portal move) on a
339
+ real grid twice, with MUI's own resolver and with this helper, and checks that the grid, the
340
+ panel and your callbacks see the same; it is run by hand for the same reason.
110
341
 
111
- 0.1.0. Where this stands:
112
- [gridsay.com/features#status](https://gridsay.com/features#status). The API may change before 1.0.
113
- ESM only, no runtime dependencies besides `@gridsay/core`.
342
+ Where this stands: [gridsay.com/features#status](https://gridsay.com/features#status). ESM only,
343
+ no runtime dependencies besides `@gridsay/core`.
114
344
 
115
345
  Example: [`examples/mui-x-data-grid`](https://github.com/gridsay/gridsay/tree/main/examples/mui-x-data-grid).
116
346
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { CONNECTION_FAILED, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER, INVALID_ANSWER_CODE, NOT_JSON, NOT_JSON_CODE, RequestHeaders, RequestOptions, UNAUTHENTICATED_USER, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE } from "@gridsay/core";
2
- import { DataGridPremiumProps, GridApiPremium, GridRowId, ValueOptions } from "@mui/x-data-grid-premium";
3
- type State = GridApiPremium['state'];
4
- /** The column properties the helper reads. Kept structural, so a second copy of the grid's types still fits. */
1
+ import { CANNOT_APPLY_CODE, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER_CODE, NOT_JSON_CODE, PromptData, RequestHeaders, RequestOptions, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE } from "@gridsay/core";
2
+ type RowId = string | number;
3
+ type ValueOption = string | number | object;
4
+ /** MUI's `GridFilterItem['operator']`: its operators, or any other string. */
5
+ type FilterOperator = 'contains' | 'doesNotContain' | 'equals' | 'doesNotEqual' | 'startsWith' | 'endsWith' | '=' | '!=' | '>' | '>=' | '<' | '<=' | 'is' | 'not' | 'after' | 'onOrAfter' | 'before' | 'onOrBefore' | 'isEmpty' | 'isNotEmpty' | 'isAnyOf' | (string & {});
6
+ /** The column properties the helper reads. */
5
7
  type Column = {
6
8
  field: string;
7
9
  type?: string;
@@ -10,57 +12,126 @@ type Column = {
10
12
  groupable?: boolean;
11
13
  pivotable?: boolean;
12
14
  aggregable?: boolean;
15
+ hideable?: boolean | undefined;
13
16
  availableAggregationFunctions?: string[];
14
17
  filterOperators?: readonly {
15
18
  value: string;
16
19
  requiresFilterValue?: boolean;
17
20
  }[];
18
- valueOptions?: ValueOptions[] | ((params: {
21
+ valueOptions?: ValueOption[] | ((params: {
19
22
  field: string;
20
- }) => ValueOptions[]);
21
- getOptionValue?: (option: ValueOptions) => unknown;
22
- getOptionLabel?: (option: ValueOptions) => string;
23
+ }) => ValueOption[]);
24
+ getOptionValue?: (option: ValueOption) => unknown;
25
+ getOptionLabel?: (option: ValueOption) => string;
23
26
  };
24
- /** The part of the grid API the helper reads and drives. */
25
- type GridApi = Pick<GridApiPremium, 'getSortedRowIds' | 'setRowSelectionModel' | 'setAggregationModel' | 'setPivotActive'> & {
27
+ /** The part of the grid API the helper reads and drives: what `apiRef` must point to. */
28
+ type GridApi = {
26
29
  getAllColumns: () => Column[];
27
- getRowNode: (id: GridRowId) => {
30
+ getSortedRowIds: () => RowId[];
31
+ getRowNode: (id: RowId) => {
28
32
  type: string;
29
33
  } | null;
34
+ setRowSelectionModel: (model: {
35
+ type: 'include' | 'exclude';
36
+ ids: Set<RowId>;
37
+ }, reason?: 'singleRowSelection' | 'multipleRowsSelection') => void;
38
+ setAggregationModel: (model: Record<string, string>) => void;
39
+ setPivotActive: (active: boolean | ((prev: boolean) => boolean)) => void;
40
+ setColumnVisibilityModel?: ((model: Record<string, boolean>) => void) | undefined;
30
41
  subscribeEvent: (event: 'rowsSet' | 'aggregationModelChange', handler: () => void) => () => void;
42
+ rootElementRef: {
43
+ readonly current: {
44
+ readonly isConnected: boolean;
45
+ } | null;
46
+ };
31
47
  state: {
32
- filter: Pick<State['filter'], 'filteredRowsLookup'> & {
33
- filterModel: Pick<State['filter']['filterModel'], 'items'> & {
34
- logicOperator?: string;
48
+ filter: {
49
+ filteredRowsLookup: Record<RowId, false>;
50
+ filterModel: {
51
+ items: {
52
+ id?: number | string;
53
+ field: string;
54
+ operator: FilterOperator;
55
+ value?: unknown;
56
+ }[];
57
+ logicOperator?: 'and' | 'or';
35
58
  };
36
59
  };
37
- sorting: Pick<State['sorting'], 'sortModel'>;
38
- rowGrouping: Pick<State['rowGrouping'], 'model'>;
39
- aggregation: Pick<State['aggregation'], 'model'>;
40
- pivoting: Pick<State['pivoting'], 'active' | 'model'>;
41
- chartsIntegration: Pick<State['chartsIntegration'], 'activeChartId'>;
42
- rows: Pick<State['rows'], 'loading'>;
60
+ sorting: {
61
+ sortModel: readonly {
62
+ field: string;
63
+ sort: 'asc' | 'desc' | null | undefined;
64
+ }[];
65
+ };
66
+ rowGrouping: {
67
+ model: string[];
68
+ };
69
+ aggregation: {
70
+ model: Record<string, string>;
71
+ };
72
+ pivoting: {
73
+ active: boolean;
74
+ model: {
75
+ columns: {
76
+ field: string;
77
+ sort?: 'asc' | 'desc';
78
+ hidden?: boolean;
79
+ }[];
80
+ rows: {
81
+ field: string;
82
+ hidden?: boolean;
83
+ }[];
84
+ values: {
85
+ field: string;
86
+ aggFunc: string;
87
+ hidden?: boolean;
88
+ }[];
89
+ };
90
+ };
91
+ chartsIntegration: {
92
+ activeChartId: string;
93
+ };
94
+ rows: {
95
+ loading?: boolean;
96
+ };
97
+ /** Read for its `columnVisibilityModel`: any value fits, as any did in 1.0.0. */
98
+ columns?: unknown;
43
99
  };
44
100
  };
45
- type PromptResolver = NonNullable<DataGridPremiumProps['onPrompt']>;
101
+ /**
102
+ * The grid's `onPrompt`, declared here so a grid release cannot change it. A test checks it still
103
+ * fits the grid's own prop at the tested version.
104
+ */
105
+ type PromptResolver = (prompt: string, context: string, conversationId?: string) => Promise<PromptData>;
106
+ export declare const CONNECTION_FAILED: string;
107
+ export declare const INVALID_ANSWER: string;
108
+ export declare const NOT_JSON: string;
109
+ export declare const UNAUTHENTICATED_USER: string;
46
110
  export type PromptResolverOptions = {
47
111
  /** Where the prompt is posted: your own proxy route, or the Gridsay gateway. */
48
112
  url: string;
49
113
  /** With it, the helper describes the grid to the server and adapts answers to the grid. */
50
114
  apiRef?: {
51
115
  readonly current: GridApi | null;
52
- };
116
+ } | undefined;
53
117
  /** Added to each request. */
54
- headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>);
118
+ headers?: RequestHeaders | (() => RequestHeaders | Promise<RequestHeaders>) | undefined;
55
119
  /** A publishable key, sent as `x-api-key`. */
56
- publishableKey?: string;
120
+ publishableKey?: string | undefined;
57
121
  /** The end user's token, fetched for every request and sent as a bearer token. */
58
- getToken?: RequestOptions['getToken'];
59
- additionalContext?: string;
60
- privateMode?: boolean;
122
+ getToken?: RequestOptions['getToken'] | undefined;
123
+ additionalContext?: string | undefined;
124
+ privateMode?: boolean | undefined;
61
125
  /** Your id for the end user. */
62
- referenceId?: string;
126
+ referenceId?: string | undefined;
127
+ /**
128
+ * Abilities that are off unless switched on. `columnVisibility: true` lets questions show and
129
+ * hide columns, on a grid that can take it (see the README).
130
+ */
131
+ features?: {
132
+ columnVisibility?: boolean | undefined;
133
+ } | undefined;
63
134
  };
64
135
  /** Replaces `unstable_gridDefaultPromptResolver` as the grid's `onPrompt`. */
65
136
  export declare function createPromptResolver(options: PromptResolverOptions): PromptResolver;
66
- export { CONNECTION_FAILED, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER, INVALID_ANSWER_CODE, NOT_JSON, NOT_JSON_CODE, type PromptResolver, UNAUTHENTICATED_USER, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE };
137
+ export { CANNOT_APPLY_CODE, CONNECTION_FAILED_CODE, GridsayError, INVALID_ANSWER_CODE, NOT_JSON_CODE, type PromptResolver, UNAUTHENTICATED_USER_CODE, UNEXPECTED_ERROR_CODE };