@cubejs-client/react 1.7.12 → 1.7.14

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 (62) hide show
  1. package/dist/CubeContext.d.ts +35 -0
  2. package/dist/CubeContext.d.ts.map +1 -0
  3. package/dist/CubeProvider.d.ts +31 -0
  4. package/dist/CubeProvider.d.ts.map +1 -0
  5. package/dist/QueryBuilder.d.ts +135 -0
  6. package/dist/QueryBuilder.d.ts.map +1 -0
  7. package/dist/QueryRenderer.d.ts +34 -0
  8. package/dist/QueryRenderer.d.ts.map +1 -0
  9. package/dist/QueryRendererWithTotals.d.ts +4 -0
  10. package/dist/QueryRendererWithTotals.d.ts.map +1 -0
  11. package/dist/cubejs-client-react.cjs.js +248 -23
  12. package/dist/cubejs-client-react.cjs.js.map +1 -1
  13. package/dist/cubejs-client-react.esm.js +253 -31
  14. package/dist/cubejs-client-react.esm.js.map +1 -1
  15. package/dist/cubejs-client-react.umd.js +248 -23
  16. package/dist/cubejs-client-react.umd.js.map +1 -1
  17. package/dist/hooks/cube-fetch.d.ts +6 -0
  18. package/dist/hooks/cube-fetch.d.ts.map +1 -0
  19. package/dist/hooks/cube-meta.d.ts +4 -0
  20. package/dist/hooks/cube-meta.d.ts.map +1 -0
  21. package/dist/hooks/cube-query.d.ts +39 -0
  22. package/dist/hooks/cube-query.d.ts.map +1 -0
  23. package/dist/hooks/cube-sql.d.ts +12 -0
  24. package/dist/hooks/cube-sql.d.ts.map +1 -0
  25. package/dist/hooks/deep-compare-memoize.d.ts +2 -0
  26. package/dist/hooks/deep-compare-memoize.d.ts.map +1 -0
  27. package/dist/hooks/dry-run.d.ts +7 -0
  28. package/dist/hooks/dry-run.d.ts.map +1 -0
  29. package/dist/hooks/lazy-dry-run.d.ts +7 -0
  30. package/dist/hooks/lazy-dry-run.d.ts.map +1 -0
  31. package/dist/index.d.ts +21 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/types.d.ts +765 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils.d.ts +2 -0
  36. package/dist/utils.d.ts.map +1 -0
  37. package/package.json +14 -10
  38. package/src/CubeContext.ts +37 -0
  39. package/src/CubeProvider.tsx +42 -0
  40. package/src/{QueryBuilder.jsx → QueryBuilder.tsx} +238 -89
  41. package/src/{QueryRenderer.jsx → QueryRenderer.tsx} +39 -14
  42. package/src/QueryRendererWithTotals.tsx +24 -0
  43. package/src/hooks/cube-fetch.ts +98 -0
  44. package/src/hooks/cube-meta.ts +8 -0
  45. package/src/hooks/{cube-query.js → cube-query.ts} +90 -14
  46. package/src/hooks/cube-sql.ts +22 -0
  47. package/src/hooks/{deep-compare-memoize.js → deep-compare-memoize.ts} +2 -2
  48. package/src/hooks/dry-run.ts +17 -0
  49. package/src/hooks/lazy-dry-run.ts +24 -0
  50. package/src/index.ts +77 -0
  51. package/src/types.ts +837 -0
  52. package/src/{utils.js → utils.ts} +3 -3
  53. package/index.d.ts +0 -697
  54. package/src/CubeContext.js +0 -3
  55. package/src/CubeProvider.jsx +0 -14
  56. package/src/QueryRendererWithTotals.jsx +0 -20
  57. package/src/hooks/cube-fetch.js +0 -66
  58. package/src/hooks/cube-meta.js +0 -5
  59. package/src/hooks/cube-sql.js +0 -8
  60. package/src/hooks/dry-run.js +0 -8
  61. package/src/hooks/lazy-dry-run.js +0 -11
  62. package/src/index.js +0 -18
