flowerbi-react 3.8.3 → 3.9.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/dist/FlowerBITable.d.ts +5 -5
- package/dist/FlowerBITable.js.map +1 -1
- package/dist/useFlowerBI.d.ts +4 -4
- package/dist/useFlowerBI.js +1 -1
- package/dist/useFlowerBI.js.map +1 -1
- package/package.json +2 -2
- package/src/FlowerBITable.tsx +8 -16
- package/src/useFlowerBI.ts +18 -14
package/dist/FlowerBITable.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { QueryValues, ExpandedQueryResult, QuerySelect } from "flowerbi";
|
|
1
|
+
import { QueryValues, ExpandedQueryResult, QuerySelect, QueryCalculations } from "flowerbi";
|
|
2
2
|
export declare type ColumnDefinition = string | [string, "left" | "right"];
|
|
3
|
-
export declare type FlowerBITableProps<S extends QuerySelect
|
|
4
|
-
data: ExpandedQueryResult<S>;
|
|
3
|
+
export declare type FlowerBITableProps<S extends QuerySelect, C extends QueryCalculations<S>> = {
|
|
4
|
+
data: ExpandedQueryResult<S, C>;
|
|
5
5
|
columns: {
|
|
6
|
-
[label: string]: (record: QueryValues<S>) => ColumnDefinition;
|
|
6
|
+
[label: string]: (record: QueryValues<S, C>) => ColumnDefinition;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
export declare function FlowerBITable<S extends QuerySelect
|
|
9
|
+
export declare function FlowerBITable<S extends QuerySelect, C extends QueryCalculations<S>>({ data, columns }: FlowerBITableProps<S, C>): JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowerBITable.js","sourceRoot":"","sources":["../src/FlowerBITable.tsx"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"FlowerBITable.js","sourceRoot":"","sources":["../src/FlowerBITable.tsx"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,qCAA8H;AAI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AM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,2BAAgB,CAAO,IAAI,CAAC,MAAO,CAAC,CAAC,CAAC,EAA7E,CAA6E,CAAC,CAAM,CAC1H,CACX,CACG,CACX,CAAC;AACN,CAAC;AAxBD,sCAwBC"}
|
package/dist/useFlowerBI.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Query, QueryFetch, QuerySelect, ExpandedQueryResult } from "flowerbi";
|
|
1
|
+
import { Query, QueryFetch, QuerySelect, ExpandedQueryResult, QueryCalculations } from "flowerbi";
|
|
2
2
|
export declare type UseQueryState = "init" | "ready" | "refresh" | "error";
|
|
3
|
-
export interface UseQueryResult<S extends QuerySelect
|
|
3
|
+
export interface UseQueryResult<S extends QuerySelect, C extends QueryCalculations<S>> extends ExpandedQueryResult<S, C> {
|
|
4
4
|
/**
|
|
5
5
|
* The state of the query operation:
|
|
6
6
|
*
|
|
@@ -20,7 +20,7 @@ export declare type QueryDependency = {
|
|
|
20
20
|
/**
|
|
21
21
|
* The result of the query we depend on
|
|
22
22
|
*/
|
|
23
|
-
dependency: UseQueryResult<QuerySelect
|
|
23
|
+
dependency: UseQueryResult<QuerySelect, QueryCalculations<QuerySelect>>;
|
|
24
24
|
/**
|
|
25
25
|
* If true (default is false) then if the dependency query produces
|
|
26
26
|
* an empty result, our query should also produce an empty result,
|
|
@@ -43,7 +43,7 @@ export declare type QueryDependency = {
|
|
|
43
43
|
* results are used to build this query, so we wait for them before executing,
|
|
44
44
|
* and optionally short-circuit to an empty result if the dependency is empty.
|
|
45
45
|
*/
|
|
46
|
-
export declare function useFlowerBI<S extends QuerySelect
|
|
46
|
+
export declare function useFlowerBI<S extends QuerySelect, C extends QueryCalculations<S>>(fetch: QueryFetch, query: Query<S, C>, dependencies?: QueryDependency[]): UseQueryResult<S, C>;
|
|
47
47
|
/**
|
|
48
48
|
* Alias of useFlowerBI for backward compatibility.
|
|
49
49
|
*/
|
package/dist/useFlowerBI.js
CHANGED
|
@@ -72,7 +72,7 @@ function useFlowerBI(fetch, query, dependencies) {
|
|
|
72
72
|
};
|
|
73
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
74
|
}, [fetch, (0, json_stable_stringify_1.default)(queryJson)]);
|
|
75
|
-
return __assign(__assign({}, (0, flowerbi_1.expandQueryResult)(query.select, result)), { state: state });
|
|
75
|
+
return __assign(__assign({}, (0, flowerbi_1.expandQueryResult)(query.select, result, query.calculations)), { state: state });
|
|
76
76
|
}
|
|
77
77
|
exports.useFlowerBI = useFlowerBI;
|
|
78
78
|
/**
|
package/dist/useFlowerBI.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFlowerBI.js","sourceRoot":"","sources":["../src/useFlowerBI.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"useFlowerBI.js","sourceRoot":"","sources":["../src/useFlowerBI.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA4C;AAC5C,qCAAoJ;AACpJ,gFAAoD;AAkCpD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,WAAW,CACvB,KAAiB,EACjB,KAAkB,EAClB,YAAgC;IAEhC,IAAM,SAAS,GAAG,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC;IAEhC,IAAA,KAAoB,IAAA,gBAAQ,EAAgB,MAAM,CAAC,EAAlD,KAAK,QAAA,EAAE,QAAQ,QAAmC,CAAC;IACpD,IAAA,KAAsB,IAAA,gBAAQ,EAAkB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,EAA/D,MAAM,QAAA,EAAE,SAAS,QAA8C,CAAC;IAEvE,IAAA,iBAAS,EAAC;QACN,IAAI,QAAQ,GAAG,KAAK,CAAC,CAAC,wBAAwB;QAE9C,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,EAAE;YACtB,mCAAmC;YACnC,IAAI,YAAY,CAAC,I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AuDC;AAED;;GAEG;AACU,QAAA,QAAQ,GAAG,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowerbi-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"author": "Daniel Earwicker <dan@earwicker.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React helpers for FlowerBI",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@types/json-stable-stringify": "^1.0.32",
|
|
11
11
|
"@types/react": "^16.9.0",
|
|
12
|
-
"flowerbi": "3.
|
|
12
|
+
"flowerbi": "3.9.0",
|
|
13
13
|
"json-stable-stringify": "^1.0.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
package/src/FlowerBITable.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { QueryValues, QueryValuesRow, QueryValuesTotal, ExpandedQueryResult, QuerySelect } from "flowerbi";
|
|
2
|
+
import { QueryValues, QueryValuesRow, QueryValuesTotal, ExpandedQueryResult, QuerySelect, QueryCalculations } from "flowerbi";
|
|
3
3
|
|
|
4
4
|
export type ColumnDefinition = string | [string, "left" | "right"];
|
|
5
5
|
|
|
@@ -14,14 +14,14 @@ function renderCell(key: string, def: ColumnDefinition) {
|
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export type FlowerBITableProps<S extends QuerySelect
|
|
18
|
-
data: ExpandedQueryResult<S>;
|
|
17
|
+
export type FlowerBITableProps<S extends QuerySelect, C extends QueryCalculations<S>> = {
|
|
18
|
+
data: ExpandedQueryResult<S, C>;
|
|
19
19
|
columns: {
|
|
20
|
-
[label: string]: (record: QueryValues<S>) => ColumnDefinition;
|
|
21
|
-
}
|
|
20
|
+
[label: string]: (record: QueryValues<S, C>) => ColumnDefinition;
|
|
21
|
+
};
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export function FlowerBITable<S extends QuerySelect
|
|
24
|
+
export function FlowerBITable<S extends QuerySelect, C extends QueryCalculations<S>>({ data, columns }: FlowerBITableProps<S, C>) {
|
|
25
25
|
return (
|
|
26
26
|
<table>
|
|
27
27
|
<thead>
|
|
@@ -34,21 +34,13 @@ export function FlowerBITable<S extends QuerySelect>({data, columns}: FlowerBITa
|
|
|
34
34
|
<tbody>
|
|
35
35
|
{data.records.map((record, i) => (
|
|
36
36
|
<tr key={JSON.stringify(record.selected) ?? i}>
|
|
37
|
-
|
|
38
|
-
Object.keys(columns).map((column) => renderCell(
|
|
39
|
-
column, columns[column](new QueryValuesRow(record, data.totals))))
|
|
40
|
-
}
|
|
37
|
+
{Object.keys(columns).map((column) => renderCell(column, columns[column](new QueryValuesRow<S, C>(record, data.totals))))}
|
|
41
38
|
</tr>
|
|
42
39
|
))}
|
|
43
40
|
</tbody>
|
|
44
41
|
{data.totals && (
|
|
45
42
|
<tfoot>
|
|
46
|
-
<tr>
|
|
47
|
-
{
|
|
48
|
-
Object.keys(columns).map((column) => renderCell(
|
|
49
|
-
column, columns[column](new QueryValuesTotal(data.totals!))))
|
|
50
|
-
}
|
|
51
|
-
</tr>
|
|
43
|
+
<tr>{Object.keys(columns).map((column) => renderCell(column, columns[column](new QueryValuesTotal<S, C>(data.totals!))))}</tr>
|
|
52
44
|
</tfoot>
|
|
53
45
|
)}
|
|
54
46
|
</table>
|
package/src/useFlowerBI.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useState, useEffect
|
|
2
|
-
import { Query, QueryFetch, jsonifyQuery, QueryResultJson, QuerySelect, expandQueryResult, ExpandedQueryResult } from "flowerbi";
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { Query, QueryFetch, jsonifyQuery, QueryResultJson, QuerySelect, expandQueryResult, ExpandedQueryResult, QueryCalculations } from "flowerbi";
|
|
3
3
|
import stableStringify from "json-stable-stringify";
|
|
4
4
|
|
|
5
5
|
export type UseQueryState = "init" | "ready" | "refresh" | "error";
|
|
6
6
|
|
|
7
|
-
export interface UseQueryResult<S extends QuerySelect
|
|
7
|
+
export interface UseQueryResult<S extends QuerySelect, C extends QueryCalculations<S>> extends ExpandedQueryResult<S, C> {
|
|
8
8
|
/**
|
|
9
9
|
* The state of the query operation:
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
11
|
* - `init` - no result has been downloaded yet
|
|
12
12
|
* - `ready` - result has been downloaded
|
|
13
13
|
* - `refresh` - a new result is being downloaded
|
|
@@ -25,7 +25,7 @@ export type QueryDependency = {
|
|
|
25
25
|
/**
|
|
26
26
|
* The result of the query we depend on
|
|
27
27
|
*/
|
|
28
|
-
dependency: UseQueryResult<QuerySelect
|
|
28
|
+
dependency: UseQueryResult<QuerySelect, QueryCalculations<QuerySelect>>;
|
|
29
29
|
/**
|
|
30
30
|
* If true (default is false) then if the dependency query produces
|
|
31
31
|
* an empty result, our query should also produce an empty result,
|
|
@@ -35,21 +35,25 @@ export type QueryDependency = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* A custom React hook that evaluates to the result of a
|
|
39
|
-
* [Query](../flowerbi/interfaces/query.html), making it easy to perform a
|
|
38
|
+
* A custom React hook that evaluates to the result of a
|
|
39
|
+
* [Query](../flowerbi/interfaces/query.html), making it easy to perform a
|
|
40
40
|
* query from within a component.
|
|
41
|
-
*
|
|
41
|
+
*
|
|
42
42
|
* The returned object has a strongly-typed `records` array, and optionally
|
|
43
43
|
* a `totals` object. It has a `state` of type {@link UseQueryState} that
|
|
44
44
|
* can be used to show a loading indicator.
|
|
45
|
-
*
|
|
45
|
+
*
|
|
46
46
|
* @param fetch The fetch function to use.
|
|
47
47
|
* @param query The [Query](../flowerbi/interfaces/query.html) specification.
|
|
48
48
|
* @param dependencies Optionally, a list of one or more other queries whose
|
|
49
49
|
* results are used to build this query, so we wait for them before executing,
|
|
50
50
|
* and optionally short-circuit to an empty result if the dependency is empty.
|
|
51
51
|
*/
|
|
52
|
-
export function useFlowerBI<S extends QuerySelect
|
|
52
|
+
export function useFlowerBI<S extends QuerySelect, C extends QueryCalculations<S>>(
|
|
53
|
+
fetch: QueryFetch,
|
|
54
|
+
query: Query<S, C>,
|
|
55
|
+
dependencies?: QueryDependency[]
|
|
56
|
+
): UseQueryResult<S, C> {
|
|
53
57
|
const queryJson = jsonifyQuery(query);
|
|
54
58
|
|
|
55
59
|
const [state, setState] = useState<UseQueryState>("init");
|
|
@@ -60,7 +64,7 @@ export function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Que
|
|
|
60
64
|
|
|
61
65
|
if (dependencies?.length) {
|
|
62
66
|
// if any not ready, neither are we
|
|
63
|
-
if (dependencies.some(x => x.dependency.state !== "ready")) {
|
|
67
|
+
if (dependencies.some((x) => x.dependency.state !== "ready")) {
|
|
64
68
|
if (state !== "init") {
|
|
65
69
|
setState("refresh");
|
|
66
70
|
}
|
|
@@ -68,7 +72,7 @@ export function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Que
|
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
// if any with option nonEmpty produced empty result, so do we
|
|
71
|
-
if (dependencies.filter(x => !!x.nonEmpty).some(x => !x.dependency.records.length)) {
|
|
75
|
+
if (dependencies.filter((x) => !!x.nonEmpty).some((x) => !x.dependency.records.length)) {
|
|
72
76
|
setState("ready");
|
|
73
77
|
setResult({ records: [] });
|
|
74
78
|
return;
|
|
@@ -80,7 +84,7 @@ export function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Que
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
fetch(queryJson).then(
|
|
83
|
-
x => {
|
|
87
|
+
(x) => {
|
|
84
88
|
if (!disposed) {
|
|
85
89
|
setState("ready");
|
|
86
90
|
setResult(x);
|
|
@@ -99,7 +103,7 @@ export function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Que
|
|
|
99
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
104
|
}, [fetch, stableStringify(queryJson)]);
|
|
101
105
|
|
|
102
|
-
return { ...expandQueryResult(query.select, result), state };
|
|
106
|
+
return { ...expandQueryResult<S, C>(query.select, result, query.calculations), state };
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
/**
|