flowerbi-react 1.22.0 → 2.0.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 +1 -1
- package/dist/FlowerBITable.d.ts +0 -1
- package/dist/FlowerBITable.js +1 -0
- package/dist/FlowerBITable.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/useFlowerBI.d.ts +50 -0
- package/dist/useFlowerBI.js +82 -0
- package/dist/useFlowerBI.js.map +1 -0
- package/dist/usePageFilters.js +14 -2
- package/dist/usePageFilters.js.map +1 -1
- package/dist/useQuery.js +7 -6
- package/dist/useQuery.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +1 -1
- package/src/{useQuery.ts → useFlowerBI.ts} +6 -1
- package/src/usePageFilters.ts +12 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Defines hooks for working with FlowerBI from React applications:
|
|
4
4
|
|
|
5
|
-
- `
|
|
5
|
+
- `useFlowerBI` - the state of a query and the data it produces
|
|
6
6
|
- `usePageFilters` - a shared set of filters that chart components can interact via
|
|
7
7
|
|
|
8
8
|
Also some components:
|
package/dist/FlowerBITable.d.ts
CHANGED
package/dist/FlowerBITable.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FlowerBITable = void 0;
|
|
6
7
|
var react_1 = __importDefault(require("react"));
|
|
7
8
|
var flowerbi_1 = require("flowerbi");
|
|
8
9
|
function renderCell(key, def) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowerBITable.js","sourceRoot":"","sources":["../src/FlowerBITable.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"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ACI,0CAEI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,UAAC,MAAM,IAAK,OAAA,UAAU,CAC3C,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,2BAAgB,CAAC,IAAI,CAAC,MAAO,CAAC,CAAC,CAAC,EAD3B,CAC2B,CAAC,CAEhE,CACD,CACX,CACG,CACX,CAAC;AACN,CAAC;AAhCD,sCAgCC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
__exportStar(require("./FlowerBITable"), exports);
|
|
14
|
+
__exportStar(require("./usePageFilters"), exports);
|
|
15
|
+
__exportStar(require("./useFlowerBI"), exports);
|
|
9
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC;AACjC,gDAA8B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Query, QueryFetch, QuerySelect, ExpandedQueryResult } from "flowerbi";
|
|
2
|
+
export declare type UseQueryState = "init" | "ready" | "refresh" | "error";
|
|
3
|
+
export interface UseQueryResult<S extends QuerySelect> extends ExpandedQueryResult<S> {
|
|
4
|
+
/**
|
|
5
|
+
* The state of the query operation:
|
|
6
|
+
*
|
|
7
|
+
* - `init` - no result has been downloaded yet
|
|
8
|
+
* - `ready` - result has been downloaded
|
|
9
|
+
* - `refresh` - a new result is being downloaded
|
|
10
|
+
* - `error` - most recent query attempt failed
|
|
11
|
+
*/
|
|
12
|
+
state: UseQueryState;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Defines another query on which our query depends - for example a
|
|
16
|
+
* first query may return the top 10 vendors, and a subsequent query
|
|
17
|
+
* may then use an `in` filter to get details about those 10 vendors.
|
|
18
|
+
*/
|
|
19
|
+
export declare type QueryDependency = {
|
|
20
|
+
/**
|
|
21
|
+
* The result of the query we depend on
|
|
22
|
+
*/
|
|
23
|
+
dependency: UseQueryResult<QuerySelect>;
|
|
24
|
+
/**
|
|
25
|
+
* If true (default is false) then if the dependency query produces
|
|
26
|
+
* an empty result, our query should also produce an empty result,
|
|
27
|
+
* so there is no need to execute it.
|
|
28
|
+
*/
|
|
29
|
+
nonEmpty?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A custom React hook that evaluates to the result of a
|
|
33
|
+
* [Query](../flowerbi/interfaces/query.html), making it easy to perform a
|
|
34
|
+
* query from within a component.
|
|
35
|
+
*
|
|
36
|
+
* The returned object has a strongly-typed `records` array, and optionally
|
|
37
|
+
* a `totals` object. It has a `state` of type {@link UseQueryState} that
|
|
38
|
+
* can be used to show a loading indicator.
|
|
39
|
+
*
|
|
40
|
+
* @param fetch The fetch function to use.
|
|
41
|
+
* @param query The [Query](../flowerbi/interfaces/query.html) specification.
|
|
42
|
+
* @param dependencies Optionally, a list of one or more other queries whose
|
|
43
|
+
* results are used to build this query, so we wait for them before executing,
|
|
44
|
+
* and optionally short-circuit to an empty result if the dependency is empty.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Query<S>, dependencies?: QueryDependency[]): UseQueryResult<S>;
|
|
47
|
+
/**
|
|
48
|
+
* Alias of useFlowerBI for backward compatibility.
|
|
49
|
+
*/
|
|
50
|
+
export declare const useQuery: typeof useFlowerBI;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.useQuery = exports.useFlowerBI = void 0;
|
|
18
|
+
var react_1 = require("react");
|
|
19
|
+
var flowerbi_1 = require("flowerbi");
|
|
20
|
+
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
21
|
+
/**
|
|
22
|
+
* A custom React hook that evaluates to the result of a
|
|
23
|
+
* [Query](../flowerbi/interfaces/query.html), making it easy to perform a
|
|
24
|
+
* query from within a component.
|
|
25
|
+
*
|
|
26
|
+
* The returned object has a strongly-typed `records` array, and optionally
|
|
27
|
+
* a `totals` object. It has a `state` of type {@link UseQueryState} that
|
|
28
|
+
* can be used to show a loading indicator.
|
|
29
|
+
*
|
|
30
|
+
* @param fetch The fetch function to use.
|
|
31
|
+
* @param query The [Query](../flowerbi/interfaces/query.html) specification.
|
|
32
|
+
* @param dependencies Optionally, a list of one or more other queries whose
|
|
33
|
+
* results are used to build this query, so we wait for them before executing,
|
|
34
|
+
* and optionally short-circuit to an empty result if the dependency is empty.
|
|
35
|
+
*/
|
|
36
|
+
function useFlowerBI(fetch, query, dependencies) {
|
|
37
|
+
var queryJson = (0, flowerbi_1.jsonifyQuery)(query);
|
|
38
|
+
var _a = (0, react_1.useState)("init"), state = _a[0], setState = _a[1];
|
|
39
|
+
var _b = (0, react_1.useState)({ records: [] }), result = _b[0], setResult = _b[1];
|
|
40
|
+
(0, react_1.useEffect)(function () {
|
|
41
|
+
var disposed = false; // discard stale results
|
|
42
|
+
if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) {
|
|
43
|
+
// if any not ready, neither are we
|
|
44
|
+
if (dependencies.some(function (x) { return x.dependency.state !== "ready"; })) {
|
|
45
|
+
if (state !== "init") {
|
|
46
|
+
setState("refresh");
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// if any with option nonEmpty produced empty result, so do we
|
|
51
|
+
if (dependencies.filter(function (x) { return !!x.nonEmpty; }).some(function (x) { return !x.dependency.records.length; })) {
|
|
52
|
+
setState("ready");
|
|
53
|
+
setResult({ records: [] });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (state !== "init") {
|
|
58
|
+
setState("refresh");
|
|
59
|
+
}
|
|
60
|
+
fetch(queryJson).then(function (x) {
|
|
61
|
+
if (!disposed) {
|
|
62
|
+
setState("ready");
|
|
63
|
+
setResult(x);
|
|
64
|
+
}
|
|
65
|
+
}, function () {
|
|
66
|
+
if (!disposed) {
|
|
67
|
+
setState("error");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return function () {
|
|
71
|
+
disposed = true;
|
|
72
|
+
};
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
74
|
+
}, [fetch, (0, json_stable_stringify_1.default)(queryJson)]);
|
|
75
|
+
return __assign(__assign({}, (0, flowerbi_1.expandQueryResult)(query.select, result)), { state: state });
|
|
76
|
+
}
|
|
77
|
+
exports.useFlowerBI = useFlowerBI;
|
|
78
|
+
/**
|
|
79
|
+
* Alias of useFlowerBI for backward compatibility.
|
|
80
|
+
*/
|
|
81
|
+
exports.useQuery = useFlowerBI;
|
|
82
|
+
//# sourceMappingURL=useFlowerBI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlowerBI.js","sourceRoot":"","sources":["../src/useFlowerBI.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAoD;AACpD,qCAAiI;AACjI,gFAAoD;AAkCpD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,WAAW,CAAwB,KAAiB,EAAE,KAAe,EAAE,YAAgC;IACnH,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,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,CAAC,KAAK,KAAK,OAAO,EAA9B,CAA8B,CAAC,EAAE;gBACxD,IAAI,KAAK,KAAK,MAAM,EAAE;oBAClB,QAAQ,CAAC,SAAS,CAAC,CAAC;iBACvB;gBACD,OAAO;aACV;YAED,8DAA8D;YAC9D,IAAI,YAAY,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAZ,CAAY,CAAC,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAA5B,CAA4B,CAAC,EAAE;gBAChF,QAAQ,CAAC,OAAO,CAAC,CAAC;gBAClB,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3B,OAAO;aACV;SACJ;QAED,IAAI,KAAK,KAAK,MAAM,EAAE;YAClB,QAAQ,CAAC,SAAS,CAAC,CAAC;SACvB;QAED,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CACjB,UAAA,CAAC;YACG,IAAI,CAAC,QAAQ,EAAE;gBACX,QAAQ,CAAC,OAAO,CAAC,CAAC;gBAClB,SAAS,CAAC,CAAC,CAAC,CAAC;aAChB;QACL,CAAC,EACD;YACI,IAAI,CAAC,QAAQ,EAAE;gBACX,QAAQ,CAAC,OAAO,CAAC,CAAC;aACrB;QACL,CAAC,CACJ,CAAC;QAEF,OAAO;YACH,QAAQ,GAAG,IAAI,CAAC;QACpB,CAAC,CAAC;QACF,uDAAuD;IAC3D,CAAC,EAAE,CAAC,KAAK,EAAE,IAAA,+BAAe,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAExC,6BAAY,IAAA,4BAAiB,EAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,KAAE,KAAK,OAAA,IAAG;AACjE,CAAC;AAnDD,kCAmDC;AAED;;GAEG;AACU,QAAA,QAAQ,GAAG,WAAW,CAAC"}
|
package/dist/usePageFilters.js
CHANGED
|
@@ -10,17 +10,29 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
13
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.usePageFilters = void 0;
|
|
14
18
|
var react_1 = require("react");
|
|
19
|
+
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
15
20
|
var clearedState = {
|
|
16
21
|
global: [],
|
|
17
22
|
interactions: [],
|
|
18
23
|
interactionKey: "",
|
|
19
24
|
};
|
|
20
25
|
function usePageFilters() {
|
|
21
|
-
var _a = react_1.useState(clearedState), state = _a[0], set = _a[1];
|
|
26
|
+
var _a = (0, react_1.useState)(clearedState), state = _a[0], set = _a[1];
|
|
22
27
|
function setInteraction(interactionKey, interactions) {
|
|
23
|
-
|
|
28
|
+
console.log(interactionKey, state.interactionKey, state.interactionKey === interactionKey, interactions, state.interactions, (0, json_stable_stringify_1.default)(state.interactions), (0, json_stable_stringify_1.default)(interactions), (0, json_stable_stringify_1.default)(state.interactions) === (0, json_stable_stringify_1.default)(interactions));
|
|
29
|
+
if (state.interactionKey === interactionKey &&
|
|
30
|
+
(0, json_stable_stringify_1.default)(state.interactions) === (0, json_stable_stringify_1.default)(interactions)) {
|
|
31
|
+
clearInteraction();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
set(__assign(__assign({}, state), { interactionKey: interactionKey, interactions: interactions }));
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
37
|
function setGlobal(global) {
|
|
26
38
|
set(__assign(__assign({}, state), { global: global }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePageFilters.js","sourceRoot":"","sources":["../src/usePageFilters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePageFilters.js","sourceRoot":"","sources":["../src/usePageFilters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAiC;AAEjC,gFAAoD;AAiBpD,IAAM,YAAY,GAA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AC3B,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO,GAAG,KAAK,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACrF,CAAC;IACD,6BAAY,KAAK,KAAE,cAAc,gBAAA,EAAE,SAAS,WAAA,EAAE,gBAAgB,kBAAA,EAAE,WAAW,aAAA,EAAE,QAAQ,UAAA,EAAE,UAAU,YAAA,IAAG;AACxG,CAAC;AAhCD,wCAgCC"}
|
package/dist/useQuery.js
CHANGED
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.useQuery = void 0;
|
|
17
18
|
var react_1 = require("react");
|
|
18
19
|
var flowerbi_1 = require("flowerbi");
|
|
19
20
|
var json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
@@ -33,10 +34,10 @@ var json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
|
33
34
|
* and optionally short-circuit to an empty result if the dependency is empty.
|
|
34
35
|
*/
|
|
35
36
|
function useQuery(fetch, query, dependencies) {
|
|
36
|
-
var queryJson = flowerbi_1.jsonifyQuery(query);
|
|
37
|
-
var _a = react_1.useState("init"), state = _a[0], setState = _a[1];
|
|
38
|
-
var _b = react_1.useState({ records: [] }), result = _b[0], setResult = _b[1];
|
|
39
|
-
react_1.useEffect(function () {
|
|
37
|
+
var queryJson = (0, flowerbi_1.jsonifyQuery)(query);
|
|
38
|
+
var _a = (0, react_1.useState)("init"), state = _a[0], setState = _a[1];
|
|
39
|
+
var _b = (0, react_1.useState)({ records: [] }), result = _b[0], setResult = _b[1];
|
|
40
|
+
(0, react_1.useEffect)(function () {
|
|
40
41
|
var disposed = false; // discard stale results
|
|
41
42
|
if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) {
|
|
42
43
|
// if any not ready, neither are we
|
|
@@ -70,8 +71,8 @@ function useQuery(fetch, query, dependencies) {
|
|
|
70
71
|
disposed = true;
|
|
71
72
|
};
|
|
72
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
-
}, [fetch, json_stable_stringify_1.default(queryJson)]);
|
|
74
|
-
return __assign(__assign({}, flowerbi_1.expandQueryResult(query.select, result)), { state: state });
|
|
74
|
+
}, [fetch, (0, json_stable_stringify_1.default)(queryJson)]);
|
|
75
|
+
return __assign(__assign({}, (0, flowerbi_1.expandQueryResult)(query.select, result)), { state: state });
|
|
75
76
|
}
|
|
76
77
|
exports.useQuery = useQuery;
|
|
77
78
|
//# sourceMappingURL=useQuery.js.map
|
package/dist/useQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../src/useQuery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAoD;AACpD,qCAAiI;AACjI,gFAAoD;AAkCpD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,QAAQ,CAAwB,KAAiB,EAAE,KAAe,EAAE,YAAgC;IAChH,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,IA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AAM,EAAE,MAAM,CAAC,KAAE,KAAK,OAAA,IAAG;AACjE,CAAC;AAnDD,4BAmDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowerbi-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Daniel Earwicker <dan@earwicker.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React helpers for FlowerBI",
|
|
@@ -9,22 +9,22 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@types/json-stable-stringify": "^1.0.32",
|
|
11
11
|
"@types/react": "^16.9.0",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"flowerbi": "2.0.0",
|
|
13
|
+
"json-stable-stringify": "^1.0.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"prettier": "^2.
|
|
17
|
-
"react": "^
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"prettier": "^2.5.1",
|
|
17
|
+
"react": "^17.0.2",
|
|
18
|
+
"typedoc": "^0.22.11",
|
|
19
|
+
"typescript": "^4.5.5"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"react": "^16.13.1"
|
|
22
|
+
"react": "^16.13.1 || ^17.0.2"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"watch": "tsc -w",
|
|
27
|
-
"docs": "typedoc --
|
|
27
|
+
"docs": "typedoc --out ../../../docs/typedoc/flowerbi-react src",
|
|
28
28
|
"prepare": "npm run build && npm run docs"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type QueryDependency = {
|
|
|
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
|
|
52
|
+
export function useFlowerBI<S extends QuerySelect>(fetch: QueryFetch, query: Query<S>, dependencies?: QueryDependency[]): UseQueryResult<S> {
|
|
53
53
|
const queryJson = jsonifyQuery(query);
|
|
54
54
|
|
|
55
55
|
const [state, setState] = useState<UseQueryState>("init");
|
|
@@ -101,3 +101,8 @@ export function useQuery<S extends QuerySelect>(fetch: QueryFetch, query: Query<
|
|
|
101
101
|
|
|
102
102
|
return { ...expandQueryResult(query.select, result), state };
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Alias of useFlowerBI for backward compatibility.
|
|
107
|
+
*/
|
|
108
|
+
export const useQuery = useFlowerBI;
|
package/src/usePageFilters.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
import { FilterJson } from "flowerbi";
|
|
3
|
+
import stableStringify from "json-stable-stringify";
|
|
3
4
|
|
|
4
5
|
export interface PageFiltersState {
|
|
5
6
|
readonly global: FilterJson[];
|
|
@@ -25,7 +26,17 @@ const clearedState: PageFiltersState = {
|
|
|
25
26
|
export function usePageFilters(): PageFilters {
|
|
26
27
|
const [state, set] = useState<PageFiltersState>(clearedState);
|
|
27
28
|
function setInteraction(interactionKey: string, interactions: FilterJson[]) {
|
|
28
|
-
|
|
29
|
+
console.log(interactionKey, state.interactionKey, state.interactionKey === interactionKey,
|
|
30
|
+
interactions, state.interactions,
|
|
31
|
+
stableStringify(state.interactions), stableStringify(interactions),
|
|
32
|
+
stableStringify(state.interactions) === stableStringify(interactions));
|
|
33
|
+
|
|
34
|
+
if (state.interactionKey === interactionKey &&
|
|
35
|
+
stableStringify(state.interactions) === stableStringify(interactions)) {
|
|
36
|
+
clearInteraction();
|
|
37
|
+
} else {
|
|
38
|
+
set({ ...state, interactionKey, interactions });
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
function setGlobal(global: FilterJson[]) {
|
|
31
42
|
set({ ...state, global });
|