@@ -1,10 +1,10 @@
1
- export function removeEmpty(obj) {
1
+ export function removeEmpty<T>(obj: T): T {
2
2
  if (Array.isArray(obj) || typeof obj !== 'object') {
3
3
  return obj;
4
4
  }
5
5
 
6
6
  return Object.fromEntries(
7
- Object.entries(obj)
7
+ Object.entries(obj as Record<string, unknown>)
8
8
  .filter(([, v]) => v != null)
9
9
  .map(([k, v]) => {
10
10
  if (Array.isArray(v)) {
@@ -13,5 +13,5 @@ export function removeEmpty(obj) {
13
13
 
14
14
  return [k, typeof v === 'object' ? removeEmpty(v) : v];
15
15
  })
16
- );
16
+ ) as T;
17
17
  }
package/index.d.ts DELETED
@@ -1,697 +0,0 @@
1
- /**
2
- * @title @cubejs-client/react
3
- * @permalink /@cubejs-client-react
4
- * @menuCategory Reference
5
- * @subcategory Frontend
6
- * @menuOrder 3
7
- * @description `@cubejs-client/react` provides React Components for easy Cube.js integration in a React app.
8
- */
9
-
10
- declare module '@cubejs-client/react' {
11
- import * as React from 'react';
12
- import {
13
- CubeApi,
14
- Query,
15
- ResultSet,
16
- SqlQuery,
17
- Filter,
18
- PivotConfig,
19
- TCubeMeasure,
20
- TCubeDimension,
21
- ProgressResponse,
22
- DryRunResponse,
23
- TOrderMember,
24
- QueryOrder,
25
- TSourceAxis,
26
- Meta,
27
- TCubeSegment,
28
- TimeDimension,
29
- TimeDimensionGranularity,
30
- DateRange,
31
- UnaryOperator,
32
- BinaryOperator,
33
- DeeplyReadonly,
34
- QueryRecordType,
35
- CacheMode,
36
- } from '@cubejs-client/core';
37
-
38
- type CubeProviderOptions = {
39
- castNumerics?: boolean;
40
- }
41
-
42
- type CubeProviderProps = {
43
- cubeApi: CubeApi | null;
44
- options?: CubeProviderOptions;
45
- children: React.ReactNode;
46
- };
47
-
48
- /**
49
- * Cube.js context provider
50
- * ```js
51
- * import React from 'react';
52
- * import cube from '@cubejs-client/core';
53
- * import { CubeProvider } from '@cubejs-client/react';
54
- *
55
- * const API_URL = 'https://harsh-eel.aws-us-east-2.cubecloudapp.dev';
56
- * const CUBE_TOKEN =
57
- * 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.* eyJpYXQiOjE1OTE3MDcxNDgsImV4cCI6MTU5NDI5OTE0OH0.* n5jGLQJ14igg6_Hri_Autx9qOIzVqp4oYxmX27V-4T4';
58
- *
59
- * const cubeApi = cube(CUBE_TOKEN, {
60
- * apiUrl: `${API_URL}/cubejs-api/v1`,
61
- * });
62
- *
63
- * export default function App() {
64
- * return (
65
- * <CubeProvider cubeApi={cubeApi}>
66
- * //...
67
- * </CubeProvider>
68
- * )
69
- * }
70
- * ```
71
- * @stickyTypes
72
- * @order 10
73
- */
74
- export const CubeProvider: React.FC<CubeProviderProps>;
75
-
76
- type CubeContextProps = {
77
- cubeApi: CubeApi;
78
- options?: CubeProviderOptions;
79
- };
80
-
81
- /**
82
- * In case when you need direct access to `cubeApi` you can use `CubeContext` anywhere in your app
83
- *
84
- * ```js
85
- * import React from 'react';
86
- * import { CubeContext } from '@cubejs-client/react';
87
- *
88
- * export default function DisplayComponent() {
89
- * const { cubeApi } = React.useContext(CubeContext);
90
- * const [rawResults, setRawResults] = React.useState([]);
91
- * const query = {
92
- * ...
93
- * };
94
- *
95
- * React.useEffect(() => {
96
- * cubeApi.load(query).then((resultSet) => {
97
- * setRawResults(resultSet.rawData());
98
- * });
99
- * }, [query]);
100
- *
101
- * return (
102
- * <>
103
- * {rawResults.map(row => (
104
- * ...
105
- * ))}
106
- * </>
107
- * )
108
- * }
109
- * ```
110
- */
111
- export const CubeContext: React.Context<CubeContextProps>;
112
-
113
- type TLoadingState = {
114
- isLoading: boolean;
115
- };
116
-
117
- type QueryRendererRenderProps = {
118
- resultSet: ResultSet | null;
119
- error: Error | null;
120
- loadingState: TLoadingState;
121
- sqlQuery: SqlQuery | null;
122
- };
123
-
124
- type QueryRendererProps = {
125
- /**
126
- * Analytic query. [Learn more about it's format](/product/apis-integrations/rest-api/query-format)
127
- */
128
- query: Query | Query[];
129
- queries?: { [key: string]: Query };
130
- /**
131
- * Indicates whether the generated by `Cube.js` SQL Code should be requested. See [rest-api#sql](/reference/rest-api#v1sql). When set to `only` then only the request to [/v1/sql](/reference/rest-api#v1sql) will be performed. When set to `true` the sql request will be performed along with the query request. Will not be performed if set to `false`
132
- */
133
- loadSql?: 'only' | boolean;
134
- /**
135
- * When `true` the **resultSet** will be reset to `null` first on every state change
136
- */
137
- resetResultSetOnChange?: boolean;
138
- updateOnlyOnStateChange?: boolean;
139
- /**
140
- * `CubeApi` instance to use
141
- */
142
- cubeApi?: CubeApi;
143
- /**
144
- * Server-side cache policy for query execution. Does not control client-side caching.
145
- */
146
- cache?: CacheMode;
147
- /**
148
- * Output of this function will be rendered by the `QueryRenderer`
149
- */
150
- render: (renderProps: QueryRendererRenderProps) => void;
151
- /**
152
- * @hidden
153
- */
154
- children?: never;
155
- };
156
-
157
- /**
158
- * `<QueryRenderer />` a react component that accepts a query, fetches the given query, and uses the render prop to render the resulting data
159
- * @stickyTypes QueryRendererProps, QueryRendererRenderProps
160
- * @noInheritDoc
161
- */
162
- export class QueryRenderer extends React.Component<QueryRendererProps> {}
163
-
164
- export type ChartType = 'line' | 'bar' | 'table' | 'area' | 'number' | 'pie';
165
-
166
- type VizState = {
167
- query?: Query;
168
- pivotConfig?: PivotConfig;
169
- chartType?: ChartType;
170
- };
171
-
172
- type QueryBuilderProps = {
173
- /**
174
- * `CubeApi` instance to use
175
- */
176
- cubeApi?: CubeApi;
177
- /**
178
- * State for the QueryBuilder to start with. Pass in the value previously saved from onVizStateChanged to restore a session.
179
- */
180
- initialVizState?: VizState;
181
- /**
182
- * Called by the `QueryBuilder` when the viz state has changed. Use it to save state outside of the `QueryBuilder` component.
183
- */
184
- onVizStateChanged?: (vizState: VizState) => void;
185
- /**
186
- * @default defaultChartType line (used when initialVizState is not set or does not contain chartType)
187
- */
188
- defaultChartType?: ChartType;
189
- /**
190
- * Default query (used when initialVizState is not set or does not contain query)
191
- */
192
- defaultQuery?: Query;
193
- /**
194
- * Defaults to `false`. This means that the default heuristics will be applied. For example: when the query is empty and you select a measure that has a default time dimension it will be pushed to the query.
195
- * @default disableHeuristics false
196
- */
197
- disableHeuristics?: boolean;
198
- wrapWithQueryRenderer?: boolean;
199
- render: (renderProps: QueryBuilderRenderProps) => React.ReactNode;
200
- /**
201
- * A function that accepts the `newState` just before it's applied. You can use it to override the **defaultHeuristics** or to tweak the query or the vizState in any way.
202
- */
203
- stateChangeHeuristics?: (state: QueryBuilderState, newState: QueryBuilderState) => QueryBuilderState;
204
- /**
205
- * @ignore @deprecated Controlled query
206
- */
207
- query?: Query;
208
- /**
209
- * @ignore @deprecated Controlled query setter
210
- */
211
- setQuery?: (query: Query) => void;
212
- /**
213
- * @ignore @deprecated Controlled vizState
214
- */
215
- vizState?: VizState;
216
- /**
217
- * @ignore @deprecated Controlled vizState setter
218
- */
219
- setVizState?: (vizState: VizState) => void;
220
- /**
221
- * @hidden
222
- */
223
- schemaVersion?: number;
224
- /**
225
- * @hidden
226
- */
227
- queryVersion?: number | string;
228
- /**
229
- * @hidden
230
- */
231
- onSchemaChange?: (props: SchemaChangeProps) => void;
232
- };
233
-
234
- /**
235
- * @hidden
236
- */
237
- type SchemaChangeProps = {
238
- schemaVersion: number;
239
- refresh: () => Promise<void>;
240
- };
241
-
242
- type QueryBuilderState = VizState & {
243
- query?: Query;
244
- };
245
-
246
- type QueryBuilderRenderProps = {
247
- // Todo: should fix DRY, duplicate props from QueryRendererRenderProps, see https://github.com/cube-js/cube.js/issues/1192
248
- resultSet?: ResultSet | null;
249
- error?: Error | null;
250
- loadingState?: TLoadingState;
251
-
252
- meta: Meta | undefined;
253
- metaError?: Error | null;
254
- richMetaError?: Error | null;
255
- metaErrorStack?: string | null;
256
- isFetchingMeta: boolean;
257
- /**
258
- * Indicates whether the query is ready to be displayed or not
259
- */
260
- isQueryPresent: boolean;
261
- measures: (TCubeMeasure & { index: number })[];
262
- dimensions: (TCubeDimension & { index: number })[];
263
- segments: (TCubeSegment & { index: number })[];
264
- timeDimensions: (TimeDimensionWithExtraFields & { index: number })[];
265
-
266
- availableMembers: AvailableMembers;
267
-
268
- availableFilterMembers: Array<AvailableCube<TCubeMeasure> | AvailableCube<TCubeDimension>>;
269
- /**
270
- * An array of available measures to select. They are loaded via the API from Cube.js Backend.
271
- */
272
- availableMeasures: TCubeMeasure[];
273
- /**
274
- * An array of available dimensions to select. They are loaded via the API from Cube.js Backend.
275
- */
276
- availableDimensions: TCubeDimension[];
277
- /**
278
- * An array of available time dimensions to select. They are loaded via the API from Cube.js Backend.
279
- */
280
- availableTimeDimensions: TCubeDimension[];
281
- /**
282
- * An array of available segments to select. They are loaded via the API from Cube.js Backend.
283
- */
284
- availableSegments: TCubeSegment[];
285
-
286
- updateMeasures: MeasureUpdater;
287
- updateDimensions: DimensionUpdater;
288
- updateSegments: SegmentUpdater;
289
- updateTimeDimensions: TimeDimensionUpdater;
290
- updateFilters: FilterUpdater;
291
- /**
292
- * Used for partial of full query update
293
- */
294
- updateQuery: (query: Query) => void;
295
- filters: (FilterWithExtraFields & { index: number })[];
296
- /**
297
- * All possible order members for the query
298
- */
299
- orderMembers: TOrderMember[];
300
- /**
301
- * Used for query order update
302
- */
303
- updateOrder: OrderUpdater;
304
- /**
305
- * See [Pivot Config](@cubejs-client-core#types-pivot-config)
306
- */
307
- pivotConfig?: PivotConfig;
308
- /**
309
- * Helper method for `pivotConfig` updates
310
- */
311
- updatePivotConfig: PivotConfigUpdater;
312
-
313
- /**
314
- * Selected chart type
315
- */
316
- chartType?: ChartType;
317
-
318
- /**
319
- * Used for chart type update
320
- */
321
- updateChartType: (chartType: ChartType) => void;
322
-
323
- /**
324
- * Used to set the initial query for this component. Note that adding this prop turns this into an
325
- * uncontrolled component and will only be able to execute `dryRun` queries. To use this component
326
- * as a controlled component, use `setQuery` instead.
327
- */
328
- query: Query;
329
- validatedQuery: Query;
330
- refresh: () => void;
331
- missingMembers: string[];
332
- dryRunResponse?: DryRunResponse;
333
- };
334
-
335
- export type AvailableMembers = {
336
- measures: AvailableCube<TCubeMeasure>[];
337
- dimensions: AvailableCube<TCubeDimension>[];
338
- segments: AvailableCube<TCubeSegment>[];
339
- timeDimensions: AvailableCube<TCubeDimension>[];
340
- };
341
-
342
- // todo: CubeMember
343
- export type AvailableCube<T = any> = {
344
- type: 'cube' | 'view';
345
- public: boolean;
346
- cubeName: string;
347
- cubeTitle: string;
348
- members: T[];
349
- };
350
-
351
- /**
352
- * `<QueryBuilder />` is used to build interactive analytics query builders. It abstracts state management and API calls to Cube.js Backend. It uses render prop technique and doesn’t render anything itself, but calls the render function instead.
353
- *
354
- * **Example**
355
- *
356
- * [Open in CodeSandbox](https://codesandbox.io/s/z6r7qj8wm)
357
- * ```js
358
- * import React from 'react';
359
- * import ReactDOM from 'react-dom';
360
- * import { Layout, Divider, Empty, Select } from 'antd';
361
- * import { QueryBuilder } from '@cubejs-client/react';
362
- * import cube from '@cubejs-client/core';
363
- * import 'antd/dist/antd.css';
364
- *
365
- * import ChartRenderer from './ChartRenderer';
366
- *
367
- * const cubeApi = cube('YOUR-CUBE-API-TOKEN', {
368
- * apiUrl: 'http://localhost:4000/cubejs-api/v1',
369
- * });
370
- *
371
- * const App = () => (
372
- * <QueryBuilder
373
- * query={{
374
- * timeDimensions: [
375
- * {
376
- * dimension: 'LineItems.createdAt',
377
- * granularity: 'month',
378
- * },
379
- * ],
380
- * }}
381
- * cubeApi={cubeApi}
382
- * render={({ resultSet, measures, availableMeasures, updateMeasures }) => (
383
- * <Layout.Content style={{ padding: '20px' }}>
384
- * <Select
385
- * mode="multiple"
386
- * style={{ width: '100%' }}
387
- * placeholder="Please select"
388
- * onSelect={(measure) => updateMeasures.add(measure)}
389
- * onDeselect={(measure) => updateMeasures.remove(measure)}
390
- * >
391
- * {availableMeasures.map((measure) => (
392
- * <Select.Option key={measure.name} value={measure}>
393
- * {measure.title}
394
- * </Select.Option>
395
- * ))}
396
- * </Select>
397
- * <Divider />
398
- * {measures.length > 0 ? (
399
- * <ChartRenderer resultSet={resultSet} />
400
- * ) : (
401
- * <Empty description="Select measure or dimension to get started" />
402
- * )}
403
- * </Layout.Content>
404
- * )}
405
- * />
406
- * );
407
- *
408
- * const rootElement = document.getElementById("root");
409
- * ReactDOM.render(<App />, rootElement);
410
- * ```
411
- * @stickyTypes QueryBuilderProps, QueryBuilderRenderProps, QueryBuilderState
412
- * @noInheritDoc
413
- * @order 2
414
- */
415
- export class QueryBuilder extends React.Component<QueryBuilderProps, QueryBuilderState> {}
416
-
417
- /**
418
- * A React hook for executing Cube.js queries
419
- * ```js
420
- * import React from 'react';
421
- * import { Table } from 'antd';
422
- * import { useCubeQuery } from '@cubejs-client/react';
423
- *
424
- * export default function App() {
425
- * const { resultSet, isLoading, error, progress } = useCubeQuery({
426
- * measures: ['Orders.count'],
427
- * dimensions: ['Orders.createdAt.month'],
428
- * });
429
- *
430
- * if (isLoading) {
431
- * return <div>{progress?.stage || 'Loading...'}</div>;
432
- * }
433
- *
434
- * if (error) {
435
- * return <div>{error.toString()}</div>;
436
- * }
437
- *
438
- * if (!resultSet) {
439
- * return null;
440
- * }
441
- *
442
- * const dataSource = resultSet.tablePivot();
443
- * const columns = resultSet.tableColumns();
444
- *
445
- * return <Table columns={columns} dataSource={dataSource} />;
446
- * }
447
- *
448
- * ```
449
- * @order 1
450
- * @stickyTypes
451
- */
452
- export function useCubeQuery<
453
- TData,
454
- TQuery extends DeeplyReadonly<Query | Query[]> = DeeplyReadonly<Query | Query[]>>(
455
- query: TQuery,
456
- options?: UseCubeQueryOptions,
457
- ): UseCubeQueryResult<
458
- TQuery,
459
- unknown extends TData
460
- ? QueryRecordType<TQuery>
461
- : TData
462
- >;
463
-
464
- type UseCubeQueryOptions = {
465
- /**
466
- * A `CubeApi` instance to use. Taken from the context if the param is not passed
467
- */
468
- cubeApi?: CubeApi;
469
- /**
470
- * Query execution will be skipped when `skip` is set to `true`. You can use this flag to avoid sending incomplete queries.
471
- */
472
- skip?: boolean;
473
- /**
474
- * Use continuous fetch behavior. See [Real-Time Data Fetch](/product/apis-integrations/rest-api/real-time-data-fetch)
475
- */
476
- subscribe?: boolean;
477
- /**
478
- * When `true` the resultSet will be reset to `null` first
479
- */
480
- resetResultSetOnChange?: boolean;
481
- /**
482
- * If enabled, all members of the 'number' type will be automatically converted to numerical values on the client side
483
- */
484
- castNumerics?: boolean;
485
- /**
486
- * Server-side cache policy for query execution. Does not control client-side caching.
487
- */
488
- cache?: CacheMode;
489
- };
490
-
491
- type UseCubeQueryResult<TQuery, TData> = {
492
- error: Error | null;
493
- isLoading: boolean;
494
- resultSet: ResultSet<TData> | null;
495
- progress: ProgressResponse;
496
- previousQuery: TQuery;
497
- refetch: () => Promise<void>;
498
- };
499
-
500
- /**
501
- * @hidden
502
- */
503
- type CubeFetchOptions = {
504
- skip?: boolean;
505
- cubeApi?: CubeApi;
506
- query?: Query;
507
- };
508
-
509
- /**
510
- * @hidden
511
- */
512
- type CubeFetchResult<T> = {
513
- isLoading: boolean;
514
- error: Error | null;
515
- response: T;
516
- };
517
-
518
- /**
519
- * @hidden
520
- */
521
- type UseDryRunResult = CubeFetchResult<DryRunResponse>;
522
-
523
- /**
524
- * @hidden
525
- */
526
- export function useDryRun(query: Query | Query[], options?: CubeFetchOptions): UseDryRunResult;
527
-
528
- /**
529
- * @hidden
530
- */
531
- export type LoadLazyDryRunOptions = {
532
- query?: Query | Query[];
533
- };
534
-
535
- /**
536
- * @hidden
537
- */
538
- export function useLazyDryRun(
539
- query?: Query | Query[],
540
- options?: CubeFetchOptions
541
- ): [(loadOptions?: LoadLazyDryRunOptions) => Promise<void>, UseDryRunResult];
542
-
543
- /**
544
- * @hidden
545
- */
546
- type UseCubeSqlResponse = {
547
- sql: string;
548
- };
549
-
550
- export function useCubeMeta(options?: Omit<CubeFetchOptions, 'query'>): CubeFetchResult<Meta>;
551
-
552
- /**
553
- * @hidden
554
- */
555
- export function useCubeSql(query: Query | Query[], options?: CubeFetchOptions): UseDryRunResult;
556
-
557
- /**
558
- * Checks whether the query is ready
559
- */
560
- export function isQueryPresent(query: Query | Query[]): boolean;
561
-
562
- /**
563
- * You can use the following methods for member manipulaltion
564
- * ```js
565
- * <QueryBuilder
566
- * // ...
567
- * cubeApi={cubeApi}
568
- * render={({
569
- * // ...
570
- * availableMeasures,
571
- * updateMeasures,
572
- * }) => {
573
- * return (
574
- * // ...
575
- * <Select
576
- * mode="multiple"
577
- * placeholder="Please select"
578
- * onSelect={(measure) => updateMeasures.add(measure)}
579
- * onDeselect={(measure) => updateMeasures.remove(measure)}
580
- * >
581
- * {availableMeasures.map((measure) => (
582
- * <Select.Option key={measure.name} value={measure}>
583
- * {measure.title}
584
- * </Select.Option>
585
- * ))}
586
- * </Select>
587
- * );
588
- * }}
589
- * />
590
- * ```
591
- *
592
- * NOTE: if you need to add or remove more than one member at a time you should use `updateQuery` prop of {@see QueryBuilderRenderProps}
593
- * ```js
594
- * <QueryBuilder
595
- * // ...
596
- * cubeApi={cubeApi}
597
- * render={({
598
- * // ...
599
- * measures,
600
- * updateMeasures,
601
- * updateQuery,
602
- * }) => {
603
- * // ...
604
- * return (
605
- * <>
606
- * // WRONG: This code will not work properly
607
- * <button
608
- * onClick={() =>
609
- * measures.forEach((measure) => updateMeasures.remove(measure))
610
- * }
611
- * >
612
- * Remove all
613
- * </button>
614
- *
615
- * // CORRECT: Using `updateQuery` for removing all measures
616
- * <button
617
- * onClick={() =>
618
- * updateQuery({
619
- * measures: [],
620
- * })
621
- * }
622
- * >
623
- * Remove all
624
- * </button>
625
- * </>
626
- * );
627
- * }}
628
- * />
629
- * ```
630
- */
631
- type MemberUpdater<T> = {
632
- add: (member: T) => void;
633
- remove: (member: { index: number }) => void;
634
- update: (member: { index: number }, updateWith: T) => void;
635
- };
636
-
637
- type FilterExtraFields = {
638
- dimension: TCubeDimension | TCubeMeasure;
639
- operators: { name: string; title: string }[];
640
- };
641
- type FilterWithExtraFields = Omit<Filter, 'dimension'> & FilterExtraFields;
642
-
643
- type GranularityOptions = {
644
- granularities: { name: string; title: string }[];
645
- };
646
- type TimeDimensionExtraFields = {
647
- dimension: TCubeDimension & GranularityOptions;
648
- };
649
- type TimeDimensionWithExtraFields = Omit<TimeDimension, 'dimension'> & TimeDimensionExtraFields;
650
-
651
- type DimensionUpdater = MemberUpdater<TCubeDimension>;
652
- type MeasureUpdater = MemberUpdater<TCubeMeasure>;
653
- type SegmentUpdater = MemberUpdater<TCubeSegment>;
654
-
655
- // Only require the fields that are actually used (otherwise fields like `operators` are required just to add/update)
656
- type TimeDimensionRangedUpdateFields = {
657
- granularity?: TimeDimensionGranularity;
658
- dateRange?: DateRange;
659
- dimension: TCubeDimension;
660
- };
661
- type TimeDimensionComparisonUpdateFields = {
662
- granularity?: TimeDimensionGranularity;
663
- compareDateRange: Array<DateRange>;
664
- dimension: TCubeDimension;
665
- };
666
- type TimeDimensionUpdater = MemberUpdater<TimeDimensionRangedUpdateFields | TimeDimensionComparisonUpdateFields>;
667
-
668
- type FilterUpdateFields = {
669
- member?: string;
670
- operator: BinaryOperator | UnaryOperator;
671
- values?: string[];
672
- dimension: TCubeDimension | TCubeMeasure;
673
- };
674
- type FilterUpdater = MemberUpdater<FilterUpdateFields>;
675
-
676
- type OrderUpdater = {
677
- set: (memberId: string, order: QueryOrder | 'none') => void;
678
- update: (order: Query['order']) => void;
679
- reorder: (sourceIndex: number, destinationIndex: number) => void;
680
- };
681
-
682
- type PivotConfigUpdaterArgs = {
683
- sourceIndex: number;
684
- destinationIndex: number;
685
- sourceAxis: TSourceAxis;
686
- destinationAxis: TSourceAxis;
687
- };
688
-
689
- type PivotConfigExtraUpdateFields = {
690
- limit?: number;
691
- };
692
-
693
- type PivotConfigUpdater = {
694
- moveItem: (args: PivotConfigUpdaterArgs) => void;
695
- update: (pivotConfig: PivotConfig & PivotConfigExtraUpdateFields) => void;
696
- };
697
- }
@@ -1,3 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export default createContext(null);