Skip to content

Commit 5c8114a

Browse files
committed
refactor(analytics): consolidate shared logic
- Centralize analytics SSE parsing across React hooks - Share metric filter types and runtime operator vocabulary - Reuse metadata and label formatters; refresh size baseline Signed-off-by: Atila Fassina <atila@fassina.eu>
1 parent cfd233a commit 5c8114a

15 files changed

Lines changed: 748 additions & 493 deletions

File tree

bundle-size-baseline.json

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
{
44
"name": "@databricks/appkit",
55
"tarball": {
6-
"packed": 781571,
7-
"unpacked": 2737743
6+
"packed": 822780,
7+
"unpacked": 2869800
88
},
99
"dist": {
1010
"total": {
11-
"raw": 2724086,
12-
"gzip": 913249
11+
"raw": 2856143,
12+
"gzip": 958494
1313
},
1414
"js": {
15-
"raw": 809876,
16-
"gzip": 282994
15+
"raw": 844411,
16+
"gzip": 295130
1717
},
1818
"types": {
19-
"raw": 291641,
20-
"gzip": 99520
19+
"raw": 311200,
20+
"gzip": 106583
2121
},
2222
"maps": {
23-
"raw": 1611774,
24-
"gzip": 526917
23+
"raw": 1689737,
24+
"gzip": 552963
2525
},
2626
"css": {
2727
"raw": 0,
@@ -31,22 +31,22 @@
3131
"raw": 10795,
3232
"gzip": 3818
3333
},
34-
"fileCount": 551
34+
"fileCount": 563
3535
},
3636
"entries": [
3737
{
3838
"id": ".",
39-
"gzip": 90672,
39+
"gzip": 91159,
4040
"composition": {
41-
"initialGzip": 88098,
41+
"initialGzip": 88585,
4242
"lazyGzip": 2574,
43-
"totalGzip": 90672,
44-
"own": 288090,
43+
"totalGzip": 91159,
44+
"own": 289429,
4545
"nodeModules": null,
4646
"chunks": [
4747
{
4848
"label": "index.js",
49-
"gzip": 84000,
49+
"gzip": 84487,
5050
"kind": "initial"
5151
},
5252
{
@@ -64,60 +64,80 @@
6464
},
6565
{
6666
"id": "./beta",
67-
"gzip": 40758,
67+
"gzip": 45645,
6868
"composition": {
69-
"initialGzip": 40527,
70-
"lazyGzip": 231,
71-
"totalGzip": 40758,
72-
"own": 121992,
69+
"initialGzip": 45216,
70+
"lazyGzip": 429,
71+
"totalGzip": 45645,
72+
"own": 131711,
7373
"nodeModules": null,
7474
"chunks": [
7575
{
7676
"label": "beta.js",
77-
"gzip": 31149,
77+
"gzip": 29230,
78+
"kind": "initial"
79+
},
80+
{
81+
"label": "stream-manager.js",
82+
"gzip": 5948,
83+
"kind": "initial"
84+
},
85+
{
86+
"label": "wide-event-emitter.js",
87+
"gzip": 3239,
7888
"kind": "initial"
7989
},
8090
{
8191
"label": "databricks.js",
82-
"gzip": 5928,
92+
"gzip": 3107,
93+
"kind": "initial"
94+
},
95+
{
96+
"label": "configuration.js",
97+
"gzip": 2104,
8398
"kind": "initial"
8499
},
85100
{
86101
"label": "service-context.js",
87-
"gzip": 3230,
102+
"gzip": 1368,
88103
"kind": "initial"
89104
},
90105
{
91106
"label": "client-options.js",
92107
"gzip": 220,
93108
"kind": "initial"
94109
},
110+
{
111+
"label": "supervisor-api.js",
112+
"gzip": 184,
113+
"kind": "lazy"
114+
},
95115
{
96116
"label": "databricks.js",
97-
"gzip": 128,
117+
"gzip": 132,
98118
"kind": "lazy"
99119
},
100120
{
101121
"label": "index.js",
102-
"gzip": 103,
122+
"gzip": 113,
103123
"kind": "lazy"
104124
}
105125
]
106126
}
107127
},
108128
{
109129
"id": "./type-generator",
110-
"gzip": 19143,
130+
"gzip": 19377,
111131
"composition": {
112-
"initialGzip": 19143,
132+
"initialGzip": 19377,
113133
"lazyGzip": 0,
114-
"totalGzip": 19143,
115-
"own": 55109,
134+
"totalGzip": 19377,
135+
"own": 55765,
116136
"nodeModules": null,
117137
"chunks": [
118138
{
119139
"label": "index.js",
120-
"gzip": 19143,
140+
"gzip": 19377,
121141
"kind": "initial"
122142
}
123143
]
@@ -128,25 +148,25 @@
128148
{
129149
"name": "@databricks/appkit-ui",
130150
"tarball": {
131-
"packed": 312421,
132-
"unpacked": 1300636
151+
"packed": 342438,
152+
"unpacked": 1390991
133153
},
134154
"dist": {
135155
"total": {
136-
"raw": 1296690,
137-
"gzip": 431573
156+
"raw": 1387045,
157+
"gzip": 465995
138158
},
139159
"js": {
140-
"raw": 367812,
141-
"gzip": 122278
160+
"raw": 390404,
161+
"gzip": 131301
142162
},
143163
"types": {
144-
"raw": 210200,
145-
"gzip": 76204
164+
"raw": 230599,
165+
"gzip": 83923
146166
},
147167
"maps": {
148-
"raw": 701818,
149-
"gzip": 229745
168+
"raw": 749182,
169+
"gzip": 247425
150170
},
151171
"css": {
152172
"raw": 16860,
@@ -156,22 +176,22 @@
156176
"raw": 0,
157177
"gzip": 0
158178
},
159-
"fileCount": 472
179+
"fileCount": 490
160180
},
161181
"entries": [
162182
{
163183
"id": "./js",
164-
"gzip": 4254,
184+
"gzip": 4914,
165185
"composition": {
166-
"initialGzip": 4410,
186+
"initialGzip": 5069,
167187
"lazyGzip": 50587,
168-
"totalGzip": 54997,
169-
"own": 11865,
188+
"totalGzip": 55656,
189+
"own": 13629,
170190
"nodeModules": 213288,
171191
"chunks": [
172192
{
173193
"label": "index.js",
174-
"gzip": 4290,
194+
"gzip": 4949,
175195
"kind": "initial"
176196
},
177197
{
@@ -207,17 +227,17 @@
207227
},
208228
{
209229
"id": "./react",
210-
"gzip": 47419,
230+
"gzip": 48938,
211231
"composition": {
212-
"initialGzip": 439507,
232+
"initialGzip": 440934,
213233
"lazyGzip": 49772,
214-
"totalGzip": 489279,
215-
"own": 171753,
216-
"nodeModules": 1403070,
234+
"totalGzip": 490706,
235+
"own": 176021,
236+
"nodeModules": 1403082,
217237
"chunks": [
218238
{
219239
"label": "index.js",
220-
"gzip": 437357,
240+
"gzip": 438784,
221241
"kind": "initial"
222242
},
223243
{

packages/appkit-ui/src/js/metric-filter/index.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
import { describe, expect, test } from "vitest";
2-
import { type MetricFilter, toMetricFilter } from "./index";
1+
import type {
2+
MetricFilter as SharedMetricFilter,
3+
MetricFilterOperatorName as SharedMetricFilterOperatorName,
4+
MetricPredicate as SharedMetricPredicate,
5+
} from "shared";
6+
import { describe, expect, expectTypeOf, test } from "vitest";
7+
import {
8+
type MetricFilter,
9+
type MetricFilterOperatorName,
10+
type MetricPredicate,
11+
toMetricFilter,
12+
} from "./index";
313

414
describe("toMetricFilter", () => {
15+
test("re-exports the shared metric-filter AST types", () => {
16+
expectTypeOf<MetricFilter>().toEqualTypeOf<SharedMetricFilter>();
17+
expectTypeOf<MetricFilterOperatorName>().toEqualTypeOf<SharedMetricFilterOperatorName>();
18+
expectTypeOf<MetricPredicate>().toEqualTypeOf<SharedMetricPredicate>();
19+
});
20+
521
test("returns undefined for an empty selection", () => {
622
expect(toMetricFilter({})).toBeUndefined();
723
});

packages/appkit-ui/src/js/metric-filter/index.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
1-
// ────────────────────────────────────────────────────────────────────────────
2-
// Metric filter vocabulary + builder.
3-
//
4-
// **Kept in sync with appkit `plugins/analytics/types.ts`** — appkit-ui cannot
5-
// depend on appkit, so this mirrors the twelve-operator filter grammar by hand.
6-
// ────────────────────────────────────────────────────────────────────────────
1+
import type { MetricFilter, MetricPredicate } from "shared";
72

8-
export type MetricFilterOperatorName =
9-
| "equals"
10-
| "notEquals"
11-
| "in"
12-
| "notIn"
13-
| "gt"
14-
| "gte"
15-
| "lt"
16-
| "lte"
17-
| "contains"
18-
| "notContains"
19-
| "set"
20-
| "notSet";
21-
22-
/** A single filter predicate — the leaf node of the recursive {@link MetricFilter} tree. */
23-
export interface MetricPredicate {
24-
member: string;
25-
operator: MetricFilterOperatorName;
26-
values?: ReadonlyArray<string | number>;
27-
}
28-
29-
/** Recursive filter expression: a leaf {@link MetricPredicate} or an `and`/`or` group. */
30-
export type MetricFilter =
31-
| MetricPredicate
32-
| { and: ReadonlyArray<MetricFilter> }
33-
| { or: ReadonlyArray<MetricFilter> };
3+
export type {
4+
MetricFilter,
5+
MetricFilterOperatorName,
6+
MetricPredicate,
7+
} from "shared";
348

359
/**
3610
* Shorthand map of `dimension -> selected value(s)` that {@link toMetricFilter}

0 commit comments

Comments
 (0)